@zfqh/uview-x 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +51 -8
  3. package/components/uv-badge/uv-badge.vue +4 -4
  4. package/components/uv-button/uv-button.vue +10 -10
  5. package/components/uv-checkbox/uv-checkbox.vue +11 -9
  6. package/components/uv-checkbox-group/uv-checkbox-group.vue +2 -2
  7. package/components/uv-code/uv-code.vue +2 -2
  8. package/components/uv-dialog/uv-dialog.vue +11 -10
  9. package/components/uv-form/uv-form.vue +244 -246
  10. package/components/uv-form-item/uv-form-item.vue +10 -9
  11. package/components/uv-icon/uv-icon.vue +13 -13
  12. package/components/uv-input/uv-input.vue +6 -5
  13. package/components/uv-line/uv-line.vue +7 -6
  14. package/components/uv-line-progress/uv-line-progress.vue +5 -5
  15. package/components/uv-loading-icon/uv-loading-icon.vue +9 -8
  16. package/components/uv-overlay/uv-overlay.vue +3 -2
  17. package/components/uv-popup/uv-popup.vue +7 -5
  18. package/components/uv-safe-bottom/uv-safe-bottom.vue +4 -3
  19. package/components/uv-status-bar/uv-status-bar.vue +4 -3
  20. package/components/uv-tabs/uv-tabs.vue +15 -12
  21. package/components/uv-transition/uv-transition.vue +2 -2
  22. package/hooks/index.ts +5 -5
  23. package/hooks/useDebounce.ts +33 -35
  24. package/hooks/useI18n.ts +4 -3
  25. package/hooks/useThrottle.ts +36 -38
  26. package/index.ts +50 -29
  27. package/locales/en.ts +56 -79
  28. package/locales/es.ts +47 -69
  29. package/locales/fr.ts +47 -69
  30. package/locales/index.ts +15 -159
  31. package/locales/ru.ts +47 -69
  32. package/locales/zh-Hans.ts +57 -79
  33. package/locales/zh-Hant.ts +47 -69
  34. package/package.json +2 -2
  35. package/types/index.d.ts +68 -66
  36. package/utils/color.ts +139 -0
  37. package/utils/compress.ts +28 -28
  38. package/utils/config.ts +45 -10
  39. package/utils/debounce.ts +4 -4
  40. package/utils/function.ts +2 -87
  41. package/utils/locale.ts +444 -304
  42. package/utils/merge.ts +74 -0
  43. package/utils/platform.ts +28 -28
  44. package/utils/route.ts +123 -129
  45. package/utils/scrollbar.ts +19 -19
  46. package/utils/throttle.ts +4 -4
  47. package/utils/colorGradient.ts +0 -139
  48. package/utils/index.ts +0 -58
@@ -1,254 +1,252 @@
1
1
  <template>
2
- <view
3
- class="uv-form"
4
- :class="[p.customClass]"
5
- :style="[$uv.addStyle(p.customStyle)]"
6
- >
7
- <slot />
8
- </view>
2
+ <view class="uv-form" :class="[p.customClass]" :style="[addStyle(p.customStyle)]">
3
+ <slot />
4
+ </view>
9
5
  </template>
10
6
 
11
7
  <script setup lang="ts">
12
- import { nextTick, provide, reactive, watch } from 'vue'
13
- import { $uv } from '../../utils'
14
- import props from './props'
15
- import { useI18n } from '../../hooks'
16
- import { buildFormValidationMessages } from '../../locales'
17
-
18
- import Schema from './valid.ts'
19
-
20
- // 去除警告信息
21
- Schema.warning = function () {}
22
-
23
- // 内置校验文案(locales/ 的 uv.form.*),用户 rules[].message 仍优先
24
- const { t } = useI18n({ useScope: 'global' })
25
-
26
- defineOptions({
27
- name: 'uv-form',
28
- // #ifdef UNI-APP-X
29
- styleIsolation: 'app-and-page',
30
- // #endif
31
- virtualHost: true,
32
- })
33
-
34
- /**
35
- * Form 表单
36
- * @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
37
- * @tutorial https://www.uvui.cn/components/form.html
38
- * @property {Object} model 当前form的需要验证字段的集合
39
- * @property {Object | Function | Array} rules 验证规则
40
- * @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
41
- * @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
42
- * @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
43
- * @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
44
- * @property {String} labelAlign lable字体的对齐方式 ( 默认 'left' )
45
- * @property {Object} labelStyle lable的样式,对象形式
46
- * @property {Object} customStyle 定义需要用到的外部样式
47
- * @example <uv-form labelPosition="left" :model="model1" :rules="rules" ref="form1"></uv-form>
48
- */
49
- const p = defineProps(props)
50
-
51
- // 原始model快照,用于resetFields方法重置表单时使用
52
- let originalModel: any = null
53
- // 校验规则(函数形式的规则由 setRules 手动赋值,避免小程序过滤函数)
54
- let formRules: any = {}
55
-
56
- // 表单上下文:provide/inject 替代 $parent/children 链
57
- // 表单上下文 key(与 uv-form-item/uv-input 内 inject 的字符串保持一致)
58
- const formContext: any = reactive({
59
- model: p.model,
60
- originalModel: null,
61
- errorType: p.errorType,
62
- borderBottom: p.borderBottom,
63
- labelPosition: p.labelPosition,
64
- labelWidth: p.labelWidth,
65
- labelAlign: p.labelAlign,
66
- labelStyle: p.labelStyle,
67
- // 已注册的 uv-form-item 句柄
68
- items: []
69
- })
70
-
71
- // 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
72
- const setRules = (rules: any) => {
73
- // 判断是否有规则
74
- if (!rules || Object.keys(rules).length === 0) return
75
- if (process.env.NODE_ENV === 'development' && Object.keys(formContext.model || {}).length === 0) {
76
- $uv.error('设置rules,model必须设置!如果已经设置,请刷新页面。')
77
- return
78
- }
79
- formRules = rules
80
- }
81
-
82
- // 注册/注销表单子项
83
- const register = (handle: any) => {
84
- formContext.items.push(handle)
85
- }
86
- const unregister = (handle: any) => {
87
- const index = formContext.items.indexOf(handle)
88
- if (index > -1) formContext.items.splice(index, 1)
89
- }
90
-
91
- // 重置model为初始值的快照
92
- const resetModel = () => {
93
- // 历遍所有uv-form-item,根据其prop属性,还原model的原始快照
94
- formContext.items.forEach((child: any) => {
95
- const prop = child.prop
96
- const value = $uv.getProperty(originalModel, prop)
97
- $uv.setProperty(formContext.model, prop, value)
98
- })
99
- }
100
-
101
- // 清空所有uv-form-item组件的内容,本质上是调用了uv-form-item组件中的resetField()方法
102
- const resetFields = () => {
103
- resetModel()
104
- }
105
-
106
- // 清空校验结果
107
- const clearValidate = (props?: any) => {
108
- const propsArr = ([] as any[]).concat(props)
109
- formContext.items.forEach((child: any) => {
110
- // 如果uv-form-item的prop在props数组中,则清除对应的校验结果信息
111
- if (propsArr[0] === undefined || propsArr.includes(child.prop)) {
112
- child.setMessage(null)
113
- }
114
- })
115
- }
116
-
117
- // 对部分表单字段进行校验
118
- const validateField = (value: any, callback?: any, event: string | null = null) => {
119
- // nextTick是必须的,否则model的变更,可能会延后于此方法的执行
120
- nextTick(() => {
121
- // 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息
122
- const errorsRes: any[] = []
123
- // 如果为字符串,转为数组
124
- const values = ([] as any[]).concat(value)
125
- // 历遍所有子form-item
126
- formContext.items.forEach((child: any) => {
127
- // 用于存放form-item的错误信息
128
- const childErrors: any[] = []
129
- if (!values.includes(child.prop)) return
130
- // 获取对应的属性,通过类似'a.b.c'的形式
131
- const propertyVal = $uv.getProperty(formContext.model, child.prop)
132
- // 属性链数组
133
- const propertyChain = String(child.prop).split('.')
134
- const propertyName = propertyChain[propertyChain.length - 1]
135
- const rule = formRules[child.prop]
136
- // 如果不存在对应的规则,直接返回,否则校验器会报错
137
- if (!rule) return
138
- // rule规则可为数组形式,也可为对象形式,此处拼接成为数组
139
- const rules = ([] as any[]).concat(rule)
140
- // 对rules数组进行校验
141
- for (let i = 0; i < rules.length; i++) {
142
- const ruleItem = rules[i]
143
- // 将uv-form-item的触发器转为数组形式
144
- const trigger = ([] as any[]).concat(ruleItem && ruleItem.trigger)
145
- // 如果是有传入触发事件,但是此form-item却没有配置此触发器的话,不执行校验操作
146
- if (event && !trigger.includes(event)) continue
147
- // 实例化校验对象,传入构造规则
148
- const validator = new Schema({
149
- [propertyName]: ruleItem
150
- })
151
- // 使用内置 i18n 校验文案(显式 ruleItem.message 仍优先)
152
- validator.messages(buildFormValidationMessages((key: string) => String(t(key))))
153
- validator.validate(
154
- {
155
- [propertyName]: propertyVal
156
- },
157
- (errors: any) => {
158
- if ($uv.test.array(errors)) {
159
- errorsRes.push(...errors)
160
- childErrors.push(...errors)
161
- }
162
- nextTick(() => {
163
- child.setMessage(childErrors[0] && childErrors[0].message ? childErrors[0].message : null)
164
- })
165
- }
166
- )
167
- }
168
- })
169
- // 执行回调函数
170
- if (typeof callback === 'function') callback(errorsRes)
171
- })
172
- }
173
-
174
- // 校验全部数据
175
- const validate = () => {
176
- return new Promise((resolve, reject) => {
177
- nextTick(() => {
178
- // 获取所有form-item的prop,交给validateField方法进行校验
179
- const formItemProps = formContext.items.map((item: any) => item.prop)
180
- validateField(formItemProps, (errors: any[]) => {
181
- if (errors.length) {
182
- // 如果错误提示方式为toast,则进行提示
183
- if (formContext.errorType === 'toast') $uv.toast(errors[0].message)
184
- reject(errors)
185
- } else {
186
- resolve(true)
187
- }
188
- })
189
- })
190
- })
191
- }
192
-
193
- formContext.register = register
194
- formContext.unregister = unregister
195
- formContext.setRules = setRules
196
- formContext.resetFields = resetFields
197
- formContext.resetModel = resetModel
198
- formContext.clearValidate = clearValidate
199
- formContext.validateField = validateField
200
- formContext.validate = validate
201
-
202
- provide('uv-form-context', formContext)
203
-
204
- // 监听规则的变化
205
- watch(
206
- () => p.rules,
207
- (rules: any) => {
208
- setRules(rules)
209
- },
210
- { immediate: true }
211
- )
212
-
213
- // 监听model的初始值作为重置表单的快照
214
- watch(
215
- () => p.model,
216
- (model: any) => {
217
- formContext.model = model
218
- if (!originalModel) {
219
- originalModel = $uv.deepClone(model)
220
- formContext.originalModel = originalModel
221
- }
222
- },
223
- { immediate: true }
224
- )
225
-
226
- // 监听属性的变化,供 uv-form-item 响应式读取
227
- watch(
228
- () => [p.errorType, p.borderBottom, p.labelPosition, p.labelWidth, p.labelAlign, p.labelStyle],
229
- () => {
230
- formContext.errorType = p.errorType
231
- formContext.borderBottom = p.borderBottom
232
- formContext.labelPosition = p.labelPosition
233
- formContext.labelWidth = p.labelWidth
234
- formContext.labelAlign = p.labelAlign
235
- formContext.labelStyle = p.labelStyle
236
- }
237
- )
238
-
239
- defineExpose({
240
- setRules,
241
- resetFields,
242
- resetModel,
243
- clearValidate,
244
- validateField,
245
- validate
246
- })
8
+ import { nextTick, provide, reactive, watch } from 'vue';
9
+ import { addStyle, error, getProperty, setProperty, toast } from '../../utils/function'
10
+ import { deepClone } from '../../utils/merge'
11
+ import { array as isArray } from '../../utils/test'
12
+ import props from './props';
13
+ import { useI18n } from '../../hooks';
14
+ import { buildFormValidationMessages } from '../../utils/locale';
15
+
16
+ import Schema from './valid.ts';
17
+
18
+ // 去除警告信息
19
+ Schema.warning = function () {};
20
+
21
+ // 内置校验文案(locales/ 的 uv.form.*),用户 rules[].message 仍优先
22
+ const { t } = useI18n({ useScope: 'global' });
23
+
24
+ defineOptions({
25
+ name: 'uv-form',
26
+ // #ifdef UNI-APP-X
27
+ styleIsolation: 'app-and-page',
28
+ // #endif
29
+ virtualHost: true,
30
+ });
31
+
32
+ /**
33
+ * Form 表单
34
+ * @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
35
+ * @tutorial https://www.uvui.cn/components/form.html
36
+ * @property {Object} model 当前form的需要验证字段的集合
37
+ * @property {Object | Function | Array} rules 验证规则
38
+ * @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
39
+ * @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
40
+ * @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
41
+ * @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
42
+ * @property {String} labelAlign lable字体的对齐方式 ( 默认 'left' )
43
+ * @property {Object} labelStyle lable的样式,对象形式
44
+ * @property {Object} customStyle 定义需要用到的外部样式
45
+ * @example <uv-form labelPosition="left" :model="model1" :rules="rules" ref="form1"></uv-form>
46
+ */
47
+ const p = defineProps(props);
48
+
49
+ // 原始model快照,用于resetFields方法重置表单时使用
50
+ let originalModel: any = null;
51
+ // 校验规则(函数形式的规则由 setRules 手动赋值,避免小程序过滤函数)
52
+ let formRules: any = {};
53
+
54
+ // 表单上下文:provide/inject 替代 $parent/children 链
55
+ // 表单上下文 key(与 uv-form-item/uv-input 内 inject 的字符串保持一致)
56
+ const formContext: any = reactive({
57
+ model: p.model,
58
+ originalModel: null,
59
+ errorType: p.errorType,
60
+ borderBottom: p.borderBottom,
61
+ labelPosition: p.labelPosition,
62
+ labelWidth: p.labelWidth,
63
+ labelAlign: p.labelAlign,
64
+ labelStyle: p.labelStyle,
65
+ // 已注册的 uv-form-item 句柄
66
+ items: [],
67
+ });
68
+
69
+ // 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
70
+ const setRules = (rules: any) => {
71
+ // 判断是否有规则
72
+ if (!rules || Object.keys(rules).length === 0) return;
73
+ if (process.env.NODE_ENV === 'development' && Object.keys(formContext.model || {}).length === 0) {
74
+ error('设置rules,model必须设置!如果已经设置,请刷新页面。');
75
+ return;
76
+ }
77
+ formRules = rules;
78
+ };
79
+
80
+ // 注册/注销表单子项
81
+ const register = (handle: any) => {
82
+ formContext.items.push(handle);
83
+ };
84
+ const unregister = (handle: any) => {
85
+ const index = formContext.items.indexOf(handle);
86
+ if (index > -1) formContext.items.splice(index, 1);
87
+ };
88
+
89
+ // 重置model为初始值的快照
90
+ const resetModel = () => {
91
+ // 历遍所有uv-form-item,根据其prop属性,还原model的原始快照
92
+ formContext.items.forEach((child: any) => {
93
+ const prop = child.prop;
94
+ const value = getProperty(originalModel, prop);
95
+ setProperty(formContext.model, prop, value);
96
+ });
97
+ };
98
+
99
+ // 清空所有uv-form-item组件的内容,本质上是调用了uv-form-item组件中的resetField()方法
100
+ const resetFields = () => {
101
+ resetModel();
102
+ };
103
+
104
+ // 清空校验结果
105
+ const clearValidate = (props?: any) => {
106
+ const propsArr = ([] as any[]).concat(props);
107
+ formContext.items.forEach((child: any) => {
108
+ // 如果uv-form-item的prop在props数组中,则清除对应的校验结果信息
109
+ if (propsArr[0] === undefined || propsArr.includes(child.prop)) {
110
+ child.setMessage(null);
111
+ }
112
+ });
113
+ };
114
+
115
+ // 对部分表单字段进行校验
116
+ const validateField = (value: any, callback?: any, event: string | null = null) => {
117
+ // nextTick是必须的,否则model的变更,可能会延后于此方法的执行
118
+ nextTick(() => {
119
+ // 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息
120
+ const errorsRes: any[] = [];
121
+ // 如果为字符串,转为数组
122
+ const values = ([] as any[]).concat(value);
123
+ // 历遍所有子form-item
124
+ formContext.items.forEach((child: any) => {
125
+ // 用于存放form-item的错误信息
126
+ const childErrors: any[] = [];
127
+ if (!values.includes(child.prop)) return;
128
+ // 获取对应的属性,通过类似'a.b.c'的形式
129
+ const propertyVal = getProperty(formContext.model, child.prop);
130
+ // 属性链数组
131
+ const propertyChain = String(child.prop).split('.');
132
+ const propertyName = propertyChain[propertyChain.length - 1];
133
+ const rule = formRules[child.prop];
134
+ // 如果不存在对应的规则,直接返回,否则校验器会报错
135
+ if (!rule) return;
136
+ // rule规则可为数组形式,也可为对象形式,此处拼接成为数组
137
+ const rules = ([] as any[]).concat(rule);
138
+ // 对rules数组进行校验
139
+ for (let i = 0; i < rules.length; i++) {
140
+ const ruleItem = rules[i];
141
+ // 将uv-form-item的触发器转为数组形式
142
+ const trigger = ([] as any[]).concat(ruleItem && ruleItem.trigger);
143
+ // 如果是有传入触发事件,但是此form-item却没有配置此触发器的话,不执行校验操作
144
+ if (event && !trigger.includes(event)) continue;
145
+ // 实例化校验对象,传入构造规则
146
+ const validator = new Schema({
147
+ [propertyName]: ruleItem,
148
+ });
149
+ // 使用内置 i18n 校验文案(显式 ruleItem.message 仍优先)
150
+ validator.messages(buildFormValidationMessages((key: string) => String(t(key))));
151
+ validator.validate(
152
+ {
153
+ [propertyName]: propertyVal,
154
+ },
155
+ (errors: any) => {
156
+ if (isArray(errors)) {
157
+ errorsRes.push(...errors);
158
+ childErrors.push(...errors);
159
+ }
160
+ nextTick(() => {
161
+ child.setMessage(childErrors[0] && childErrors[0].message ? childErrors[0].message : null);
162
+ });
163
+ },
164
+ );
165
+ }
166
+ });
167
+ // 执行回调函数
168
+ if (typeof callback === 'function') callback(errorsRes);
169
+ });
170
+ };
171
+
172
+ // 校验全部数据
173
+ const validate = () => {
174
+ return new Promise((resolve, reject) => {
175
+ nextTick(() => {
176
+ // 获取所有form-item的prop,交给validateField方法进行校验
177
+ const formItemProps = formContext.items.map((item: any) => item.prop);
178
+ validateField(formItemProps, (errors: any[]) => {
179
+ if (errors.length) {
180
+ // 如果错误提示方式为toast,则进行提示
181
+ if (formContext.errorType === 'toast') toast(errors[0].message);
182
+ reject(errors);
183
+ } else {
184
+ resolve(true);
185
+ }
186
+ });
187
+ });
188
+ });
189
+ };
190
+
191
+ formContext.register = register;
192
+ formContext.unregister = unregister;
193
+ formContext.setRules = setRules;
194
+ formContext.resetFields = resetFields;
195
+ formContext.resetModel = resetModel;
196
+ formContext.clearValidate = clearValidate;
197
+ formContext.validateField = validateField;
198
+ formContext.validate = validate;
199
+
200
+ provide('uv-form-context', formContext);
201
+
202
+ // 监听规则的变化
203
+ watch(
204
+ () => p.rules,
205
+ (rules: any) => {
206
+ setRules(rules);
207
+ },
208
+ { immediate: true },
209
+ );
210
+
211
+ // 监听model的初始值作为重置表单的快照
212
+ watch(
213
+ () => p.model,
214
+ (model: any) => {
215
+ formContext.model = model;
216
+ if (!originalModel) {
217
+ originalModel = deepClone(model);
218
+ formContext.originalModel = originalModel;
219
+ }
220
+ },
221
+ { immediate: true },
222
+ );
223
+
224
+ // 监听属性的变化,供 uv-form-item 响应式读取
225
+ watch(
226
+ () => [p.errorType, p.borderBottom, p.labelPosition, p.labelWidth, p.labelAlign, p.labelStyle],
227
+ () => {
228
+ formContext.errorType = p.errorType;
229
+ formContext.borderBottom = p.borderBottom;
230
+ formContext.labelPosition = p.labelPosition;
231
+ formContext.labelWidth = p.labelWidth;
232
+ formContext.labelAlign = p.labelAlign;
233
+ formContext.labelStyle = p.labelStyle;
234
+ },
235
+ );
236
+
237
+ defineExpose({
238
+ setRules,
239
+ resetFields,
240
+ resetModel,
241
+ clearValidate,
242
+ validateField,
243
+ validate,
244
+ });
247
245
  </script>
248
246
 
249
247
  <style lang="scss">
250
- .uv-form {
251
- display: flex;
252
- flex-direction: column;
253
- }
248
+ .uv-form {
249
+ display: flex;
250
+ flex-direction: column;
251
+ }
254
252
  </style>
@@ -69,7 +69,8 @@
69
69
 
70
70
  <script setup lang="ts">
71
71
  import { computed, inject, onUnmounted, provide, reactive, ref, watch } from 'vue'
72
- import { $uv } from '../../utils'
72
+ import { addStyle, addUnit, error, getProperty, setProperty } from '../../utils/function'
73
+ import { deepMerge } from '../../utils/merge'
73
74
  import props from './props'
74
75
  import UvIcon from '../uv-icon/uv-icon.vue'
75
76
  import UvTransition from '../uv-transition/uv-transition.vue'
@@ -120,7 +121,7 @@
120
121
  if (formContext) {
121
122
  formContext.register(handle)
122
123
  } else {
123
- $uv.error('uv-form-item需要结合uv-form组件使用')
124
+ error('uv-form-item需要结合uv-form组件使用')
124
125
  }
125
126
 
126
127
  watch(
@@ -168,16 +169,16 @@
168
169
 
169
170
  const bodyStyle = computed(() => {
170
171
  // 与旧版保持一致:自定义样式在前,flexDirection 在后覆盖
171
- const customStyle = $uv.addStyle(p.customStyle) || {}
172
+ const customStyle = addStyle(p.customStyle) || {}
172
173
  const style: any = {
173
174
  flexDirection: parentData.value.labelPosition === 'left' ? 'row' : 'column'
174
175
  }
175
- return $uv.deepMerge(customStyle, style)
176
+ return deepMerge(customStyle, style)
176
177
  })
177
178
 
178
179
  const leftStyle = computed(() => {
179
180
  const style: any = {
180
- width: $uv.addUnit(parentData.value.labelWidth),
181
+ width: addUnit(parentData.value.labelWidth),
181
182
  marginBottom: parentData.value.labelPosition === 'left' ? 0 : '5px'
182
183
  }
183
184
  return style
@@ -192,12 +193,12 @@
192
193
  ? 'center'
193
194
  : 'flex-end'
194
195
  }
195
- return $uv.deepMerge($uv.addStyle(parentData.value.labelStyle), style)
196
+ return deepMerge(addStyle(parentData.value.labelStyle), style)
196
197
  })
197
198
 
198
199
  const messageStyle = computed(() => {
199
200
  const style: any = {
200
- marginLeft: $uv.addUnit(parentData.value.labelPosition === 'top' ? 0 : parentData.value.labelWidth)
201
+ marginLeft: addUnit(parentData.value.labelPosition === 'top' ? 0 : parentData.value.labelWidth)
201
202
  }
202
203
  return style
203
204
  })
@@ -211,9 +212,9 @@
211
212
  const resetField = () => {
212
213
  if (!formContext) return
213
214
  // 找到原始值
214
- const value = $uv.getProperty(formContext.originalModel, p.prop)
215
+ const value = getProperty(formContext.originalModel, p.prop)
215
216
  // 将uv-form的model的prop属性链还原原始值
216
- $uv.setProperty(formContext.model, p.prop, value)
217
+ setProperty(formContext.model, p.prop, value)
217
218
  // 移除校验结果
218
219
  message.value = null
219
220
  }
@@ -5,13 +5,13 @@
5
5
  class="uv-icon__img"
6
6
  :src="p.name"
7
7
  :mode="p.imgMode"
8
- :style="[imgStyle, $uv.addStyle(p.customStyle)]"
8
+ :style="[imgStyle, addStyle(p.customStyle)]"
9
9
  ></image>
10
10
  <text
11
11
  v-else
12
12
  class="uv-icon__icon"
13
13
  :class="uClasses"
14
- :style="[iconStyle, $uv.addStyle(p.customStyle)]"
14
+ :style="[iconStyle, addStyle(p.customStyle)]"
15
15
  :hover-class="p.hoverClass"
16
16
  >{{ icon }}</text
17
17
  >
@@ -20,11 +20,11 @@
20
20
  class="uv-icon__label"
21
21
  :style="{
22
22
  color: p.labelColor,
23
- fontSize: $uv.addUnit(p.labelSize),
24
- marginLeft: p.labelPos === 'right' ? $uv.addUnit(p.space) : 0,
25
- marginTop: p.labelPos === 'bottom' ? $uv.addUnit(p.space) : 0,
26
- marginRight: p.labelPos === 'left' ? $uv.addUnit(p.space) : 0,
27
- marginBottom: p.labelPos === 'top' ? $uv.addUnit(p.space) : 0,
23
+ fontSize: addUnit(p.labelSize),
24
+ marginLeft: p.labelPos === 'right' ? addUnit(p.space) : 0,
25
+ marginTop: p.labelPos === 'bottom' ? addUnit(p.space) : 0,
26
+ marginRight: p.labelPos === 'left' ? addUnit(p.space) : 0,
27
+ marginBottom: p.labelPos === 'top' ? addUnit(p.space) : 0,
28
28
  }"
29
29
  >{{ p.label }}</text
30
30
  >
@@ -33,7 +33,7 @@
33
33
 
34
34
  <script setup lang="ts">
35
35
  import { computed } from 'vue';
36
- import { $uv } from '../../utils';
36
+ import { addStyle, addUnit } from '../../utils/function'
37
37
  import props from './props';
38
38
  import { preventEvent } from '../../utils/compat';
39
39
 
@@ -111,10 +111,10 @@ const uClasses = computed(() => {
111
111
 
112
112
  const iconStyle = computed(() => {
113
113
  const style: any = {
114
- fontSize: $uv.addUnit(p.size),
115
- lineHeight: $uv.addUnit(p.size),
114
+ fontSize: addUnit(p.size),
115
+ lineHeight: addUnit(p.size),
116
116
  fontWeight: p.bold ? 'bold' : 'normal',
117
- top: $uv.addUnit(p.top),
117
+ top: addUnit(p.top),
118
118
  };
119
119
  if (p.color && !colorType.includes(p.color)) {
120
120
  style.color = p.color;
@@ -129,8 +129,8 @@ const iconStyle = computed(() => {
129
129
 
130
130
  const imgStyle = computed(() => {
131
131
  const style: any = {};
132
- style.width = p.width ? $uv.addUnit(p.width) : $uv.addUnit(p.size);
133
- style.height = p.height ? $uv.addUnit(p.height) : $uv.addUnit(p.size);
132
+ style.width = p.width ? addUnit(p.width) : addUnit(p.size);
133
+ style.height = p.height ? addUnit(p.height) : addUnit(p.size);
134
134
  return style;
135
135
  });
136
136