Commit 4065387b543ffbaf1b1dbb66e2bec06b06fb4ddb
1 parent
9794d1cf
feat: export
Showing
4 changed files
with
27 additions
and
27 deletions
yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
| ... | ... | @@ -4,6 +4,7 @@ import { useAppStore } from '@/store/modules/app' |
| 4 | 4 | import { VxeAllSchemas } from './useVxeCrudSchemas' |
| 5 | 5 | import { useI18n } from '@/hooks/web/useI18n' |
| 6 | 6 | import { useMessage } from '@/hooks/web/useMessage' |
| 7 | +import download from '@/utils/download' | |
| 7 | 8 | |
| 8 | 9 | const { t } = useI18n() |
| 9 | 10 | const message = useMessage() // 消息弹窗 |
| ... | ... | @@ -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 | 161 | return { |
| 149 | 162 | gridOptions, |
| 150 | 163 | reloadList, |
| 151 | 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 | 30 | // 全局相关的 import |
| 31 | 31 | import { ref } from 'vue' |
| 32 | 32 | import { useI18n } from '@/hooks/web/useI18n' |
| 33 | -import { useMessage } from '@/hooks/web/useMessage' | |
| 34 | 33 | import { useVxeGrid } from '@/hooks/web/useVxeGrid' |
| 35 | 34 | import { VxeGridInstance } from 'vxe-table' |
| 36 | 35 | // 业务相关的 import |
| 37 | 36 | import { allSchemas } from './loginLog.data' |
| 38 | 37 | import { getLoginLogPageApi, exportLoginLogApi, LoginLogVO } from '@/api/system/loginLog' |
| 39 | -import download from '@/utils/download' | |
| 40 | 38 | |
| 41 | 39 | const { t } = useI18n() // 国际化 |
| 42 | -const message = useMessage() // 消息弹窗 | |
| 43 | 40 | // 列表相关的变量 |
| 44 | 41 | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref |
| 45 | -const { gridOptions, getSearchData } = useVxeGrid<LoginLogVO>({ | |
| 42 | +const { gridOptions, exportList } = useVxeGrid<LoginLogVO>({ | |
| 46 | 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) => { |
| 60 | 58 | |
| 61 | 59 | // 导出操作 |
| 62 | 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 | 63 | </script> | ... | ... |
yudao-ui-admin-vue3/src/views/system/operatelog/index.vue
| ... | ... | @@ -45,21 +45,19 @@ |
| 45 | 45 | // 全局相关的 import |
| 46 | 46 | import { ref } from 'vue' |
| 47 | 47 | import { useI18n } from '@/hooks/web/useI18n' |
| 48 | -import { useMessage } from '@/hooks/web/useMessage' | |
| 49 | 48 | import { useVxeGrid } from '@/hooks/web/useVxeGrid' |
| 50 | 49 | import { VxeGridInstance } from 'vxe-table' |
| 51 | 50 | // 业务相关的 import |
| 52 | 51 | import * as OperateLogApi from '@/api/system/operatelog' |
| 53 | 52 | import { allSchemas } from './operatelog.data' |
| 54 | -import download from '@/utils/download' | |
| 55 | 53 | |
| 56 | 54 | const { t } = useI18n() // 国际化 |
| 57 | -const message = useMessage() // 消息弹窗 | |
| 58 | 55 | // 列表相关的变量 |
| 59 | 56 | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref |
| 60 | -const { gridOptions, getSearchData } = useVxeGrid<OperateLogApi.OperateLogVO>({ | |
| 57 | +const { gridOptions, exportList } = useVxeGrid<OperateLogApi.OperateLogVO>({ | |
| 61 | 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) => { |
| 76 | 74 | |
| 77 | 75 | // 导出操作 |
| 78 | 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 | 79 | </script> | ... | ... |
yudao-ui-admin-vue3/src/views/system/post/index.vue
| ... | ... | @@ -84,16 +84,16 @@ import { FormExpose } from '@/components/Form' |
| 84 | 84 | // 业务相关的 import |
| 85 | 85 | import * as PostApi from '@/api/system/post' |
| 86 | 86 | import { rules, allSchemas } from './post.data' |
| 87 | -import download from '@/utils/download' | |
| 88 | 87 | |
| 89 | 88 | const { t } = useI18n() // 国际化 |
| 90 | 89 | const message = useMessage() // 消息弹窗 |
| 91 | 90 | // 列表相关的变量 |
| 92 | 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 | 93 | allSchemas: allSchemas, |
| 95 | 94 | getListApi: PostApi.getPostPageApi, |
| 96 | - delListApi: PostApi.deletePostApi | |
| 95 | + delListApi: PostApi.deletePostApi, | |
| 96 | + exportListApi: PostApi.exportPostApi | |
| 97 | 97 | }) |
| 98 | 98 | // 弹窗相关的变量 |
| 99 | 99 | const dialogVisible = ref(false) // 是否显示弹出层 |
| ... | ... | @@ -117,9 +117,7 @@ const handleCreate = () => { |
| 117 | 117 | |
| 118 | 118 | // 导出操作 |
| 119 | 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 | // 修改操作 | ... | ... |