@v2coding/ui 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/v2coding-ui.esm.js +1108 -1133
- package/dist/v2coding-ui.min.js +1 -1
- package/dist/v2coding-ui.ssr.js +1128 -1159
- package/package.json +1 -1
- package/src/components/field/field.rich.vue +0 -10
- package/src/components/form/form.item.vue +0 -3
- package/src/components/form/form.vue +48 -39
- package/src/components/icon/icon.vue +4 -4
- package/src/components/table/table.select.vue +1 -1
package/package.json
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
import 'quill/dist/quill.snow.css';
|
|
12
12
|
import 'quill/dist/quill.bubble.css';
|
|
13
13
|
import Objects from '../../util/objects';
|
|
14
|
-
import {addFieldType} from '../form/form.field';
|
|
15
14
|
|
|
16
15
|
const Font = Quill.import('formats/font');
|
|
17
16
|
|
|
@@ -77,15 +76,6 @@
|
|
|
77
76
|
},
|
|
78
77
|
};
|
|
79
78
|
|
|
80
|
-
/**
|
|
81
|
-
* ui-form-item 添加 type="rich" 支持
|
|
82
|
-
*/
|
|
83
|
-
const attachToFormItem = () => {
|
|
84
|
-
addFieldType('rich', RichField);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
RichField.attachToFormItem = attachToFormItem;
|
|
88
|
-
|
|
89
79
|
export default RichField;
|
|
90
80
|
</script>
|
|
91
81
|
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
<script>
|
|
9
9
|
import throttle from 'lodash.throttle';
|
|
10
10
|
import Objects from '../../util/objects';
|
|
11
|
+
import FormItem from './form.item';
|
|
12
|
+
import TableSelectItem from '../table/table.select.item';
|
|
11
13
|
|
|
12
14
|
export default {
|
|
13
15
|
name: 'ui-form',
|
|
@@ -59,8 +61,6 @@
|
|
|
59
61
|
fieldList: [],// [[name, value], ...]
|
|
60
62
|
};
|
|
61
63
|
},
|
|
62
|
-
created() {
|
|
63
|
-
},
|
|
64
64
|
computed: {
|
|
65
65
|
model() {
|
|
66
66
|
return Object.fromEntries(this.fieldList);
|
|
@@ -71,7 +71,11 @@
|
|
|
71
71
|
return listeners;
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
|
+
beforeCreate() {
|
|
75
|
+
this.isMounted = false;
|
|
76
|
+
},
|
|
74
77
|
mounted() {
|
|
78
|
+
this.isMounted = true;
|
|
75
79
|
this.$el.addEventListener('reset', this.onReset);
|
|
76
80
|
this.checkFieldsReady();
|
|
77
81
|
},
|
|
@@ -104,11 +108,12 @@
|
|
|
104
108
|
if (!Objects.isObject(values)) {
|
|
105
109
|
values = {};
|
|
106
110
|
}
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
const formItems = this.getFormItems();
|
|
112
|
+
formItems.forEach(item => {
|
|
113
|
+
if (Object.prototype.hasOwnProperty.call(values, item.name)) {
|
|
114
|
+
item.resetField(values[item.name]);
|
|
110
115
|
} else {
|
|
111
|
-
|
|
116
|
+
item.resetField();
|
|
112
117
|
}
|
|
113
118
|
});
|
|
114
119
|
},
|
|
@@ -119,19 +124,40 @@
|
|
|
119
124
|
if (!values || !Objects.isObject(values)) {
|
|
120
125
|
return;
|
|
121
126
|
}
|
|
127
|
+
const formItems = this.getFormItems();
|
|
122
128
|
Object.entries(values).forEach(([fieldName, fieldValue]) => {
|
|
123
|
-
const fieldItem =
|
|
129
|
+
const fieldItem = formItems.find(item => item.name === fieldName);
|
|
124
130
|
if (!fieldItem) {
|
|
125
131
|
return;
|
|
126
132
|
}
|
|
127
|
-
fieldItem
|
|
133
|
+
fieldItem.fieldValue = fieldValue;
|
|
128
134
|
});
|
|
129
135
|
},
|
|
130
136
|
/**
|
|
131
137
|
* @public
|
|
132
138
|
*/
|
|
133
139
|
getValues() {
|
|
134
|
-
|
|
140
|
+
const formItems = this.getFormItems();
|
|
141
|
+
return formItems.reduce((values, item) => {
|
|
142
|
+
if (item.ignore === true) {
|
|
143
|
+
return values;
|
|
144
|
+
}
|
|
145
|
+
return {...values, [item.name]: item.fieldValue};
|
|
146
|
+
}, {});
|
|
147
|
+
},
|
|
148
|
+
getFormItems() {
|
|
149
|
+
const listSearchItem = (items) => {
|
|
150
|
+
return items.reduce((results, item) => {
|
|
151
|
+
// TableSelectItem mixins FormItem
|
|
152
|
+
if ([FormItem.name, TableSelectItem.name].includes(item.$options.name)) {
|
|
153
|
+
results.push(item);
|
|
154
|
+
} else {
|
|
155
|
+
results.push(...listSearchItem(item.$children || []));
|
|
156
|
+
}
|
|
157
|
+
return results;
|
|
158
|
+
}, []);
|
|
159
|
+
};
|
|
160
|
+
return listSearchItem(this.$children);
|
|
135
161
|
},
|
|
136
162
|
/**
|
|
137
163
|
* @private
|
|
@@ -207,31 +233,14 @@
|
|
|
207
233
|
}
|
|
208
234
|
this[`onField${e}`](...args);
|
|
209
235
|
},
|
|
210
|
-
getAllFields() {
|
|
211
|
-
const getFormFields = (components) => {
|
|
212
|
-
if (!Array.isArray(components) || !components.length) {
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
|
-
return components.reduce((total, component) => {
|
|
216
|
-
// ui-table-select-item mixins ui-form-item
|
|
217
|
-
if (['ui-form-item', 'ui-table-select-item'].includes(component.$options.name)) {
|
|
218
|
-
!component.ignore && component.name && total.push(component.name);
|
|
219
|
-
} else {
|
|
220
|
-
total.push(...getFormFields(component.$children));
|
|
221
|
-
}
|
|
222
|
-
return total;
|
|
223
|
-
}, []);
|
|
224
|
-
};
|
|
225
|
-
this.formFields = getFormFields(this.$children);
|
|
226
|
-
return this.formFields;
|
|
227
|
-
},
|
|
228
236
|
/**
|
|
229
237
|
* @private
|
|
230
238
|
*/
|
|
231
239
|
onFieldPending(component) {
|
|
232
|
-
if(component.name) {
|
|
233
|
-
|
|
240
|
+
if (!component.name) {
|
|
241
|
+
return;
|
|
234
242
|
}
|
|
243
|
+
this.fieldStatus.push({name: component.name, status: false, instance: component});
|
|
235
244
|
},
|
|
236
245
|
/**
|
|
237
246
|
* @private
|
|
@@ -244,8 +253,8 @@
|
|
|
244
253
|
const i = this.fieldList.findIndex(item => item[0] === component.name);
|
|
245
254
|
this.fieldList.splice(i, 1);
|
|
246
255
|
}
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
256
|
+
const formItems = this.getFormItems();
|
|
257
|
+
if (formItems.length === this.fieldStatus.length) {
|
|
249
258
|
this.checkFieldsReady();
|
|
250
259
|
}
|
|
251
260
|
},
|
|
@@ -257,13 +266,9 @@
|
|
|
257
266
|
return;
|
|
258
267
|
}
|
|
259
268
|
const index = this.fieldStatus.findIndex(item => item.name === component.name);
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.fieldStatus.splice(index, 1, {name: component.name, status: true, instance: component});
|
|
264
|
-
}
|
|
265
|
-
const formFields = this.getAllFields();
|
|
266
|
-
if (formFields.length === this.fieldStatus.length) {
|
|
269
|
+
index !== -1 && this.fieldStatus.splice(index, 1, {name: component.name, status: true, instance: component});
|
|
270
|
+
const formItems = this.getFormItems();
|
|
271
|
+
if (formItems.length === this.fieldStatus.length) {
|
|
267
272
|
this.checkFieldsReady();
|
|
268
273
|
}
|
|
269
274
|
},
|
|
@@ -277,8 +282,12 @@
|
|
|
277
282
|
}
|
|
278
283
|
},
|
|
279
284
|
checkFieldsReady() {
|
|
285
|
+
if (!this.isMounted) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
280
288
|
const isPending = this.fieldStatus.some(item => !item.status);
|
|
281
|
-
if (!isPending) {
|
|
289
|
+
if (!isPending && !this.isReady) {
|
|
290
|
+
this.isReady = true;
|
|
282
291
|
this.$emit('ready');
|
|
283
292
|
}
|
|
284
293
|
},
|
|
@@ -37,7 +37,7 @@ export default {
|
|
|
37
37
|
};
|
|
38
38
|
</script>
|
|
39
39
|
|
|
40
|
-
<style scoped>
|
|
40
|
+
<style lang="less" scoped>
|
|
41
41
|
.ui-icon {
|
|
42
42
|
width: 1em;
|
|
43
43
|
height: 1em;
|
|
@@ -45,10 +45,10 @@ export default {
|
|
|
45
45
|
fill: currentColor;
|
|
46
46
|
overflow: hidden;
|
|
47
47
|
display: inline-block;
|
|
48
|
-
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
&.ui-icon-loading {
|
|
50
|
+
animation: rotating 2s linear infinite;
|
|
51
|
+
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
@keyframes rotating {
|