@tmagic/form 1.1.6 → 1.2.0-beta.10

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