@tmagic/form 1.2.0-beta.2 → 1.2.0-beta.21
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 +1 -1
- package/dist/tmagic-form.js +3673 -0
- package/dist/tmagic-form.js.map +1 -0
- package/dist/tmagic-form.umd.cjs +3713 -0
- package/dist/tmagic-form.umd.cjs.map +1 -0
- package/package.json +10 -9
- package/src/Form.vue +124 -159
- package/src/FormDialog.vue +108 -126
- package/src/containers/Col.vue +24 -38
- package/src/containers/Container.vue +143 -171
- package/src/containers/Fieldset.vue +15 -8
- package/src/containers/GroupList.vue +86 -116
- package/src/containers/GroupListItem.vue +91 -125
- package/src/containers/Panel.vue +29 -49
- package/src/containers/Row.vue +20 -40
- package/src/containers/Step.vue +38 -48
- package/src/containers/Table.vue +466 -481
- package/src/containers/Tabs.vue +94 -118
- package/src/fields/Cascader.vue +88 -136
- package/src/fields/Checkbox.vue +46 -50
- package/src/fields/CheckboxGroup.vue +39 -35
- package/src/fields/ColorPicker.vue +5 -3
- package/src/fields/Date.vue +21 -27
- package/src/fields/DateTime.vue +31 -39
- package/src/fields/Daterange.vue +4 -3
- package/src/fields/Display.vue +1 -1
- package/src/fields/DynamicField.vue +63 -77
- package/src/fields/Hidden.vue +1 -1
- package/src/fields/Link.vue +65 -86
- package/src/fields/Number.vue +32 -34
- package/src/fields/RadioGroup.vue +23 -23
- package/src/fields/Select.vue +294 -310
- package/src/fields/SelectOptionGroups.vue +11 -6
- package/src/fields/SelectOptions.vue +5 -3
- package/src/fields/Switch.vue +46 -49
- package/src/fields/Text.vue +99 -107
- package/src/fields/Textarea.vue +32 -44
- package/src/fields/Time.vue +21 -30
- package/src/index.ts +22 -23
- package/src/schema.ts +50 -12
- package/src/theme/form.scss +1 -1
- package/src/utils/form.ts +9 -5
- package/types/Form.vue.d.ts +211 -111
- package/types/FormDialog.vue.d.ts +813 -154
- package/types/containers/Col.vue.d.ts +96 -40
- package/types/containers/Container.vue.d.ts +126 -65
- package/types/containers/Fieldset.vue.d.ts +5 -3
- package/types/containers/GroupList.vue.d.ts +90 -53
- package/types/containers/GroupListItem.vue.d.ts +101 -67
- package/types/containers/Panel.vue.d.ts +96 -39
- package/types/containers/Row.vue.d.ts +96 -39
- package/types/containers/Step.vue.d.ts +106 -42
- package/types/containers/Table.vue.d.ts +161 -130
- package/types/containers/Tabs.vue.d.ts +97 -50
- package/types/fields/Cascader.vue.d.ts +95 -71
- package/types/fields/Checkbox.vue.d.ts +95 -56
- package/types/fields/CheckboxGroup.vue.d.ts +95 -53
- package/types/fields/ColorPicker.vue.d.ts +1 -3
- package/types/fields/Date.vue.d.ts +95 -54
- package/types/fields/DateTime.vue.d.ts +95 -54
- package/types/fields/Daterange.vue.d.ts +1 -3
- package/types/fields/Display.vue.d.ts +1 -3
- package/types/fields/DynamicField.vue.d.ts +95 -64
- package/types/fields/Hidden.vue.d.ts +1 -3
- package/types/fields/Link.vue.d.ts +60 -657
- package/types/fields/Number.vue.d.ts +99 -56
- package/types/fields/RadioGroup.vue.d.ts +96 -52
- package/types/fields/Select.vue.d.ts +97 -65
- package/types/fields/SelectOptionGroups.vue.d.ts +1 -3
- package/types/fields/SelectOptions.vue.d.ts +1 -3
- package/types/fields/Switch.vue.d.ts +95 -56
- package/types/fields/Text.vue.d.ts +98 -57
- package/types/fields/Textarea.vue.d.ts +100 -60
- package/types/fields/Time.vue.d.ts +95 -55
- package/types/index.d.ts +0 -1
- package/types/schema.d.ts +42 -9
- package/types/utils/form.d.ts +2 -1
- package/dist/tmagic-form.mjs +0 -3925
- package/dist/tmagic-form.mjs.map +0 -1
- package/dist/tmagic-form.umd.js +0 -3965
- package/dist/tmagic-form.umd.js.map +0 -1
- package/src/utils/fieldProps.ts +0 -39
- package/types/utils/fieldProps.d.ts +0 -21
package/src/fields/Select.vue
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicSelect
|
|
3
3
|
v-if="model"
|
|
4
4
|
v-model="model[name]"
|
|
5
5
|
v-loading="loading"
|
|
6
6
|
class="m-select"
|
|
7
|
-
ref="
|
|
7
|
+
ref="tMagicSelect"
|
|
8
8
|
clearable
|
|
9
9
|
filterable
|
|
10
10
|
:popper-class="`m-select-popper ${popperClass}`"
|
|
@@ -19,346 +19,330 @@
|
|
|
19
19
|
@change="changeHandler"
|
|
20
20
|
@visible-change="visibleHandler"
|
|
21
21
|
>
|
|
22
|
-
<template v-if="config.group"><
|
|
23
|
-
<template v-else><
|
|
22
|
+
<template v-if="config.group"><SelectOptionGroups :options="groupOptions"></SelectOptionGroups></template>
|
|
23
|
+
<template v-else><SelectOptions :options="itemOptions"></SelectOptions></template>
|
|
24
24
|
<div v-loading="true" v-if="moreLoadingVisible"></div>
|
|
25
|
-
</
|
|
25
|
+
</TMagicSelect>
|
|
26
26
|
</template>
|
|
27
27
|
|
|
28
|
-
<script lang="ts">
|
|
29
|
-
import {
|
|
28
|
+
<script lang="ts" setup name="MFormSelect">
|
|
29
|
+
import { inject, nextTick, onBeforeMount, onMounted, Ref, ref, watchEffect } from 'vue';
|
|
30
|
+
|
|
31
|
+
import { TMagicSelect } from '@tmagic/design';
|
|
30
32
|
|
|
31
33
|
import { FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
|
|
32
34
|
import { getConfig } from '../utils/config';
|
|
33
|
-
import fieldProps from '../utils/fieldProps';
|
|
34
35
|
import { useAddField } from '../utils/useAddField';
|
|
35
36
|
|
|
36
37
|
import SelectOptionGroups from './SelectOptionGroups.vue';
|
|
37
38
|
import SelectOptions from './SelectOptions.vue';
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
config: props.config,
|
|
123
|
-
}) as Record<string, any>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
body.query = query.value;
|
|
127
|
-
body.pgSize = pgSize.value;
|
|
128
|
-
body.pgIndex = pgIndex.value;
|
|
129
|
-
postOptions.data = body;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const requestFuc = getConfig('request') as Function;
|
|
133
|
-
|
|
134
|
-
if (typeof option.beforeRequest === 'function') {
|
|
135
|
-
postOptions = option.beforeRequest(mForm, postOptions, {
|
|
136
|
-
model: props.model,
|
|
137
|
-
formValue: mForm?.values,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (option.method?.toLocaleLowerCase() === 'jsonp') {
|
|
142
|
-
postOptions.jsonpCallback = option.jsonpCallback || 'callback';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
let res = await requestFuc(postOptions);
|
|
146
|
-
|
|
147
|
-
if (typeof option.afterRequest === 'function') {
|
|
148
|
-
res = option.afterRequest(mForm, res, {
|
|
149
|
-
model: props.model,
|
|
150
|
-
formValue: mForm?.values,
|
|
151
|
-
formValues: mForm?.values,
|
|
152
|
-
config: props.config,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const optionsData = res[option.root];
|
|
40
|
+
const props = defineProps<{
|
|
41
|
+
config: SelectConfig;
|
|
42
|
+
model: any;
|
|
43
|
+
initValues?: any;
|
|
44
|
+
values?: any;
|
|
45
|
+
name: string;
|
|
46
|
+
prop: string;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
size: 'mini' | 'small' | 'medium';
|
|
49
|
+
}>();
|
|
50
|
+
|
|
51
|
+
const emit = defineEmits(['change']);
|
|
52
|
+
|
|
53
|
+
if (!props.model) throw new Error('不能没有model');
|
|
54
|
+
useAddField(props.prop);
|
|
55
|
+
|
|
56
|
+
const tMagicSelect = ref<InstanceType<typeof TMagicSelect>>();
|
|
57
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
58
|
+
const options = ref<SelectOption[] | SelectGroupOption[]>([]);
|
|
59
|
+
const localOptions = ref<SelectOption[] | SelectGroupOption[]>([]);
|
|
60
|
+
const loading = ref(false);
|
|
61
|
+
const moreLoadingVisible = ref(false);
|
|
62
|
+
const total = ref(0);
|
|
63
|
+
const pgIndex = ref(0);
|
|
64
|
+
const pgSize = ref(20);
|
|
65
|
+
const query = ref('');
|
|
66
|
+
const remoteData = ref<any[]>([]);
|
|
67
|
+
const remote = ref(true);
|
|
68
|
+
|
|
69
|
+
const equalValue = (value: any, v: any): boolean => {
|
|
70
|
+
if (typeof v === 'object') {
|
|
71
|
+
const key = props.config.valueKey || 'value';
|
|
72
|
+
return v[key] === value[key];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return value === v;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const mapOptions = (data: any[]) => {
|
|
79
|
+
const { option } = props.config;
|
|
80
|
+
const { text } = option;
|
|
81
|
+
const { value } = option;
|
|
82
|
+
|
|
83
|
+
return data.map((item) => ({
|
|
84
|
+
text: typeof text === 'function' ? text(item) : item[text || 'text'],
|
|
85
|
+
value: typeof value === 'function' ? value(item) : item[value || 'value'],
|
|
86
|
+
}));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const getOptions = async () => {
|
|
90
|
+
if (!props.model) return [];
|
|
91
|
+
|
|
92
|
+
if (localOptions.value.length) {
|
|
93
|
+
return localOptions.value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
loading.value = true;
|
|
97
|
+
|
|
98
|
+
let items: SelectOption[] | SelectGroupOption[] = [];
|
|
99
|
+
|
|
100
|
+
const { config } = props;
|
|
101
|
+
const { option } = config;
|
|
102
|
+
let { body } = option;
|
|
103
|
+
|
|
104
|
+
let postOptions: Record<string, any> = {
|
|
105
|
+
method: option.method || 'POST',
|
|
106
|
+
url: option.url,
|
|
107
|
+
cache: option.cache,
|
|
108
|
+
timeout: option.timeout,
|
|
109
|
+
mode: option.mode,
|
|
110
|
+
headers: option.headers || {},
|
|
111
|
+
json: option.json || false,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (body) {
|
|
115
|
+
if (typeof body === 'function') {
|
|
116
|
+
body = body(mForm, {
|
|
117
|
+
model: props.model,
|
|
118
|
+
formValue: mForm?.values,
|
|
119
|
+
formValues: mForm?.values,
|
|
120
|
+
config: props.config,
|
|
121
|
+
}) as Record<string, any>;
|
|
122
|
+
}
|
|
157
123
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
124
|
+
body.query = query.value;
|
|
125
|
+
body.pgSize = pgSize.value;
|
|
126
|
+
body.pgIndex = pgIndex.value;
|
|
127
|
+
postOptions.data = body;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const requestFuc = getConfig('request') as Function;
|
|
131
|
+
|
|
132
|
+
if (typeof option.beforeRequest === 'function') {
|
|
133
|
+
postOptions = option.beforeRequest(mForm, postOptions, {
|
|
134
|
+
model: props.model,
|
|
135
|
+
formValue: mForm?.values,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (option.method?.toLocaleLowerCase() === 'jsonp') {
|
|
140
|
+
postOptions.jsonpCallback = option.jsonpCallback || 'callback';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let res = await requestFuc(postOptions);
|
|
144
|
+
|
|
145
|
+
if (typeof option.afterRequest === 'function') {
|
|
146
|
+
res = option.afterRequest(mForm, res, {
|
|
147
|
+
model: props.model,
|
|
148
|
+
formValue: mForm?.values,
|
|
149
|
+
formValues: mForm?.values,
|
|
150
|
+
config: props.config,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const optionsData = res[option.root];
|
|
155
|
+
|
|
156
|
+
if (res.total > 0) {
|
|
157
|
+
total.value = res.total;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
remoteData.value = remoteData.value.concat(optionsData);
|
|
161
|
+
if (optionsData) {
|
|
162
|
+
if (typeof option.item === 'function') {
|
|
163
|
+
items = option.item(optionsData);
|
|
164
|
+
} else if (optionsData.map) {
|
|
165
|
+
items = mapOptions(optionsData);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
if (optionsData) {
|
|
164
|
-
if (typeof option.item === 'function') {
|
|
165
|
-
items = option.item(optionsData);
|
|
166
|
-
} else if (optionsData.map) {
|
|
167
|
-
items = mapOptions(optionsData);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
169
|
+
loading.value = false;
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (isInclude && !(items as any[]).find((op: any) => op.value === o.value)) {
|
|
179
|
-
selectedOptions.push(o);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
171
|
+
// 多选过滤时会导致已选的选项显示不了,所以要把已选的选项保留不要过滤没了
|
|
172
|
+
const selectedOptions: SelectOption[] | SelectGroupOption[] = [];
|
|
173
|
+
if (props.config.multiple && props.model[props.name]) {
|
|
174
|
+
options.value.forEach((o: any) => {
|
|
175
|
+
const isInclude = props.model?.[props.name].includes(o.value);
|
|
176
|
+
if (isInclude && !(items as any[]).find((op: any) => op.value === o.value)) {
|
|
177
|
+
selectedOptions.push(o);
|
|
182
178
|
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
183
181
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const getInitLocalOption = async () => {
|
|
188
|
-
if (!props.model) return [];
|
|
182
|
+
return pgIndex.value === 0 ? (selectedOptions as any[]).concat(items) : (options.value as any).concat(items);
|
|
183
|
+
};
|
|
189
184
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
localOptions.value = await getOptions();
|
|
185
|
+
const getInitLocalOption = async () => {
|
|
186
|
+
if (!props.model) return [];
|
|
193
187
|
|
|
194
|
-
|
|
188
|
+
const value = props.model[props.name];
|
|
189
|
+
const { config } = props;
|
|
190
|
+
localOptions.value = await getOptions();
|
|
195
191
|
|
|
196
|
-
|
|
197
|
-
if (config.multiple && value.findIndex) {
|
|
198
|
-
return (localOptions.value as SelectGroupOption[]).filter(
|
|
199
|
-
(group) => group.options.findIndex((item) => value.find((v: any) => equalValue(item.value, v)) > -1) > -1,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
192
|
+
remote.value = false;
|
|
202
193
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
if (config.group) {
|
|
195
|
+
if (config.multiple && value.findIndex) {
|
|
196
|
+
return (localOptions.value as SelectGroupOption[]).filter(
|
|
197
|
+
(group) => group.options.findIndex((item) => value.find((v: any) => equalValue(item.value, v)) > -1) > -1,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
207
200
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
return (localOptions.value as any[]).filter((item) => equalValue(item.value, value));
|
|
214
|
-
};
|
|
201
|
+
return (localOptions.value as SelectGroupOption[]).filter(
|
|
202
|
+
(group) => group.options.findIndex((item) => equalValue(item.value, value)) > -1,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
215
205
|
|
|
216
|
-
|
|
217
|
-
|
|
206
|
+
if (config.multiple && value.findIndex) {
|
|
207
|
+
return (localOptions.value as any[]).filter((item) => value.findIndex((v: any) => equalValue(item.value, v)) > -1);
|
|
208
|
+
}
|
|
209
|
+
return (localOptions.value as any[]).filter((item) => equalValue(item.value, value));
|
|
210
|
+
};
|
|
218
211
|
|
|
219
|
-
|
|
220
|
-
|
|
212
|
+
const getInitOption = async () => {
|
|
213
|
+
if (!props.model) return [];
|
|
221
214
|
|
|
222
|
-
|
|
215
|
+
const { config } = props;
|
|
216
|
+
const { option } = config;
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
if (!url) {
|
|
226
|
-
return getInitLocalOption();
|
|
227
|
-
}
|
|
218
|
+
let options: SelectOption[] | SelectGroupOption[] = [];
|
|
228
219
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
220
|
+
let url = option.initUrl;
|
|
221
|
+
if (!url) {
|
|
222
|
+
return getInitLocalOption();
|
|
223
|
+
}
|
|
232
224
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
data: {
|
|
237
|
-
id: props.model[props.name],
|
|
238
|
-
},
|
|
239
|
-
mode: option.mode,
|
|
240
|
-
headers: option.headers || {},
|
|
241
|
-
json: option.json || false,
|
|
242
|
-
};
|
|
243
|
-
if (option.method?.toLocaleLowerCase() === 'jsonp') {
|
|
244
|
-
postOptions.jsonpCallback = option.jsonpCallback || 'callback';
|
|
245
|
-
}
|
|
225
|
+
if (typeof url === 'function') {
|
|
226
|
+
url = await url(mForm, { model: props.model, formValue: mForm?.values });
|
|
227
|
+
}
|
|
246
228
|
|
|
247
|
-
|
|
248
|
-
|
|
229
|
+
const postOptions: Record<string, any> = {
|
|
230
|
+
method: option.method || 'POST',
|
|
231
|
+
url,
|
|
232
|
+
data: {
|
|
233
|
+
id: props.model[props.name],
|
|
234
|
+
},
|
|
235
|
+
mode: option.mode,
|
|
236
|
+
headers: option.headers || {},
|
|
237
|
+
json: option.json || false,
|
|
238
|
+
};
|
|
239
|
+
if (option.method?.toLocaleLowerCase() === 'jsonp') {
|
|
240
|
+
postOptions.jsonpCallback = option.jsonpCallback || 'callback';
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const requestFuc = getConfig('request') as Function;
|
|
244
|
+
const res = await requestFuc(postOptions);
|
|
245
|
+
|
|
246
|
+
let initData = res[option.root];
|
|
247
|
+
if (initData) {
|
|
248
|
+
if (!Array.isArray(initData)) {
|
|
249
|
+
initData = [initData];
|
|
250
|
+
}
|
|
249
251
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
if (typeof option.item === 'function') {
|
|
253
|
+
options = option.item(initData);
|
|
254
|
+
} else if (initData.map) {
|
|
255
|
+
options = mapOptions(initData);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
255
258
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
} else if (initData.map) {
|
|
259
|
-
options = mapOptions(initData);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
259
|
+
return options;
|
|
260
|
+
};
|
|
262
261
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}),
|
|
277
|
-
).then((data) => {
|
|
278
|
-
options.value = data;
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
} else if (Array.isArray(props.config.options)) {
|
|
282
|
-
watchEffect(() => {
|
|
283
|
-
options.value = props.config.options as SelectOption[] | SelectGroupOption[];
|
|
262
|
+
if (typeof props.config.options === 'function') {
|
|
263
|
+
watchEffect(() => {
|
|
264
|
+
typeof props.config.options === 'function' &&
|
|
265
|
+
Promise.resolve(
|
|
266
|
+
props.config.options(mForm, {
|
|
267
|
+
model: props.model,
|
|
268
|
+
prop: props.prop,
|
|
269
|
+
formValues: mForm?.values,
|
|
270
|
+
formValue: mForm?.values,
|
|
271
|
+
config: props.config,
|
|
272
|
+
}),
|
|
273
|
+
).then((data) => {
|
|
274
|
+
options.value = data;
|
|
284
275
|
});
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
276
|
+
});
|
|
277
|
+
} else if (Array.isArray(props.config.options)) {
|
|
278
|
+
watchEffect(() => {
|
|
279
|
+
options.value = props.config.options as SelectOption[] | SelectGroupOption[];
|
|
280
|
+
});
|
|
281
|
+
} else if (props.config.option) {
|
|
282
|
+
onBeforeMount(() => {
|
|
283
|
+
if (!props.model) return;
|
|
284
|
+
const v = props.model[props.name];
|
|
285
|
+
if (Array.isArray(v) ? v.length : typeof v !== 'undefined') {
|
|
286
|
+
getInitOption().then((data) => {
|
|
287
|
+
options.value = data;
|
|
294
288
|
});
|
|
295
289
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
// 多选时如果过滤选项会导致已选好的标签异常,需要重新刷新一下el-select的状态
|
|
355
|
-
if (props.config.multiple)
|
|
356
|
-
setTimeout(() => {
|
|
357
|
-
select.value?.setSelected();
|
|
358
|
-
}, 0);
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
},
|
|
363
|
-
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
props.config.remote &&
|
|
294
|
+
onMounted(async () => {
|
|
295
|
+
await nextTick();
|
|
296
|
+
tMagicSelect.value?.scrollbarWrap?.addEventListener('scroll', async (e: Event) => {
|
|
297
|
+
const el = e.currentTarget as HTMLDivElement;
|
|
298
|
+
if (moreLoadingVisible.value) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (el.scrollHeight - el.clientHeight - el.scrollTop > 1) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (total.value <= options.value.length) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
moreLoadingVisible.value = true;
|
|
308
|
+
pgIndex.value += 1;
|
|
309
|
+
options.value = await getOptions();
|
|
310
|
+
moreLoadingVisible.value = false;
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const popperClass = mForm?.popperClass;
|
|
315
|
+
|
|
316
|
+
const changeHandler = (value: any) => {
|
|
317
|
+
emit('change', value);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const visibleHandler = async (visible: boolean) => {
|
|
321
|
+
if (!visible) return;
|
|
322
|
+
|
|
323
|
+
if (!props.config.remote) return;
|
|
324
|
+
if (query.value && tMagicSelect.value) {
|
|
325
|
+
tMagicSelect.value.setQuery(query.value);
|
|
326
|
+
tMagicSelect.value.setPreviousQuery(query.value);
|
|
327
|
+
tMagicSelect.value.setSelectedLabel(query.value);
|
|
328
|
+
} else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
|
|
329
|
+
options.value = await getOptions();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const remoteMethod = async (q: string) => {
|
|
334
|
+
if (!localOptions.value.length) {
|
|
335
|
+
query.value = q;
|
|
336
|
+
pgIndex.value = 0;
|
|
337
|
+
options.value = await getOptions();
|
|
338
|
+
// 多选时如果过滤选项会导致已选好的标签异常,需要重新刷新一下el-select的状态
|
|
339
|
+
if (props.config.multiple)
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
tMagicSelect.value?.setSelected();
|
|
342
|
+
}, 0);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const itemOptions = options as Ref<SelectOption[]>;
|
|
347
|
+
const groupOptions = options as Ref<SelectGroupOption[]>;
|
|
364
348
|
</script>
|