@tmagic/form 1.0.0-beta.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/dist/style.css +161 -0
- package/dist/tmagic-form.es.js +3749 -0
- package/dist/tmagic-form.es.js.map +1 -0
- package/dist/tmagic-form.umd.js +3790 -0
- package/dist/tmagic-form.umd.js.map +1 -0
- package/dist/types/src/Form.vue.d.ts +304 -0
- package/dist/types/src/FormDialog.vue.d.ts +641 -0
- package/dist/types/src/containers/Container.vue.d.ts +69 -0
- package/dist/types/src/containers/Fieldset.vue.d.ts +56 -0
- package/dist/types/src/containers/GroupList.vue.d.ts +56 -0
- package/dist/types/src/containers/GroupListItem.vue.d.ts +72 -0
- package/dist/types/src/containers/Panel.vue.d.ts +41 -0
- package/dist/types/src/containers/Row.vue.d.ts +42 -0
- package/dist/types/src/containers/Step.vue.d.ts +45 -0
- package/dist/types/src/containers/Table.vue.d.ts +1401 -0
- package/dist/types/src/containers/Tabs.vue.d.ts +45 -0
- package/dist/types/src/fields/Cascader.vue.d.ts +1748 -0
- package/dist/types/src/fields/Checkbox.vue.d.ts +59 -0
- package/dist/types/src/fields/CheckboxGroup.vue.d.ts +56 -0
- package/dist/types/src/fields/Date.vue.d.ts +58 -0
- package/dist/types/src/fields/DateTime.vue.d.ts +57 -0
- package/dist/types/src/fields/Daterange.vue.d.ts +57 -0
- package/dist/types/src/fields/Display.vue.d.ts +3 -0
- package/dist/types/src/fields/DynamicField.vue.d.ts +76 -0
- package/dist/types/src/fields/Hidden.vue.d.ts +3 -0
- package/dist/types/src/fields/Link.vue.d.ts +1365 -0
- package/dist/types/src/fields/Number.vue.d.ts +59 -0
- package/dist/types/src/fields/RadioGroup.vue.d.ts +55 -0
- package/dist/types/src/fields/Select.vue.d.ts +975 -0
- package/dist/types/src/fields/Switch.vue.d.ts +59 -0
- package/dist/types/src/fields/Text.vue.d.ts +61 -0
- package/dist/types/src/fields/Textarea.vue.d.ts +56 -0
- package/dist/types/src/fields/Time.vue.d.ts +54 -0
- package/dist/types/src/index.d.ts +36 -0
- package/dist/types/src/schema.d.ts +495 -0
- package/dist/types/src/shims-vue.d.ts +6 -0
- package/dist/types/src/utils/config.d.ts +3 -0
- package/dist/types/src/utils/fieldProps.d.ts +21 -0
- package/dist/types/src/utils/form.d.ts +8 -0
- package/dist/types/src/utils/useAddField.d.ts +1 -0
- package/dist/types/src/vite-env.d.ts +1 -0
- package/package.json +51 -0
- package/src/Form.vue +188 -0
- package/src/FormDialog.vue +163 -0
- package/src/containers/Container.vue +263 -0
- package/src/containers/Fieldset.vue +138 -0
- package/src/containers/GroupList.vue +152 -0
- package/src/containers/GroupListItem.vue +159 -0
- package/src/containers/Panel.vue +106 -0
- package/src/containers/Row.vue +68 -0
- package/src/containers/Step.vue +82 -0
- package/src/containers/Table.vue +624 -0
- package/src/containers/Tabs.vue +176 -0
- package/src/fields/Cascader.vue +147 -0
- package/src/fields/Checkbox.vue +67 -0
- package/src/fields/CheckboxGroup.vue +44 -0
- package/src/fields/ColorPicker.vue +38 -0
- package/src/fields/Date.vue +51 -0
- package/src/fields/DateTime.vue +59 -0
- package/src/fields/Daterange.vue +75 -0
- package/src/fields/Display.vue +34 -0
- package/src/fields/DynamicField.vue +109 -0
- package/src/fields/Hidden.vue +29 -0
- package/src/fields/Link.vue +112 -0
- package/src/fields/Number.vue +53 -0
- package/src/fields/RadioGroup.vue +33 -0
- package/src/fields/Select.vue +393 -0
- package/src/fields/Switch.vue +65 -0
- package/src/fields/Text.vue +134 -0
- package/src/fields/Textarea.vue +62 -0
- package/src/fields/Time.vue +48 -0
- package/src/index.ts +127 -0
- package/src/schema.ts +638 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/theme/date-time.scss +7 -0
- package/src/theme/fieldset.scss +24 -0
- package/src/theme/form-dialog.scss +13 -0
- package/src/theme/form.scss +30 -0
- package/src/theme/group-list.scss +23 -0
- package/src/theme/index.scss +9 -0
- package/src/theme/link.scss +3 -0
- package/src/theme/panel.scss +18 -0
- package/src/theme/select.scss +3 -0
- package/src/theme/table.scss +69 -0
- package/src/theme/tabs.scss +25 -0
- package/src/utils/config.ts +27 -0
- package/src/utils/containerProps.ts +50 -0
- package/src/utils/createForm.ts +25 -0
- package/src/utils/fieldProps.ts +39 -0
- package/src/utils/form.ts +266 -0
- package/src/utils/useAddField.ts +40 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +9 -0
- package/vite.config.ts +27 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-select
|
|
3
|
+
v-if="model"
|
|
4
|
+
v-model="model[name]"
|
|
5
|
+
v-loading="loading"
|
|
6
|
+
class="m-select"
|
|
7
|
+
ref="select"
|
|
8
|
+
clearable
|
|
9
|
+
filterable
|
|
10
|
+
:size="size"
|
|
11
|
+
:remote="remote"
|
|
12
|
+
:placeholder="config.placeholder"
|
|
13
|
+
:multiple="config.multiple"
|
|
14
|
+
:value-key="config.valueKey || 'value'"
|
|
15
|
+
:allow-create="config.allowCreate"
|
|
16
|
+
:disabled="disabled"
|
|
17
|
+
:remote-method="remoteMethod"
|
|
18
|
+
@change="changeHandler"
|
|
19
|
+
@visible-change="visibleHandler"
|
|
20
|
+
>
|
|
21
|
+
<template v-if="config.group">
|
|
22
|
+
<el-option-group
|
|
23
|
+
v-for="(group, index) in options"
|
|
24
|
+
:key="group.label + index"
|
|
25
|
+
:label="group.label"
|
|
26
|
+
:disabled="group.disabled"
|
|
27
|
+
>
|
|
28
|
+
<el-option
|
|
29
|
+
v-for="(item, index) in group.options"
|
|
30
|
+
:key="item.label + index"
|
|
31
|
+
:label="item.label"
|
|
32
|
+
:value="item.value"
|
|
33
|
+
:disabled="item.disabled"
|
|
34
|
+
>
|
|
35
|
+
</el-option>
|
|
36
|
+
</el-option-group>
|
|
37
|
+
</template>
|
|
38
|
+
<template v-else>
|
|
39
|
+
<el-option
|
|
40
|
+
v-for="option in options"
|
|
41
|
+
:label="option.text"
|
|
42
|
+
:value="option.value"
|
|
43
|
+
:key="config.valueKey ? option.value[config.valueKey] : option.value"
|
|
44
|
+
:disabled="option.disabled"
|
|
45
|
+
></el-option>
|
|
46
|
+
</template>
|
|
47
|
+
<div v-loading="true" v-if="moreLoadingVisible"></div>
|
|
48
|
+
</el-select>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import { defineComponent, inject, onBeforeMount, onMounted, PropType, ref, watch } from 'vue';
|
|
53
|
+
import { ElSelect } from 'element-plus';
|
|
54
|
+
|
|
55
|
+
import { FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
|
|
56
|
+
import { getConfig } from '../utils/config';
|
|
57
|
+
import fieldProps from '../utils/fieldProps';
|
|
58
|
+
import { useAddField } from '../utils/useAddField';
|
|
59
|
+
|
|
60
|
+
export default defineComponent({
|
|
61
|
+
name: 'm-fields-select',
|
|
62
|
+
|
|
63
|
+
props: {
|
|
64
|
+
...fieldProps,
|
|
65
|
+
config: {
|
|
66
|
+
type: Object as PropType<SelectConfig>,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
emits: ['change'],
|
|
72
|
+
|
|
73
|
+
setup(props, { emit }) {
|
|
74
|
+
if (!props.model) throw new Error('不能没有model');
|
|
75
|
+
useAddField(props.prop);
|
|
76
|
+
|
|
77
|
+
const select = ref<typeof ElSelect>();
|
|
78
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
79
|
+
const options = ref<SelectOption[] | SelectGroupOption[]>([]);
|
|
80
|
+
const localOptions = ref<SelectOption[] | SelectGroupOption[]>([]);
|
|
81
|
+
const loading = ref(false);
|
|
82
|
+
const moreLoadingVisible = ref(false);
|
|
83
|
+
const total = ref(0);
|
|
84
|
+
const pgIndex = ref(0);
|
|
85
|
+
const pgSize = ref(20);
|
|
86
|
+
const query = ref('');
|
|
87
|
+
const remoteData = ref<any[]>([]);
|
|
88
|
+
const remote = ref(true);
|
|
89
|
+
|
|
90
|
+
const equalValue = (value: any, v: any): boolean => {
|
|
91
|
+
if (typeof v === 'object') {
|
|
92
|
+
const key = props.config.valueKey || 'value';
|
|
93
|
+
return v[key] === value[key];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return value === v;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const mapOptions = (data: any[]) => {
|
|
100
|
+
const { option } = props.config;
|
|
101
|
+
const { text } = option;
|
|
102
|
+
const { value } = option;
|
|
103
|
+
|
|
104
|
+
return data.map((item) => ({
|
|
105
|
+
text: typeof text === 'function' ? text(item) : item[text || 'text'],
|
|
106
|
+
value: typeof value === 'function' ? value(item) : item[value || 'value'],
|
|
107
|
+
}));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const getOptions = async () => {
|
|
111
|
+
if (!props.model) return [];
|
|
112
|
+
|
|
113
|
+
if (localOptions.value.length) {
|
|
114
|
+
return localOptions.value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
loading.value = true;
|
|
118
|
+
|
|
119
|
+
let items: SelectOption[] | SelectGroupOption[] = [];
|
|
120
|
+
|
|
121
|
+
const { config } = props;
|
|
122
|
+
const { option } = config;
|
|
123
|
+
let { body } = option;
|
|
124
|
+
|
|
125
|
+
let postOptions: Record<string, any> = {
|
|
126
|
+
method: option.method || 'POST',
|
|
127
|
+
url: option.url,
|
|
128
|
+
cache: option.cache,
|
|
129
|
+
timeout: option.timeout,
|
|
130
|
+
mode: option.mode,
|
|
131
|
+
headers: option.headers || {},
|
|
132
|
+
json: option.json || false,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (body) {
|
|
136
|
+
if (typeof body === 'function') {
|
|
137
|
+
body = body(mForm, {
|
|
138
|
+
model: props.model,
|
|
139
|
+
formValue: mForm?.values,
|
|
140
|
+
formValues: mForm?.values,
|
|
141
|
+
}) as Record<string, any>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
body.query = query.value;
|
|
145
|
+
body.pgSize = pgSize.value;
|
|
146
|
+
body.pgIndex = pgIndex.value;
|
|
147
|
+
postOptions.data = body;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const requestFuc = getConfig('request') as Function;
|
|
151
|
+
|
|
152
|
+
if (typeof option.beforeRequest === 'function') {
|
|
153
|
+
postOptions = option.beforeRequest(mForm, postOptions, {
|
|
154
|
+
model: props.model,
|
|
155
|
+
formValue: mForm?.values,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (option.method?.toLocaleLowerCase() === 'jsonp') {
|
|
160
|
+
postOptions.jsonpCallback = option.jsonpCallback || 'callback';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let res = await requestFuc(postOptions);
|
|
164
|
+
|
|
165
|
+
if (typeof option.afterRequest === 'function') {
|
|
166
|
+
res = option.afterRequest(mForm, res, {
|
|
167
|
+
model: props.model,
|
|
168
|
+
formValue: mForm?.values,
|
|
169
|
+
formValues: mForm?.values,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const optionsData = res[option.root];
|
|
174
|
+
|
|
175
|
+
if (res.total > 0) {
|
|
176
|
+
total.value = res.total;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
remoteData.value = remoteData.value.concat(optionsData);
|
|
180
|
+
if (optionsData) {
|
|
181
|
+
if (typeof option.item === 'function') {
|
|
182
|
+
items = option.item(optionsData);
|
|
183
|
+
} else if (optionsData.map) {
|
|
184
|
+
items = mapOptions(optionsData);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
loading.value = false;
|
|
189
|
+
|
|
190
|
+
// 多选过滤时会导致已选的选项显示不了,所以要把已选的选项保留不要过滤没了
|
|
191
|
+
const selectedOptions: SelectOption[] | SelectGroupOption[] = [];
|
|
192
|
+
if (props.config.multiple && props.model[props.name]) {
|
|
193
|
+
options.value.forEach((o: any) => {
|
|
194
|
+
const isInclude = props.model?.[props.name].includes(o.value);
|
|
195
|
+
if (isInclude && !(items as any[]).find((op: any) => op.value === o.value)) {
|
|
196
|
+
selectedOptions.push(o);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return pgIndex.value === 0 ? (selectedOptions as any[]).concat(items) : (options.value as any).concat(items);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const getInitLocalOption = async () => {
|
|
205
|
+
if (!props.model) return [];
|
|
206
|
+
|
|
207
|
+
const value = props.model[props.name];
|
|
208
|
+
const { config } = props;
|
|
209
|
+
localOptions.value = await getOptions();
|
|
210
|
+
|
|
211
|
+
remote.value = false;
|
|
212
|
+
|
|
213
|
+
if (config.group) {
|
|
214
|
+
if (config.multiple && value.findIndex) {
|
|
215
|
+
return (localOptions.value as SelectGroupOption[]).filter(
|
|
216
|
+
(group) => group.options.findIndex((item) => value.find((v: any) => equalValue(item.value, v)) > -1) > -1,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return (localOptions.value as SelectGroupOption[]).filter(
|
|
221
|
+
(group) => group.options.findIndex((item) => equalValue(item.value, value)) > -1,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (config.multiple && value.findIndex) {
|
|
226
|
+
return (localOptions.value as any[]).filter(
|
|
227
|
+
(item) => value.findIndex((v: any) => equalValue(item.value, v)) > -1,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
return (localOptions.value as any[]).filter((item) => equalValue(item.value, value));
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const getInitOption = async () => {
|
|
234
|
+
if (!props.model) return [];
|
|
235
|
+
|
|
236
|
+
const { config } = props;
|
|
237
|
+
const { option } = config;
|
|
238
|
+
|
|
239
|
+
let options: SelectOption[] | SelectGroupOption[] = [];
|
|
240
|
+
|
|
241
|
+
let url = option.initUrl;
|
|
242
|
+
if (!url) {
|
|
243
|
+
return getInitLocalOption();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (typeof url === 'function') {
|
|
247
|
+
url = await url(mForm, { model: props.model, formValue: mForm?.values });
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const postOptions: Record<string, any> = {
|
|
251
|
+
method: option.method || 'POST',
|
|
252
|
+
url,
|
|
253
|
+
data: {
|
|
254
|
+
id: props.model[props.name],
|
|
255
|
+
},
|
|
256
|
+
mode: option.mode,
|
|
257
|
+
headers: option.headers || {},
|
|
258
|
+
json: option.json || false,
|
|
259
|
+
};
|
|
260
|
+
if (option.method?.toLocaleLowerCase() === 'jsonp') {
|
|
261
|
+
postOptions.jsonpCallback = option.jsonpCallback || 'callback';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const requestFuc = getConfig('request') as Function;
|
|
265
|
+
const res = await requestFuc(postOptions);
|
|
266
|
+
|
|
267
|
+
let initData = res[option.root];
|
|
268
|
+
if (initData) {
|
|
269
|
+
if (!Array.isArray(initData)) {
|
|
270
|
+
initData = [initData];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (typeof option.item === 'function') {
|
|
274
|
+
options = option.item(initData);
|
|
275
|
+
} else if (initData.map) {
|
|
276
|
+
options = mapOptions(initData);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return options;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
if (typeof props.config.options === 'function') {
|
|
284
|
+
watch(
|
|
285
|
+
() => mForm?.values,
|
|
286
|
+
() => {
|
|
287
|
+
typeof props.config.options === 'function' &&
|
|
288
|
+
Promise.resolve(
|
|
289
|
+
props.config.options(mForm, {
|
|
290
|
+
model: props.model,
|
|
291
|
+
formValues: mForm?.values,
|
|
292
|
+
formValue: mForm?.values,
|
|
293
|
+
}),
|
|
294
|
+
).then((data) => {
|
|
295
|
+
options.value = data;
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
deep: true,
|
|
300
|
+
immediate: true,
|
|
301
|
+
},
|
|
302
|
+
);
|
|
303
|
+
} else if (Array.isArray(props.config.options)) {
|
|
304
|
+
watch(
|
|
305
|
+
() => props.config.options,
|
|
306
|
+
() => {
|
|
307
|
+
options.value = props.config.options as SelectOption[] | SelectGroupOption[];
|
|
308
|
+
},
|
|
309
|
+
{ immediate: true },
|
|
310
|
+
);
|
|
311
|
+
} else if (props.config.option) {
|
|
312
|
+
onBeforeMount(() => {
|
|
313
|
+
if (!props.model) return;
|
|
314
|
+
const v = props.model[props.name];
|
|
315
|
+
if (Array.isArray(v) ? v.length : v) {
|
|
316
|
+
getInitOption().then((data) => {
|
|
317
|
+
options.value = data;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
props.config.remote &&
|
|
324
|
+
onMounted(() => {
|
|
325
|
+
select.value?.scrollbar.wrap$.addEventListener('scroll', async (e: Event) => {
|
|
326
|
+
const el = e.currentTarget as HTMLDivElement;
|
|
327
|
+
if (moreLoadingVisible.value) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (el.scrollHeight - el.clientHeight - el.scrollTop > 1) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (total.value <= options.value.length) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
moreLoadingVisible.value = true;
|
|
337
|
+
pgIndex.value += 1;
|
|
338
|
+
options.value = await getOptions();
|
|
339
|
+
moreLoadingVisible.value = false;
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
select,
|
|
345
|
+
loading,
|
|
346
|
+
remote,
|
|
347
|
+
options,
|
|
348
|
+
moreLoadingVisible,
|
|
349
|
+
|
|
350
|
+
getRequestFuc() {
|
|
351
|
+
return getConfig('request');
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
async getInitOption() {},
|
|
355
|
+
|
|
356
|
+
changeHandler(value: any) {
|
|
357
|
+
emit('change', value);
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
async visibleHandler(visible: boolean) {
|
|
361
|
+
if (!visible) return;
|
|
362
|
+
|
|
363
|
+
if (!props.config.remote) return;
|
|
364
|
+
if (query.value && select.value) {
|
|
365
|
+
select.value.query = query.value;
|
|
366
|
+
select.value.previousQuery = query.value;
|
|
367
|
+
select.value.selectedLabel = query.value;
|
|
368
|
+
} else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
|
|
369
|
+
options.value = await getOptions();
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
async editAfterAction() {
|
|
374
|
+
pgIndex.value = 0;
|
|
375
|
+
options.value = await getOptions();
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
async remoteMethod(q: string) {
|
|
379
|
+
if (!localOptions.value.length) {
|
|
380
|
+
query.value = q;
|
|
381
|
+
pgIndex.value = 0;
|
|
382
|
+
options.value = await getOptions();
|
|
383
|
+
// 多选时如果过滤选项会导致已选好的标签异常,需要重新刷新一下el-select的状态
|
|
384
|
+
if (props.config.multiple)
|
|
385
|
+
setTimeout(() => {
|
|
386
|
+
select.value?.setSelected();
|
|
387
|
+
}, 0);
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
</script>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-switch
|
|
3
|
+
v-if="model"
|
|
4
|
+
v-model="model[n]"
|
|
5
|
+
:size="size"
|
|
6
|
+
:activeValue="activeValue"
|
|
7
|
+
:inactiveValue="inactiveValue"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
@change="changeHandler"
|
|
10
|
+
></el-switch>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { computed, defineComponent, PropType } from 'vue';
|
|
15
|
+
|
|
16
|
+
import { SwitchConfig } from '../schema';
|
|
17
|
+
import fieldProps from '../utils/fieldProps';
|
|
18
|
+
import { useAddField } from '../utils/useAddField';
|
|
19
|
+
export default defineComponent({
|
|
20
|
+
name: 'm-fields-switch',
|
|
21
|
+
|
|
22
|
+
props: {
|
|
23
|
+
...fieldProps,
|
|
24
|
+
config: {
|
|
25
|
+
type: Object as PropType<SwitchConfig>,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
emits: ['change'],
|
|
31
|
+
|
|
32
|
+
setup(props, { emit }) {
|
|
33
|
+
useAddField(props.prop);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
n: computed(() => props.name || props.config.name || ''),
|
|
37
|
+
activeValue: computed(() => {
|
|
38
|
+
if (typeof props.config.activeValue === 'undefined') {
|
|
39
|
+
if (props.config.filter === 'number') {
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
return props.config.activeValue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return true;
|
|
47
|
+
}),
|
|
48
|
+
inactiveValue: computed(() => {
|
|
49
|
+
if (typeof props.config.inactiveValue === 'undefined') {
|
|
50
|
+
if (props.config.filter === 'number') {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
return props.config.inactiveValue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false;
|
|
58
|
+
}),
|
|
59
|
+
changeHandler: (v: boolean | number | string) => {
|
|
60
|
+
emit('change', v);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
</script>
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-input
|
|
3
|
+
v-model="model[modelName]"
|
|
4
|
+
clearable
|
|
5
|
+
:size="size"
|
|
6
|
+
:placeholder="config.placeholder"
|
|
7
|
+
:disabled="disabled"
|
|
8
|
+
@change="changeHandler"
|
|
9
|
+
@input="inputHandler"
|
|
10
|
+
@keyup="keyUpHandler($event)"
|
|
11
|
+
>
|
|
12
|
+
<template #append v-if="config.append">
|
|
13
|
+
<span v-if="typeof config.append === 'string'">{{ config.append }}</span>
|
|
14
|
+
<el-button
|
|
15
|
+
v-if="typeof config.append === 'object' && config.append.type === 'button'"
|
|
16
|
+
style="color: #409eff"
|
|
17
|
+
@click="buttonClickHandler"
|
|
18
|
+
>
|
|
19
|
+
{{ config.append.text }}
|
|
20
|
+
</el-button>
|
|
21
|
+
</template>
|
|
22
|
+
</el-input>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { computed, defineComponent, inject, PropType } from 'vue';
|
|
27
|
+
|
|
28
|
+
import { FormState, TextConfig } from '../schema';
|
|
29
|
+
import fieldProps from '../utils/fieldProps';
|
|
30
|
+
import { useAddField } from '../utils/useAddField';
|
|
31
|
+
|
|
32
|
+
export default defineComponent({
|
|
33
|
+
name: 'm-fields-text',
|
|
34
|
+
|
|
35
|
+
props: {
|
|
36
|
+
...fieldProps,
|
|
37
|
+
config: {
|
|
38
|
+
type: Object as PropType<TextConfig>,
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
emits: ['change', 'input'],
|
|
44
|
+
|
|
45
|
+
setup(props, { emit }) {
|
|
46
|
+
useAddField(props.prop);
|
|
47
|
+
|
|
48
|
+
const modelName = computed(() => props.name || props.config.name || '');
|
|
49
|
+
return {
|
|
50
|
+
modelName,
|
|
51
|
+
|
|
52
|
+
changeHandler(v: string | number) {
|
|
53
|
+
emit('change', v);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
inputHandler(v: string | number) {
|
|
57
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
58
|
+
emit('input', v);
|
|
59
|
+
mForm?.$emit('field-input', props.prop, v);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
buttonClickHandler() {
|
|
63
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
64
|
+
|
|
65
|
+
if (typeof props.config.append === 'string') return;
|
|
66
|
+
|
|
67
|
+
if (props.config.append?.handler) {
|
|
68
|
+
props.config.append.handler(mForm, {
|
|
69
|
+
model: props.model,
|
|
70
|
+
values: mForm?.values,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
keyUpHandler($event: KeyboardEvent) {
|
|
76
|
+
if (!props.model) return;
|
|
77
|
+
if (!modelName.value) return;
|
|
78
|
+
|
|
79
|
+
const arrowUp = $event.key === 'ArrowUp';
|
|
80
|
+
const arrowDown = $event.key === 'ArrowDown';
|
|
81
|
+
|
|
82
|
+
if (!arrowUp && !arrowDown) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const value = props.model[modelName.value];
|
|
87
|
+
let num;
|
|
88
|
+
let unit;
|
|
89
|
+
if (/^([0-9.]+)$/.test(value)) {
|
|
90
|
+
num = +value;
|
|
91
|
+
} else {
|
|
92
|
+
value.replace(/^([0-9.]+)([a-z%]+)$/, ($0: string, $1: string, $2: string) => {
|
|
93
|
+
num = +$1;
|
|
94
|
+
unit = $2;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (num === undefined) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const ctrl = navigator.platform.match('Mac') ? $event.metaKey : $event.ctrlKey;
|
|
103
|
+
const shif = $event.shiftKey;
|
|
104
|
+
const alt = $event.altKey;
|
|
105
|
+
|
|
106
|
+
if (arrowUp) {
|
|
107
|
+
if (ctrl) {
|
|
108
|
+
num += 100;
|
|
109
|
+
} else if (alt) {
|
|
110
|
+
num = (num * 10000 + 1000) / 10000;
|
|
111
|
+
} else if (shif) {
|
|
112
|
+
num = num + 10;
|
|
113
|
+
} else {
|
|
114
|
+
num += 1;
|
|
115
|
+
}
|
|
116
|
+
} else if (arrowDown) {
|
|
117
|
+
if (ctrl) {
|
|
118
|
+
num -= 100;
|
|
119
|
+
} else if (alt) {
|
|
120
|
+
num = (num * 10000 - 1000) / 10000;
|
|
121
|
+
} else if (shif) {
|
|
122
|
+
num -= 10;
|
|
123
|
+
} else {
|
|
124
|
+
num -= 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
props.model[modelName.value] = `${num}${unit || ''}`;
|
|
129
|
+
emit('change', props.model[modelName.value]);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
</script>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="model">
|
|
3
|
+
<el-input
|
|
4
|
+
v-model="model[name]"
|
|
5
|
+
type="textarea"
|
|
6
|
+
:size="size"
|
|
7
|
+
clearable
|
|
8
|
+
:placeholder="config.placeholder"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
@change="changeHandler"
|
|
11
|
+
@input="inputHandler"
|
|
12
|
+
>
|
|
13
|
+
</el-input>
|
|
14
|
+
</div>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { defineComponent, inject, PropType } from 'vue';
|
|
19
|
+
|
|
20
|
+
import { FormState, TextareaConfig } from '../schema';
|
|
21
|
+
import fieldProps from '../utils/fieldProps';
|
|
22
|
+
import { useAddField } from '../utils/useAddField';
|
|
23
|
+
export default defineComponent({
|
|
24
|
+
name: 'm-fields-textarea',
|
|
25
|
+
|
|
26
|
+
props: {
|
|
27
|
+
...fieldProps,
|
|
28
|
+
config: {
|
|
29
|
+
type: Object as PropType<TextareaConfig>,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
emits: {
|
|
35
|
+
change(values: string | number) {
|
|
36
|
+
return values;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
input(values: string | number) {
|
|
40
|
+
return values;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
setup(props, { emit }) {
|
|
45
|
+
useAddField(props.prop);
|
|
46
|
+
|
|
47
|
+
const mForm = inject<FormState | null>('mForm');
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
mForm,
|
|
51
|
+
changeHandler: (v: string) => {
|
|
52
|
+
emit('change', v);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
inputHandler: (v: string) => {
|
|
56
|
+
emit('input', v);
|
|
57
|
+
mForm?.$emit('field-input', props.prop, v);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<el-time-picker
|
|
4
|
+
v-model="model[name]"
|
|
5
|
+
:size="size"
|
|
6
|
+
value-format="HH:mm:ss"
|
|
7
|
+
:placeholder="config.placeholder"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
@change="changeHandler"
|
|
10
|
+
></el-time-picker>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { defineComponent, PropType } from 'vue';
|
|
16
|
+
|
|
17
|
+
import { TimeConfig } from '../schema';
|
|
18
|
+
import fieldProps from '../utils/fieldProps';
|
|
19
|
+
import { useAddField } from '../utils/useAddField';
|
|
20
|
+
|
|
21
|
+
export default defineComponent({
|
|
22
|
+
name: 'm-fields-time',
|
|
23
|
+
|
|
24
|
+
props: {
|
|
25
|
+
...fieldProps,
|
|
26
|
+
config: {
|
|
27
|
+
type: Object as PropType<TimeConfig>,
|
|
28
|
+
required: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
emits: {
|
|
33
|
+
change(values: Date) {
|
|
34
|
+
return values;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
setup(props, { emit }) {
|
|
39
|
+
useAddField(props.prop);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
changeHandler: (v: Date) => {
|
|
43
|
+
emit('change', v);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
</script>
|