Commit 4065387b543ffbaf1b1dbb66e2bec06b06fb4ddb

Authored by xingyu4j
1 parent 9794d1cf

feat: export

yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
@@ -4,6 +4,7 @@ import { useAppStore } from '@/store/modules/app' @@ -4,6 +4,7 @@ import { useAppStore } from '@/store/modules/app'
4 import { VxeAllSchemas } from './useVxeCrudSchemas' 4 import { VxeAllSchemas } from './useVxeCrudSchemas'
5 import { useI18n } from '@/hooks/web/useI18n' 5 import { useI18n } from '@/hooks/web/useI18n'
6 import { useMessage } from '@/hooks/web/useMessage' 6 import { useMessage } from '@/hooks/web/useMessage'
  7 +import download from '@/utils/download'
7 8
8 const { t } = useI18n() 9 const { t } = useI18n()
9 const message = useMessage() // 消息弹窗 10 const message = useMessage() // 消息弹窗
@@ -144,11 +145,24 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { @@ -144,11 +145,24 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
144 }) 145 })
145 }) 146 })
146 } 147 }
  148 + // 导出
  149 + const exportList = async (ref, fileName?: string) => {
  150 + await nextTick()
  151 + const queryParams = Object.assign(
  152 + {},
  153 + JSON.parse(JSON.stringify(ref.value?.getProxyInfo()?.form))
  154 + )
  155 + message.exportConfirm().then(async () => {
  156 + const res = await (config?.exportListApi && config?.exportListApi(queryParams))
  157 + download.excel(res as unknown as Blob, fileName ? fileName : 'excel.xls')
  158 + })
  159 + }
147 160
148 return { 161 return {
149 gridOptions, 162 gridOptions,
150 reloadList, 163 reloadList,
151 getSearchData, 164 getSearchData,
152 - delList 165 + delList,
  166 + exportList
153 } 167 }
154 } 168 }
yudao-ui-admin-vue3/src/views/system/loginlog/index.vue
@@ -30,21 +30,19 @@ @@ -30,21 +30,19 @@
30 // 全局相关的 import 30 // 全局相关的 import
31 import { ref } from 'vue' 31 import { ref } from 'vue'
32 import { useI18n } from '@/hooks/web/useI18n' 32 import { useI18n } from '@/hooks/web/useI18n'
33 -import { useMessage } from '@/hooks/web/useMessage'  
34 import { useVxeGrid } from '@/hooks/web/useVxeGrid' 33 import { useVxeGrid } from '@/hooks/web/useVxeGrid'
35 import { VxeGridInstance } from 'vxe-table' 34 import { VxeGridInstance } from 'vxe-table'
36 // 业务相关的 import 35 // 业务相关的 import
37 import { allSchemas } from './loginLog.data' 36 import { allSchemas } from './loginLog.data'
38 import { getLoginLogPageApi, exportLoginLogApi, LoginLogVO } from '@/api/system/loginLog' 37 import { getLoginLogPageApi, exportLoginLogApi, LoginLogVO } from '@/api/system/loginLog'
39 -import download from '@/utils/download'  
40 38
41 const { t } = useI18n() // 国际化 39 const { t } = useI18n() // 国际化
42 -const message = useMessage() // 消息弹窗  
43 // 列表相关的变量 40 // 列表相关的变量
44 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref 41 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
45 -const { gridOptions, getSearchData } = useVxeGrid<LoginLogVO>({ 42 +const { gridOptions, exportList } = useVxeGrid<LoginLogVO>({
46 allSchemas: allSchemas, 43 allSchemas: allSchemas,
47 - getListApi: getLoginLogPageApi 44 + getListApi: getLoginLogPageApi,
  45 + exportListApi: exportLoginLogApi
48 }) 46 })
49 47
50 // 详情操作 48 // 详情操作
@@ -60,10 +58,6 @@ const handleDetail = async (row: LoginLogVO) =&gt; { @@ -60,10 +58,6 @@ const handleDetail = async (row: LoginLogVO) =&gt; {
60 58
61 // 导出操作 59 // 导出操作
62 const handleExport = async () => { 60 const handleExport = async () => {
63 - message.exportConfirm().then(async () => {  
64 - const queryParams = await getSearchData(xGrid)  
65 - const res = await exportLoginLogApi(queryParams)  
66 - download.excel(res, '登录列表.xls')  
67 - }) 61 + exportList(xGrid, '登录列表.xls')
68 } 62 }
69 </script> 63 </script>
yudao-ui-admin-vue3/src/views/system/operatelog/index.vue
@@ -45,21 +45,19 @@ @@ -45,21 +45,19 @@
45 // 全局相关的 import 45 // 全局相关的 import
46 import { ref } from 'vue' 46 import { ref } from 'vue'
47 import { useI18n } from '@/hooks/web/useI18n' 47 import { useI18n } from '@/hooks/web/useI18n'
48 -import { useMessage } from '@/hooks/web/useMessage'  
49 import { useVxeGrid } from '@/hooks/web/useVxeGrid' 48 import { useVxeGrid } from '@/hooks/web/useVxeGrid'
50 import { VxeGridInstance } from 'vxe-table' 49 import { VxeGridInstance } from 'vxe-table'
51 // 业务相关的 import 50 // 业务相关的 import
52 import * as OperateLogApi from '@/api/system/operatelog' 51 import * as OperateLogApi from '@/api/system/operatelog'
53 import { allSchemas } from './operatelog.data' 52 import { allSchemas } from './operatelog.data'
54 -import download from '@/utils/download'  
55 53
56 const { t } = useI18n() // 国际化 54 const { t } = useI18n() // 国际化
57 -const message = useMessage() // 消息弹窗  
58 // 列表相关的变量 55 // 列表相关的变量
59 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref 56 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
60 -const { gridOptions, getSearchData } = useVxeGrid<OperateLogApi.OperateLogVO>({ 57 +const { gridOptions, exportList } = useVxeGrid<OperateLogApi.OperateLogVO>({
61 allSchemas: allSchemas, 58 allSchemas: allSchemas,
62 - getListApi: OperateLogApi.getOperateLogPageApi 59 + getListApi: OperateLogApi.getOperateLogPageApi,
  60 + exportListApi: OperateLogApi.exportOperateLogApi
63 }) 61 })
64 62
65 // 弹窗相关的变量 63 // 弹窗相关的变量
@@ -76,10 +74,6 @@ const handleDetail = (row: OperateLogApi.OperateLogVO) =&gt; { @@ -76,10 +74,6 @@ const handleDetail = (row: OperateLogApi.OperateLogVO) =&gt; {
76 74
77 // 导出操作 75 // 导出操作
78 const handleExport = async () => { 76 const handleExport = async () => {
79 - message.exportConfirm().then(async () => {  
80 - const queryParams = await getSearchData(xGrid)  
81 - const res = await OperateLogApi.exportOperateLogApi(queryParams)  
82 - download.excel(res, '岗位列表.xls')  
83 - }) 77 + exportList(xGrid, '岗位列表.xls')
84 } 78 }
85 </script> 79 </script>
yudao-ui-admin-vue3/src/views/system/post/index.vue
@@ -84,16 +84,16 @@ import { FormExpose } from &#39;@/components/Form&#39; @@ -84,16 +84,16 @@ import { FormExpose } from &#39;@/components/Form&#39;
84 // 业务相关的 import 84 // 业务相关的 import
85 import * as PostApi from '@/api/system/post' 85 import * as PostApi from '@/api/system/post'
86 import { rules, allSchemas } from './post.data' 86 import { rules, allSchemas } from './post.data'
87 -import download from '@/utils/download'  
88 87
89 const { t } = useI18n() // 国际化 88 const { t } = useI18n() // 国际化
90 const message = useMessage() // 消息弹窗 89 const message = useMessage() // 消息弹窗
91 // 列表相关的变量 90 // 列表相关的变量
92 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref 91 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
93 -const { gridOptions, reloadList, delList, getSearchData } = useVxeGrid<PostApi.PostVO>({ 92 +const { gridOptions, reloadList, delList, exportList } = useVxeGrid<PostApi.PostVO>({
94 allSchemas: allSchemas, 93 allSchemas: allSchemas,
95 getListApi: PostApi.getPostPageApi, 94 getListApi: PostApi.getPostPageApi,
96 - delListApi: PostApi.deletePostApi 95 + delListApi: PostApi.deletePostApi,
  96 + exportListApi: PostApi.exportPostApi
97 }) 97 })
98 // 弹窗相关的变量 98 // 弹窗相关的变量
99 const dialogVisible = ref(false) // 是否显示弹出层 99 const dialogVisible = ref(false) // 是否显示弹出层
@@ -117,9 +117,7 @@ const handleCreate = () =&gt; { @@ -117,9 +117,7 @@ const handleCreate = () =&gt; {
117 117
118 // 导出操作 118 // 导出操作
119 const handleExport = async () => { 119 const handleExport = async () => {
120 - const queryParams = await getSearchData(xGrid)  
121 - const res = await PostApi.exportPostApi(queryParams)  
122 - download.excel(res, '岗位列表.xls') 120 + await exportList(xGrid, '岗位列表.xls')
123 } 121 }
124 122
125 // 修改操作 123 // 修改操作