Commit 5fae2b02eae7dc91baef774ca9dfdf0da91b8040
Committed by
GitHub
1 parent
3ff70bb5
perf: add Coordinating the selection of provinces and cities (#534)
Co-authored-by: M69W <M69W@M69W>
Showing
1 changed file
with
97 additions
and
0 deletions
src/views/demo/form/index.vue
@@ -19,6 +19,58 @@ | @@ -19,6 +19,58 @@ | ||
19 | import { PageWrapper } from '/@/components/Page'; | 19 | import { PageWrapper } from '/@/components/Page'; |
20 | 20 | ||
21 | import { optionsListApi } from '/@/api/demo/select'; | 21 | import { optionsListApi } from '/@/api/demo/select'; |
22 | + | ||
23 | + const provincesOptions = [ | ||
24 | + { | ||
25 | + id: 'guangdong', | ||
26 | + label: '广东省', | ||
27 | + value: '1', | ||
28 | + key: '1', | ||
29 | + }, | ||
30 | + { | ||
31 | + id: 'jiangsu', | ||
32 | + label: '江苏省', | ||
33 | + value: '2', | ||
34 | + key: '2', | ||
35 | + }, | ||
36 | + ]; | ||
37 | + const citiesOptionsData = { | ||
38 | + guangdong: [ | ||
39 | + { | ||
40 | + label: '珠海市', | ||
41 | + value: '1', | ||
42 | + key: '1', | ||
43 | + }, | ||
44 | + { | ||
45 | + label: '深圳市', | ||
46 | + value: '2', | ||
47 | + key: '2', | ||
48 | + }, | ||
49 | + { | ||
50 | + label: '广州市', | ||
51 | + value: '3', | ||
52 | + key: '3', | ||
53 | + }, | ||
54 | + ], | ||
55 | + jiangsu: [ | ||
56 | + { | ||
57 | + label: '南京市', | ||
58 | + value: '1', | ||
59 | + key: '1', | ||
60 | + }, | ||
61 | + { | ||
62 | + label: '无锡市', | ||
63 | + value: '2', | ||
64 | + key: '2', | ||
65 | + }, | ||
66 | + { | ||
67 | + label: '苏州市', | ||
68 | + value: '3', | ||
69 | + key: '3', | ||
70 | + }, | ||
71 | + ], | ||
72 | + }; | ||
73 | + | ||
22 | const schemas: FormSchema[] = [ | 74 | const schemas: FormSchema[] = [ |
23 | { | 75 | { |
24 | field: 'field1', | 76 | field: 'field1', |
@@ -236,6 +288,51 @@ | @@ -236,6 +288,51 @@ | ||
236 | span: 8, | 288 | span: 8, |
237 | }, | 289 | }, |
238 | }, | 290 | }, |
291 | + { | ||
292 | + field: 'province', | ||
293 | + component: 'Select', | ||
294 | + label: '省份', | ||
295 | + colProps: { | ||
296 | + span: 8, | ||
297 | + }, | ||
298 | + componentProps: ({ formModel, formActionType }) => { | ||
299 | + return { | ||
300 | + options: provincesOptions, | ||
301 | + placeholder: '省份与城市联动', | ||
302 | + onChange: (e: any) => { | ||
303 | + // console.log(e) | ||
304 | + let citiesOptions = | ||
305 | + e == 1 | ||
306 | + ? citiesOptionsData[provincesOptions[0].id] | ||
307 | + : citiesOptionsData[provincesOptions[1].id]; | ||
308 | + // console.log(citiesOptions) | ||
309 | + if (e === undefined) { | ||
310 | + citiesOptions = []; | ||
311 | + } | ||
312 | + formModel.city = undefined; // reset city value | ||
313 | + const { updateSchema } = formActionType; | ||
314 | + updateSchema({ | ||
315 | + field: 'city', | ||
316 | + componentProps: { | ||
317 | + options: citiesOptions, | ||
318 | + }, | ||
319 | + }); | ||
320 | + }, | ||
321 | + }; | ||
322 | + }, | ||
323 | + }, | ||
324 | + { | ||
325 | + field: 'city', | ||
326 | + component: 'Select', | ||
327 | + label: '城市', | ||
328 | + colProps: { | ||
329 | + span: 8, | ||
330 | + }, | ||
331 | + componentProps: { | ||
332 | + options: [], // defalut [] | ||
333 | + placeholder: '省份与城市联动', | ||
334 | + }, | ||
335 | + }, | ||
239 | ]; | 336 | ]; |
240 | 337 | ||
241 | export default defineComponent({ | 338 | export default defineComponent({ |