Commit a207cafec98461b39882f352f2bf5c7d3c21716a
1 parent
7101587b
fix(excel): update excel demo
Showing
10 changed files
with
154 additions
and
73 deletions
src/components/Excel/src/ExportExcelModel.vue
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | import { defineComponent } from 'vue'; | 12 | import { defineComponent } from 'vue'; |
13 | import { BasicModal, useModalInner } from '/@/components/Modal'; | 13 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
14 | import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'; | 14 | import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'; |
15 | + import { ExportModalResult } from './types'; | ||
15 | 16 | ||
16 | const schemas: FormSchema[] = [ | 17 | const schemas: FormSchema[] = [ |
17 | { | 18 | { |
@@ -59,7 +60,7 @@ | @@ -59,7 +60,7 @@ | ||
59 | const [registerModal, { closeModal }] = useModalInner(); | 60 | const [registerModal, { closeModal }] = useModalInner(); |
60 | 61 | ||
61 | async function handleOk() { | 62 | async function handleOk() { |
62 | - const res = await validateFields(); | 63 | + const res: ExportModalResult = await validateFields(); |
63 | const { filename, bookType } = res; | 64 | const { filename, bookType } = res; |
64 | 65 | ||
65 | emit('success', { | 66 | emit('success', { |
src/router/menus/modules/demo/charts.ts
@@ -27,6 +27,28 @@ const menu: MenuModule = { | @@ -27,6 +27,28 @@ const menu: MenuModule = { | ||
27 | }, | 27 | }, |
28 | ], | 28 | ], |
29 | }, | 29 | }, |
30 | + // { | ||
31 | + // path: '/excel', | ||
32 | + // name: 'excel', | ||
33 | + // children: [ | ||
34 | + { | ||
35 | + path: '/customExport', | ||
36 | + name: '选择导出格式', | ||
37 | + }, | ||
38 | + { | ||
39 | + path: '/jsonExport', | ||
40 | + name: 'JSON数据导出', | ||
41 | + }, | ||
42 | + { | ||
43 | + path: '/arrayExport', | ||
44 | + name: 'Array数据导出', | ||
45 | + }, | ||
46 | + { | ||
47 | + path: '/importExcel', | ||
48 | + name: '导入', | ||
49 | + }, | ||
50 | + // ], | ||
51 | + // }, | ||
30 | ], | 52 | ], |
31 | }, | 53 | }, |
32 | }; | 54 | }; |
src/router/menus/modules/demo/comp.ts
@@ -66,20 +66,6 @@ const menu: MenuModule = { | @@ -66,20 +66,6 @@ const menu: MenuModule = { | ||
66 | path: '/strength-meter', | 66 | path: '/strength-meter', |
67 | name: '密码强度组件', | 67 | name: '密码强度组件', |
68 | }, | 68 | }, |
69 | - { | ||
70 | - path: '/excel', | ||
71 | - name: 'excel', | ||
72 | - children: [ | ||
73 | - { | ||
74 | - path: '/export', | ||
75 | - name: 'Export', | ||
76 | - }, | ||
77 | - { | ||
78 | - path: '/import', | ||
79 | - name: 'Import', | ||
80 | - }, | ||
81 | - ], | ||
82 | - }, | ||
83 | ], | 69 | ], |
84 | }, | 70 | }, |
85 | }; | 71 | }; |
src/router/routes/modules/demo/charts.ts
@@ -56,5 +56,47 @@ export default { | @@ -56,5 +56,47 @@ export default { | ||
56 | }, | 56 | }, |
57 | component: () => import('/@/views/demo/echarts/apex/index.vue'), | 57 | component: () => import('/@/views/demo/echarts/apex/index.vue'), |
58 | }, | 58 | }, |
59 | + // { | ||
60 | + // path: '/excel', | ||
61 | + // name: 'ExcelDemo', | ||
62 | + // redirect: '/charts/excel/export', | ||
63 | + // meta: { | ||
64 | + // title: 'excel', | ||
65 | + // }, | ||
66 | + // children: [ | ||
67 | + { | ||
68 | + path: '/customExport', | ||
69 | + name: 'CustomExport', | ||
70 | + component: () => import('/@/views/demo/echarts/excel/CustomExport.vue'), | ||
71 | + meta: { | ||
72 | + title: '选择导出格式', | ||
73 | + }, | ||
74 | + }, | ||
75 | + { | ||
76 | + path: '/jsonExport', | ||
77 | + name: 'JsonExport', | ||
78 | + component: () => import('/@/views/demo/echarts/excel/JsonExport.vue'), | ||
79 | + meta: { | ||
80 | + title: 'JSON数据导出', | ||
81 | + }, | ||
82 | + }, | ||
83 | + { | ||
84 | + path: '/arrayExport', | ||
85 | + name: 'ArrayExport', | ||
86 | + component: () => import('/@/views/demo/echarts/excel/ArrayExport.vue'), | ||
87 | + meta: { | ||
88 | + title: 'Array数据导出', | ||
89 | + }, | ||
90 | + }, | ||
91 | + { | ||
92 | + path: '/importExcel', | ||
93 | + name: 'ImportExcel', | ||
94 | + component: () => import('/@/views/demo/echarts/excel/ImportExcel.vue'), | ||
95 | + meta: { | ||
96 | + title: '导入', | ||
97 | + }, | ||
98 | + }, | ||
99 | + // ], | ||
100 | + // }, | ||
59 | ], | 101 | ], |
60 | } as AppRouteModule; | 102 | } as AppRouteModule; |
src/router/routes/modules/demo/comp.ts
@@ -136,31 +136,5 @@ export default { | @@ -136,31 +136,5 @@ export default { | ||
136 | title: '密码强度组件', | 136 | title: '密码强度组件', |
137 | }, | 137 | }, |
138 | }, | 138 | }, |
139 | - { | ||
140 | - path: '/excel', | ||
141 | - name: 'ExcelDemo', | ||
142 | - redirect: '/comp/excel/export', | ||
143 | - meta: { | ||
144 | - title: 'excel', | ||
145 | - }, | ||
146 | - children: [ | ||
147 | - { | ||
148 | - path: 'export', | ||
149 | - name: 'Export2Excel', | ||
150 | - component: () => import('/@/views/demo/comp/excel/ExportToExcel.vue'), | ||
151 | - meta: { | ||
152 | - title: 'Export2Excel', | ||
153 | - }, | ||
154 | - }, | ||
155 | - { | ||
156 | - path: 'import', | ||
157 | - name: 'ImportExcel', | ||
158 | - component: () => import('/@/views/demo/comp/excel/ImportExcel.vue'), | ||
159 | - meta: { | ||
160 | - title: 'ImportExcel', | ||
161 | - }, | ||
162 | - }, | ||
163 | - ], | ||
164 | - }, | ||
165 | ], | 139 | ], |
166 | } as AppRouteModule; | 140 | } as AppRouteModule; |
src/views/demo/echarts/excel/ArrayExport.vue
0 → 100644
1 | +<template> | ||
2 | + <div class="m-4"> | ||
3 | + <BasicTable title="基础表格" :columns="columns" :dataSource="data"> | ||
4 | + <template #toolbar> | ||
5 | + <a-button @click="aoaToExcel">导出</a-button> | ||
6 | + </template> | ||
7 | + </BasicTable> | ||
8 | + </div> | ||
9 | +</template> | ||
10 | + | ||
11 | +<script lang="ts"> | ||
12 | + import { defineComponent } from 'vue'; | ||
13 | + import { BasicTable } from '/@/components/Table'; | ||
14 | + import { aoaToSheetXlsx, ExportExcelModel } from '/@/components/Excel'; | ||
15 | + import { arrHeader, arrData, columns, data } from './data'; | ||
16 | + | ||
17 | + export default defineComponent({ | ||
18 | + components: { BasicTable, ExportExcelModel }, | ||
19 | + setup() { | ||
20 | + function aoaToExcel() { | ||
21 | + // 保证data顺序与header一致 | ||
22 | + aoaToSheetXlsx({ | ||
23 | + data: arrData, | ||
24 | + header: arrHeader, | ||
25 | + filename: '二维数组方式导出excel.xlsx', | ||
26 | + }); | ||
27 | + } | ||
28 | + | ||
29 | + return { | ||
30 | + aoaToExcel, | ||
31 | + columns, | ||
32 | + data, | ||
33 | + }; | ||
34 | + }, | ||
35 | + }); | ||
36 | +</script> |
src/views/demo/echarts/excel/CustomExport.vue
0 → 100644
1 | +<template> | ||
2 | + <div class="m-4"> | ||
3 | + <BasicTable title="基础表格" :columns="columns" :dataSource="data"> | ||
4 | + <template #toolbar> | ||
5 | + <a-button @click="openModal">导出</a-button> | ||
6 | + </template> | ||
7 | + </BasicTable> | ||
8 | + <ExportExcelModel @register="register" @success="defaultHeader" /> | ||
9 | + </div> | ||
10 | +</template> | ||
11 | + | ||
12 | +<script lang="ts"> | ||
13 | + import { defineComponent } from 'vue'; | ||
14 | + import { BasicTable } from '/@/components/Table'; | ||
15 | + import { jsonToSheetXlsx, ExportExcelModel, ExportModalResult } from '/@/components/Excel'; | ||
16 | + import { columns, data } from './data'; | ||
17 | + import { useModal } from '/@/components/Modal'; | ||
18 | + | ||
19 | + export default defineComponent({ | ||
20 | + components: { BasicTable, ExportExcelModel }, | ||
21 | + setup() { | ||
22 | + function defaultHeader({ filename, bookType }: ExportModalResult) { | ||
23 | + // 默认Object.keys(data[0])作为header | ||
24 | + jsonToSheetXlsx({ | ||
25 | + data, | ||
26 | + filename, | ||
27 | + write2excelOpts: { | ||
28 | + bookType, | ||
29 | + }, | ||
30 | + }); | ||
31 | + } | ||
32 | + const [register, { openModal }] = useModal(); | ||
33 | + | ||
34 | + return { | ||
35 | + defaultHeader, | ||
36 | + columns, | ||
37 | + data, | ||
38 | + register, | ||
39 | + openModal, | ||
40 | + }; | ||
41 | + }, | ||
42 | + }); | ||
43 | +</script> |
src/views/demo/comp/excel/ImportExcel.vue renamed to src/views/demo/echarts/excel/ImportExcel.vue
src/views/demo/comp/excel/ExportToExcel.vue renamed to src/views/demo/echarts/excel/JsonExport.vue
1 | <template> | 1 | <template> |
2 | - <div> | 2 | + <div class="m-4"> |
3 | <BasicTable title="基础表格" :columns="columns" :dataSource="data"> | 3 | <BasicTable title="基础表格" :columns="columns" :dataSource="data"> |
4 | <template #toolbar> | 4 | <template #toolbar> |
5 | - <a-button @click="openModal">JSON格式导出:默认头部</a-button> | ||
6 | - <a-button @click="customHeader">JSON格式导出:自定义头部</a-button> | ||
7 | - <a-button @click="aoaToExcel">二维数组格式导出</a-button> | 5 | + <a-button @click="defaultHeader">导出:默认头部</a-button> |
6 | + <a-button @click="customHeader">导出:自定义头部</a-button> | ||
8 | </template> | 7 | </template> |
9 | </BasicTable> | 8 | </BasicTable> |
10 | - <ExportExcelModel @register="register" @success="defaultHeader" /> | ||
11 | </div> | 9 | </div> |
12 | </template> | 10 | </template> |
13 | 11 | ||
14 | <script lang="ts"> | 12 | <script lang="ts"> |
15 | import { defineComponent } from 'vue'; | 13 | import { defineComponent } from 'vue'; |
16 | import { BasicTable } from '/@/components/Table'; | 14 | import { BasicTable } from '/@/components/Table'; |
17 | - import { | ||
18 | - jsonToSheetXlsx, | ||
19 | - aoaToSheetXlsx, | ||
20 | - ExportExcelModel, | ||
21 | - ExportModalResult, | ||
22 | - } from '/@/components/Excel'; | ||
23 | - import { columns, data, arrHeader, arrData } from './data'; | ||
24 | - import { useModal } from '/@/components/Modal'; | 15 | + import { jsonToSheetXlsx, ExportExcelModel } from '/@/components/Excel'; |
16 | + import { columns, data } from './data'; | ||
25 | 17 | ||
26 | export default defineComponent({ | 18 | export default defineComponent({ |
27 | components: { BasicTable, ExportExcelModel }, | 19 | components: { BasicTable, ExportExcelModel }, |
28 | setup() { | 20 | setup() { |
29 | - function defaultHeader({ filename, bookType }: ExportModalResult) { | 21 | + function defaultHeader() { |
30 | // 默认Object.keys(data[0])作为header | 22 | // 默认Object.keys(data[0])作为header |
31 | jsonToSheetXlsx({ | 23 | jsonToSheetXlsx({ |
32 | data, | 24 | data, |
33 | - filename, | ||
34 | - write2excelOpts: { | ||
35 | - bookType, | ||
36 | - }, | 25 | + filename: '使用key作为默认头部.xlsx', |
37 | }); | 26 | }); |
38 | } | 27 | } |
39 | function customHeader() { | 28 | function customHeader() { |
@@ -48,31 +37,19 @@ | @@ -48,31 +37,19 @@ | ||
48 | beginTime: '开始时间', | 37 | beginTime: '开始时间', |
49 | endTime: '结束时间', | 38 | endTime: '结束时间', |
50 | }, | 39 | }, |
51 | - filename: '文件名头部修改.xlsx', | 40 | + filename: '自定义头部.xlsx', |
52 | json2sheetOpts: { | 41 | json2sheetOpts: { |
53 | // 指定顺序 | 42 | // 指定顺序 |
54 | header: ['name', 'id'], | 43 | header: ['name', 'id'], |
55 | }, | 44 | }, |
56 | }); | 45 | }); |
57 | } | 46 | } |
58 | - function aoaToExcel() { | ||
59 | - // 保证data顺序与header一致 | ||
60 | - aoaToSheetXlsx({ | ||
61 | - data: arrData, | ||
62 | - header: arrHeader, | ||
63 | - filename: '数组方式导出excel.xlsx', | ||
64 | - }); | ||
65 | - } | ||
66 | - const [register, { openModal }] = useModal(); | ||
67 | 47 | ||
68 | return { | 48 | return { |
69 | defaultHeader, | 49 | defaultHeader, |
70 | customHeader, | 50 | customHeader, |
71 | - aoaToExcel, | ||
72 | columns, | 51 | columns, |
73 | data, | 52 | data, |
74 | - register, | ||
75 | - openModal, | ||
76 | }; | 53 | }; |
77 | }, | 54 | }, |
78 | }); | 55 | }); |
src/views/demo/comp/excel/data.ts renamed to src/views/demo/echarts/excel/data.ts