@kengic/uni 0.5.1 → 0.5.2-beta.1

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 (146) hide show
  1. package/dist/uni/uni-ui/uni-badge/uni-badge.vue +222 -219
  2. package/dist/uni/uni-ui/uni-breadcrumb/uni-breadcrumb.vue +29 -29
  3. package/dist/uni/uni-ui/uni-breadcrumb-item/uni-breadcrumb-item.vue +88 -88
  4. package/dist/uni/uni-ui/uni-calendar/calendar.js +936 -532
  5. package/dist/uni/uni-ui/uni-calendar/i18n/en.json +10 -10
  6. package/dist/uni/uni-ui/uni-calendar/i18n/index.js +8 -7
  7. package/dist/uni/uni-ui/uni-calendar/i18n/zh-Hans.json +10 -10
  8. package/dist/uni/uni-ui/uni-calendar/i18n/zh-Hant.json +10 -10
  9. package/dist/uni/uni-ui/uni-calendar/uni-calendar-item.vue +190 -168
  10. package/dist/uni/uni-ui/uni-calendar/uni-calendar.vue +459 -459
  11. package/dist/uni/uni-ui/uni-calendar/util.js +324 -340
  12. package/dist/uni/uni-ui/uni-card/uni-card.vue +8 -1
  13. package/dist/uni/uni-ui/uni-col/uni-col.vue +294 -287
  14. package/dist/uni/uni-ui/uni-collapse/uni-collapse.vue +139 -140
  15. package/dist/uni/uni-ui/uni-collapse-item/uni-collapse-item.vue +381 -378
  16. package/dist/uni/uni-ui/uni-combox/uni-combox.vue +280 -272
  17. package/dist/uni/uni-ui/uni-countdown/i18n/en.json +4 -4
  18. package/dist/uni/uni-ui/uni-countdown/i18n/index.js +8 -7
  19. package/dist/uni/uni-ui/uni-countdown/i18n/zh-Hans.json +4 -4
  20. package/dist/uni/uni-ui/uni-countdown/i18n/zh-Hant.json +4 -4
  21. package/dist/uni/uni-ui/uni-countdown/uni-countdown.vue +249 -257
  22. package/dist/uni/uni-ui/uni-data-checkbox/uni-data-checkbox.vue +832 -813
  23. package/dist/uni/uni-ui/uni-data-picker/keypress.js +42 -42
  24. package/dist/uni/uni-ui/uni-data-picker/uni-data-picker.vue +535 -516
  25. package/dist/uni/uni-ui/uni-data-pickerview/uni-data-picker.js +623 -618
  26. package/dist/uni/uni-ui/uni-data-pickerview/uni-data-pickerview.vue +293 -288
  27. package/dist/uni/uni-ui/uni-data-select/uni-data-select.vue +495 -509
  28. package/dist/uni/uni-ui/uni-dateformat/date-format.js +181 -184
  29. package/dist/uni/uni-ui/uni-dateformat/uni-dateformat.vue +81 -82
  30. package/dist/uni/uni-ui/uni-datetime-picker/calendar-item.vue +176 -170
  31. package/dist/uni/uni-ui/uni-datetime-picker/calendar.vue +926 -920
  32. package/dist/uni/uni-ui/uni-datetime-picker/i18n/en.json +20 -20
  33. package/dist/uni/uni-ui/uni-datetime-picker/i18n/index.js +8 -7
  34. package/dist/uni/uni-ui/uni-datetime-picker/i18n/zh-Hans.json +21 -21
  35. package/dist/uni/uni-ui/uni-datetime-picker/i18n/zh-Hant.json +21 -21
  36. package/dist/uni/uni-ui/uni-datetime-picker/time-picker.vue +921 -926
  37. package/dist/uni/uni-ui/uni-datetime-picker/uni-datetime-picker.vue +1059 -1012
  38. package/dist/uni/uni-ui/uni-datetime-picker/util.js +366 -377
  39. package/dist/uni/uni-ui/uni-drawer/keypress.js +42 -42
  40. package/dist/uni/uni-ui/uni-drawer/uni-drawer.vue +176 -167
  41. package/dist/uni/uni-ui/uni-easyinput/common.js +40 -42
  42. package/dist/uni/uni-ui/uni-easyinput/uni-easyinput.vue +628 -547
  43. package/dist/uni/uni-ui/uni-fab/uni-fab.vue +507 -483
  44. package/dist/uni/uni-ui/uni-fav/i18n/en.json +2 -2
  45. package/dist/uni/uni-ui/uni-fav/i18n/index.js +8 -7
  46. package/dist/uni/uni-ui/uni-fav/i18n/zh-Hans.json +2 -2
  47. package/dist/uni/uni-ui/uni-fav/i18n/zh-Hant.json +2 -2
  48. package/dist/uni/uni-ui/uni-fav/uni-fav.vue +155 -147
  49. package/dist/uni/uni-ui/uni-file-picker/choose-and-upload-file.js +172 -198
  50. package/dist/uni/uni-ui/uni-file-picker/uni-file-picker.vue +636 -634
  51. package/dist/uni/uni-ui/uni-file-picker/upload-file.vue +294 -293
  52. package/dist/uni/uni-ui/uni-file-picker/upload-image.vue +267 -270
  53. package/dist/uni/uni-ui/uni-file-picker/utils.js +81 -82
  54. package/dist/uni/uni-ui/uni-forms/uni-forms.vue +360 -372
  55. package/dist/uni/uni-ui/uni-forms/utils.js +170 -174
  56. package/dist/uni/uni-ui/uni-forms/validate.js +447 -456
  57. package/dist/uni/uni-ui/uni-forms-item/uni-forms-item.vue +497 -497
  58. package/dist/uni/uni-ui/uni-goods-nav/i18n/en.json +4 -4
  59. package/dist/uni/uni-ui/uni-goods-nav/i18n/index.js +8 -7
  60. package/dist/uni/uni-ui/uni-goods-nav/i18n/zh-Hans.json +4 -4
  61. package/dist/uni/uni-ui/uni-goods-nav/i18n/zh-Hant.json +4 -4
  62. package/dist/uni/uni-ui/uni-goods-nav/uni-goods-nav.vue +238 -222
  63. package/dist/uni/uni-ui/uni-grid/uni-grid.vue +134 -134
  64. package/dist/uni/uni-ui/uni-grid-item/uni-grid-item.vue +121 -119
  65. package/dist/uni/uni-ui/uni-group/uni-group.vue +121 -121
  66. package/dist/uni/uni-ui/uni-icons/icons.js +1170 -1168
  67. package/dist/uni/uni-ui/uni-icons/uni-icons.vue +91 -86
  68. package/dist/uni/uni-ui/uni-icons/uniicons.css +166 -166
  69. package/dist/uni/uni-ui/uni-indexed-list/uni-indexed-list-item.vue +129 -129
  70. package/dist/uni/uni-ui/uni-indexed-list/uni-indexed-list.vue +352 -347
  71. package/dist/uni/uni-ui/uni-link/uni-link.vue +134 -119
  72. package/dist/uni/uni-ui/uni-list/uni-list.vue +119 -110
  73. package/dist/uni/uni-ui/uni-list/uni-refresh.vue +14 -14
  74. package/dist/uni/uni-ui/uni-list/uni-refresh.wxs +14 -14
  75. package/dist/uni/uni-ui/uni-list-ad/uni-list-ad.vue +101 -95
  76. package/dist/uni/uni-ui/uni-list-chat/uni-list-chat.scss +18 -18
  77. package/dist/uni/uni-ui/uni-list-chat/uni-list-chat.vue +602 -586
  78. package/dist/uni/uni-ui/uni-list-item/uni-list-item.vue +507 -503
  79. package/dist/uni/uni-ui/uni-load-more/i18n/en.json +3 -3
  80. package/dist/uni/uni-ui/uni-load-more/i18n/index.js +8 -7
  81. package/dist/uni/uni-ui/uni-load-more/i18n/zh-Hans.json +3 -3
  82. package/dist/uni/uni-ui/uni-load-more/i18n/zh-Hant.json +3 -3
  83. package/dist/uni/uni-ui/uni-load-more/uni-load-more.vue +402 -392
  84. package/dist/uni/uni-ui/uni-nav-bar/uni-nav-bar.vue +328 -330
  85. package/dist/uni/uni-ui/uni-nav-bar/uni-status-bar.vue +17 -17
  86. package/dist/uni/uni-ui/uni-notice-bar/uni-notice-bar.vue +422 -401
  87. package/dist/uni/uni-ui/uni-number-box/uni-number-box.vue +211 -205
  88. package/dist/uni/uni-ui/uni-pagination/i18n/en.json +3 -3
  89. package/dist/uni/uni-ui/uni-pagination/i18n/es.json +3 -3
  90. package/dist/uni/uni-ui/uni-pagination/i18n/fr.json +3 -3
  91. package/dist/uni/uni-ui/uni-pagination/i18n/index.js +12 -11
  92. package/dist/uni/uni-ui/uni-pagination/i18n/zh-Hans.json +3 -3
  93. package/dist/uni/uni-ui/uni-pagination/i18n/zh-Hant.json +3 -3
  94. package/dist/uni/uni-ui/uni-pagination/uni-pagination.vue +450 -433
  95. package/dist/uni/uni-ui/uni-popup/uni-popup.vue +404 -404
  96. package/dist/uni/uni-ui/uni-popup-dialog/keypress.js +42 -42
  97. package/dist/uni/uni-ui/uni-popup-dialog/uni-popup-dialog.vue +1 -0
  98. package/dist/uni/uni-ui/uni-popup-message/uni-popup-message.vue +126 -125
  99. package/dist/uni/uni-ui/uni-popup-share/uni-popup-share.vue +172 -172
  100. package/dist/uni/uni-ui/uni-rate/uni-rate.vue +343 -347
  101. package/dist/uni/uni-ui/uni-row/uni-row.vue +180 -182
  102. package/dist/uni/uni-ui/uni-scss/changelog.md +11 -4
  103. package/dist/uni/uni-ui/uni-scss/package.json +73 -73
  104. package/dist/uni/uni-ui/uni-scss/readme.md +2 -1
  105. package/dist/uni/uni-ui/uni-scss/styles/setting/_border.scss +2 -2
  106. package/dist/uni/uni-ui/uni-scss/styles/setting/_color.scss +46 -47
  107. package/dist/uni/uni-ui/uni-scss/styles/setting/_radius.scss +49 -49
  108. package/dist/uni/uni-ui/uni-scss/styles/setting/_space.scss +52 -53
  109. package/dist/uni/uni-ui/uni-scss/styles/setting/_styles.scss +142 -147
  110. package/dist/uni/uni-ui/uni-scss/styles/setting/_text.scss +20 -20
  111. package/dist/uni/uni-ui/uni-scss/styles/setting/_variables.scss +111 -95
  112. package/dist/uni/uni-ui/uni-scss/styles/tools/functions.scss +28 -18
  113. package/dist/uni/uni-ui/uni-scss/theme.scss +10 -7
  114. package/dist/uni/uni-ui/uni-scss/variables.scss +42 -24
  115. package/dist/uni/uni-ui/uni-search-bar/i18n/en.json +3 -3
  116. package/dist/uni/uni-ui/uni-search-bar/i18n/index.js +8 -7
  117. package/dist/uni/uni-ui/uni-search-bar/i18n/zh-Hans.json +2 -2
  118. package/dist/uni/uni-ui/uni-search-bar/i18n/zh-Hant.json +2 -2
  119. package/dist/uni/uni-ui/uni-search-bar/uni-search-bar.vue +290 -281
  120. package/dist/uni/uni-ui/uni-section/uni-section.vue +149 -146
  121. package/dist/uni/uni-ui/uni-segmented-control/uni-segmented-control.vue +141 -131
  122. package/dist/uni/uni-ui/uni-steps/uni-steps.vue +255 -236
  123. package/dist/uni/uni-ui/uni-swipe-action/uni-swipe-action.vue +51 -51
  124. package/dist/uni/uni-ui/uni-swipe-action-item/bindingx.js +276 -282
  125. package/dist/uni/uni-ui/uni-swipe-action-item/isPC.js +10 -10
  126. package/dist/uni/uni-ui/uni-swipe-action-item/mpalipay.js +182 -187
  127. package/dist/uni/uni-ui/uni-swipe-action-item/mpother.js +235 -244
  128. package/dist/uni/uni-ui/uni-swipe-action-item/mpwxs.js +70 -75
  129. package/dist/uni/uni-ui/uni-swipe-action-item/render.js +238 -247
  130. package/dist/uni/uni-ui/uni-swipe-action-item/uni-swipe-action-item.vue +387 -313
  131. package/dist/uni/uni-ui/uni-swipe-action-item/wx.wxs +206 -215
  132. package/dist/uni/uni-ui/uni-swiper-dot/uni-swiper-dot.vue +241 -197
  133. package/dist/uni/uni-ui/uni-table/uni-table.vue +445 -447
  134. package/dist/uni/uni-ui/uni-tag/uni-tag.vue +234 -244
  135. package/dist/uni/uni-ui/uni-tbody/uni-tbody.vue +20 -23
  136. package/dist/uni/uni-ui/uni-td/uni-td.vue +79 -80
  137. package/dist/uni/uni-ui/uni-th/filter-dropdown.vue +510 -503
  138. package/dist/uni/uni-ui/uni-th/uni-th.vue +289 -273
  139. package/dist/uni/uni-ui/uni-thead/uni-thead.vue +115 -114
  140. package/dist/uni/uni-ui/uni-title/uni-title.vue +151 -154
  141. package/dist/uni/uni-ui/uni-tooltip/uni-tooltip.vue +55 -60
  142. package/dist/uni/uni-ui/uni-tr/table-checkbox.vue +162 -163
  143. package/dist/uni/uni-ui/uni-tr/uni-tr.vue +158 -157
  144. package/dist/uni/uni-ui/uni-transition/createAnimation.js +130 -113
  145. package/dist/uni/uni-ui/uni-transition/uni-transition.vue +274 -272
  146. package/package.json +1 -1
@@ -35,567 +35,567 @@
35
35
  </template>
36
36
 
37
37
  <script>
38
- /**
39
- * uni-fomrs-item 表单子组件
40
- * @description uni-fomrs-item 表单子组件,提供了基础布局已经校验能力
41
- * @tutorial https://ext.dcloud.net.cn/plugin?id=2773
42
- * @property {Boolean} required 是否必填,左边显示红色"*"号
43
- * @property {String } label 输入框左边的文字提示
44
- * @property {Number } labelWidth label的宽度,单位px(默认65)
45
- * @property {String } labelAlign = [left|center|right] label的文字对齐方式(默认left)
46
- * @value left label 左侧显示
47
- * @value center label 居中
48
- * @value right label 右侧对齐
49
- * @property {String } errorMessage 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
50
- * @property {String } name 表单域的属性名,在使用校验规则时必填
51
- * @property {String } leftIcon 【1.4.0废弃】label左边的图标,限 uni-ui 的图标名称
52
- * @property {String } iconColor 【1.4.0废弃】左边通过icon配置的图标的颜色(默认#606266)
53
- * @property {String} validateTrigger = [bind|submit|blur] 【1.4.0废弃】校验触发器方式 默认 submit
54
- * @value bind 发生变化时触发
55
- * @value submit 提交时触发
56
- * @value blur 失去焦点触发
57
- * @property {String } labelPosition = [top|left] 【1.4.0废弃】label的文字的位置(默认left)
58
- * @value top 顶部显示 label
59
- * @value left 左侧显示 label
60
- */
61
- import { defineComponent } from 'vue';
62
-
63
- export default defineComponent({
64
- name: 'UniFormsItem',
65
- options: {
66
- virtualHost: true,
67
- },
68
- provide() {
69
- return {
70
- uniFormItem: this,
71
- };
72
- },
73
- inject: {
74
- form: {
75
- from: 'uniForm',
76
- default: null,
38
+ /**
39
+ * uni-fomrs-item 表单子组件
40
+ * @description uni-fomrs-item 表单子组件,提供了基础布局已经校验能力
41
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=2773
42
+ * @property {Boolean} required 是否必填,左边显示红色"*"号
43
+ * @property {String } label 输入框左边的文字提示
44
+ * @property {Number } labelWidth label的宽度,单位px(默认65)
45
+ * @property {String } labelAlign = [left|center|right] label的文字对齐方式(默认left)
46
+ * @value left label 左侧显示
47
+ * @value center label 居中
48
+ * @value right label 右侧对齐
49
+ * @property {String } errorMessage 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
50
+ * @property {String } name 表单域的属性名,在使用校验规则时必填
51
+ * @property {String } leftIcon 【1.4.0废弃】label左边的图标,限 uni-ui 的图标名称
52
+ * @property {String } iconColor 【1.4.0废弃】左边通过icon配置的图标的颜色(默认#606266)
53
+ * @property {String} validateTrigger = [bind|submit|blur] 【1.4.0废弃】校验触发器方式 默认 submit
54
+ * @value bind 发生变化时触发
55
+ * @value submit 提交时触发
56
+ * @value blur 失去焦点触发
57
+ * @property {String } labelPosition = [top|left] 【1.4.0废弃】label的文字的位置(默认left)
58
+ * @value top 顶部显示 label
59
+ * @value left 左侧显示 label
60
+ */
61
+ import { defineComponent } from 'vue';
62
+
63
+ export default defineComponent({
64
+ name: 'UniFormsItem',
65
+ options: {
66
+ virtualHost: true,
77
67
  },
78
- },
79
- props: {
80
- // 表单校验规则
81
- rules: {
82
- type: Array,
83
- default() {
84
- return null;
85
- },
86
- },
87
- // 表单域的属性名,在使用校验规则时必填
88
- name: {
89
- type: [String, Array],
90
- default: '',
91
- },
92
- required: {
93
- type: Boolean,
94
- default: false,
95
- },
96
- label: {
97
- type: String,
98
- default: '',
99
- },
100
- // label的宽度 ,默认 80
101
- labelWidth: {
102
- type: [String, Number],
103
- default: '',
104
- },
105
- // label 居中方式,默认 left 取值 left/center/right
106
- labelAlign: {
107
- type: String,
108
- default: '',
68
+ provide() {
69
+ return {
70
+ uniFormItem: this,
71
+ };
109
72
  },
110
- // 强制显示错误信息
111
- errorMessage: {
112
- type: [String, Boolean],
113
- default: '',
114
- },
115
- // 1.4.0 弃用,统一使用 form 的校验时机
116
- // validateTrigger: {
117
- // type: String,
118
- // default: ''
119
- // },
120
- // 1.4.0 弃用,统一使用 form 的label 位置
121
- // labelPosition: {
122
- // type: String,
123
- // default: ''
124
- // },
125
- // 1.4.0 以下属性已经废弃,请使用 #label 插槽代替
126
- leftIcon: String,
127
- iconColor: {
128
- type: String,
129
- default: '#606266',
130
- },
131
- },
132
- data() {
133
- return {
134
- errMsg: '',
135
- userRules: null,
136
- localLabelAlign: 'left',
137
- localLabelWidth: '65px',
138
- localLabelPos: 'left',
139
- border: false,
140
- isFirstBorder: false,
141
- };
142
- },
143
- computed: {
144
- // 处理错误信息
145
- msg() {
146
- return this.errorMessage || this.errMsg;
73
+ inject: {
74
+ form: {
75
+ from: 'uniForm',
76
+ default: null,
77
+ },
147
78
  },
148
- },
149
- watch: {
150
- // 规则发生变化通知子组件更新
151
- 'form.formRules'(val) {
152
- // TODO 处理头条vue3 watch不生效的问题
153
- // #ifndef MP-TOUTIAO
154
- this.init();
155
- // #endif
79
+ props: {
80
+ // 表单校验规则
81
+ rules: {
82
+ type: Array,
83
+ default() {
84
+ return null;
85
+ },
86
+ },
87
+ // 表单域的属性名,在使用校验规则时必填
88
+ name: {
89
+ type: [String, Array],
90
+ default: '',
91
+ },
92
+ required: {
93
+ type: Boolean,
94
+ default: false,
95
+ },
96
+ label: {
97
+ type: String,
98
+ default: '',
99
+ },
100
+ // label的宽度 ,默认 80
101
+ labelWidth: {
102
+ type: [String, Number],
103
+ default: '',
104
+ },
105
+ // label 居中方式,默认 left 取值 left/center/right
106
+ labelAlign: {
107
+ type: String,
108
+ default: '',
109
+ },
110
+ // 强制显示错误信息
111
+ errorMessage: {
112
+ type: [String, Boolean],
113
+ default: '',
114
+ },
115
+ // 1.4.0 弃用,统一使用 form 的校验时机
116
+ // validateTrigger: {
117
+ // type: String,
118
+ // default: ''
119
+ // },
120
+ // 1.4.0 弃用,统一使用 form 的label 位置
121
+ // labelPosition: {
122
+ // type: String,
123
+ // default: ''
124
+ // },
125
+ // 1.4.0 以下属性已经废弃,请使用 #label 插槽代替
126
+ leftIcon: String,
127
+ iconColor: {
128
+ type: String,
129
+ default: '#606266',
130
+ },
156
131
  },
157
- 'form.labelWidth'(val) {
158
- // 宽度
159
- this.localLabelWidth = this._labelWidthUnit(val);
132
+ data() {
133
+ return {
134
+ errMsg: '',
135
+ userRules: null,
136
+ localLabelAlign: 'left',
137
+ localLabelWidth: '65px',
138
+ localLabelPos: 'left',
139
+ border: false,
140
+ isFirstBorder: false,
141
+ };
160
142
  },
161
- 'form.labelPosition'(val) {
162
- // 标签位置
163
- this.localLabelPos = this._labelPosition();
143
+ computed: {
144
+ // 处理错误信息
145
+ msg() {
146
+ return this.errorMessage || this.errMsg;
147
+ },
164
148
  },
165
- 'form.labelAlign'(val) {},
166
- },
167
- created() {
168
- this.init(true);
169
- if (this.name && this.form) {
170
- // TODO 处理头条vue3 watch不生效的问题
171
- // #ifdef MP-TOUTIAO
172
- this.$watch('form.formRules', () => {
149
+ watch: {
150
+ // 规则发生变化通知子组件更新
151
+ 'form.formRules'(val) {
152
+ // TODO 处理头条vue3 watch不生效的问题
153
+ // #ifndef MP-TOUTIAO
173
154
  this.init();
174
- });
175
- // #endif
176
-
177
- // 监听变化
178
- this.$watch(
179
- () => {
180
- const val = this.form._getDataValue(this.name, this.form.localData);
181
- return val;
182
- },
183
- (value, oldVal) => {
184
- const isEqual = this.form._isEqual(value, oldVal);
185
- // 简单判断前后值的变化,只有发生变化才会发生校验
186
- // TODO 如果 oldVal = undefined ,那么大概率是源数据里没有值导致 ,这个情况不哦校验 ,可能不严谨 ,需要在做观察
187
- // fix by mehaotian 暂时取消 && oldVal !== undefined ,如果formData 中不存在,可能会不校验
188
- if (!isEqual) {
189
- const val = this.itemSetValue(value);
190
- this.onFieldChange(val, false);
191
- }
192
- },
193
- {
194
- immediate: false,
195
- },
196
- );
197
- }
198
- },
199
- // #ifndef VUE3
200
- destroyed() {
201
- if (this.__isUnmounted) return;
202
- this.unInit();
203
- },
204
- // #endif
205
- // #ifdef VUE3
206
- unmounted() {
207
- this.__isUnmounted = true;
208
- this.unInit();
209
- },
210
- // #endif
211
- methods: {
212
- /**
213
- * 外部调用方法
214
- * 设置规则 ,主要用于小程序自定义检验规则
215
- * @param {Array} rules 规则源数据
216
- */
217
- setRules(rules = null) {
218
- this.userRules = rules;
219
- this.init(false);
220
- },
221
- // 兼容老版本表单组件
222
- setValue() {
223
- // console.log('setValue 方法已经弃用,请使用最新版本的 uni-forms 表单组件以及其他关联组件。');
155
+ // #endif
156
+ },
157
+ 'form.labelWidth'(val) {
158
+ // 宽度
159
+ this.localLabelWidth = this._labelWidthUnit(val);
160
+ },
161
+ 'form.labelPosition'(val) {
162
+ // 标签位置
163
+ this.localLabelPos = this._labelPosition();
164
+ },
165
+ 'form.labelAlign'(val) {},
224
166
  },
225
- /**
226
- * 外部调用方法
227
- * 校验数据
228
- * @param {any} value 需要校验的数据
229
- * @param {boolean} 是否立即校验
230
- * @return {Array|null} 校验内容
231
- */
232
- async onFieldChange(value, formtrigger = true) {
233
- const { formData, localData, errShowType, validateCheck, validateTrigger, _isRequiredField, _realName } = this.form;
234
- const name = _realName(this.name);
235
- if (!value) {
236
- value = this.form.formData[name];
237
- }
238
- // fixd by mehaotian 不在校验前清空信息,解决闪屏的问题
239
- // this.errMsg = '';
240
-
241
- // fix by mehaotian 解决没有检验规则的情况下,抛出错误的问题
242
- const ruleLen = this.itemRules.rules && this.itemRules.rules.length;
243
- if (!this.validator || !ruleLen || ruleLen === 0) return;
244
-
245
- // 检验时机
246
- // let trigger = this.isTrigger(this.itemRules.validateTrigger, this.validateTrigger, validateTrigger);
247
- const isRequiredField = _isRequiredField(this.itemRules.rules || []);
248
- let result = null;
249
- // 只有等于 bind 时 ,才能开启时实校验
250
- if (validateTrigger === 'bind' || formtrigger) {
251
- // 校验当前表单项
252
- result = await this.validator.validateUpdate(
167
+ created() {
168
+ this.init(true);
169
+ if (this.name && this.form) {
170
+ // TODO 处理头条vue3 watch不生效的问题
171
+ // #ifdef MP-TOUTIAO
172
+ this.$watch('form.formRules', () => {
173
+ this.init();
174
+ });
175
+ // #endif
176
+
177
+ // 监听变化
178
+ this.$watch(
179
+ () => {
180
+ const val = this.form._getDataValue(this.name, this.form.localData);
181
+ return val;
182
+ },
183
+ (value, oldVal) => {
184
+ const isEqual = this.form._isEqual(value, oldVal);
185
+ // 简单判断前后值的变化,只有发生变化才会发生校验
186
+ // TODO 如果 oldVal = undefined ,那么大概率是源数据里没有值导致 ,这个情况不哦校验 ,可能不严谨 ,需要在做观察
187
+ // fix by mehaotian 暂时取消 && oldVal !== undefined ,如果formData 中不存在,可能会不校验
188
+ if (!isEqual) {
189
+ const val = this.itemSetValue(value);
190
+ this.onFieldChange(val, false);
191
+ }
192
+ },
253
193
  {
254
- [name]: value,
194
+ immediate: false,
255
195
  },
256
- formData,
257
196
  );
258
-
259
- // 判断是否必填,非必填,不填不校验,填写才校验 ,暂时只处理 undefined 和空的情况
260
- if (!isRequiredField && (value === undefined || value === '')) {
261
- result = null;
197
+ }
198
+ },
199
+ // #ifndef VUE3
200
+ destroyed() {
201
+ if (this.__isUnmounted) return;
202
+ this.unInit();
203
+ },
204
+ // #endif
205
+ // #ifdef VUE3
206
+ unmounted() {
207
+ this.__isUnmounted = true;
208
+ this.unInit();
209
+ },
210
+ // #endif
211
+ methods: {
212
+ /**
213
+ * 外部调用方法
214
+ * 设置规则 ,主要用于小程序自定义检验规则
215
+ * @param {Array} rules 规则源数据
216
+ */
217
+ setRules(rules = null) {
218
+ this.userRules = rules;
219
+ this.init(false);
220
+ },
221
+ // 兼容老版本表单组件
222
+ setValue() {
223
+ // console.log('setValue 方法已经弃用,请使用最新版本的 uni-forms 表单组件以及其他关联组件。');
224
+ },
225
+ /**
226
+ * 外部调用方法
227
+ * 校验数据
228
+ * @param {any} value 需要校验的数据
229
+ * @param {boolean} 是否立即校验
230
+ * @return {Array|null} 校验内容
231
+ */
232
+ async onFieldChange(value, formtrigger = true) {
233
+ const { formData, localData, errShowType, validateCheck, validateTrigger, _isRequiredField, _realName } = this.form;
234
+ const name = _realName(this.name);
235
+ if (!value) {
236
+ value = this.form.formData[name];
262
237
  }
263
-
264
- // 判断错误信息显示类型
265
- if (result && result.errorMessage) {
266
- if (errShowType === 'undertext') {
267
- // 获取错误信息
268
- this.errMsg = !result ? '' : result.errorMessage;
269
- }
270
- if (errShowType === 'toast') {
271
- uni.showToast({
272
- title: result.errorMessage || '校验错误',
273
- icon: 'none',
274
- });
238
+ // fixd by mehaotian 不在校验前清空信息,解决闪屏的问题
239
+ // this.errMsg = '';
240
+
241
+ // fix by mehaotian 解决没有检验规则的情况下,抛出错误的问题
242
+ const ruleLen = this.itemRules.rules && this.itemRules.rules.length;
243
+ if (!this.validator || !ruleLen || ruleLen === 0) return;
244
+
245
+ // 检验时机
246
+ // let trigger = this.isTrigger(this.itemRules.validateTrigger, this.validateTrigger, validateTrigger);
247
+ const isRequiredField = _isRequiredField(this.itemRules.rules || []);
248
+ let result = null;
249
+ // 只有等于 bind 时 ,才能开启时实校验
250
+ if (validateTrigger === 'bind' || formtrigger) {
251
+ // 校验当前表单项
252
+ result = await this.validator.validateUpdate(
253
+ {
254
+ [name]: value,
255
+ },
256
+ formData,
257
+ );
258
+
259
+ // 判断是否必填,非必填,不填不校验,填写才校验 ,暂时只处理 undefined 和空的情况
260
+ if (!isRequiredField && (value === undefined || value === '')) {
261
+ result = null;
275
262
  }
276
- if (errShowType === 'modal') {
277
- uni.showModal({
278
- title: '提示',
279
- content: result.errorMessage || '校验错误',
280
- });
263
+
264
+ // 判断错误信息显示类型
265
+ if (result && result.errorMessage) {
266
+ if (errShowType === 'undertext') {
267
+ // 获取错误信息
268
+ this.errMsg = !result ? '' : result.errorMessage;
269
+ }
270
+ if (errShowType === 'toast') {
271
+ uni.showToast({
272
+ title: result.errorMessage || '校验错误',
273
+ icon: 'none',
274
+ });
275
+ }
276
+ if (errShowType === 'modal') {
277
+ uni.showModal({
278
+ title: '提示',
279
+ content: result.errorMessage || '校验错误',
280
+ });
281
+ }
282
+ } else {
283
+ this.errMsg = '';
281
284
  }
285
+ // 通知 form 组件更新事件
286
+ validateCheck(result ? result : null);
282
287
  } else {
283
288
  this.errMsg = '';
284
289
  }
285
- // 通知 form 组件更新事件
286
- validateCheck(result ? result : null);
287
- } else {
288
- this.errMsg = '';
289
- }
290
- return result ? result : null;
291
- },
292
- /**
293
- * 初始组件数据
294
- */
295
- init(type = false) {
296
- const { validator, formRules, childrens, formData, localData, _realName, labelWidth, _getDataValue, _setDataValue } = this.form || {};
297
- // 对齐方式
298
- this.localLabelAlign = this._justifyContent();
299
- // 宽度
300
- this.localLabelWidth = this._labelWidthUnit(labelWidth);
301
- // 标签位置
302
- this.localLabelPos = this._labelPosition();
303
- // 将需要校验的子组件加入form 队列
304
- this.form && type && childrens.push(this);
305
-
306
- if (!validator || !formRules) return;
307
- // 判断第一个 item
308
- if (!this.form.isFirstBorder) {
309
- this.form.isFirstBorder = true;
310
- this.isFirstBorder = true;
311
- }
312
-
313
- // 判断 group 里的第一个 item
314
- if (this.group) {
315
- if (!this.group.isFirstBorder) {
316
- this.group.isFirstBorder = true;
290
+ return result ? result : null;
291
+ },
292
+ /**
293
+ * 初始组件数据
294
+ */
295
+ init(type = false) {
296
+ const { validator, formRules, childrens, formData, localData, _realName, labelWidth, _getDataValue, _setDataValue } = this.form || {};
297
+ // 对齐方式
298
+ this.localLabelAlign = this._justifyContent();
299
+ // 宽度
300
+ this.localLabelWidth = this._labelWidthUnit(labelWidth);
301
+ // 标签位置
302
+ this.localLabelPos = this._labelPosition();
303
+ // 将需要校验的子组件加入form 队列
304
+ this.form && type && childrens.push(this);
305
+
306
+ if (!validator || !formRules) return;
307
+ // 判断第一个 item
308
+ if (!this.form.isFirstBorder) {
309
+ this.form.isFirstBorder = true;
317
310
  this.isFirstBorder = true;
318
311
  }
319
- }
320
- this.border = this.form.border;
321
- // 获取子域的真实名称
322
- const name = _realName(this.name);
323
- const itemRule = this.userRules || this.rules;
324
- if (typeof formRules === 'object' && itemRule) {
325
- // 子规则替换父规则
326
- formRules[name] = {
327
- rules: itemRule,
328
- };
329
- validator.updateSchema(formRules);
330
- }
331
- // 注册校验规则
332
- const itemRules = formRules[name] || {};
333
- this.itemRules = itemRules;
334
- // 注册校验函数
335
- this.validator = validator;
336
- // 默认值赋予
337
- this.itemSetValue(_getDataValue(this.name, localData));
338
- },
339
- unInit() {
340
- if (this.form) {
341
- const { childrens, formData, _realName } = this.form;
342
- childrens.forEach((item, index) => {
343
- if (item === this) {
344
- this.form.childrens.splice(index, 1);
345
- delete formData[_realName(item.name)];
312
+
313
+ // 判断 group 里的第一个 item
314
+ if (this.group) {
315
+ if (!this.group.isFirstBorder) {
316
+ this.group.isFirstBorder = true;
317
+ this.isFirstBorder = true;
346
318
  }
347
- });
348
- }
349
- },
350
- // 设置item 的值
351
- itemSetValue(value) {
352
- const name = this.form._realName(this.name);
353
- const rules = this.itemRules.rules || [];
354
- const val = this.form._getValue(name, value, rules);
355
- this.form._setDataValue(name, this.form.formData, val);
356
- return val;
357
- },
319
+ }
320
+ this.border = this.form.border;
321
+ // 获取子域的真实名称
322
+ const name = _realName(this.name);
323
+ const itemRule = this.userRules || this.rules;
324
+ if (typeof formRules === 'object' && itemRule) {
325
+ // 子规则替换父规则
326
+ formRules[name] = {
327
+ rules: itemRule,
328
+ };
329
+ validator.updateSchema(formRules);
330
+ }
331
+ // 注册校验规则
332
+ const itemRules = formRules[name] || {};
333
+ this.itemRules = itemRules;
334
+ // 注册校验函数
335
+ this.validator = validator;
336
+ // 默认值赋予
337
+ this.itemSetValue(_getDataValue(this.name, localData));
338
+ },
339
+ unInit() {
340
+ if (this.form) {
341
+ const { childrens, formData, _realName } = this.form;
342
+ childrens.forEach((item, index) => {
343
+ if (item === this) {
344
+ this.form.childrens.splice(index, 1);
345
+ delete formData[_realName(item.name)];
346
+ }
347
+ });
348
+ }
349
+ },
350
+ // 设置item 的值
351
+ itemSetValue(value) {
352
+ const name = this.form._realName(this.name);
353
+ const rules = this.itemRules.rules || [];
354
+ const val = this.form._getValue(name, value, rules);
355
+ this.form._setDataValue(name, this.form.formData, val);
356
+ return val;
357
+ },
358
358
 
359
- /**
360
- * 移除该表单项的校验结果
361
- */
362
- clearValidate() {
363
- this.errMsg = '';
364
- },
359
+ /**
360
+ * 移除该表单项的校验结果
361
+ */
362
+ clearValidate() {
363
+ this.errMsg = '';
364
+ },
365
365
 
366
- // 是否显示星号
367
- _isRequired() {
368
- // TODO 不根据规则显示 星号,考虑后续兼容
369
- // if (this.form) {
370
- // if (this.form._isRequiredField(this.itemRules.rules || []) && this.required) {
371
- // return true
372
- // }
373
- // return false
374
- // }
375
- return this.required;
376
- },
366
+ // 是否显示星号
367
+ _isRequired() {
368
+ // TODO 不根据规则显示 星号,考虑后续兼容
369
+ // if (this.form) {
370
+ // if (this.form._isRequiredField(this.itemRules.rules || []) && this.required) {
371
+ // return true
372
+ // }
373
+ // return false
374
+ // }
375
+ return this.required;
376
+ },
377
377
 
378
- // 处理对齐方式
379
- _justifyContent() {
380
- if (this.form) {
381
- const { labelAlign } = this.form;
382
- let labelAli = this.labelAlign ? this.labelAlign : labelAlign;
383
- if (labelAli === 'left') return 'flex-start';
384
- if (labelAli === 'center') return 'center';
385
- if (labelAli === 'right') return 'flex-end';
386
- }
387
- return 'flex-start';
388
- },
389
- // 处理 label宽度单位 ,继承父元素的值
390
- _labelWidthUnit(labelWidth) {
391
- // if (this.form) {
392
- // const {
393
- // labelWidth
394
- // } = this.form
395
- return this.num2px(this.labelWidth ? this.labelWidth : labelWidth || (this.label ? 65 : 'auto'));
396
- // }
397
- // return '65px'
398
- },
399
- // 处理 label 位置
400
- _labelPosition() {
401
- if (this.form) return this.form.labelPosition || 'left';
402
- return 'left';
403
- },
378
+ // 处理对齐方式
379
+ _justifyContent() {
380
+ if (this.form) {
381
+ const { labelAlign } = this.form;
382
+ let labelAli = this.labelAlign ? this.labelAlign : labelAlign;
383
+ if (labelAli === 'left') return 'flex-start';
384
+ if (labelAli === 'center') return 'center';
385
+ if (labelAli === 'right') return 'flex-end';
386
+ }
387
+ return 'flex-start';
388
+ },
389
+ // 处理 label宽度单位 ,继承父元素的值
390
+ _labelWidthUnit(labelWidth) {
391
+ // if (this.form) {
392
+ // const {
393
+ // labelWidth
394
+ // } = this.form
395
+ return this.num2px(this.labelWidth ? this.labelWidth : labelWidth || (this.label ? 65 : 'auto'));
396
+ // }
397
+ // return '65px'
398
+ },
399
+ // 处理 label 位置
400
+ _labelPosition() {
401
+ if (this.form) return this.form.labelPosition || 'left';
402
+ return 'left';
403
+ },
404
404
 
405
- /**
406
- * 触发时机
407
- * @param {Object} rule 当前规则内时机
408
- * @param {Object} itemRlue 当前组件时机
409
- * @param {Object} parentRule 父组件时机
410
- */
411
- isTrigger(rule, itemRlue, parentRule) {
412
- // bind submit
413
- if (rule === 'submit' || !rule) {
414
- if (rule === undefined) {
415
- if (itemRlue !== 'bind') {
416
- if (!itemRlue) {
417
- return parentRule === '' ? 'bind' : 'submit';
405
+ /**
406
+ * 触发时机
407
+ * @param {Object} rule 当前规则内时机
408
+ * @param {Object} itemRlue 当前组件时机
409
+ * @param {Object} parentRule 父组件时机
410
+ */
411
+ isTrigger(rule, itemRlue, parentRule) {
412
+ // bind submit
413
+ if (rule === 'submit' || !rule) {
414
+ if (rule === undefined) {
415
+ if (itemRlue !== 'bind') {
416
+ if (!itemRlue) {
417
+ return parentRule === '' ? 'bind' : 'submit';
418
+ }
419
+ return 'submit';
418
420
  }
419
- return 'submit';
421
+ return 'bind';
420
422
  }
421
- return 'bind';
423
+ return 'submit';
422
424
  }
423
- return 'submit';
424
- }
425
- return 'bind';
426
- },
427
- num2px(num) {
428
- if (typeof num === 'number') {
429
- return `${num}px`;
430
- }
431
- return num;
425
+ return 'bind';
426
+ },
427
+ num2px(num) {
428
+ if (typeof num === 'number') {
429
+ return `${num}px`;
430
+ }
431
+ return num;
432
+ },
432
433
  },
433
- },
434
- });
434
+ });
435
435
  </script>
436
436
 
437
437
  <style lang="scss">
438
- .uni-forms-item {
439
- position: relative;
440
- display: flex;
441
- /* #ifdef APP-NVUE */
442
- // 在 nvue 中,使用 margin-bottom error 信息会被隐藏
443
- padding-bottom: 22px;
444
- /* #endif */
445
- /* #ifndef APP-NVUE */
446
- margin-bottom: 22px;
447
- /* #endif */
448
- flex-direction: row;
449
-
450
- &__label {
438
+ .uni-forms-item {
439
+ position: relative;
451
440
  display: flex;
452
- flex-direction: row;
453
- align-items: center;
454
- text-align: left;
455
- font-size: 14px;
456
- color: #606266;
457
- height: 36px;
458
- padding: 0 12px 0 0;
459
- /* #ifndef APP-NVUE */
460
- vertical-align: middle;
461
- flex-shrink: 0;
462
- /* #endif */
463
-
464
- /* #ifndef APP-NVUE */
465
- box-sizing: border-box;
466
-
467
- /* #endif */
468
- &.no-label {
469
- padding: 0;
470
- }
471
- }
472
-
473
- &__content {
474
- /* #ifndef MP-TOUTIAO */
475
- // display: flex;
476
- // align-items: center;
441
+ /* #ifdef APP-NVUE */
442
+ // 在 nvue 中,使用 margin-bottom error 信息会被隐藏
443
+ padding-bottom: 22px;
477
444
  /* #endif */
478
- position: relative;
479
- font-size: 14px;
480
- flex: 1;
481
445
  /* #ifndef APP-NVUE */
482
- box-sizing: border-box;
446
+ margin-bottom: 22px;
483
447
  /* #endif */
484
448
  flex-direction: row;
485
449
 
486
- /* #ifndef APP || H5 || MP-WEIXIN || APP-NVUE */
487
- // TODO 因为小程序平台会多一层标签节点 ,所以需要在多余节点继承当前样式
488
- & > uni-easyinput,
489
- & > uni-data-picker {
490
- width: 100%;
450
+ &__label {
451
+ display: flex;
452
+ flex-direction: row;
453
+ align-items: center;
454
+ text-align: left;
455
+ font-size: 14px;
456
+ color: #606266;
457
+ height: 36px;
458
+ padding: 0 12px 0 0;
459
+ /* #ifndef APP-NVUE */
460
+ vertical-align: middle;
461
+ flex-shrink: 0;
462
+ /* #endif */
463
+
464
+ /* #ifndef APP-NVUE */
465
+ box-sizing: border-box;
466
+
467
+ /* #endif */
468
+ &.no-label {
469
+ padding: 0;
470
+ }
491
471
  }
492
472
 
493
- /* #endif */
494
- }
473
+ &__content {
474
+ /* #ifndef MP-TOUTIAO */
475
+ // display: flex;
476
+ // align-items: center;
477
+ /* #endif */
478
+ position: relative;
479
+ font-size: 14px;
480
+ flex: 1;
481
+ /* #ifndef APP-NVUE */
482
+ box-sizing: border-box;
483
+ /* #endif */
484
+ flex-direction: row;
495
485
 
496
- & .uni-forms-item__nuve-content {
497
- display: flex;
498
- flex-direction: column;
499
- flex: 1;
500
- }
486
+ /* #ifndef APP || H5 || MP-WEIXIN || APP-NVUE */
487
+ // TODO 因为小程序平台会多一层标签节点 ,所以需要在多余节点继承当前样式
488
+ & > uni-easyinput,
489
+ & > uni-data-picker {
490
+ width: 100%;
491
+ }
501
492
 
502
- &__error {
503
- color: #f56c6c;
504
- font-size: 12px;
505
- line-height: 1;
506
- padding-top: 4px;
507
- position: absolute;
508
- /* #ifndef APP-NVUE */
509
- top: 100%;
510
- left: 0;
511
- transform: translateY(-100%);
512
- /* #endif */
513
- /* #ifdef APP-NVUE */
514
- bottom: 5px;
515
- /* #endif */
493
+ /* #endif */
494
+ }
516
495
 
517
- opacity: 0;
496
+ & .uni-forms-item__nuve-content {
497
+ display: flex;
498
+ flex-direction: column;
499
+ flex: 1;
500
+ }
518
501
 
519
- .error-text {
520
- // 只有 nvue 下这个样式才生效
502
+ &__error {
521
503
  color: #f56c6c;
522
504
  font-size: 12px;
505
+ line-height: 1;
506
+ padding-top: 4px;
507
+ position: absolute;
508
+ /* #ifndef APP-NVUE */
509
+ top: 100%;
510
+ left: 0;
511
+ transform: translateY(-100%);
512
+ /* #endif */
513
+ /* #ifdef APP-NVUE */
514
+ bottom: 5px;
515
+ /* #endif */
516
+
517
+ opacity: 0;
518
+
519
+ .error-text {
520
+ // 只有 nvue 下这个样式才生效
521
+ color: #f56c6c;
522
+ font-size: 12px;
523
+ }
524
+
525
+ &.msg--active {
526
+ opacity: 1;
527
+ transform: translateY(0%);
528
+ }
523
529
  }
524
530
 
525
- &.msg--active {
526
- opacity: 1;
527
- transform: translateY(0%);
531
+ // 位置修饰样式
532
+ &.is-direction-left {
533
+ flex-direction: row;
528
534
  }
529
- }
530
535
 
531
- // 位置修饰样式
532
- &.is-direction-left {
533
- flex-direction: row;
534
- }
536
+ &.is-direction-top {
537
+ flex-direction: column;
535
538
 
536
- &.is-direction-top {
537
- flex-direction: column;
539
+ .uni-forms-item__label {
540
+ padding: 0 0 8px;
541
+ line-height: 1.5715;
542
+ text-align: left;
543
+ /* #ifndef APP-NVUE */
544
+ white-space: initial;
545
+ /* #endif */
546
+ }
547
+ }
538
548
 
539
- .uni-forms-item__label {
540
- padding: 0 0 8px;
541
- line-height: 1.5715;
542
- text-align: left;
543
- /* #ifndef APP-NVUE */
544
- white-space: initial;
545
- /* #endif */
549
+ .is-required {
550
+ // color: $uni-color-error;
551
+ color: #dd524d;
552
+ font-weight: bold;
546
553
  }
547
554
  }
548
555
 
549
- .is-required {
550
- // color: $uni-color-error;
551
- color: #dd524d;
552
- font-weight: bold;
553
- }
554
- }
556
+ .uni-forms-item--border {
557
+ margin-bottom: 0;
558
+ padding: 10px 0;
559
+ // padding-bottom: 0;
560
+ border-top: 1px #eee solid;
561
+
562
+ /* #ifndef APP-NVUE */
563
+ .uni-forms-item__content {
564
+ flex-direction: column;
565
+ justify-content: flex-start;
566
+ align-items: flex-start;
567
+
568
+ .uni-forms-item__error {
569
+ position: relative;
570
+ top: 5px;
571
+ left: 0;
572
+ padding-top: 0;
573
+ }
574
+ }
555
575
 
556
- .uni-forms-item--border {
557
- margin-bottom: 0;
558
- padding: 10px 0;
559
- // padding-bottom: 0;
560
- border-top: 1px #eee solid;
576
+ /* #endif */
561
577
 
562
- /* #ifndef APP-NVUE */
563
- .uni-forms-item__content {
578
+ /* #ifdef APP-NVUE */
579
+ display: flex;
564
580
  flex-direction: column;
565
- justify-content: flex-start;
566
- align-items: flex-start;
567
581
 
568
582
  .uni-forms-item__error {
569
583
  position: relative;
570
- top: 5px;
584
+ top: 0px;
571
585
  left: 0;
572
586
  padding-top: 0;
587
+ margin-top: 5px;
573
588
  }
574
- }
575
-
576
- /* #endif */
577
-
578
- /* #ifdef APP-NVUE */
579
- display: flex;
580
- flex-direction: column;
581
589
 
582
- .uni-forms-item__error {
583
- position: relative;
584
- top: 0px;
585
- left: 0;
586
- padding-top: 0;
587
- margin-top: 5px;
590
+ /* #endif */
588
591
  }
589
592
 
590
- /* #endif */
591
- }
592
-
593
- .is-first-border {
594
- /* #ifndef APP-NVUE */
595
- border: none;
596
- /* #endif */
597
- /* #ifdef APP-NVUE */
598
- border-width: 0;
599
- /* #endif */
600
- }
593
+ .is-first-border {
594
+ /* #ifndef APP-NVUE */
595
+ border: none;
596
+ /* #endif */
597
+ /* #ifdef APP-NVUE */
598
+ border-width: 0;
599
+ /* #endif */
600
+ }
601
601
  </style>