@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.
Files changed (83) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-form.js +3673 -0
  3. package/dist/tmagic-form.js.map +1 -0
  4. package/dist/tmagic-form.umd.cjs +3713 -0
  5. package/dist/tmagic-form.umd.cjs.map +1 -0
  6. package/package.json +10 -9
  7. package/src/Form.vue +124 -159
  8. package/src/FormDialog.vue +108 -126
  9. package/src/containers/Col.vue +24 -38
  10. package/src/containers/Container.vue +143 -171
  11. package/src/containers/Fieldset.vue +15 -8
  12. package/src/containers/GroupList.vue +86 -116
  13. package/src/containers/GroupListItem.vue +91 -125
  14. package/src/containers/Panel.vue +29 -49
  15. package/src/containers/Row.vue +20 -40
  16. package/src/containers/Step.vue +38 -48
  17. package/src/containers/Table.vue +466 -481
  18. package/src/containers/Tabs.vue +94 -118
  19. package/src/fields/Cascader.vue +88 -136
  20. package/src/fields/Checkbox.vue +46 -50
  21. package/src/fields/CheckboxGroup.vue +39 -35
  22. package/src/fields/ColorPicker.vue +5 -3
  23. package/src/fields/Date.vue +21 -27
  24. package/src/fields/DateTime.vue +31 -39
  25. package/src/fields/Daterange.vue +4 -3
  26. package/src/fields/Display.vue +1 -1
  27. package/src/fields/DynamicField.vue +63 -77
  28. package/src/fields/Hidden.vue +1 -1
  29. package/src/fields/Link.vue +65 -86
  30. package/src/fields/Number.vue +32 -34
  31. package/src/fields/RadioGroup.vue +23 -23
  32. package/src/fields/Select.vue +294 -310
  33. package/src/fields/SelectOptionGroups.vue +11 -6
  34. package/src/fields/SelectOptions.vue +5 -3
  35. package/src/fields/Switch.vue +46 -49
  36. package/src/fields/Text.vue +99 -107
  37. package/src/fields/Textarea.vue +32 -44
  38. package/src/fields/Time.vue +21 -30
  39. package/src/index.ts +22 -23
  40. package/src/schema.ts +50 -12
  41. package/src/theme/form.scss +1 -1
  42. package/src/utils/form.ts +9 -5
  43. package/types/Form.vue.d.ts +211 -111
  44. package/types/FormDialog.vue.d.ts +813 -154
  45. package/types/containers/Col.vue.d.ts +96 -40
  46. package/types/containers/Container.vue.d.ts +126 -65
  47. package/types/containers/Fieldset.vue.d.ts +5 -3
  48. package/types/containers/GroupList.vue.d.ts +90 -53
  49. package/types/containers/GroupListItem.vue.d.ts +101 -67
  50. package/types/containers/Panel.vue.d.ts +96 -39
  51. package/types/containers/Row.vue.d.ts +96 -39
  52. package/types/containers/Step.vue.d.ts +106 -42
  53. package/types/containers/Table.vue.d.ts +161 -130
  54. package/types/containers/Tabs.vue.d.ts +97 -50
  55. package/types/fields/Cascader.vue.d.ts +95 -71
  56. package/types/fields/Checkbox.vue.d.ts +95 -56
  57. package/types/fields/CheckboxGroup.vue.d.ts +95 -53
  58. package/types/fields/ColorPicker.vue.d.ts +1 -3
  59. package/types/fields/Date.vue.d.ts +95 -54
  60. package/types/fields/DateTime.vue.d.ts +95 -54
  61. package/types/fields/Daterange.vue.d.ts +1 -3
  62. package/types/fields/Display.vue.d.ts +1 -3
  63. package/types/fields/DynamicField.vue.d.ts +95 -64
  64. package/types/fields/Hidden.vue.d.ts +1 -3
  65. package/types/fields/Link.vue.d.ts +60 -657
  66. package/types/fields/Number.vue.d.ts +99 -56
  67. package/types/fields/RadioGroup.vue.d.ts +96 -52
  68. package/types/fields/Select.vue.d.ts +97 -65
  69. package/types/fields/SelectOptionGroups.vue.d.ts +1 -3
  70. package/types/fields/SelectOptions.vue.d.ts +1 -3
  71. package/types/fields/Switch.vue.d.ts +95 -56
  72. package/types/fields/Text.vue.d.ts +98 -57
  73. package/types/fields/Textarea.vue.d.ts +100 -60
  74. package/types/fields/Time.vue.d.ts +95 -55
  75. package/types/index.d.ts +0 -1
  76. package/types/schema.d.ts +42 -9
  77. package/types/utils/form.d.ts +2 -1
  78. package/dist/tmagic-form.mjs +0 -3925
  79. package/dist/tmagic-form.mjs.map +0 -1
  80. package/dist/tmagic-form.umd.js +0 -3965
  81. package/dist/tmagic-form.umd.js.map +0 -1
  82. package/src/utils/fieldProps.ts +0 -39
  83. 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,346 +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, watchEffect } 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
- }
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
- if (res.total > 0) {
159
- total.value = res.total;
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
- 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
- }
169
+ loading.value = false;
170
170
 
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
- });
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
- return pgIndex.value === 0 ? (selectedOptions as any[]).concat(items) : (options.value as any).concat(items);
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
- const value = props.model[props.name];
191
- const { config } = props;
192
- localOptions.value = await getOptions();
185
+ const getInitLocalOption = async () => {
186
+ if (!props.model) return [];
193
187
 
194
- remote.value = false;
188
+ const value = props.model[props.name];
189
+ const { config } = props;
190
+ localOptions.value = await getOptions();
195
191
 
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
- }
192
+ remote.value = false;
202
193
 
203
- return (localOptions.value as SelectGroupOption[]).filter(
204
- (group) => group.options.findIndex((item) => equalValue(item.value, value)) > -1,
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
- 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
- };
201
+ return (localOptions.value as SelectGroupOption[]).filter(
202
+ (group) => group.options.findIndex((item) => equalValue(item.value, value)) > -1,
203
+ );
204
+ }
215
205
 
216
- const getInitOption = async () => {
217
- if (!props.model) return [];
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
- const { config } = props;
220
- const { option } = config;
212
+ const getInitOption = async () => {
213
+ if (!props.model) return [];
221
214
 
222
- let options: SelectOption[] | SelectGroupOption[] = [];
215
+ const { config } = props;
216
+ const { option } = config;
223
217
 
224
- let url = option.initUrl;
225
- if (!url) {
226
- return getInitLocalOption();
227
- }
218
+ let options: SelectOption[] | SelectGroupOption[] = [];
228
219
 
229
- if (typeof url === 'function') {
230
- url = await url(mForm, { model: props.model, formValue: mForm?.values });
231
- }
220
+ let url = option.initUrl;
221
+ if (!url) {
222
+ return getInitLocalOption();
223
+ }
232
224
 
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';
245
- }
225
+ if (typeof url === 'function') {
226
+ url = await url(mForm, { model: props.model, formValue: mForm?.values });
227
+ }
246
228
 
247
- const requestFuc = getConfig('request') as Function;
248
- const res = await requestFuc(postOptions);
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
- let initData = res[option.root];
251
- if (initData) {
252
- if (!Array.isArray(initData)) {
253
- initData = [initData];
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
- if (typeof option.item === 'function') {
257
- options = option.item(initData);
258
- } else if (initData.map) {
259
- options = mapOptions(initData);
260
- }
261
- }
259
+ return options;
260
+ };
262
261
 
263
- return options;
264
- };
265
-
266
- if (typeof props.config.options === 'function') {
267
- watchEffect(() => {
268
- typeof props.config.options === 'function' &&
269
- Promise.resolve(
270
- props.config.options(mForm, {
271
- model: props.model,
272
- prop: props.prop,
273
- formValues: mForm?.values,
274
- formValue: mForm?.values,
275
- config: props.config,
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
- } else if (props.config.option) {
286
- onBeforeMount(() => {
287
- if (!props.model) return;
288
- const v = props.model[props.name];
289
- if (Array.isArray(v) ? v.length : typeof v !== 'undefined') {
290
- getInitOption().then((data) => {
291
- options.value = data;
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
- props.config.remote &&
298
- onMounted(() => {
299
- select.value?.scrollbar.wrap$.addEventListener('scroll', async (e: Event) => {
300
- const el = e.currentTarget as HTMLDivElement;
301
- if (moreLoadingVisible.value) {
302
- return;
303
- }
304
- if (el.scrollHeight - el.clientHeight - el.scrollTop > 1) {
305
- return;
306
- }
307
- if (total.value <= options.value.length) {
308
- return;
309
- }
310
- moreLoadingVisible.value = true;
311
- pgIndex.value += 1;
312
- options.value = await getOptions();
313
- moreLoadingVisible.value = false;
314
- });
315
- });
316
-
317
- return {
318
- select,
319
- loading,
320
- remote,
321
- options: options as Ref<SelectOption[]>,
322
- groupOptions: options as Ref<SelectGroupOption[]>,
323
- moreLoadingVisible,
324
- popperClass: mForm?.popperClass,
325
-
326
- getOptions,
327
-
328
- getRequestFuc() {
329
- return getConfig('request');
330
- },
331
-
332
- changeHandler(value: any) {
333
- emit('change', value);
334
- },
335
-
336
- async visibleHandler(visible: boolean) {
337
- if (!visible) return;
338
-
339
- if (!props.config.remote) return;
340
- if (query.value && select.value) {
341
- select.value.query = query.value;
342
- select.value.previousQuery = query.value;
343
- select.value.selectedLabel = query.value;
344
- } else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
345
- options.value = await getOptions();
346
- }
347
- },
348
-
349
- async remoteMethod(q: string) {
350
- if (!localOptions.value.length) {
351
- query.value = q;
352
- pgIndex.value = 0;
353
- options.value = await getOptions();
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>