@10yun/cv-mobile-ui 0.5.30 → 0.5.32
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/package.json +5 -1
- package/ui-cv/components/cv-btn-base/cv-btn-base.vue +1 -1
- package/uview-plus/README.md +1 -1
- package/uview-plus/components/u-action-sheet/u-action-sheet.vue +8 -8
- package/uview-plus/components/u-album/u-album.vue +1 -1
- package/uview-plus/components/u-alert/u-alert.vue +5 -5
- package/uview-plus/components/u-app-update/u-app-update.vue +2 -2
- package/uview-plus/components/u-avatar/u-avatar.vue +2 -2
- package/uview-plus/components/u-avatar-group/u-avatar-group.vue +79 -3
- package/uview-plus/components/u-back-top/u-back-top.vue +4 -4
- package/uview-plus/components/u-badge/u-badge.vue +1 -1
- package/uview-plus/components/u-button/u-button.vue +8 -8
- package/uview-plus/components/u-button-wu/u-button-wu.vue +9 -9
- package/uview-plus/components/u-calendar/u-calendar.vue +5 -6
- package/uview-plus/components/u-car-keyboard/u-car-keyboard.vue +2 -2
- package/uview-plus/components/u-card/u-card.vue +139 -3
- package/uview-plus/components/u-cell/u-cell.vue +4 -4
- package/uview-plus/components/u-cell-group/u-cell-group.vue +2 -2
- package/uview-plus/components/u-checkbox/u-checkbox.vue +4 -4
- package/uview-plus/components/u-checkbox-group/u-checkbox-group.vue +1 -1
- package/uview-plus/components/u-code/u-code.vue +1 -1
- package/uview-plus/components/u-code-input/u-code-input.vue +1 -1
- package/uview-plus/components/u-col/u-col.vue +1 -1
- package/uview-plus/components/u-collapse/u-collapse.vue +2 -2
- package/uview-plus/components/u-collapse-item/u-collapse-item.vue +218 -3
- package/uview-plus/components/u-column-notice/u-column-notice.vue +3 -3
- package/uview-plus/components/u-copy/u-copy.vue +68 -1
- package/uview-plus/components/u-count-down/u-count-down.vue +1 -1
- package/uview-plus/components/u-count-to/u-count-to.vue +1 -1
- package/uview-plus/components/u-datetime-picker/u-datetime-picker.vue +3 -3
- package/uview-plus/components/u-divider/u-divider.vue +3 -3
- package/uview-plus/components/u-dropdown/u-dropdown.vue +3 -3
- package/uview-plus/components/u-dropdown-item/u-dropdown-item.vue +1 -1
- package/uview-plus/components/u-empty/u-empty.vue +3 -3
- package/uview-plus/components/u-form/u-form.vue +243 -1
- package/uview-plus/components/u-form-item/u-form-item.vue +4 -4
- package/uview-plus/components/u-gap/u-gap.vue +1 -1
- package/uview-plus/components/u-grid/u-grid.vue +1 -1
- package/uview-plus/components/u-grid-item/u-grid-item.vue +1 -1
- package/uview-plus/components/u-icon/u-icon.vue +1 -1
- package/uview-plus/components/u-icon/u-icon2.vue +1 -1
- package/uview-plus/components/u-image/u-image.vue +5 -5
- package/uview-plus/components/u-image-wu/u-image-wu.vue +5 -5
- package/uview-plus/components/u-index-anchor/u-index-anchor.vue +1 -1
- package/uview-plus/components/u-index-list/u-index-list.vue +2 -2
- package/uview-plus/components/u-input/u-input.vue +4 -4
- package/uview-plus/components/u-keyboard/u-keyboard.vue +6 -6
- package/uview-plus/components/u-lazy-load/u-lazy-load.vue +257 -3
- package/uview-plus/components/u-line/u-line.vue +1 -1
- package/uview-plus/components/u-line-progress/u-line-progress.vue +1 -1
- package/uview-plus/components/u-link/u-link.vue +1 -1
- package/uview-plus/components/u-list/u-list.vue +1 -1
- package/uview-plus/components/u-list-item/u-list-item.vue +1 -1
- package/uview-plus/components/u-loading-icon/u-loading-icon.vue +191 -3
- package/uview-plus/components/u-loading-page/u-loading-page.vue +4 -4
- package/uview-plus/components/u-loadmore/u-loadmore.vue +4 -4
- package/uview-plus/components/u-mask/u-mask.vue +120 -113
- package/uview-plus/components/u-message-input/u-message-input.vue +1 -1
- package/uview-plus/components/u-modal/u-modal.vue +6 -6
- package/uview-plus/components/u-navbar/u-navbar.vue +4 -4
- package/uview-plus/components/u-navbar-mini/u-navbar-mini.vue +2 -2
- package/uview-plus/components/u-navbar-wu/u-navbar-wu.vue +4 -4
- package/uview-plus/components/u-no-network/u-no-network.vue +5 -5
- package/uview-plus/components/u-notice-bar/u-notice-bar.vue +5 -5
- package/uview-plus/components/u-notify/u-notify.vue +6 -6
- package/uview-plus/components/u-number-box/u-number-box.vue +9 -3
- package/uview-plus/components/u-number-keyboard/u-number-keyboard.vue +1 -1
- package/uview-plus/components/u-overlay/u-overlay.vue +3 -3
- package/uview-plus/components/u-picker/u-picker.vue +5 -5
- package/uview-plus/components/u-popup/u-popup.vue +8 -8
- package/uview-plus/components/u-popup-wu/u-popup-wu.vue +7 -7
- package/uview-plus/components/u-qrcode/u-qrcode.vue +275 -3
- package/uview-plus/components/u-radio/u-radio.vue +4 -4
- package/uview-plus/components/u-radio-group/u-radio-group.vue +1 -1
- package/uview-plus/components/u-rate/u-rate.vue +5 -5
- package/uview-plus/components/u-read-more/u-read-more.vue +126 -3
- package/uview-plus/components/u-row/u-row.vue +1 -1
- package/uview-plus/components/u-row-notice/u-row-notice.vue +3 -3
- package/uview-plus/components/u-safe-bottom/u-safe-bottom.vue +48 -3
- package/uview-plus/components/u-search/u-search.vue +4 -4
- package/uview-plus/components/u-select/u-select.vue +175 -3
- package/uview-plus/components/u-skeleton/u-skeleton.vue +3 -3
- package/uview-plus/components/u-sku-wu/u-sku-wu.vue +4 -4
- package/uview-plus/components/u-status-bar/u-status-bar.vue +1 -1
- package/uview-plus/components/u-steps/u-steps.vue +1 -1
- package/uview-plus/components/u-steps-item/u-steps-item.vue +7 -7
- package/uview-plus/components/u-sticky/u-sticky.vue +1 -1
- package/uview-plus/components/u-subsection/u-subsection.vue +1 -1
- package/uview-plus/components/u-swipe-action/u-swipe-action.vue +1 -1
- package/uview-plus/components/u-swipe-action-item/u-swipe-action-item.vue +3 -3
- package/uview-plus/components/u-swiper/u-swiper.vue +1 -1
- package/uview-plus/components/u-swiper-indicator/u-swiper-indicator.vue +1 -1
- package/uview-plus/components/u-switch/u-switch.vue +2 -2
- package/uview-plus/components/u-tabbar/u-tabbar.vue +2 -2
- package/uview-plus/components/u-tabbar-item/u-tabbar-item.vue +9 -4
- package/uview-plus/components/u-table/u-table.vue +1 -1
- package/uview-plus/components/u-tabs/u-tabs.vue +3 -3
- package/uview-plus/components/u-tag/u-tag.vue +5 -5
- package/uview-plus/components/u-text/u-text.vue +159 -3
- package/uview-plus/components/u-toast/u-toast.vue +8 -8
- package/uview-plus/components/u-tooltip/u-tooltip.vue +6 -6
- package/uview-plus/components/u-upload/u-upload.vue +10 -10
- package/uview-plus/components/u-waterfall/u-waterfall.vue +221 -3
- package/uview-plus/index.js +4 -2
- package/uview-plus/libs/ctocode/image.js +17 -0
- package/uview-plus/libs/ctocode/index.js +150 -0
- package/uview-plus/libs/ctocode/map.js +38 -0
- package/uview-plus/libs/function/index-wu.js +6 -34
- package/uview-plus/package.json +3 -3
- package/uview-plus/readme-wu.md +1 -1
- package/uview-plus/libs/function/cc.js +0 -66
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-empty" :style="[emptyStyle]" v-if="show">
|
|
3
|
-
<
|
|
3
|
+
<up-icon
|
|
4
4
|
v-if="!isSrc"
|
|
5
5
|
:name="mode === 'message' ? 'chat' : `empty-${mode}`"
|
|
6
6
|
:size="iconSize"
|
|
7
7
|
:color="iconColor"
|
|
8
8
|
margin-top="14"
|
|
9
|
-
></
|
|
9
|
+
></up-icon>
|
|
10
10
|
<image
|
|
11
11
|
v-else
|
|
12
12
|
:style="{
|
|
@@ -47,7 +47,7 @@ import { addUnit, addStyle, deepMerge } from '../../libs/function/index';
|
|
|
47
47
|
*
|
|
48
48
|
* @event {Function} click 点击组件时触发
|
|
49
49
|
* @event {Function} close 点击关闭按钮时触发
|
|
50
|
-
* @example <
|
|
50
|
+
* @example <up-empty text="所谓伊人,在水一方" mode="list"></up-empty>
|
|
51
51
|
*/
|
|
52
52
|
export default {
|
|
53
53
|
name: 'u-empty',
|
|
@@ -1 +1,243 @@
|
|
|
1
|
-
<template>
|
|
2
1
|
<view class="u-form">
|
|
3
2
|
<slot />
|
|
4
3
|
</view>
|
|
5
4
|
* Form 表单
|
|
6
5
|
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
7
6
|
* @tutorial https://ijry.github.io/uview-plus/components/form.html
|
|
8
7
|
* @property {Object} model 当前form的需要验证字段的集合
|
|
9
8
|
* @property {Object | Function | Array} rules 验证规则
|
|
10
9
|
* @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
|
|
11
10
|
* @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
|
|
12
11
|
* @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
|
|
13
12
|
* @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
|
|
14
13
|
* @property {String} labelAlign lable字体的对齐方式 ( 默认 ‘left' )
|
|
15
14
|
* @property {Object} labelStyle lable的样式,对象形式
|
|
16
15
|
* @example <up-formlabelPosition="left" :model="model1" :rules="rules" ref="form1"></up-form>
|
|
17
16
|
*/
|
|
18
17
|
name: 'u-form',
|
|
19
18
|
mixins: [mpMixin, mixin, props],
|
|
20
19
|
provide() {
|
|
21
20
|
return {
|
|
22
21
|
uForm: this
|
|
23
22
|
};
|
|
24
23
|
},
|
|
25
24
|
data() {
|
|
26
25
|
return {
|
|
27
26
|
formRules: {},
|
|
28
27
|
// 规则校验器
|
|
29
28
|
validator: {},
|
|
30
29
|
// 原始的model快照,用于resetFields方法重置表单时使用
|
|
31
30
|
originalModel: null
|
|
32
31
|
};
|
|
33
32
|
},
|
|
34
33
|
watch: {
|
|
35
34
|
// 监听规则的变化
|
|
36
35
|
rules: {
|
|
37
36
|
immediate: true,
|
|
38
37
|
handler(n) {
|
|
39
38
|
this.setRules(n);
|
|
40
39
|
}
|
|
41
40
|
},
|
|
42
41
|
// 监听属性的变化,通知子组件u-form-item重新获取信息
|
|
43
42
|
propsChange(n) {
|
|
44
43
|
if (this.children?.length) {
|
|
45
44
|
this.children.map((child) => {
|
|
46
45
|
// 判断子组件(u-form-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
|
|
47
46
|
typeof child.updateParentData == 'function' && child.updateParentData();
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
},
|
|
51
50
|
// 监听model的初始值作为重置表单的快照
|
|
52
51
|
model: {
|
|
53
52
|
immediate: true,
|
|
54
53
|
handler(n) {
|
|
55
54
|
if (!this.originalModel) {
|
|
56
55
|
this.originalModel = deepClone(n);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
},
|
|
61
60
|
computed: {
|
|
62
61
|
propsChange() {
|
|
63
62
|
return [this.errorType, this.borderBottom, this.labelPosition, this.labelWidth, this.labelAlign, this.labelStyle];
|
|
64
63
|
}
|
|
65
64
|
},
|
|
66
65
|
created() {
|
|
67
66
|
// 存储当前form下的所有u-form-item的实例
|
|
68
67
|
// 不能定义在data中,否则微信小程序会造成循环引用而报错
|
|
69
68
|
this.children = [];
|
|
70
69
|
},
|
|
71
70
|
methods: {
|
|
72
71
|
// 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
|
|
73
72
|
setRules(rules) {
|
|
74
73
|
// 判断是否有规则
|
|
75
74
|
if (Object.keys(rules).length === 0) return;
|
|
76
75
|
if (process.env.NODE_ENV === 'development' && Object.keys(this.model).length === 0) {
|
|
77
76
|
error('设置rules,model必须设置!如果已经设置,请刷新页面。');
|
|
78
77
|
return;
|
|
79
78
|
}
|
|
80
79
|
this.formRules = rules;
|
|
81
80
|
// 重新将规则赋予Validator
|
|
82
81
|
this.validator = new Schema(rules);
|
|
83
82
|
},
|
|
84
83
|
// 清空所有u-form-item组件的内容,本质上是调用了u-form-item组件中的resetField()方法
|
|
85
84
|
resetFields() {
|
|
86
85
|
this.resetModel();
|
|
87
86
|
},
|
|
88
87
|
// 重置model为初始值的快照
|
|
89
88
|
resetModel(obj) {
|
|
90
89
|
// 历遍所有u-form-item,根据其prop属性,还原model的原始快照
|
|
91
90
|
this.children.map((child) => {
|
|
92
91
|
const prop = child?.prop;
|
|
93
92
|
const value = getProperty(this.originalModel, prop);
|
|
94
93
|
setProperty(this.model, prop, value);
|
|
95
94
|
});
|
|
96
95
|
},
|
|
97
96
|
// 清空校验结果
|
|
98
97
|
clearValidate(props) {
|
|
99
98
|
props = [].concat(props);
|
|
100
99
|
this.children.map((child) => {
|
|
101
100
|
// 如果u-form-item的prop在props数组中,则清除对应的校验结果信息
|
|
102
101
|
if (props[0] === undefined || props.includes(child.prop)) {
|
|
103
102
|
child.message = null;
|
|
104
103
|
}
|
|
105
104
|
});
|
|
106
105
|
},
|
|
107
106
|
// 对部分表单字段进行校验
|
|
108
107
|
async validateField(value, callback, event = null, options) {
|
|
109
108
|
// $nextTick是必须的,否则model的变更,可能会延后于此方法的执行
|
|
110
109
|
this.$nextTick(() => {
|
|
111
110
|
// 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息
|
|
112
111
|
const errorsRes = [];
|
|
113
112
|
// 如果为字符串,转为数组
|
|
114
113
|
value = [].concat(value);
|
|
115
114
|
// 历遍children所有子form-item
|
|
116
115
|
let promises = this.children.map((child) => {
|
|
117
116
|
return new Promise((resolve, reject) => {
|
|
118
117
|
// 用于存放form-item的错误信息
|
|
119
118
|
const childErrors = [];
|
|
120
119
|
if (value.includes(child.prop)) {
|
|
121
120
|
// 获取对应的属性,通过类似'a.b.c'的形式
|
|
122
121
|
const propertyVal = getProperty(this.model, child.prop);
|
|
123
122
|
// 属性链数组
|
|
124
123
|
const propertyChain = child.prop.split('.');
|
|
125
124
|
const propertyName = propertyChain[propertyChain.length - 1];
|
|
126
125
|
let rule = [];
|
|
127
126
|
if (child.itemRules && child.itemRules.length > 0) {
|
|
128
127
|
rule = child.itemRules;
|
|
129
128
|
} else {
|
|
130
129
|
rule = this.formRules[child.prop];
|
|
131
130
|
}
|
|
132
131
|
// 如果不存在对应的规则,直接返回,否则校验器会报错
|
|
133
132
|
if (!rule) {
|
|
134
133
|
resolve();
|
|
135
134
|
return;
|
|
136
135
|
}
|
|
137
136
|
// rule规则可为数组形式,也可为对象形式,此处拼接成为数组
|
|
138
137
|
const rules = [].concat(rule);
|
|
139
138
|
// 对rules数组进行校验
|
|
140
139
|
if (!rules.length) {
|
|
141
140
|
resolve();
|
|
142
141
|
}
|
|
143
142
|
for (let i = 0; i < rules.length; i++) {
|
|
144
143
|
const ruleItem = rules[i];
|
|
145
144
|
// 将u-form-item的触发器转为数组形式
|
|
146
145
|
const trigger = [].concat(ruleItem?.trigger);
|
|
147
146
|
// 如果是有传入触发事件,但是此form-item却没有配置此触发器的话,不执行校验操作
|
|
148
147
|
if (event && !trigger.includes(event)) {
|
|
149
148
|
resolve();
|
|
150
149
|
continue;
|
|
151
150
|
}
|
|
152
151
|
// 实例化校验对象,传入构造规则
|
|
153
152
|
const validator = new Schema({
|
|
154
153
|
[propertyName]: ruleItem
|
|
155
154
|
});
|
|
156
155
|
validator.validate(
|
|
157
156
|
{
|
|
158
157
|
[propertyName]: propertyVal
|
|
159
158
|
},
|
|
160
159
|
(errors, fields) => {
|
|
161
160
|
if (test.array(errors)) {
|
|
162
161
|
errors.forEach((element) => {
|
|
163
162
|
element.prop = child.prop;
|
|
164
163
|
});
|
|
165
164
|
errorsRes.push(...errors);
|
|
166
165
|
childErrors.push(...errors);
|
|
167
166
|
}
|
|
168
167
|
//没有配置,或者配置了showErrorMsg为true时候,才修改子组件message,默认没有配置
|
|
169
168
|
if (!options || options?.showErrorMsg == true) {
|
|
170
169
|
child.message = childErrors[0]?.message ? childErrors[0].message : null;
|
|
171
170
|
}
|
|
172
171
|
if (i == rules.length - 1) {
|
|
173
172
|
resolve(errorsRes);
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
175
|
);
|
|
177
176
|
}
|
|
178
177
|
} else {
|
|
179
178
|
resolve({});
|
|
180
179
|
}
|
|
181
180
|
});
|
|
182
181
|
});
|
|
183
182
|
// 使用Promise.all来等待所有Promise完成
|
|
184
183
|
Promise.all(promises)
|
|
185
184
|
.then((results) => {
|
|
186
185
|
// 执行回调函数
|
|
187
186
|
typeof callback === 'function' && callback(errorsRes);
|
|
188
187
|
})
|
|
189
188
|
.catch((error) => {
|
|
190
189
|
console.error('An error occurred:', error);
|
|
191
190
|
});
|
|
192
191
|
});
|
|
193
192
|
},
|
|
194
193
|
/**
|
|
195
194
|
* 校验全部数据
|
|
196
195
|
* @param {Object} options
|
|
197
196
|
* @param {Boolean} options.showErrorMsg -是否显示校验信息,
|
|
198
197
|
*/
|
|
199
198
|
validate(options) {
|
|
200
199
|
// 开发环境才提示,生产环境不会提示
|
|
201
200
|
if (process.env.NODE_ENV === 'development' && Object.keys(this.formRules).length === 0) {
|
|
202
201
|
error('未设置rules,请看文档说明!如果已经设置,请刷新页面。');
|
|
203
202
|
return;
|
|
204
203
|
}
|
|
205
204
|
return new Promise((resolve, reject) => {
|
|
206
205
|
// $nextTick是必须的,否则model的变更,可能会延后于validate方法
|
|
207
206
|
this.$nextTick(() => {
|
|
208
207
|
// 获取所有form-item的prop,交给validateField方法进行校验
|
|
209
208
|
const formItemProps = this.children.map((item) => item.prop);
|
|
210
209
|
// console.log(formItemProps)
|
|
211
210
|
this.validateField(
|
|
212
211
|
formItemProps,
|
|
213
212
|
(errors) => {
|
|
214
213
|
if (errors.length) {
|
|
215
214
|
// 如果错误提示方式为toast,则进行提示
|
|
216
215
|
this.errorType === 'toast' && toast(errors[0].message);
|
|
217
216
|
reject(errors);
|
|
218
217
|
} else {
|
|
219
218
|
resolve(true);
|
|
220
219
|
}
|
|
221
220
|
},
|
|
222
221
|
null,
|
|
223
222
|
options
|
|
224
223
|
);
|
|
225
224
|
});
|
|
226
225
|
});
|
|
227
226
|
}
|
|
228
227
|
}
|
|
228
|
+
<template>
|
|
229
|
+
<view class="u-form">
|
|
230
|
+
<slot />
|
|
231
|
+
</view>
|
|
232
|
+
</template>
|
|
233
|
+
<script>
|
|
234
|
+
import { props } from './props.js';
|
|
235
|
+
import { mpMixin } from '../../libs/mixin/mpMixin';
|
|
236
|
+
import { mixin } from '../../libs/mixin/mixin';
|
|
237
|
+
import Schema from '../../libs/util/async-validator';
|
|
238
|
+
import { toast, getProperty, setProperty, deepClone, error } from '../../libs/function/index';
|
|
239
|
+
import test from '../../libs/function/test';
|
|
240
|
+
// 去除警告信息
|
|
241
|
+
Schema.warning = function () {};
|
|
242
|
+
/**
|
|
243
|
+
* Form 表单
|
|
244
|
+
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
245
|
+
* @tutorial https://ijry.github.io/uview-plus/components/form.html
|
|
246
|
+
* @property {Object} model 当前form的需要验证字段的集合
|
|
247
|
+
* @property {Object | Function | Array} rules 验证规则
|
|
248
|
+
* @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
|
|
249
|
+
* @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
|
|
250
|
+
* @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
|
|
251
|
+
* @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
|
|
252
|
+
* @property {String} labelAlign lable字体的对齐方式 ( 默认 ‘left' )
|
|
253
|
+
* @property {Object} labelStyle lable的样式,对象形式
|
|
254
|
+
* @example <up-formlabelPosition="left" :model="model1" :rules="rules" ref="form1"></up-form>
|
|
255
|
+
*/
|
|
256
|
+
export default {
|
|
257
|
+
name: 'u-form',
|
|
258
|
+
mixins: [mpMixin, mixin, props],
|
|
259
|
+
provide() {
|
|
260
|
+
return {
|
|
261
|
+
uForm: this
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
data() {
|
|
265
|
+
return {
|
|
266
|
+
formRules: {},
|
|
267
|
+
// 规则校验器
|
|
268
|
+
validator: {},
|
|
269
|
+
// 原始的model快照,用于resetFields方法重置表单时使用
|
|
270
|
+
originalModel: null
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
watch: {
|
|
274
|
+
// 监听规则的变化
|
|
275
|
+
rules: {
|
|
276
|
+
immediate: true,
|
|
277
|
+
handler(n) {
|
|
278
|
+
this.setRules(n);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
// 监听属性的变化,通知子组件u-form-item重新获取信息
|
|
282
|
+
propsChange(n) {
|
|
283
|
+
if (this.children?.length) {
|
|
284
|
+
this.children.map((child) => {
|
|
285
|
+
// 判断子组件(u-form-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
|
|
286
|
+
typeof child.updateParentData == 'function' && child.updateParentData();
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
// 监听model的初始值作为重置表单的快照
|
|
291
|
+
model: {
|
|
292
|
+
immediate: true,
|
|
293
|
+
handler(n) {
|
|
294
|
+
if (!this.originalModel) {
|
|
295
|
+
this.originalModel = deepClone(n);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
computed: {
|
|
301
|
+
propsChange() {
|
|
302
|
+
return [this.errorType, this.borderBottom, this.labelPosition, this.labelWidth, this.labelAlign, this.labelStyle];
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
created() {
|
|
306
|
+
// 存储当前form下的所有u-form-item的实例
|
|
307
|
+
// 不能定义在data中,否则微信小程序会造成循环引用而报错
|
|
308
|
+
this.children = [];
|
|
309
|
+
},
|
|
310
|
+
methods: {
|
|
311
|
+
// 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
|
|
312
|
+
setRules(rules) {
|
|
313
|
+
// 判断是否有规则
|
|
314
|
+
if (Object.keys(rules).length === 0) return;
|
|
315
|
+
if (process.env.NODE_ENV === 'development' && Object.keys(this.model).length === 0) {
|
|
316
|
+
error('设置rules,model必须设置!如果已经设置,请刷新页面。');
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
this.formRules = rules;
|
|
320
|
+
// 重新将规则赋予Validator
|
|
321
|
+
this.validator = new Schema(rules);
|
|
322
|
+
},
|
|
323
|
+
// 清空所有u-form-item组件的内容,本质上是调用了u-form-item组件中的resetField()方法
|
|
324
|
+
resetFields() {
|
|
325
|
+
this.resetModel();
|
|
326
|
+
},
|
|
327
|
+
// 重置model为初始值的快照
|
|
328
|
+
resetModel(obj) {
|
|
329
|
+
// 历遍所有u-form-item,根据其prop属性,还原model的原始快照
|
|
330
|
+
this.children.map((child) => {
|
|
331
|
+
const prop = child?.prop;
|
|
332
|
+
const value = getProperty(this.originalModel, prop);
|
|
333
|
+
setProperty(this.model, prop, value);
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
// 清空校验结果
|
|
337
|
+
clearValidate(props) {
|
|
338
|
+
props = [].concat(props);
|
|
339
|
+
this.children.map((child) => {
|
|
340
|
+
// 如果u-form-item的prop在props数组中,则清除对应的校验结果信息
|
|
341
|
+
if (props[0] === undefined || props.includes(child.prop)) {
|
|
342
|
+
child.message = null;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
// 对部分表单字段进行校验
|
|
347
|
+
async validateField(value, callback, event = null, options) {
|
|
348
|
+
// $nextTick是必须的,否则model的变更,可能会延后于此方法的执行
|
|
349
|
+
this.$nextTick(() => {
|
|
350
|
+
// 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息
|
|
351
|
+
const errorsRes = [];
|
|
352
|
+
// 如果为字符串,转为数组
|
|
353
|
+
value = [].concat(value);
|
|
354
|
+
// 历遍children所有子form-item
|
|
355
|
+
let promises = this.children.map((child) => {
|
|
356
|
+
return new Promise((resolve, reject) => {
|
|
357
|
+
// 用于存放form-item的错误信息
|
|
358
|
+
const childErrors = [];
|
|
359
|
+
if (value.includes(child.prop)) {
|
|
360
|
+
// 获取对应的属性,通过类似'a.b.c'的形式
|
|
361
|
+
const propertyVal = getProperty(this.model, child.prop);
|
|
362
|
+
// 属性链数组
|
|
363
|
+
const propertyChain = child.prop.split('.');
|
|
364
|
+
const propertyName = propertyChain[propertyChain.length - 1];
|
|
365
|
+
let rule = [];
|
|
366
|
+
if (child.itemRules && child.itemRules.length > 0) {
|
|
367
|
+
rule = child.itemRules;
|
|
368
|
+
} else {
|
|
369
|
+
rule = this.formRules[child.prop];
|
|
370
|
+
}
|
|
371
|
+
// 如果不存在对应的规则,直接返回,否则校验器会报错
|
|
372
|
+
if (!rule) {
|
|
373
|
+
resolve();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
// rule规则可为数组形式,也可为对象形式,此处拼接成为数组
|
|
377
|
+
const rules = [].concat(rule);
|
|
378
|
+
// 对rules数组进行校验
|
|
379
|
+
if (!rules.length) {
|
|
380
|
+
resolve();
|
|
381
|
+
}
|
|
382
|
+
for (let i = 0; i < rules.length; i++) {
|
|
383
|
+
const ruleItem = rules[i];
|
|
384
|
+
// 将u-form-item的触发器转为数组形式
|
|
385
|
+
const trigger = [].concat(ruleItem?.trigger);
|
|
386
|
+
// 如果是有传入触发事件,但是此form-item却没有配置此触发器的话,不执行校验操作
|
|
387
|
+
if (event && !trigger.includes(event)) {
|
|
388
|
+
resolve();
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
// 实例化校验对象,传入构造规则
|
|
392
|
+
const validator = new Schema({
|
|
393
|
+
[propertyName]: ruleItem
|
|
394
|
+
});
|
|
395
|
+
validator.validate(
|
|
396
|
+
{
|
|
397
|
+
[propertyName]: propertyVal
|
|
398
|
+
},
|
|
399
|
+
(errors, fields) => {
|
|
400
|
+
if (test.array(errors)) {
|
|
401
|
+
errors.forEach((element) => {
|
|
402
|
+
element.prop = child.prop;
|
|
403
|
+
});
|
|
404
|
+
errorsRes.push(...errors);
|
|
405
|
+
childErrors.push(...errors);
|
|
406
|
+
}
|
|
407
|
+
//没有配置,或者配置了showErrorMsg为true时候,才修改子组件message,默认没有配置
|
|
408
|
+
if (!options || options?.showErrorMsg == true) {
|
|
409
|
+
child.message = childErrors[0]?.message ? childErrors[0].message : null;
|
|
410
|
+
}
|
|
411
|
+
if (i == rules.length - 1) {
|
|
412
|
+
resolve(errorsRes);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
resolve({});
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
// 使用Promise.all来等待所有Promise完成
|
|
423
|
+
Promise.all(promises)
|
|
424
|
+
.then((results) => {
|
|
425
|
+
// 执行回调函数
|
|
426
|
+
typeof callback === 'function' && callback(errorsRes);
|
|
427
|
+
})
|
|
428
|
+
.catch((error) => {
|
|
429
|
+
console.error('An error occurred:', error);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
},
|
|
433
|
+
/**
|
|
434
|
+
* 校验全部数据
|
|
435
|
+
* @param {Object} options
|
|
436
|
+
* @param {Boolean} options.showErrorMsg -是否显示校验信息,
|
|
437
|
+
*/
|
|
438
|
+
validate(options) {
|
|
439
|
+
// 开发环境才提示,生产环境不会提示
|
|
440
|
+
if (process.env.NODE_ENV === 'development' && Object.keys(this.formRules).length === 0) {
|
|
441
|
+
error('未设置rules,请看文档说明!如果已经设置,请刷新页面。');
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
return new Promise((resolve, reject) => {
|
|
445
|
+
// $nextTick是必须的,否则model的变更,可能会延后于validate方法
|
|
446
|
+
this.$nextTick(() => {
|
|
447
|
+
// 获取所有form-item的prop,交给validateField方法进行校验
|
|
448
|
+
const formItemProps = this.children.map((item) => item.prop);
|
|
449
|
+
// console.log(formItemProps)
|
|
450
|
+
this.validateField(
|
|
451
|
+
formItemProps,
|
|
452
|
+
(errors) => {
|
|
453
|
+
if (errors.length) {
|
|
454
|
+
// 如果错误提示方式为toast,则进行提示
|
|
455
|
+
this.errorType === 'toast' && toast(errors[0].message);
|
|
456
|
+
reject(errors);
|
|
457
|
+
} else {
|
|
458
|
+
resolve(true);
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
null,
|
|
462
|
+
options
|
|
463
|
+
);
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
</script>
|
|
470
|
+
<style scoped></style>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<!-- nvue不支持伪元素before -->
|
|
27
27
|
<text v-if="required" class="u-form-item__body__left__content__required">*</text>
|
|
28
28
|
<view class="u-form-item__body__left__content__icon" v-if="leftIcon">
|
|
29
|
-
<
|
|
29
|
+
<up-icon :name="leftIcon" :custom-style="leftIconStyle"></up-icon>
|
|
30
30
|
</view>
|
|
31
31
|
<text
|
|
32
32
|
class="u-form-item__body__left__content__label"
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
{{ message }}
|
|
66
66
|
</text>
|
|
67
67
|
</slot>
|
|
68
|
-
<
|
|
68
|
+
<up-line
|
|
69
69
|
v-if="borderBottom"
|
|
70
70
|
:color="message && parentData.errorType === 'border-bottom' ? color.error : propsLine.color"
|
|
71
71
|
:customStyle="`margin-top: ${message && parentData.errorType === 'message' ? '5px' : 0}`"
|
|
72
|
-
></
|
|
72
|
+
></up-line>
|
|
73
73
|
</view>
|
|
74
74
|
</template>
|
|
75
75
|
<script>
|
|
@@ -93,7 +93,7 @@ import { addStyle, addUnit, getProperty, setProperty, error } from '../../libs/f
|
|
|
93
93
|
* @property {String | Object} leftIconStyle 左侧图标的样式
|
|
94
94
|
* @property {Boolean} required 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置 (默认 false )
|
|
95
95
|
*
|
|
96
|
-
* @example <
|
|
96
|
+
* @example <up-form-item label="姓名" prop="userInfo.name" borderBottom ref="item1"></up-form-item>
|
|
97
97
|
*/
|
|
98
98
|
export default {
|
|
99
99
|
name: 'u-form-item',
|
|
@@ -16,7 +16,7 @@ import { addStyle, addUnit, deepMerge } from '../../libs/function/index.js';
|
|
|
16
16
|
* @property {String | Number} marginBottom 与后一个组件的距离,单位px (默认 0 )
|
|
17
17
|
* @property {Object} customStyle 定义需要用到的外部样式
|
|
18
18
|
*
|
|
19
|
-
* @example <
|
|
19
|
+
* @example <up-gap height="80" bg-color="#bbb"></up-gap>
|
|
20
20
|
*/
|
|
21
21
|
export default {
|
|
22
22
|
name: 'u-gap',
|
|
@@ -17,7 +17,7 @@ import { addStyle, deepMerge } from '../../libs/function/index';
|
|
|
17
17
|
* @property {String} align 宫格对齐方式,表现为数量少的时候,靠左,居中,还是靠右 (默认 'left' )
|
|
18
18
|
* @property {Object} customStyle 定义需要用到的外部样式
|
|
19
19
|
* @event {Function} click 点击宫格触发
|
|
20
|
-
* @example <
|
|
20
|
+
* @example <up-grid :col="3" @click="click"></up-grid>
|
|
21
21
|
*/
|
|
22
22
|
export default {
|
|
23
23
|
name: 'u-grid',
|
|
@@ -31,7 +31,7 @@ import { addStyle, deepMerge } from '../../libs/function/index';
|
|
|
31
31
|
* @property {String} bgColor 宫格的背景颜色 (默认 'transparent' )
|
|
32
32
|
* @property {Object} customStyle 自定义样式,对象形式
|
|
33
33
|
* @event {Function} click 点击宫格触发
|
|
34
|
-
* @example <
|
|
34
|
+
* @example <up-grid-item></up-grid-item>
|
|
35
35
|
*/
|
|
36
36
|
export default {
|
|
37
37
|
name: 'u-grid-item',
|
|
@@ -53,7 +53,7 @@ import { addUnit, addStyle } from '../../libs/function/index';
|
|
|
53
53
|
* @property {Object} customStyle icon的样式,对象形式
|
|
54
54
|
* @event {Function} click 点击图标时触发
|
|
55
55
|
* @event {Function} touchstart 事件触摸时触发
|
|
56
|
-
* @example <
|
|
56
|
+
* @example <up-icon name="photo" color="#2979ff" size="28"></up-icon>
|
|
57
57
|
*/
|
|
58
58
|
export default {
|
|
59
59
|
name: 'u-icon',
|
|
@@ -58,7 +58,7 @@ import props from './props.js';
|
|
|
58
58
|
* @property {Object} customStyle icon的样式,对象形式
|
|
59
59
|
* @event {Function} click 点击图标时触发
|
|
60
60
|
* @event {Function} touchstart 事件触摸时触发
|
|
61
|
-
* @example <
|
|
61
|
+
* @example <up-icon name="photo" color="#2979ff" size="28"></up-icon>
|
|
62
62
|
*/
|
|
63
63
|
export default {
|
|
64
64
|
name: 'wu-icon',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<up-transition mode="fade" :show="show" :style="transStyle" :duration="fade ? 1000 : 0">
|
|
3
3
|
<view class="u-image box-border" @tap="onClick" :style="[wrapStyle, backgroundStyle]">
|
|
4
4
|
<image
|
|
5
5
|
v-if="!isError"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}"
|
|
28
28
|
>
|
|
29
29
|
<slot name="loading">
|
|
30
|
-
<
|
|
30
|
+
<up-icon :name="loadingIcon"></up-icon>
|
|
31
31
|
</slot>
|
|
32
32
|
</view>
|
|
33
33
|
<view
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
}"
|
|
39
39
|
>
|
|
40
40
|
<slot name="error">
|
|
41
|
-
<
|
|
41
|
+
<up-icon :name="errorIcon"></up-icon>
|
|
42
42
|
</slot>
|
|
43
43
|
</view>
|
|
44
44
|
</view>
|
|
45
|
-
</
|
|
45
|
+
</up-transition>
|
|
46
46
|
</template>
|
|
47
47
|
<script>
|
|
48
48
|
import { props } from './props';
|
|
@@ -73,7 +73,7 @@ import { addUnit, addStyle, deepMerge } from '../../libs/function/index';
|
|
|
73
73
|
* @event {Function} click 点击图片时触发
|
|
74
74
|
* @event {Function} error 图片加载失败时触发
|
|
75
75
|
* @event {Function} load 图片加载成功时触发
|
|
76
|
-
* @example <
|
|
76
|
+
* @example <up-image width="100%" height="300px" :src="src"></up-image>
|
|
77
77
|
*/
|
|
78
78
|
export default {
|
|
79
79
|
name: 'u-image',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<up-transition mode="fade" :custom-style="wrapStyle" :show="show" :duration="fade ? 1000 : 0">
|
|
3
3
|
<view class="u-image" @tap="onClick" :style="[wrapStyle, backgroundStyle]">
|
|
4
4
|
<image
|
|
5
5
|
v-if="!isError && loadingImage"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}"
|
|
27
27
|
>
|
|
28
28
|
<slot name="loading">
|
|
29
|
-
<
|
|
29
|
+
<up-icon :name="loadingIcon" :width="width" :height="height"></up-icon>
|
|
30
30
|
</slot>
|
|
31
31
|
</view>
|
|
32
32
|
<view
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
}"
|
|
40
40
|
>
|
|
41
41
|
<slot name="error">
|
|
42
|
-
<
|
|
42
|
+
<up-icon :name="errorIcon" :width="width" :height="height"></up-icon>
|
|
43
43
|
</slot>
|
|
44
44
|
</view>
|
|
45
45
|
</view>
|
|
46
|
-
</
|
|
46
|
+
</up-transition>
|
|
47
47
|
</template>
|
|
48
48
|
|
|
49
49
|
<script>
|
|
@@ -76,7 +76,7 @@ import props from './props.js';
|
|
|
76
76
|
* @event {Function} click 点击图片时触发
|
|
77
77
|
* @event {Function} error 图片加载失败时触发
|
|
78
78
|
* @event {Function} load 图片加载成功时触发
|
|
79
|
-
* @example <
|
|
79
|
+
* @example <up-image width="100%" height="300px" :src="src"></up-image>
|
|
80
80
|
*/
|
|
81
81
|
export default {
|
|
82
82
|
name: 'u-image',
|
|
@@ -41,7 +41,7 @@ const dom = uni.requireNativePlugin('dom');
|
|
|
41
41
|
* @property {String | Number} size 列表锚点文字大小,单位默认px ( 默认 14 )
|
|
42
42
|
* @property {String} bgColor 列表锚点背景颜色 ( 默认 '#dedede' )
|
|
43
43
|
* @property {String | Number} height 列表锚点高度,单位默认px ( 默认 32 )
|
|
44
|
-
* @example <
|
|
44
|
+
* @example <up-index-anchor :text="indexList[index]"></up-index-anchor>
|
|
45
45
|
*/
|
|
46
46
|
export default {
|
|
47
47
|
name: 'u-index-anchor',
|