@gmcb/uv-ui 0.2.26
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 +295 -0
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/components/uv-action-sheet/props.js +50 -0
- package/components/uv-action-sheet/uv-action-sheet.vue +280 -0
- package/components/uv-album/uv-album.vue +312 -0
- package/components/uv-alert/props.js +45 -0
- package/components/uv-alert/uv-alert.vue +246 -0
- package/components/uv-avatar/props.js +85 -0
- package/components/uv-avatar/uv-avatar.vue +182 -0
- package/components/uv-avatar-group/props.js +53 -0
- package/components/uv-avatar-group/uv-avatar-group.vue +106 -0
- package/components/uv-back-top/props.js +58 -0
- package/components/uv-back-top/uv-back-top.vue +116 -0
- package/components/uv-badge/props.js +73 -0
- package/components/uv-badge/uv-badge.vue +176 -0
- package/components/uv-button/nvue.scss +46 -0
- package/components/uv-button/props.js +163 -0
- package/components/uv-button/uv-button.vue +529 -0
- package/components/uv-button/vue.scss +93 -0
- package/components/uv-calendar/calendar.js +546 -0
- package/components/uv-calendar/header.vue +104 -0
- package/components/uv-calendar/month.vue +616 -0
- package/components/uv-calendar/props.js +145 -0
- package/components/uv-calendar/uv-calendar.vue +390 -0
- package/components/uv-calendars/calendar-body.vue +376 -0
- package/components/uv-calendars/calendar-item.vue +248 -0
- package/components/uv-calendars/calendar.js +546 -0
- package/components/uv-calendars/i18n/en.json +12 -0
- package/components/uv-calendars/i18n/index.js +8 -0
- package/components/uv-calendars/i18n/zh-Hans.json +12 -0
- package/components/uv-calendars/i18n/zh-Hant.json +12 -0
- package/components/uv-calendars/util.js +435 -0
- package/components/uv-calendars/uv-calendars.vue +452 -0
- package/components/uv-cell/props.js +116 -0
- package/components/uv-cell/uv-cell.vue +209 -0
- package/components/uv-cell-group/props.js +15 -0
- package/components/uv-cell-group/uv-cell-group.vue +63 -0
- package/components/uv-checkbox/props.js +70 -0
- package/components/uv-checkbox/uv-checkbox.vue +371 -0
- package/components/uv-checkbox-group/props.js +84 -0
- package/components/uv-checkbox-group/uv-checkbox-group.vue +119 -0
- package/components/uv-code/props.js +35 -0
- package/components/uv-code/uv-code.vue +136 -0
- package/components/uv-code-input/props.js +83 -0
- package/components/uv-code-input/uv-code-input.vue +272 -0
- package/components/uv-col/props.js +30 -0
- package/components/uv-col/uv-col.vue +165 -0
- package/components/uv-collapse/props.js +20 -0
- package/components/uv-collapse/uv-collapse.vue +86 -0
- package/components/uv-collapse-item/props.js +60 -0
- package/components/uv-collapse-item/uv-collapse-item.vue +228 -0
- package/components/uv-column-notice/props.js +61 -0
- package/components/uv-column-notice/uv-column-notice.vue +176 -0
- package/components/uv-count-down/props.js +25 -0
- package/components/uv-count-down/utils.js +62 -0
- package/components/uv-count-down/uv-count-down.vue +169 -0
- package/components/uv-count-to/props.js +60 -0
- package/components/uv-count-to/uv-count-to.vue +187 -0
- package/components/uv-datetime-picker/props.js +130 -0
- package/components/uv-datetime-picker/uv-datetime-picker.vue +355 -0
- package/components/uv-divider/props.js +45 -0
- package/components/uv-divider/uv-divider.vue +113 -0
- package/components/uv-drop-down/uv-drop-down.vue +135 -0
- package/components/uv-drop-down-item/uv-drop-down-item.vue +169 -0
- package/components/uv-drop-down-popup/uv-drop-down-popup.vue +242 -0
- package/components/uv-empty/props.js +60 -0
- package/components/uv-empty/uv-empty.vue +126 -0
- package/components/uv-form/props.js +46 -0
- package/components/uv-form/uv-form.vue +209 -0
- package/components/uv-form/valid.js +1343 -0
- package/components/uv-form-item/props.js +49 -0
- package/components/uv-form-item/uv-form-item.vue +226 -0
- package/components/uv-gap/props.js +25 -0
- package/components/uv-gap/uv-gap.vue +36 -0
- package/components/uv-grid/props.js +20 -0
- package/components/uv-grid/uv-grid.vue +100 -0
- package/components/uv-grid-item/props.js +15 -0
- package/components/uv-grid-item/uv-grid-item.vue +223 -0
- package/components/uv-icon/icons.js +160 -0
- package/components/uv-icon/props.js +90 -0
- package/components/uv-icon/uv-icon.vue +226 -0
- package/components/uv-icon/uvicons.ttf +0 -0
- package/components/uv-image/props.js +100 -0
- package/components/uv-image/uv-image.vue +296 -0
- package/components/uv-index-anchor/props.js +30 -0
- package/components/uv-index-anchor/uv-index-anchor.vue +98 -0
- package/components/uv-index-item/uv-index-item.vue +87 -0
- package/components/uv-index-list/props.js +30 -0
- package/components/uv-index-list/uv-index-list.vue +461 -0
- package/components/uv-input/props.js +175 -0
- package/components/uv-input/uv-input.vue +348 -0
- package/components/uv-keyboard/props.js +95 -0
- package/components/uv-keyboard/uv-keyboard.vue +180 -0
- package/components/uv-keyboard-car/props.js +24 -0
- package/components/uv-keyboard-car/uv-keyboard-car.vue +347 -0
- package/components/uv-keyboard-number/props.js +19 -0
- package/components/uv-keyboard-number/uv-keyboard-number.vue +201 -0
- package/components/uv-line/props.js +34 -0
- package/components/uv-line/uv-line.vue +60 -0
- package/components/uv-line-progress/props.js +29 -0
- package/components/uv-line-progress/uv-line-progress.vue +146 -0
- package/components/uv-link/props.js +40 -0
- package/components/uv-link/uv-link.vue +83 -0
- package/components/uv-list/uv-list.vue +147 -0
- package/components/uv-list-item/uv-list-item.vue +535 -0
- package/components/uv-load-more/props.js +95 -0
- package/components/uv-load-more/uv-load-more.vue +152 -0
- package/components/uv-loading-icon/props.js +67 -0
- package/components/uv-loading-icon/uv-loading-icon.vue +347 -0
- package/components/uv-loading-page/props.js +55 -0
- package/components/uv-loading-page/uv-loading-page.vue +96 -0
- package/components/uv-modal/props.js +90 -0
- package/components/uv-modal/uv-modal.vue +245 -0
- package/components/uv-navbar/props.js +89 -0
- package/components/uv-navbar/uv-navbar.vue +245 -0
- package/components/uv-no-network/props.js +20 -0
- package/components/uv-no-network/uv-no-network.vue +222 -0
- package/components/uv-notice-bar/props.js +76 -0
- package/components/uv-notice-bar/uv-notice-bar.vue +110 -0
- package/components/uv-notify/props.js +45 -0
- package/components/uv-notify/uv-notify.vue +220 -0
- package/components/uv-number-box/props.js +118 -0
- package/components/uv-number-box/uv-number-box.vue +397 -0
- package/components/uv-overlay/props.js +25 -0
- package/components/uv-overlay/uv-overlay.vue +85 -0
- package/components/uv-parse/node/node.vue +576 -0
- package/components/uv-parse/parser.js +1335 -0
- package/components/uv-parse/uv-parse.vue +498 -0
- package/components/uv-pick-color/colors.js +217 -0
- package/components/uv-pick-color/props.js +47 -0
- package/components/uv-pick-color/uv-pick-color.vue +551 -0
- package/components/uv-picker/props.js +95 -0
- package/components/uv-picker/uv-picker.vue +329 -0
- package/components/uv-popup/keypress.js +45 -0
- package/components/uv-popup/uv-popup.vue +537 -0
- package/components/uv-preview-video/uv-preview-video.vue +52 -0
- package/components/uv-qrcode/cache.js +1 -0
- package/components/uv-qrcode/gcanvas/bridge/bridge-weex.js +241 -0
- package/components/uv-qrcode/gcanvas/context-2d/FillStyleLinearGradient.js +18 -0
- package/components/uv-qrcode/gcanvas/context-2d/FillStylePattern.js +8 -0
- package/components/uv-qrcode/gcanvas/context-2d/FillStyleRadialGradient.js +17 -0
- package/components/uv-qrcode/gcanvas/context-2d/RenderingContext.js +666 -0
- package/components/uv-qrcode/gcanvas/context-webgl/ActiveInfo.js +11 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Buffer.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Framebuffer.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/GLenum.js +298 -0
- package/components/uv-qrcode/gcanvas/context-webgl/GLmethod.js +142 -0
- package/components/uv-qrcode/gcanvas/context-webgl/GLtype.js +23 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Program.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Renderbuffer.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/RenderingContext.js +1191 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Shader.js +22 -0
- package/components/uv-qrcode/gcanvas/context-webgl/ShaderPrecisionFormat.js +11 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Texture.js +22 -0
- package/components/uv-qrcode/gcanvas/context-webgl/UniformLocation.js +22 -0
- package/components/uv-qrcode/gcanvas/context-webgl/classUtils.js +3 -0
- package/components/uv-qrcode/gcanvas/env/canvas.js +74 -0
- package/components/uv-qrcode/gcanvas/env/image.js +96 -0
- package/components/uv-qrcode/gcanvas/env/tool.js +24 -0
- package/components/uv-qrcode/gcanvas/index.js +39 -0
- package/components/uv-qrcode/props.js +85 -0
- package/components/uv-qrcode/qrcode.js +34 -0
- package/components/uv-qrcode/queue.js +41 -0
- package/components/uv-qrcode/uv-qrcode.vue +1038 -0
- package/components/uv-radio/props.js +65 -0
- package/components/uv-radio/uv-radio.vue +349 -0
- package/components/uv-radio-group/props.js +89 -0
- package/components/uv-radio-group/uv-radio-group.vue +115 -0
- package/components/uv-rate/props.js +73 -0
- package/components/uv-rate/uv-rate.vue +274 -0
- package/components/uv-read-more/props.js +62 -0
- package/components/uv-read-more/uv-read-more.vue +162 -0
- package/components/uv-row/props.js +20 -0
- package/components/uv-row/uv-row.vue +95 -0
- package/components/uv-row-notice/props.js +40 -0
- package/components/uv-row-notice/uv-row-notice.vue +341 -0
- package/components/uv-safe-bottom/uv-safe-bottom.vue +67 -0
- package/components/uv-scroll-list/nvue.js +29 -0
- package/components/uv-scroll-list/props.js +35 -0
- package/components/uv-scroll-list/scrollWxs.wxs +51 -0
- package/components/uv-scroll-list/uv-scroll-list.vue +218 -0
- package/components/uv-search/props.js +127 -0
- package/components/uv-search/uv-search.vue +311 -0
- package/components/uv-skeleton/props.js +65 -0
- package/components/uv-skeleton/uv-skeleton.vue +250 -0
- package/components/uv-skeletons/uv-skeletons.vue +247 -0
- package/components/uv-slider/props.js +58 -0
- package/components/uv-slider/uv-slider.vue +58 -0
- package/components/uv-status-bar/props.js +8 -0
- package/components/uv-status-bar/uv-status-bar.vue +54 -0
- package/components/uv-steps/props.js +40 -0
- package/components/uv-steps/uv-steps.vue +83 -0
- package/components/uv-steps-item/props.js +25 -0
- package/components/uv-steps-item/uv-steps-item.vue +347 -0
- package/components/uv-sticky/props.js +41 -0
- package/components/uv-sticky/uv-sticky.vue +223 -0
- package/components/uv-subsection/props.js +54 -0
- package/components/uv-subsection/uv-subsection.vue +269 -0
- package/components/uv-swipe-action/props.js +10 -0
- package/components/uv-swipe-action/uv-swipe-action.vue +65 -0
- package/components/uv-swipe-action-item/index - backup.wxs +256 -0
- package/components/uv-swipe-action-item/index.wxs +225 -0
- package/components/uv-swipe-action-item/nvue - backup.js +264 -0
- package/components/uv-swipe-action-item/nvue.js +182 -0
- package/components/uv-swipe-action-item/props.js +40 -0
- package/components/uv-swipe-action-item/uv-swipe-action-item.vue +200 -0
- package/components/uv-swipe-action-item/wxs.js +15 -0
- package/components/uv-swiper/props.js +136 -0
- package/components/uv-swiper/uv-swiper.vue +263 -0
- package/components/uv-swiper-indicator/props.js +30 -0
- package/components/uv-swiper-indicator/uv-swiper-indicator.vue +112 -0
- package/components/uv-switch/props.js +58 -0
- package/components/uv-switch/uv-switch.vue +182 -0
- package/components/uv-tabbar/props.js +50 -0
- package/components/uv-tabbar/uv-tabbar.vue +146 -0
- package/components/uv-tabbar-item/props.js +40 -0
- package/components/uv-tabbar-item/uv-tabbar-item.vue +146 -0
- package/components/uv-tabs/props.js +71 -0
- package/components/uv-tabs/uv-tabs.vue +391 -0
- package/components/uv-tags/props.js +104 -0
- package/components/uv-tags/uv-tags.vue +379 -0
- package/components/uv-text/props.js +113 -0
- package/components/uv-text/uv-text.vue +218 -0
- package/components/uv-text/value.js +87 -0
- package/components/uv-textarea/props.js +138 -0
- package/components/uv-textarea/uv-textarea.vue +238 -0
- package/components/uv-toast/uv-toast.vue +292 -0
- package/components/uv-toolbar/props.js +40 -0
- package/components/uv-toolbar/uv-toolbar.vue +109 -0
- package/components/uv-tooltip/props.js +60 -0
- package/components/uv-tooltip/uv-tooltip.vue +372 -0
- package/components/uv-transition/createAnimation.js +131 -0
- package/components/uv-transition/props.js +31 -0
- package/components/uv-transition/uv-transition.vue +320 -0
- package/components/uv-upload/mixin.js +22 -0
- package/components/uv-upload/props.js +130 -0
- package/components/uv-upload/utils.js +151 -0
- package/components/uv-upload/uv-upload.vue +488 -0
- package/components/uv-vtabs/props.js +79 -0
- package/components/uv-vtabs/uv-vtabs.vue +438 -0
- package/components/uv-vtabs-item/uv-vtabs-item.vue +68 -0
- package/components/uv-waterfall/props.js +69 -0
- package/components/uv-waterfall/uv-waterfall.vue +265 -0
- package/index.js +82 -0
- package/index.scss +7 -0
- package/libs/config/config.js +34 -0
- package/libs/css/color.scss +32 -0
- package/libs/css/common.scss +100 -0
- package/libs/css/components.scss +23 -0
- package/libs/css/variable.scss +111 -0
- package/libs/css/vue.scss +40 -0
- package/libs/function/colorGradient.js +134 -0
- package/libs/function/compress.js +27 -0
- package/libs/function/debounce.js +29 -0
- package/libs/function/digit.js +167 -0
- package/libs/function/index.js +734 -0
- package/libs/function/platform.js +75 -0
- package/libs/function/test.js +287 -0
- package/libs/function/throttle.js +30 -0
- package/libs/luch-request/adapters/index.js +132 -0
- package/libs/luch-request/core/InterceptorManager.js +51 -0
- package/libs/luch-request/core/Request.js +201 -0
- package/libs/luch-request/core/buildFullPath.js +20 -0
- package/libs/luch-request/core/defaults.js +33 -0
- package/libs/luch-request/core/dispatchRequest.js +6 -0
- package/libs/luch-request/core/mergeConfig.js +126 -0
- package/libs/luch-request/core/settle.js +16 -0
- package/libs/luch-request/helpers/buildURL.js +64 -0
- package/libs/luch-request/helpers/combineURLs.js +14 -0
- package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/libs/luch-request/index.d.ts +197 -0
- package/libs/luch-request/index.js +2 -0
- package/libs/luch-request/utils/clone.js +264 -0
- package/libs/luch-request/utils.js +135 -0
- package/libs/mixin/button.js +13 -0
- package/libs/mixin/mixin.js +172 -0
- package/libs/mixin/mpMixin.js +8 -0
- package/libs/mixin/mpShare.js +13 -0
- package/libs/mixin/openType.js +47 -0
- package/libs/mixin/touch.js +59 -0
- package/libs/util/dayjs.js +216 -0
- package/libs/util/route.js +126 -0
- package/package.json +28 -0
- package/theme.scss +43 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="uv-form">
|
|
3
|
+
<slot />
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import mpMixin from '../../libs/mixin/mpMixin.js'
|
|
9
|
+
import mixin from '../../libs/mixin/mixin.js'
|
|
10
|
+
import props from "./props.js";
|
|
11
|
+
import Schema from "./valid.js";
|
|
12
|
+
// 去除警告信息
|
|
13
|
+
Schema.warning = function() {};
|
|
14
|
+
/**
|
|
15
|
+
* Form 表单
|
|
16
|
+
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
17
|
+
* @tutorial https://www.uvui.cn/components/form.html
|
|
18
|
+
* @property {Object} model 当前form的需要验证字段的集合
|
|
19
|
+
* @property {Object | Function | Array} rules 验证规则
|
|
20
|
+
* @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
|
|
21
|
+
* @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
|
|
22
|
+
* @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
|
|
23
|
+
* @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
|
|
24
|
+
* @property {String} labelAlign lable字体的对齐方式 ( 默认 ‘left' )
|
|
25
|
+
* @property {Object} labelStyle lable的样式,对象形式
|
|
26
|
+
* @example <uv-form labelPosition="left" :model="model1" :rules="rules" ref="form1"></uv-form>
|
|
27
|
+
*/
|
|
28
|
+
export default {
|
|
29
|
+
name: "uv-form",
|
|
30
|
+
mixins: [mpMixin, mixin, props],
|
|
31
|
+
provide() {
|
|
32
|
+
return {
|
|
33
|
+
uForm: this,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
data() {
|
|
37
|
+
return {
|
|
38
|
+
formRules: {},
|
|
39
|
+
// 规则校验器
|
|
40
|
+
validator: {},
|
|
41
|
+
// 原始的model快照,用于resetFields方法重置表单时使用
|
|
42
|
+
originalModel: null,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
watch: {
|
|
46
|
+
// 监听规则的变化
|
|
47
|
+
rules: {
|
|
48
|
+
immediate: true,
|
|
49
|
+
handler(n) {
|
|
50
|
+
this.setRules(n);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
// 监听属性的变化,通知子组件uv-form-item重新获取信息
|
|
54
|
+
propsChange(n) {
|
|
55
|
+
if (this.children?.length) {
|
|
56
|
+
this.children.map((child) => {
|
|
57
|
+
// 判断子组件(uv-form-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
|
|
58
|
+
typeof child.updateParentData == "function" &&
|
|
59
|
+
child.updateParentData();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
// 监听model的初始值作为重置表单的快照
|
|
64
|
+
model: {
|
|
65
|
+
immediate: true,
|
|
66
|
+
handler(n) {
|
|
67
|
+
if (!this.originalModel) {
|
|
68
|
+
this.originalModel = this.$uv.deepClone(n);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
computed: {
|
|
74
|
+
propsChange() {
|
|
75
|
+
return [
|
|
76
|
+
this.errorType,
|
|
77
|
+
this.borderBottom,
|
|
78
|
+
this.labelPosition,
|
|
79
|
+
this.labelWidth,
|
|
80
|
+
this.labelAlign,
|
|
81
|
+
this.labelStyle,
|
|
82
|
+
];
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
created() {
|
|
86
|
+
// 存储当前form下的所有uv-form-item的实例
|
|
87
|
+
// 不能定义在data中,否则微信小程序会造成循环引用而报错
|
|
88
|
+
this.children = [];
|
|
89
|
+
},
|
|
90
|
+
methods: {
|
|
91
|
+
// 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
|
|
92
|
+
setRules(rules) {
|
|
93
|
+
// 判断是否有规则
|
|
94
|
+
if (Object.keys(rules).length === 0) return;
|
|
95
|
+
if (process.env.NODE_ENV === 'development' && Object.keys(this.model).length === 0) {
|
|
96
|
+
this.$uv.error('设置rules,model必须设置!如果已经设置,请刷新页面。');
|
|
97
|
+
return;
|
|
98
|
+
};
|
|
99
|
+
this.formRules = rules;
|
|
100
|
+
// 重新将规则赋予Validator
|
|
101
|
+
this.validator = new Schema(rules);
|
|
102
|
+
},
|
|
103
|
+
// 清空所有uv-form-item组件的内容,本质上是调用了uv-form-item组件中的resetField()方法
|
|
104
|
+
resetFields() {
|
|
105
|
+
this.resetModel();
|
|
106
|
+
},
|
|
107
|
+
// 重置model为初始值的快照
|
|
108
|
+
resetModel(obj) {
|
|
109
|
+
// 历遍所有uv-form-item,根据其prop属性,还原model的原始快照
|
|
110
|
+
this.children.map((child) => {
|
|
111
|
+
const prop = child?.prop;
|
|
112
|
+
const value = this.$uv.getProperty(this.originalModel, prop);
|
|
113
|
+
this.$uv.setProperty(this.model, prop, value);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
// 清空校验结果
|
|
117
|
+
clearValidate(props) {
|
|
118
|
+
props = [].concat(props);
|
|
119
|
+
this.children.map((child) => {
|
|
120
|
+
// 如果uv-form-item的prop在props数组中,则清除对应的校验结果信息
|
|
121
|
+
if (props[0] === undefined || props.includes(child.prop)) {
|
|
122
|
+
child.message = null;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
// 对部分表单字段进行校验
|
|
127
|
+
async validateField(value, callback, event = null) {
|
|
128
|
+
// $nextTick是必须的,否则model的变更,可能会延后于此方法的执行
|
|
129
|
+
this.$nextTick(() => {
|
|
130
|
+
// 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息
|
|
131
|
+
const errorsRes = [];
|
|
132
|
+
// 如果为字符串,转为数组
|
|
133
|
+
value = [].concat(value);
|
|
134
|
+
// 历遍children所有子form-item
|
|
135
|
+
this.children.map((child) => {
|
|
136
|
+
// 用于存放form-item的错误信息
|
|
137
|
+
const childErrors = [];
|
|
138
|
+
if (value.includes(child.prop)) {
|
|
139
|
+
// 获取对应的属性,通过类似'a.b.c'的形式
|
|
140
|
+
const propertyVal = this.$uv.getProperty(
|
|
141
|
+
this.model,
|
|
142
|
+
child.prop
|
|
143
|
+
);
|
|
144
|
+
// 属性链数组
|
|
145
|
+
const propertyChain = child.prop.split(".");
|
|
146
|
+
const propertyName =
|
|
147
|
+
propertyChain[propertyChain.length - 1];
|
|
148
|
+
|
|
149
|
+
const rule = this.formRules[child.prop];
|
|
150
|
+
// 如果不存在对应的规则,直接返回,否则校验器会报错
|
|
151
|
+
if (!rule) return;
|
|
152
|
+
// rule规则可为数组形式,也可为对象形式,此处拼接成为数组
|
|
153
|
+
const rules = [].concat(rule);
|
|
154
|
+
|
|
155
|
+
// 对rules数组进行校验
|
|
156
|
+
for (let i = 0; i < rules.length; i++) {
|
|
157
|
+
const ruleItem = rules[i];
|
|
158
|
+
// 将uv-form-item的触发器转为数组形式
|
|
159
|
+
const trigger = [].concat(ruleItem?.trigger);
|
|
160
|
+
// 如果是有传入触发事件,但是此form-item却没有配置此触发器的话,不执行校验操作
|
|
161
|
+
if (event && !trigger.includes(event)) continue;
|
|
162
|
+
// 实例化校验对象,传入构造规则
|
|
163
|
+
const validator = new Schema({
|
|
164
|
+
[propertyName]: ruleItem,
|
|
165
|
+
});
|
|
166
|
+
validator.validate({
|
|
167
|
+
[propertyName]: propertyVal,
|
|
168
|
+
},
|
|
169
|
+
(errors, fields) => {
|
|
170
|
+
if (this.$uv.test.array(errors)) {
|
|
171
|
+
errorsRes.push(...errors);
|
|
172
|
+
childErrors.push(...errors);
|
|
173
|
+
}
|
|
174
|
+
this.$nextTick(() => {
|
|
175
|
+
child.message = childErrors[0]?.message ? childErrors[0]?.message : null;
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
// 执行回调函数
|
|
183
|
+
typeof callback === "function" && callback(errorsRes);
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
// 校验全部数据
|
|
187
|
+
validate(callback) {
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
// $nextTick是必须的,否则model的变更,可能会延后于validate方法
|
|
190
|
+
this.$nextTick(() => {
|
|
191
|
+
// 获取所有form-item的prop,交给validateField方法进行校验
|
|
192
|
+
const formItemProps = this.children.map(
|
|
193
|
+
(item) => item.prop
|
|
194
|
+
);
|
|
195
|
+
this.validateField(formItemProps, (errors) => {
|
|
196
|
+
if (errors.length) {
|
|
197
|
+
// 如果错误提示方式为toast,则进行提示
|
|
198
|
+
this.errorType === 'toast' && this.$uv.toast(errors[0].message)
|
|
199
|
+
reject(errors)
|
|
200
|
+
} else {
|
|
201
|
+
resolve(true)
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
</script>
|