@10yun/cv-mobile-ui 0.5.50 → 0.5.52
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/build/common_func.js +3 -1
- package/build/parse-create.js +17 -8
- package/build/parse-pages-pkg.js +10 -4
- package/empty-devtools.js +3 -0
- package/libs/aes.js +50 -0
- package/libs/bledefine/bledefine.js +51 -0
- package/libs/bledefine/ios-ble-statuscode.js +97 -0
- package/libs/nfc/hexiii-nfc.js +236 -0
- package/libs/nfc.js +179 -0
- package/libs/sdk/html2canvas.js +8 -0
- package/libs/sdk/sdk-h5.js +585 -0
- package/{plugins → libs}/storage2.js +0 -5
- package/{plugins → libs}/storage3.js +0 -4
- package/libs/validators/index.js +438 -0
- package/libs/weapp-qrcode.js +1108 -0
- package/package.json +2 -3
- package/ui-cv/components/cv-dialog-share/tui-share.vue +16 -16
- package/ui-cv/components/cv-mask-png/cv-mask-png.vue +27 -0
- package/ui-cv/components/cv-mask-svg/cv-mask-svg.vue +22 -0
- package/ui-cv/components/cv-mask-svg/mixins.js +131 -0
- package/ui-fireui/components/{fui-actionsheet/fui-actionsheet.vue → u-action-sheet/u-action-sheet.vue} +21 -21
- package/ui-fireui/components/{fui-alert/fui-alert.vue → u-alert/u-alert.vue} +13 -13
- package/ui-fireui/components/{fui-badge/fui-badge.vue → u-badge/u-badge.vue} +16 -16
- package/ui-fireui/components/{fui-bottom-navigation/fui-bottom-navigation.vue → u-bottom-navigation/u-bottom-navigation.vue} +47 -46
- package/ui-fireui/components/{fui-bottom-popup/fui-bottom-popup.vue → u-bottom-popup/u-bottom-popup.vue} +9 -8
- package/ui-fireui/components/{fui-bubble-popup/fui-bubble-popup.vue → u-bubble-popup/u-bubble-popup.vue} +19 -15
- package/ui-fireui/components/{fui-button/fui-button.vue → u-button/u-button.vue} +69 -69
- package/ui-fireui/components/u-button/u-button2.vue +553 -0
- package/ui-fireui/components/{fui-calendar/fui-calendar.vue → u-calendar/u-calendar.vue} +78 -78
- package/ui-fireui/components/u-calendar/u-calendar2.vue +801 -0
- package/ui-fireui/components/{fui-card/fui-card.vue → u-card/u-card.vue} +24 -24
- package/ui-fireui/components/{fui-cascade-selection/fui-cascade-selection.vue → u-cascade-selection/u-cascade-selection.vue} +32 -32
- package/ui-fireui/components/{fui-circular-progress/fui-circular-progress.vue → u-circular-progress/u-circular-progress.vue} +14 -6
- package/ui-fireui/components/{fui-collapse/fui-collapse.vue → u-collapse/u-collapse.vue} +19 -19
- package/ui-fireui/components/{fui-countdown/fui-countdown.vue → u-countdown/u-countdown.vue} +28 -28
- package/ui-fireui/components/{fui-datetime/fui-datetime.vue → u-datetime/u-datetime.vue} +51 -51
- package/ui-fireui/components/{fui-divider/fui-divider.vue → u-divider/u-divider.vue} +6 -6
- package/ui-fireui/components/{fui-drawer/fui-drawer.vue → u-drawer/u-drawer.vue} +11 -11
- package/ui-fireui/components/{fui-dropdown-list/fui-dropdown-list.vue → u-dropdown-list/u-dropdown-list.vue} +11 -6
- package/ui-fireui/components/{fui-fab/fui-fab.vue → u-fab/u-fab.vue} +30 -30
- package/ui-fireui/components/{fui-footer/fui-footer.vue → u-footer/u-footer.vue} +19 -15
- package/ui-fireui/components/{fui-grid/fui-grid.vue → u-grid/u-grid.vue} +13 -5
- package/ui-fireui/components/{fui-grid-item/fui-grid-item.vue → u-grid-item/u-grid-item.vue} +19 -19
- package/ui-fireui/components/{fui-icon/fui-icon.vue → u-icon/u-icon.vue} +191 -191
- package/ui-fireui/components/{fui-image-cropper/fui-image-cropper.vue → u-image-cropper/u-image-cropper.vue} +44 -44
- package/ui-fireui/components/{fui-image-group/fui-image-group.vue → u-image-group/u-image-group.vue} +7 -7
- package/ui-fireui/components/{fui-keyboard/fui-keyboard.vue → u-keyboard/u-keyboard.vue} +29 -32
- package/ui-fireui/components/{fui-keyboard-input/fui-keyboard-input.vue → u-keyboard-input/u-keyboard-input.vue} +9 -9
- package/ui-fireui/components/{fui-list-cell/fui-list-cell.vue → u-list-cell/u-list-cell.vue} +23 -23
- package/ui-fireui/components/{fui-list-view/fui-list-view.vue → u-list-view/u-list-view.vue} +11 -11
- package/ui-fireui/components/{fui-loading/fui-loading.vue → u-loading/u-loading.vue} +6 -6
- package/ui-fireui/components/{fui-loadmore/fui-loadmore.vue → u-loadmore/u-loadmore.vue} +15 -15
- package/ui-fireui/components/{fui-modal/fui-modal.vue → u-modal/u-modal.vue} +58 -58
- package/ui-fireui/components/{fui-navigation-bar/fui-navigation-bar.vue → u-navigation-bar/u-navigation-bar.vue} +11 -10
- package/ui-fireui/components/{fui-no-data/fui-no-data.vue → u-no-data/u-no-data.vue} +11 -11
- package/ui-fireui/components/{fui-nomore/fui-nomore.vue → u-nomore/u-nomore.vue} +10 -10
- package/ui-fireui/components/{fui-numberbox/fui-numberbox.vue → u-numberbox/u-numberbox.vue} +12 -12
- package/ui-fireui/components/{fui-numberbox-border/fui-numberbox-border.vue → u-numberbox-border/u-numberbox-border.vue} +10 -10
- package/ui-fireui/components/{fui-picture-cropper/fui-picture-cropper.vue → u-picture-cropper/u-picture-cropper.vue} +42 -42
- package/ui-fireui/components/u-picture-cropper/u-picture-cropper.wxs +582 -0
- package/ui-fireui/components/{fui-round-progress/fui-round-progress.vue → u-round-progress/u-round-progress.vue} +2 -2
- package/ui-fireui/components/{fui-scroll-top/fui-scroll-top.vue → u-scroll-top/u-scroll-top.vue} +21 -21
- package/ui-fireui/components/{fui-sharemodel/fui-sharemodel.vue → u-share-model/u-share-model.vue} +24 -24
- package/ui-fireui/components/{fui-skeleton/fui-skeleton.vue → u-skeleton/u-skeleton.vue} +22 -22
- package/ui-fireui/components/{fui-steps/fui-steps.vue → u-steps/u-steps.vue} +27 -27
- package/ui-fireui/components/{fui-sticky/fui-sticky.vue → u-sticky/u-sticky.vue} +4 -4
- package/ui-fireui/components/{fui-sticky-wxs/fui-sticky-wxs.vue → u-sticky-wxs/u-sticky-wxs.vue} +7 -7
- package/ui-fireui/components/u-sticky-wxs/u-sticky.wxs +46 -0
- package/ui-fireui/components/{fui-swipe-action/fui-swipe-action.vue → u-swipe-action/u-swipe-action.vue} +11 -11
- package/ui-fireui/components/{fui-tabbar/fui-tabbar.vue → u-tabbar/u-tabbar.vue} +26 -30
- package/ui-fireui/components/{fui-tabs/fui-tabs.vue → u-tabs/u-tabs.vue} +17 -17
- package/ui-fireui/components/{fui-tabs2/fui-tabs2.vue → u-tabs2/u-tabs2.vue} +17 -17
- package/ui-fireui/components/{fui-tag/fui-tag.vue → u-tag/u-tag.vue} +362 -374
- package/ui-fireui/components/{fui-time-axis/fui-time-axis.vue → u-time-axis/u-time-axis.vue} +3 -3
- package/ui-fireui/components/{fui-timeaxis-item/fui-timeaxis-item.vue → u-timeaxis-item/u-timeaxis-item.vue} +4 -4
- package/ui-fireui/components/{fui-tips/fui-tips.vue → u-tips/u-tips.vue} +20 -20
- package/ui-fireui/components/{fui-toast/fui-toast.vue → u-toast/u-toast.vue} +13 -13
- package/ui-fireui/components/{fui-top-dropdown/fui-top-dropdown.vue → u-top-dropdown/u-top-dropdown.vue} +8 -8
- package/ui-fireui/components/{fui-upload/fui-upload.vue → u-upload/u-upload.vue} +30 -30
- package/ui-fireui/components/u-upload2/u-upload.vue +464 -0
- package/ui-fireui/components/{fui-uploadsamll/fui-uploadsamll.vue → u-uploadsamll/u-uploadsamll.vue} +34 -34
- package/ui-fireui/css/thorui.css +589 -0
- package/ui-fireui/{fireui.css → index.css} +306 -268
- package/ui-fireui/nvue/u-circular-progress/gcanvas/bridge/bridge-weex.js +241 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-2d/FillStyleLinearGradient.js +18 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-2d/FillStylePattern.js +8 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-2d/FillStyleRadialGradient.js +17 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-2d/RenderingContext.js +666 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/ActiveInfo.js +11 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/Buffer.js +21 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/Framebuffer.js +21 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/GLenum.js +298 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/GLmethod.js +142 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/GLtype.js +23 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/Program.js +21 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/Renderbuffer.js +21 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/RenderingContext.js +1191 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/Shader.js +22 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/ShaderPrecisionFormat.js +11 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/Texture.js +22 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/UniformLocation.js +22 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/context-webgl/classUtils.js +3 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/env/canvas.js +74 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/env/image.js +96 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/env/tool.js +24 -0
- package/ui-fireui/nvue/u-circular-progress/gcanvas/index.js +47 -0
- package/ui-fireui/nvue/u-circular-progress/u-circular-progress.nvue +203 -0
- package/ui-fireui/nvue/u-icon/icons.js +188 -0
- package/ui-fireui/nvue/u-icon/u-icon.vue +78 -0
- package/uview-plus/components/u-grid/u-grid.vue +23 -1
- package/ui-fireui/components/fui-picture-cropper/fui-picture-cropper.wxs +0 -560
- package/ui-fireui/components/fui-rate/fui-rate.vue +0 -167
- package/ui-fireui/components/fui-sticky-wxs/fui-sticky.wxs +0 -44
- /package/ui-fireui/components/{fui-calendar/fui-calendar.js → u-calendar/u-calendar.js} +0 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表单验证
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} ruleMessage 验证规则,验证信息(规则存在为空:默认验证信息。不为空:自定义验证信息)
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
class Validate {
|
|
8
|
+
constructor(ruleMessage) {
|
|
9
|
+
Object.assign(this, {
|
|
10
|
+
data: {},
|
|
11
|
+
rules: {},
|
|
12
|
+
messages: ruleMessage
|
|
13
|
+
});
|
|
14
|
+
this.__init();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* __init
|
|
18
|
+
*/
|
|
19
|
+
__init() {
|
|
20
|
+
this.__initRules();
|
|
21
|
+
this.__initMethods();
|
|
22
|
+
this.__initDefaults();
|
|
23
|
+
this.__initData();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 初始化数据
|
|
28
|
+
*/
|
|
29
|
+
__initData() {
|
|
30
|
+
this.form = {};
|
|
31
|
+
this.errorList = [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 初始化rules
|
|
36
|
+
*/
|
|
37
|
+
__initRules() {
|
|
38
|
+
let obj = {};
|
|
39
|
+
for (let rule in this.messages) {
|
|
40
|
+
obj[rule] = {};
|
|
41
|
+
for (let item in this.messages[rule]) {
|
|
42
|
+
obj[rule][item] = 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
this.rules = obj;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 初始化默认提示信息
|
|
50
|
+
*/
|
|
51
|
+
__initDefaults() {
|
|
52
|
+
this.defaults = {
|
|
53
|
+
messages: {
|
|
54
|
+
required: '这是必填字段。',
|
|
55
|
+
email: '请输入有效的电子邮件地址。',
|
|
56
|
+
tel: '请输入11位的手机号码。',
|
|
57
|
+
url: '请输入有效的网址。',
|
|
58
|
+
date: '请输入有效的日期。',
|
|
59
|
+
dateISO: '请输入有效的日期(ISO),例如:2009-06-23,1998/01/22。',
|
|
60
|
+
number: '请输入有效的数字。',
|
|
61
|
+
digits: '只能输入数字。',
|
|
62
|
+
idcard: '请输入18位的有效身份证。',
|
|
63
|
+
equalTo: this.formatTpl('输入值必须和 {0} 相同。'),
|
|
64
|
+
contains: this.formatTpl('输入值必须包含 {0}。'),
|
|
65
|
+
minlength: this.formatTpl('最少要输入 {0} 个字符。'),
|
|
66
|
+
maxlength: this.formatTpl('最多可以输入 {0} 个字符。'),
|
|
67
|
+
rangelength: this.formatTpl('请输入长度在 {0} 到 {1} 之间的字符。'),
|
|
68
|
+
min: this.formatTpl('请输入不小于 {0} 的数值。'),
|
|
69
|
+
max: this.formatTpl('请输入不大于 {0} 的数值。'),
|
|
70
|
+
range: this.formatTpl('请输入范围在 {0} 到 {1} 之间的数值。')
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 初始化默认验证方法
|
|
77
|
+
*/
|
|
78
|
+
__initMethods() {
|
|
79
|
+
const that = this;
|
|
80
|
+
that.methods = {
|
|
81
|
+
/**
|
|
82
|
+
* 验证必填元素
|
|
83
|
+
*/
|
|
84
|
+
required(value, param) {
|
|
85
|
+
if (!that.depend(param)) {
|
|
86
|
+
return 'dependency-mismatch';
|
|
87
|
+
} else if (typeof value === 'number') {
|
|
88
|
+
value = value.toString();
|
|
89
|
+
} else if (typeof value === 'boolean') {
|
|
90
|
+
return !0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return value.length > 0;
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* 验证电子邮箱格式
|
|
97
|
+
*/
|
|
98
|
+
email(value) {
|
|
99
|
+
return (
|
|
100
|
+
that.optional(value) ||
|
|
101
|
+
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(
|
|
102
|
+
value
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* 验证手机格式
|
|
108
|
+
*/
|
|
109
|
+
tel(value) {
|
|
110
|
+
return that.optional(value) || /^1[3456789]\d{9}$/.test(value);
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* 验证URL格式
|
|
114
|
+
*/
|
|
115
|
+
url(value) {
|
|
116
|
+
return (
|
|
117
|
+
that.optional(value) ||
|
|
118
|
+
/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(
|
|
119
|
+
value
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* 验证日期格式
|
|
125
|
+
*/
|
|
126
|
+
date(value) {
|
|
127
|
+
return that.optional(value) || !/Invalid|NaN/.test(new Date(value).toString());
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* 验证ISO类型的日期格式
|
|
131
|
+
*/
|
|
132
|
+
dateISO(value) {
|
|
133
|
+
return that.optional(value) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value);
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* 验证十进制数字
|
|
137
|
+
*/
|
|
138
|
+
number(value) {
|
|
139
|
+
return that.optional(value) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* 验证整数
|
|
143
|
+
*/
|
|
144
|
+
digits(value) {
|
|
145
|
+
return that.optional(value) || /^\d+$/.test(value);
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* 验证身份证号码
|
|
149
|
+
*/
|
|
150
|
+
idcard(value) {
|
|
151
|
+
return that.optional(value) || /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value);
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* 验证两个输入框的内容是否相同
|
|
155
|
+
*/
|
|
156
|
+
equalTo(value, param) {
|
|
157
|
+
return that.optional(value) || value === that.data[param];
|
|
158
|
+
},
|
|
159
|
+
/**
|
|
160
|
+
* 验证是否包含某个值
|
|
161
|
+
*/
|
|
162
|
+
contains(value, param) {
|
|
163
|
+
return that.optional(value) || value.indexOf(param) >= 0;
|
|
164
|
+
},
|
|
165
|
+
/**
|
|
166
|
+
* 验证最小长度
|
|
167
|
+
*/
|
|
168
|
+
minlength(value, param) {
|
|
169
|
+
return that.optional(value) || value.length >= param;
|
|
170
|
+
},
|
|
171
|
+
/**
|
|
172
|
+
* 验证最大长度
|
|
173
|
+
*/
|
|
174
|
+
maxlength(value, param) {
|
|
175
|
+
return that.optional(value) || value.length <= param;
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* 验证一个长度范围[min, max]
|
|
179
|
+
*/
|
|
180
|
+
rangelength(value, param) {
|
|
181
|
+
return that.optional(value) || (value.length >= param[0] && value.length <= param[1]);
|
|
182
|
+
},
|
|
183
|
+
/**
|
|
184
|
+
* 验证最小值
|
|
185
|
+
*/
|
|
186
|
+
min(value, param) {
|
|
187
|
+
return that.optional(value) || value >= param;
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* 验证最大值
|
|
191
|
+
*/
|
|
192
|
+
max(value, param) {
|
|
193
|
+
return that.optional(value) || value <= param;
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* 验证一个值范围[min, max]
|
|
197
|
+
*/
|
|
198
|
+
range(value, param) {
|
|
199
|
+
return that.optional(value) || (value >= param[0] && value <= param[1]);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 添加自定义验证方法
|
|
206
|
+
* @param {String} name 方法名
|
|
207
|
+
* @param {Function} method 函数体,接收两个参数(value, param),value表示元素的值,param表示参数
|
|
208
|
+
* @param {String} message 提示信息
|
|
209
|
+
*/
|
|
210
|
+
addMethod(name, method, message) {
|
|
211
|
+
this.methods[name] = method;
|
|
212
|
+
this.defaults.messages[name] = message !== undefined ? message : this.defaults.messages[name];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 判断验证方法是否存在
|
|
217
|
+
*/
|
|
218
|
+
isValidMethod(value) {
|
|
219
|
+
let methods = [];
|
|
220
|
+
for (let method in this.methods) {
|
|
221
|
+
if (method && typeof this.methods[method] === 'function') {
|
|
222
|
+
methods.push(method);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return methods.indexOf(value) !== -1;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 格式化提示信息模板
|
|
230
|
+
*/
|
|
231
|
+
formatTpl(source, params) {
|
|
232
|
+
const that = this;
|
|
233
|
+
if (arguments.length === 1) {
|
|
234
|
+
return function () {
|
|
235
|
+
let args = Array.from(arguments);
|
|
236
|
+
args.unshift(source);
|
|
237
|
+
return that.formatTpl.apply(this, args);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (params === undefined) {
|
|
241
|
+
return source;
|
|
242
|
+
}
|
|
243
|
+
if (arguments.length > 2 && params.constructor !== Array) {
|
|
244
|
+
params = Array.from(arguments).slice(1);
|
|
245
|
+
}
|
|
246
|
+
if (params.constructor !== Array) {
|
|
247
|
+
params = [params];
|
|
248
|
+
}
|
|
249
|
+
params.forEach(function (n, i) {
|
|
250
|
+
source = source.replace(new RegExp('\\{' + i + '\\}', 'g'), function () {
|
|
251
|
+
return n;
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
return source;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 判断规则依赖是否存在
|
|
259
|
+
*/
|
|
260
|
+
depend(param) {
|
|
261
|
+
switch (typeof param) {
|
|
262
|
+
case 'boolean':
|
|
263
|
+
param = param;
|
|
264
|
+
break;
|
|
265
|
+
case 'string':
|
|
266
|
+
param = !!param.length;
|
|
267
|
+
break;
|
|
268
|
+
case 'function':
|
|
269
|
+
param = param();
|
|
270
|
+
default:
|
|
271
|
+
param = !0;
|
|
272
|
+
}
|
|
273
|
+
return param;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* 判断输入值是否为空
|
|
278
|
+
*/
|
|
279
|
+
optional(value) {
|
|
280
|
+
return !this.methods.required(value) && 'dependency-mismatch';
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 获取自定义字段的提示信息
|
|
285
|
+
* @param {String} param 字段名
|
|
286
|
+
* @param {Object} rule 规则
|
|
287
|
+
*/
|
|
288
|
+
customMessage(param, rule) {
|
|
289
|
+
const params = this.messages[param];
|
|
290
|
+
const isObject = typeof params === 'object';
|
|
291
|
+
if (params && isObject) return params[rule.method];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 获取某个指定字段的提示信息
|
|
296
|
+
* @param {String} param 字段名
|
|
297
|
+
* @param {Object} rule 规则
|
|
298
|
+
*/
|
|
299
|
+
defaultMessage(param, rule) {
|
|
300
|
+
let message = this.customMessage(param, rule) || this.defaults.messages[rule.method];
|
|
301
|
+
let type = typeof message;
|
|
302
|
+
|
|
303
|
+
if (type === 'undefined') {
|
|
304
|
+
message = `Warning: No message defined for ${rule.method}.`;
|
|
305
|
+
} else if (type === 'function') {
|
|
306
|
+
message = message.call(this, rule.parameters);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return message;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 缓存错误信息
|
|
314
|
+
* @param {String} param 字段名
|
|
315
|
+
* @param {Object} rule 规则
|
|
316
|
+
* @param {String} value 元素的值
|
|
317
|
+
*/
|
|
318
|
+
formatTplAndAdd(param, rule, value) {
|
|
319
|
+
let msg = this.defaultMessage(param, rule);
|
|
320
|
+
|
|
321
|
+
this.errorList.push({
|
|
322
|
+
param: param,
|
|
323
|
+
msg: msg,
|
|
324
|
+
value: value
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 验证某个指定字段的规则
|
|
330
|
+
* @param {String} param 字段名
|
|
331
|
+
* @param {Object} rules 规则
|
|
332
|
+
* @param {Object} data 需要验证的数据对象
|
|
333
|
+
*/
|
|
334
|
+
checkParam(param, rules, data) {
|
|
335
|
+
// 缓存数据对象
|
|
336
|
+
this.data = data;
|
|
337
|
+
|
|
338
|
+
// 缓存字段对应的值
|
|
339
|
+
const value = data[param] !== null && data[param] !== undefined ? data[param] : '';
|
|
340
|
+
|
|
341
|
+
// 遍历某个指定字段的所有规则,依次验证规则,否则缓存错误信息
|
|
342
|
+
for (let method in rules) {
|
|
343
|
+
// 判断验证方法是否存在
|
|
344
|
+
if (this.isValidMethod(method)) {
|
|
345
|
+
// 缓存规则的属性及值
|
|
346
|
+
const rule = {
|
|
347
|
+
method: method,
|
|
348
|
+
parameters: rules[method]
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// 调用验证方法
|
|
352
|
+
const result = this.methods[method](value, rule.parameters);
|
|
353
|
+
|
|
354
|
+
// 若result返回值为dependency-mismatch,则说明该字段的值为空或非必填字段
|
|
355
|
+
if (result === 'dependency-mismatch') {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this.setValue(param, method, result, value);
|
|
360
|
+
|
|
361
|
+
// 判断是否通过验证,否则缓存错误信息,跳出循环
|
|
362
|
+
if (!result) {
|
|
363
|
+
this.formatTplAndAdd(param, rule, value);
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* 设置字段的默认验证值
|
|
372
|
+
* @param {String} param 字段名
|
|
373
|
+
*/
|
|
374
|
+
setView(param) {
|
|
375
|
+
this.form[param] = {
|
|
376
|
+
$name: param,
|
|
377
|
+
$valid: true,
|
|
378
|
+
$invalid: false,
|
|
379
|
+
$error: {},
|
|
380
|
+
$success: {},
|
|
381
|
+
$viewValue: ``
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* 设置字段的验证值
|
|
387
|
+
* @param {String} param 字段名
|
|
388
|
+
* @param {String} method 字段的方法
|
|
389
|
+
* @param {Boolean} result 是否通过验证
|
|
390
|
+
* @param {String} value 字段的值
|
|
391
|
+
*/
|
|
392
|
+
setValue(param, method, result, value) {
|
|
393
|
+
const params = this.form[param];
|
|
394
|
+
params.$valid = result;
|
|
395
|
+
params.$invalid = !result;
|
|
396
|
+
params.$error[method] = !result;
|
|
397
|
+
params.$success[method] = result;
|
|
398
|
+
params.$viewValue = value;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* 验证所有字段的规则,返回验证是否通过
|
|
403
|
+
* @param {Object} data 需要验证数据对象
|
|
404
|
+
*/
|
|
405
|
+
checkForm(data) {
|
|
406
|
+
this.__initData();
|
|
407
|
+
|
|
408
|
+
for (let param in this.rules) {
|
|
409
|
+
this.setView(param);
|
|
410
|
+
this.checkParam(param, this.rules[param], data);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return this.valid();
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* 返回验证是否通过
|
|
418
|
+
*/
|
|
419
|
+
valid() {
|
|
420
|
+
return this.size() === 0;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 返回错误信息的个数
|
|
425
|
+
*/
|
|
426
|
+
size() {
|
|
427
|
+
return this.errorList.length;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* 返回所有错误信息
|
|
432
|
+
*/
|
|
433
|
+
validationErrors() {
|
|
434
|
+
return this.errorList;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export default Validate;
|