@tdesign/uniapp 0.7.3 → 0.8.0
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.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +3 -3
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +4 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +5 -5
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +175 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +15 -3
- package/dist/form/form-item-props.ts +0 -56
|
@@ -1,391 +1,370 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
:class="
|
|
4
|
-
classPrefix +
|
|
5
|
-
' ' + classPrefix + '--' + dataLabelAlign +
|
|
6
|
-
' ' + classPrefix + '--bordered' +
|
|
7
|
-
' ' + classPrefix + '--' + (verifyStatus === 2 ? 'error' : verifyStatus === 1 ? 'success' : '') +
|
|
8
|
-
' ' + tClass
|
|
9
|
-
"
|
|
3
|
+
:class="classPrefix + ' ' + formItemClass + ' ' + formClass + '--' + dataLabelAlign + ' ' + formItemClass + '__' + name + ' ' + errorClasses + ' ' + tClass"
|
|
10
4
|
:style="tools._style([customStyle])"
|
|
11
5
|
>
|
|
12
|
-
<view
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
</text>
|
|
23
|
-
<slot
|
|
24
|
-
name="label"
|
|
25
|
-
>
|
|
26
|
-
<text>
|
|
27
|
-
{{ label }}
|
|
28
|
-
</text>
|
|
29
|
-
</slot>
|
|
30
|
-
<text
|
|
31
|
-
v-if="dataRequiredMark && requiredMarkPosition === 'right'"
|
|
32
|
-
:class="classPrefix + '__label--required'"
|
|
33
|
-
>
|
|
34
|
-
*
|
|
35
|
-
</text>
|
|
36
|
-
<text
|
|
37
|
-
v-if="colon"
|
|
38
|
-
:class="classPrefix + '__label--colon'"
|
|
6
|
+
<view :class="formItemClass + '-wrap ' + formItemClass + '--' + dataLabelAlign + ' ' + tClassWrap">
|
|
7
|
+
<!-- 标签区域 -->
|
|
8
|
+
<view
|
|
9
|
+
v-if="label"
|
|
10
|
+
:class="labelClass + ' ' + labelClass + '--' + dataLabelAlign
|
|
11
|
+
+ (dataRequiredMark ? ' ' + labelClass + '--required' : '')
|
|
12
|
+
+ (dataRequiredMark && requiredMarkPosition === 'right' ? ' ' + labelClass + '--required-right' : '')
|
|
13
|
+
+ ' ' + tClassLabel"
|
|
14
|
+
:style="'width: ' + dataLabelWidth"
|
|
39
15
|
>
|
|
40
|
-
:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
<view :class="
|
|
48
|
-
<slot />
|
|
16
|
+
<label :for="forId">{{ label }}</label>
|
|
17
|
+
<template v-if="colon">
|
|
18
|
+
{{ globalConfig.colonText }}
|
|
19
|
+
</template>
|
|
20
|
+
</view>
|
|
21
|
+
|
|
22
|
+
<!-- 内容区域 -->
|
|
23
|
+
<view :class="formClass + '__controls ' + errorClasses + ' ' + tClassControls">
|
|
49
24
|
<view
|
|
50
|
-
|
|
51
|
-
:
|
|
25
|
+
:class="formClass + '__controls-content ' + formClass + '__controls--' + dataContentAlign"
|
|
26
|
+
:style="contentStyle"
|
|
52
27
|
>
|
|
53
|
-
<
|
|
54
|
-
name="chevron-right"
|
|
55
|
-
size="16"
|
|
56
|
-
/>
|
|
28
|
+
<slot />
|
|
57
29
|
</view>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
>
|
|
64
|
-
<slot name="help">
|
|
30
|
+
<!-- 帮助信息 -->
|
|
31
|
+
<view
|
|
32
|
+
v-if="help"
|
|
33
|
+
:class="formItemClass + '-help ' + formClass + '__controls--' + dataContentAlign + ' ' + tClassHelp"
|
|
34
|
+
>
|
|
65
35
|
{{ help }}
|
|
66
|
-
</
|
|
67
|
-
</view>
|
|
36
|
+
</view>
|
|
68
37
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
v-if="successList.length > 0"
|
|
77
|
-
:class="classPrefix + '__success'"
|
|
78
|
-
>
|
|
79
|
-
{{ successList[0].message }}
|
|
38
|
+
<!-- 校验提示信息 -->
|
|
39
|
+
<view
|
|
40
|
+
v-if="(errorList.length > 0 && dataShowErrorMessage) || successList.length > 0"
|
|
41
|
+
:class="formItemClass + '-extra ' + formClass + '__controls--' + dataContentAlign + ' ' + tClassExtra"
|
|
42
|
+
>
|
|
43
|
+
{{ errorList.length > 0 && dataShowErrorMessage ? errorList[0].message : successList[0].message }}
|
|
44
|
+
</view>
|
|
80
45
|
</view>
|
|
81
46
|
</view>
|
|
82
47
|
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
48
|
+
<t-icon
|
|
49
|
+
v-if="arrow"
|
|
50
|
+
name="chevron-right"
|
|
51
|
+
size="24"
|
|
52
|
+
color="rgba(0, 0, 0, 0.4)"
|
|
53
|
+
/>
|
|
86
54
|
</view>
|
|
87
55
|
</template>
|
|
88
56
|
<script>
|
|
89
57
|
import { uniComponent } from '../common/src/index';
|
|
58
|
+
import { getRect } from '../common/utils';
|
|
90
59
|
import { prefix } from '../common/config';
|
|
91
60
|
import props from './props';
|
|
92
|
-
import {
|
|
61
|
+
import { validateRules, ValidateStatus } from './form-model';
|
|
93
62
|
import TIcon from '../icon/icon.vue';
|
|
94
|
-
import TButton from '../button/button.vue';
|
|
95
63
|
import { ChildrenMixin, RELATION_MAP } from '../common/relation';
|
|
96
64
|
import tools from '../common/utils.wxs';
|
|
97
|
-
import
|
|
65
|
+
import usingConfig from '../mixins/using-config';
|
|
66
|
+
import { isNumeric } from '../common/validator';
|
|
98
67
|
|
|
99
|
-
const
|
|
68
|
+
const parentComponentName = 'form';
|
|
69
|
+
const componentName = 'form-item';
|
|
70
|
+
const name = `${prefix}-${componentName}`;
|
|
100
71
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
`${prefix}-class-controls`,
|
|
110
|
-
`${prefix}-class-help`,
|
|
111
|
-
`${prefix}-class-extra`,
|
|
112
|
-
],
|
|
113
|
-
provide() {
|
|
114
|
-
return {
|
|
115
|
-
[RELATION_MAP.FormKey]: this,
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
mixins: [ChildrenMixin(RELATION_MAP.FormItem)],
|
|
72
|
+
/** 规范化 labelWidth,确保输出带有 CSS 单位 */
|
|
73
|
+
function normalizeLabelWidth(value) {
|
|
74
|
+
if (!value) return '';
|
|
75
|
+
if (isNumeric(value)) return `${value}px`;
|
|
76
|
+
return String(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default {
|
|
119
80
|
components: {
|
|
120
81
|
TIcon,
|
|
121
|
-
TButton,
|
|
122
|
-
},
|
|
123
|
-
props: {
|
|
124
|
-
...props,
|
|
125
|
-
},
|
|
126
|
-
data() {
|
|
127
|
-
return {
|
|
128
|
-
prefix,
|
|
129
|
-
classPrefix: name,
|
|
130
|
-
errorList: [],
|
|
131
|
-
successList: [],
|
|
132
|
-
verifyStatus: ValidateStatus.TO_BE_VALIDATED,
|
|
133
|
-
needResetField: false,
|
|
134
|
-
resetValidating: false,
|
|
135
|
-
// rules: [],
|
|
136
|
-
form: {},
|
|
137
|
-
colon: false,
|
|
138
|
-
// showErrorMessage: true,
|
|
139
|
-
|
|
140
|
-
tools,
|
|
141
|
-
dataRules: this.rules,
|
|
142
|
-
dataLabelAlign: this.labelAlign,
|
|
143
|
-
dataLabelWidth: this.labelWidth,
|
|
144
|
-
dataRequiredMark: this.requiredMark,
|
|
145
|
-
dataShowErrorMessage: this.showErrorMessage,
|
|
146
|
-
dataContentAlign: this.contentAlign,
|
|
147
|
-
|
|
148
|
-
errorPosition: '',
|
|
149
|
-
};
|
|
150
|
-
},
|
|
151
|
-
computed: {
|
|
152
|
-
contentStyle() {
|
|
153
|
-
const { labelWidth, labelAlign } = this;
|
|
154
|
-
let contentStyle = {};
|
|
155
|
-
if (labelWidth && labelAlign !== 'top') {
|
|
156
|
-
if (isNumber(labelWidth)) {
|
|
157
|
-
contentStyle = { marginLeft: `${labelWidth}px` };
|
|
158
|
-
} else {
|
|
159
|
-
contentStyle = { marginLeft: labelWidth };
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return tools._style(contentStyle);
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
watch: {
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
created() {
|
|
170
|
-
// this.initFormItem();
|
|
171
|
-
},
|
|
172
|
-
beforeUnmount() {
|
|
173
|
-
if (this.form) {
|
|
174
|
-
this.form.unregisterChild(this.name);
|
|
175
|
-
}
|
|
176
82
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.form = target;
|
|
182
|
-
this.initFormItem();
|
|
183
|
-
|
|
184
|
-
const { requiredMark, labelAlign, labelWidth, showErrorMessage, contentAlign } = this;
|
|
185
|
-
const isRequired = target.rules[this.name]?.some(rule => rule.required);
|
|
186
|
-
|
|
187
|
-
this.dataRules = target.rules[this.name];
|
|
188
|
-
this.colon = target.colon;
|
|
189
|
-
this.dataLabelAlign = labelAlign || target.labelAlign || 'right';
|
|
190
|
-
this.dataLabelWidth = labelWidth || target.labelWidth;
|
|
191
|
-
this.dataContentAlign = contentAlign || target.contentAlign,
|
|
192
|
-
this.dataRequiredMark = (() => {
|
|
193
|
-
if (!isRequired) {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
if (typeof requiredMark === 'boolean') {
|
|
197
|
-
return requiredMark;
|
|
198
|
-
}
|
|
199
|
-
return target.requiredMark || false;
|
|
200
|
-
})();
|
|
201
|
-
this.dataShowErrorMessage = typeof showErrorMessage === 'boolean' ? showErrorMessage : target.showErrorMessage;
|
|
202
|
-
this.requiredMarkPosition = target.requiredMarkPosition;
|
|
203
|
-
|
|
204
|
-
setTimeout(() => {
|
|
205
|
-
this.errorPosition = this.dataLabelAlign !== 'top' && `text-align: ${this.dataContentAlign}`;
|
|
206
|
-
}, 33);
|
|
83
|
+
...uniComponent({
|
|
84
|
+
name,
|
|
85
|
+
options: {
|
|
86
|
+
styleIsolation: 'shared',
|
|
207
87
|
},
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
current: urls[0],
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
// 初始化表单项
|
|
225
|
-
initFormItem() {
|
|
226
|
-
this.setInitialValue();
|
|
88
|
+
externalClasses: [
|
|
89
|
+
`${prefix}-class`,
|
|
90
|
+
`${prefix}-class-wrap`,
|
|
91
|
+
`${prefix}-class-label`,
|
|
92
|
+
`${prefix}-class-controls`,
|
|
93
|
+
`${prefix}-class-help`,
|
|
94
|
+
`${prefix}-class-extra`,
|
|
95
|
+
],
|
|
96
|
+
provide() {
|
|
97
|
+
return {
|
|
98
|
+
[RELATION_MAP.FormKey]: this,
|
|
99
|
+
};
|
|
227
100
|
},
|
|
101
|
+
mixins: [
|
|
102
|
+
ChildrenMixin(RELATION_MAP.FormItem),
|
|
103
|
+
usingConfig({ componentName: parentComponentName }),
|
|
104
|
+
],
|
|
228
105
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const { name } = this;
|
|
232
|
-
if (name && this.form) {
|
|
233
|
-
const { formData } = this.form;
|
|
234
|
-
this.initialValue = formData[name];
|
|
235
|
-
}
|
|
106
|
+
props: {
|
|
107
|
+
...props,
|
|
236
108
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
109
|
+
data() {
|
|
110
|
+
return {
|
|
111
|
+
prefix,
|
|
112
|
+
classPrefix: name,
|
|
113
|
+
formClass: `${prefix}-form`,
|
|
114
|
+
formItemClass: `${prefix}-form__item`,
|
|
115
|
+
labelClass: `${prefix}-form__label`,
|
|
116
|
+
errorClasses: '',
|
|
117
|
+
errorList: [],
|
|
118
|
+
successList: [],
|
|
119
|
+
verifyStatus: ValidateStatus.TO_BE_VALIDATED,
|
|
120
|
+
needResetField: false,
|
|
121
|
+
resetValidating: false,
|
|
122
|
+
form: {},
|
|
123
|
+
colon: false,
|
|
124
|
+
|
|
125
|
+
tools,
|
|
126
|
+
dataRules: this.rules,
|
|
127
|
+
dataLabelAlign: this.labelAlign,
|
|
128
|
+
dataLabelWidth: this.labelWidth,
|
|
129
|
+
dataRequiredMark: this.requiredMark,
|
|
130
|
+
dataShowErrorMessage: this.showErrorMessage,
|
|
131
|
+
dataContentAlign: this.contentAlign,
|
|
132
|
+
requiredMarkPosition: '',
|
|
133
|
+
|
|
134
|
+
forId: this.for || '',
|
|
135
|
+
};
|
|
244
136
|
},
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const { formData } = this.form;
|
|
251
|
-
return formData[name];
|
|
252
|
-
}
|
|
253
|
-
return undefined;
|
|
137
|
+
computed: {
|
|
138
|
+
contentStyle() {
|
|
139
|
+
const contentAlign = this.dataContentAlign;
|
|
140
|
+
return contentAlign ? `text-align: ${contentAlign}` : '';
|
|
141
|
+
},
|
|
254
142
|
},
|
|
143
|
+
watch: {
|
|
255
144
|
|
|
256
|
-
// 获取验证规则
|
|
257
|
-
getRules() {
|
|
258
|
-
const { rules } = this;
|
|
259
|
-
|
|
260
|
-
// 优先使用组件自身的规则
|
|
261
|
-
if (rules && rules.length > 0) {
|
|
262
|
-
return rules;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// 使用表单的规则
|
|
266
|
-
return this.dataRules || [];
|
|
267
145
|
},
|
|
268
|
-
|
|
269
|
-
//
|
|
270
|
-
async validate(data, trigger, showErrorMessage) {
|
|
271
|
-
const rules = this.getRules();
|
|
272
|
-
if (rules.length === 0) {
|
|
273
|
-
return { [this.name]: true };
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// 根据触发方式过滤规则
|
|
277
|
-
const filteredRules = trigger === 'all'
|
|
278
|
-
? rules
|
|
279
|
-
: rules.filter(rule => (rule.trigger || 'change') === trigger);
|
|
280
|
-
|
|
281
|
-
if (filteredRules.length === 0) {
|
|
282
|
-
return { [this.name]: true };
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const value = data[this.name];
|
|
286
|
-
const results = await validate(value, filteredRules);
|
|
287
|
-
|
|
288
|
-
// 分析验证结果
|
|
289
|
-
const analysis = this.analysisValidateResult(results);
|
|
290
|
-
|
|
291
|
-
// 更新状态
|
|
292
|
-
this.updateValidateStatus(analysis, showErrorMessage);
|
|
293
|
-
|
|
294
|
-
// 返回验证结果
|
|
295
|
-
const result = {};
|
|
296
|
-
result[this.name] = analysis.errorList.length > 0 ? analysis.errorList : true;
|
|
297
|
-
return result;
|
|
146
|
+
created() {
|
|
147
|
+
// this.initFormItem();
|
|
298
148
|
},
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
149
|
+
beforeUnmount() {
|
|
150
|
+
if (this.form) {
|
|
151
|
+
this.form.unregisterChild(this.name);
|
|
152
|
+
}
|
|
303
153
|
},
|
|
154
|
+
methods: {
|
|
155
|
+
innerAfterLinked() {
|
|
156
|
+
const target = this[RELATION_MAP.FormItem];
|
|
157
|
+
target.registerChild(this);
|
|
158
|
+
this.form = target;
|
|
159
|
+
this.initFormItem();
|
|
160
|
+
|
|
161
|
+
const { globalConfig } = this;
|
|
162
|
+
const { requiredMark, labelAlign, labelWidth, showErrorMessage, contentAlign } = this;
|
|
163
|
+
const formRules = target.rules?.[this.name];
|
|
164
|
+
const isRequired = formRules?.some(rule => rule.required);
|
|
165
|
+
|
|
166
|
+
this.dataRules = formRules;
|
|
167
|
+
this.colon = target.colon;
|
|
168
|
+
this.dataLabelAlign = labelAlign || target.labelAlign;
|
|
169
|
+
this.dataLabelWidth = normalizeLabelWidth(labelWidth || target.labelWidth);
|
|
170
|
+
this.dataContentAlign = contentAlign || target.contentAlign;
|
|
171
|
+
this.dataRequiredMark = requiredMark || target.requiredMark || globalConfig.requiredMark || isRequired;
|
|
172
|
+
this.dataShowErrorMessage = typeof showErrorMessage === 'boolean' ? showErrorMessage : target.showErrorMessage;
|
|
173
|
+
this.requiredMarkPosition = target.requiredMarkPosition || globalConfig.requiredMarkPosition;
|
|
174
|
+
},
|
|
175
|
+
innerAfterUnlinked() {
|
|
176
|
+
if (this.form) {
|
|
177
|
+
this.form.unregisterChild(this.name);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
// 处理描述信息链接点击事件
|
|
181
|
+
handlePreviewImage(e) {
|
|
182
|
+
const { url } = e.currentTarget.dataset;
|
|
183
|
+
const urls = url.map(item => item.url) || [];
|
|
184
|
+
if (url) {
|
|
185
|
+
uni.previewImage({
|
|
186
|
+
urls,
|
|
187
|
+
current: urls[0],
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
// 初始化表单项
|
|
192
|
+
initFormItem() {
|
|
193
|
+
this.setInitialValue();
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
// 设置初始值
|
|
197
|
+
setInitialValue() {
|
|
198
|
+
const { name } = this;
|
|
199
|
+
if (name && this.form) {
|
|
200
|
+
const { formData } = this.form;
|
|
201
|
+
this.initialValue = formData[name];
|
|
202
|
+
}
|
|
203
|
+
},
|
|
304
204
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
205
|
+
// 获取表单数据
|
|
206
|
+
getFormData() {
|
|
207
|
+
if (this.form) {
|
|
208
|
+
return this.form.formData;
|
|
209
|
+
}
|
|
210
|
+
return {};
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
// 获取当前值
|
|
214
|
+
getValue() {
|
|
215
|
+
const { name } = this;
|
|
216
|
+
if (name && this.form) {
|
|
217
|
+
const { formData } = this.form;
|
|
218
|
+
return formData[name];
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
},
|
|
309
222
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
resultList: results,
|
|
314
|
-
};
|
|
315
|
-
},
|
|
223
|
+
// 获取验证规则
|
|
224
|
+
getRules() {
|
|
225
|
+
const { rules } = this;
|
|
316
226
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
227
|
+
// 优先使用组件自身的规则
|
|
228
|
+
if (rules && rules.length > 0) {
|
|
229
|
+
return rules;
|
|
230
|
+
}
|
|
320
231
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
},
|
|
232
|
+
// 使用表单的规则
|
|
233
|
+
return this.dataRules || [];
|
|
234
|
+
},
|
|
325
235
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
236
|
+
// 验证表单项
|
|
237
|
+
async validate(data, trigger, showErrorMessage) {
|
|
238
|
+
const rules = this.getRules();
|
|
239
|
+
if (rules.length === 0) {
|
|
240
|
+
return { [this.name]: true };
|
|
241
|
+
}
|
|
332
242
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
const { resetType } = this.form;
|
|
243
|
+
// 根据触发方式过滤规则
|
|
244
|
+
const filteredRules = trigger === 'all'
|
|
245
|
+
? rules
|
|
246
|
+
: rules.filter(rule => (rule.trigger || 'change') === trigger);
|
|
338
247
|
|
|
339
|
-
if (
|
|
340
|
-
this.
|
|
341
|
-
} else {
|
|
342
|
-
this.form.updateFormData(name, this.getEmptyValue());
|
|
248
|
+
if (filteredRules.length === 0) {
|
|
249
|
+
return { [this.name]: true };
|
|
343
250
|
}
|
|
344
|
-
}
|
|
345
251
|
|
|
346
|
-
|
|
347
|
-
|
|
252
|
+
const value = data[this.name];
|
|
253
|
+
const context = { formData: data, name: this.name };
|
|
254
|
+
const results = await validateRules(value, filteredRules, context);
|
|
348
255
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.errorList = validateMessage.filter(item => item.type === 'error');
|
|
352
|
-
this.successList = validateMessage.filter(item => item.type === 'warning');
|
|
353
|
-
this.verifyStatus = validateMessage.length > 0 ? ValidateStatus.FAIL : ValidateStatus.SUCCESS;
|
|
354
|
-
},
|
|
256
|
+
// 分析验证结果
|
|
257
|
+
const analysis = this.analysisValidateResult(results);
|
|
355
258
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const value = this.getValue();
|
|
259
|
+
// 更新状态
|
|
260
|
+
this.updateValidateStatus(analysis, showErrorMessage);
|
|
359
261
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
if (typeof value === 'number') {
|
|
367
|
-
return 0;
|
|
368
|
-
}
|
|
369
|
-
return '';
|
|
370
|
-
},
|
|
262
|
+
// 返回验证结果
|
|
263
|
+
const result = {};
|
|
264
|
+
result[this.name] = analysis.errorList.length > 0 ? analysis.errorList : true;
|
|
265
|
+
return result;
|
|
266
|
+
},
|
|
371
267
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
this.form.updateFormData(name, value);
|
|
268
|
+
// 纯净验证(不显示错误信息)
|
|
269
|
+
async validateOnly(trigger) {
|
|
270
|
+
return this.validate(this.getFormData(), trigger, false);
|
|
271
|
+
},
|
|
377
272
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
273
|
+
// 分析验证结果
|
|
274
|
+
analysisValidateResult(results) {
|
|
275
|
+
const { globalConfig } = this;
|
|
276
|
+
const errorMessage = (this.form && this.form.errorMessage) || (globalConfig && globalConfig.errorMessage) || {};
|
|
277
|
+
const labelName = this.label || this.name;
|
|
278
|
+
|
|
279
|
+
const errorList = results
|
|
280
|
+
.filter(item => item.result !== true)
|
|
281
|
+
.map((item) => {
|
|
282
|
+
if (item.message) return item;
|
|
283
|
+
|
|
284
|
+
Object.keys(item).forEach((key) => {
|
|
285
|
+
if (!item.message && errorMessage[key]) {
|
|
286
|
+
const template = errorMessage[key];
|
|
287
|
+
item.message = template
|
|
288
|
+
.replace(/\$\{name\}/g, labelName || '')
|
|
289
|
+
.replace(/\$\{validate\}/g, String(item[key] === true ? '' : item[key]));
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return item;
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const successList = results.filter(item => item.result === true && item.message && item.type === 'success');
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
errorList,
|
|
299
|
+
successList,
|
|
300
|
+
resultList: results,
|
|
301
|
+
};
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
// 滚动到当前 form-item
|
|
305
|
+
scrollIntoView(type, distanceTop = 0) {
|
|
306
|
+
getRect(this, `.${this.classPrefix}`).then((rect) => {
|
|
307
|
+
if (!rect) return;
|
|
308
|
+
const query = uni.createSelectorQuery();
|
|
309
|
+
query.selectViewport().scrollOffset()
|
|
310
|
+
.exec((res) => {
|
|
311
|
+
if (!res[0]) return;
|
|
312
|
+
uni.pageScrollTo({
|
|
313
|
+
scrollTop: rect.top + res[0].scrollTop - distanceTop,
|
|
314
|
+
duration: type === 'smooth' ? 300 : 0,
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
// 计算错误样式类
|
|
321
|
+
calcErrorClasses(errorList = this.errorList) {
|
|
322
|
+
if (!this.dataShowErrorMessage) return '';
|
|
323
|
+
if (!errorList || errorList.length === 0) return '';
|
|
324
|
+
const type = errorList[0].type || 'error';
|
|
325
|
+
return type === 'error' ? `${this.formItemClass}--error` : `${this.formItemClass}--warning`;
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
// 更新验证状态
|
|
329
|
+
updateValidateStatus(analysis) {
|
|
330
|
+
const { errorList, successList } = analysis;
|
|
331
|
+
|
|
332
|
+
this.errorClasses = this.calcErrorClasses(errorList);
|
|
333
|
+
this.errorList = errorList;
|
|
334
|
+
this.successList = successList;
|
|
335
|
+
this.verifyStatus = errorList.length > 0 ? ValidateStatus.FAIL : ValidateStatus.SUCCESS;
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
// 清空验证结果
|
|
339
|
+
clearValidate() {
|
|
340
|
+
this.errorClasses = '';
|
|
341
|
+
this.errorList = [];
|
|
342
|
+
this.successList = [];
|
|
343
|
+
this.verifyStatus = ValidateStatus.TO_BE_VALIDATED;
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
// 重置字段
|
|
347
|
+
resetField() {
|
|
348
|
+
this.clearValidate();
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
// 设置验证信息
|
|
352
|
+
setValidateMessage(validateMessage) {
|
|
353
|
+
const errorList = validateMessage.filter(item => item.type !== 'success');
|
|
354
|
+
const successList = validateMessage.filter(item => item.type === 'success');
|
|
355
|
+
|
|
356
|
+
let verifyStatus = ValidateStatus.SUCCESS;
|
|
357
|
+
if (validateMessage.length > 0) {
|
|
358
|
+
verifyStatus = errorList.length > 0 ? ValidateStatus.FAIL : ValidateStatus.SUCCESS;
|
|
359
|
+
}
|
|
382
360
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
361
|
+
this.errorClasses = this.calcErrorClasses(errorList);
|
|
362
|
+
this.errorList = errorList;
|
|
363
|
+
this.successList = successList;
|
|
364
|
+
this.verifyStatus = verifyStatus;
|
|
365
|
+
},
|
|
387
366
|
},
|
|
388
|
-
},
|
|
389
|
-
}
|
|
367
|
+
}),
|
|
368
|
+
};
|
|
390
369
|
</script>
|
|
391
370
|
<style scoped src="./form-item.css"></style>
|