From 708b575392edbef4f9735b8cfd9de07287d51d32 Mon Sep 17 00:00:00 2001 From: Toired <898934063@qq.com> Date: Sat, 25 Jan 2025 20:09:34 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=AF=BC=E5=87=BA=E6=8C=89=E9=92=AE=E5=8F=AF=E9=80=89?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/importExport/index.ts | 12 +++ src/api/system/importExport/types.ts | 10 +++ src/components/ExportSelector/index.vue | 106 +++++++++++++++++++++++ src/plugins/index.ts | 10 ++- src/types/module.d.ts | 10 ++- src/utils/ruoyi.ts | 13 +++ src/views/demo/demo/index.vue | 17 ++-- src/views/monitor/logininfor/index.vue | 16 ++-- src/views/monitor/operlog/index.vue | 18 ++-- src/views/system/client/index.vue | 17 ++-- src/views/system/config/index.vue | 16 ++-- src/views/system/dict/data.vue | 16 ++-- src/views/system/dict/index.vue | 16 ++-- src/views/system/post/index.vue | 17 ++-- src/views/system/role/index.vue | 16 ++-- src/views/system/tenant/index.vue | 17 ++-- src/views/system/tenantPackage/index.vue | 17 ++-- src/views/system/user/index.vue | 16 ++-- src/views/workflow/leave/index.vue | 17 ++-- 19 files changed, 284 insertions(+), 93 deletions(-) create mode 100644 src/api/system/importExport/index.ts create mode 100644 src/api/system/importExport/types.ts create mode 100644 src/components/ExportSelector/index.vue diff --git a/src/api/system/importExport/index.ts b/src/api/system/importExport/index.ts new file mode 100644 index 00000000..243a7a4a --- /dev/null +++ b/src/api/system/importExport/index.ts @@ -0,0 +1,12 @@ +import request from '@/utils/request'; +import { AxiosPromise } from 'axios'; +import {ExportColumnVo} from './types'; + +// 查询导出字段列表 +export const columns = (className: string): AxiosPromise => { + return request({ + url: '/system/importExport/columns', + method: 'get', + params: {className} + }); +}; diff --git a/src/api/system/importExport/types.ts b/src/api/system/importExport/types.ts new file mode 100644 index 00000000..0b2136f4 --- /dev/null +++ b/src/api/system/importExport/types.ts @@ -0,0 +1,10 @@ +export interface ExportColumnVo { + /** + * 字段描述 + */ + label: string; + /** + * 字段名 + */ + value: string; +} diff --git a/src/components/ExportSelector/index.vue b/src/components/ExportSelector/index.vue new file mode 100644 index 00000000..98bd83f9 --- /dev/null +++ b/src/components/ExportSelector/index.vue @@ -0,0 +1,106 @@ + + + diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 6c5e0c37..f18ea4ac 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -9,7 +9,14 @@ import animate from '@/animate'; import { download as dl } from '@/utils/request'; import { useDict } from '@/utils/dict'; import { getConfigKey, updateConfigByKey } from '@/api/system/config'; -import { parseTime, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'; +import { + parseTime, + addDateRange, + handleTree, + selectDictLabel, + selectDictLabels, + addExportClassNameAndColumnNames +} from '@/utils/ruoyi'; import { App } from 'vue'; @@ -37,6 +44,7 @@ export default function installPlugin(app: App) { app.config.globalProperties.parseTime = parseTime; app.config.globalProperties.handleTree = handleTree; app.config.globalProperties.addDateRange = addDateRange; + app.config.globalProperties.addExportClassNameAndColumnNames = addExportClassNameAndColumnNames; app.config.globalProperties.selectDictLabel = selectDictLabel; app.config.globalProperties.selectDictLabels = selectDictLabels; app.config.globalProperties.animate = animate; diff --git a/src/types/module.d.ts b/src/types/module.d.ts index 2fc273ac..1091d944 100644 --- a/src/types/module.d.ts +++ b/src/types/module.d.ts @@ -5,7 +5,14 @@ import auth from '@/plugins/auth'; import cache from '@/plugins/cache'; import animate from '@/animate'; import { useDict } from '@/utils/dict'; -import { handleTree, addDateRange, selectDictLabel, selectDictLabels, parseTime } from '@/utils/ruoyi'; +import { + handleTree, + addDateRange, + selectDictLabel, + selectDictLabels, + parseTime, + addExportClassNameAndColumnNames +} from '@/utils/ruoyi'; import { getConfigKey, updateConfigByKey } from '@/api/system/config'; import { download as rd } from '@/utils/request'; import type { LanguageType } from '@/lang'; @@ -29,6 +36,7 @@ declare module '@vue/runtime-core' { useDict: typeof useDict; addDateRange: typeof addDateRange; + addExportClassNameAndColumnNames: typeof addExportClassNameAndColumnNames; download: typeof rd; handleTree: typeof handleTree; getConfigKey: typeof getConfigKey; diff --git a/src/utils/ruoyi.ts b/src/utils/ruoyi.ts index 8efd12c5..649cef71 100644 --- a/src/utils/ruoyi.ts +++ b/src/utils/ruoyi.ts @@ -63,6 +63,19 @@ export const addDateRange = (params: any, dateRange: any[], propName?: string) = return search; }; +/** + * 添加导出类与导出字段列表 + * @param params + * @param columnNames + */ +export const addExportClassNameAndColumnNames = (params: any, columnNames: any[]) => { + const search = params; + search.params = typeof search.params === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {}; + columnNames = Array.isArray(columnNames) ? columnNames : []; + search.params['columnNames'] = columnNames; + return search; +}; + // 回显数据字典 export const selectDictLabel = (datas: any, value: number | string) => { if (value === undefined) { diff --git a/src/views/demo/demo/index.vue b/src/views/demo/demo/index.vue index da1bc167..cdd10ad5 100644 --- a/src/views/demo/demo/index.vue +++ b/src/views/demo/demo/index.vue @@ -97,6 +97,8 @@ + + @@ -106,6 +108,7 @@ import { DemoVO, DemoQuery, DemoForm } from '@/api/demo/demo/types'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; +const exportSelector = ref(null); const demoList = ref([]); const buttonLoading = ref(false); const loading = ref(true); @@ -239,13 +242,13 @@ const handleDelete = async (row?: DemoVO) => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'demo/demo/export', - { - ...queryParams.value - }, - `demo_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; + +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('demo/demo/export', params, `demo_${new Date().getTime()}.xlsx`); }; onMounted(() => { diff --git a/src/views/monitor/logininfor/index.vue b/src/views/monitor/logininfor/index.vue index d9145446..32a7bc5f 100644 --- a/src/views/monitor/logininfor/index.vue +++ b/src/views/monitor/logininfor/index.vue @@ -101,6 +101,8 @@ + + @@ -112,6 +114,7 @@ const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_device_type } = toRefs(proxy?.useDict('sys_device_type')); const { sys_common_status } = toRefs(proxy?.useDict('sys_common_status')); +const exportSelector = ref(null); const loginInfoList = ref([]); const loading = ref(true); const showSearch = ref(true); @@ -193,13 +196,12 @@ const handleUnlock = async () => { }; /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'monitor/logininfor/export', - { - ...queryParams.value - }, - `logininfor_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('monitor/logininfor/export', params, `logininfor_${new Date().getTime()}.xlsx`); }; onMounted(() => { diff --git a/src/views/monitor/operlog/index.vue b/src/views/monitor/operlog/index.vue index 0c64af4d..63a3b594 100644 --- a/src/views/monitor/operlog/index.vue +++ b/src/views/monitor/operlog/index.vue @@ -124,6 +124,8 @@ + + @@ -135,6 +137,7 @@ import OperInfoDialog from './oper-info-dialog.vue'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_oper_type, sys_common_status } = toRefs(proxy?.useDict('sys_oper_type', 'sys_common_status')); +const exportSelector = ref(null); const operlogList = ref([]); const loading = ref(true); const showSearch = ref(true); @@ -246,14 +249,15 @@ const handleClean = async () => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'monitor/operlog/export', - { - ...queryParams.value - }, - `config_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); }; + +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('monitor/operlog/export', params, `config_${new Date().getTime()}.xlsx`); +}; + onMounted(() => { getList(); }); diff --git a/src/views/system/client/index.vue b/src/views/system/client/index.vue index 37e86098..607e88f4 100644 --- a/src/views/system/client/index.vue +++ b/src/views/system/client/index.vue @@ -138,6 +138,8 @@ + + @@ -150,6 +152,7 @@ const { sys_normal_disable } = toRefs(proxy?.useDict('sys_normal_disable')) const { sys_grant_type } = toRefs(proxy?.useDict('sys_grant_type')); const { sys_device_type } = toRefs(proxy?.useDict('sys_device_type')); +const exportSelector = ref(null); const clientList = ref([]); const buttonLoading = ref(false); const loading = ref(true); @@ -289,13 +292,13 @@ const handleDelete = async (row?: ClientVO) => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/client/export', - { - ...queryParams.value - }, - `client_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; + +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/client/export', params, `client_${new Date().getTime()}.xlsx`); }; /** 状态修改 */ diff --git a/src/views/system/config/index.vue b/src/views/system/config/index.vue index ddc07537..a7c825bd 100644 --- a/src/views/system/config/index.vue +++ b/src/views/system/config/index.vue @@ -119,6 +119,8 @@ + + @@ -129,6 +131,7 @@ import { ConfigForm, ConfigQuery, ConfigVO } from '@/api/system/config/types'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_yes_no } = toRefs(proxy?.useDict('sys_yes_no')); +const exportSelector = ref(null); const configList = ref([]); const loading = ref(true); const showSearch = ref(true); @@ -241,13 +244,12 @@ const handleDelete = async (row?: ConfigVO) => { }; /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/config/export', - { - ...queryParams.value - }, - `config_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/config/export', params, `config_${new Date().getTime()}.xlsx`); }; /** 刷新缓存按钮操作 */ const handleRefreshCache = async () => { diff --git a/src/views/system/dict/data.vue b/src/views/system/dict/data.vue index 3e9b0a1c..2bcb5966 100644 --- a/src/views/system/dict/data.vue +++ b/src/views/system/dict/data.vue @@ -122,6 +122,8 @@ + + @@ -136,6 +138,7 @@ import { RouteLocationNormalized } from 'vue-router'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; const route = useRoute(); +const exportSelector = ref(null); const dataList = ref([]); const loading = ref(true); const showSearch = ref(true); @@ -293,13 +296,12 @@ const handleDelete = async (row?: DictDataVO) => { }; /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/dict/data/export', - { - ...queryParams.value - }, - `dict_data_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/dict/data/export', params, `dict_data_${new Date().getTime()}.xlsx`); }; onMounted(() => { diff --git a/src/views/system/dict/index.vue b/src/views/system/dict/index.vue index d30ad548..9f5814e1 100644 --- a/src/views/system/dict/index.vue +++ b/src/views/system/dict/index.vue @@ -104,6 +104,8 @@ + + @@ -114,6 +116,7 @@ import { DictTypeForm, DictTypeQuery, DictTypeVO } from '@/api/system/dict/type/ const { proxy } = getCurrentInstance() as ComponentInternalInstance; +const exportSelector = ref(null); const typeList = ref([]); const loading = ref(true); const showSearch = ref(true); @@ -225,13 +228,12 @@ const handleDelete = async (row?: DictTypeVO) => { }; /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/dict/type/export', - { - ...queryParams.value - }, - `dict_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/dict/type/export', params, `dict_${new Date().getTime()}.xlsx`); }; /** 刷新缓存按钮操作 */ const handleRefreshCache = async () => { diff --git a/src/views/system/post/index.vue b/src/views/system/post/index.vue index 4aa4e3a2..4d72eec1 100644 --- a/src/views/system/post/index.vue +++ b/src/views/system/post/index.vue @@ -166,6 +166,8 @@ + + @@ -178,6 +180,7 @@ import api from '@/api/system/user'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_normal_disable } = toRefs(proxy?.useDict('sys_normal_disable')); +const exportSelector = ref(null); const postList = ref([]); const loading = ref(true); const showSearch = ref(true); @@ -344,13 +347,13 @@ const handleDelete = async (row?: PostVO) => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/post/export', - { - ...queryParams.value - }, - `post_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; + +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/post/export', params, `post_${new Date().getTime()}.xlsx`); }; onMounted(() => { diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue index fc42cd5d..e3bf3769 100644 --- a/src/views/system/role/index.vue +++ b/src/views/system/role/index.vue @@ -188,6 +188,8 @@ + + @@ -201,6 +203,7 @@ const router = useRouter(); const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_normal_disable } = toRefs(proxy?.useDict('sys_normal_disable')); +const exportSelector = ref(null); const roleList = ref(); const loading = ref(true); const showSearch = ref(true); @@ -306,13 +309,12 @@ const handleDelete = async (row?: RoleVO) => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/role/export', - { - ...queryParams.value - }, - `role_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/role/export', params, `role_${new Date().getTime()}.xlsx`); }; /** 多选框选中数据 */ const handleSelectionChange = (selection: RoleVO[]) => { diff --git a/src/views/system/tenant/index.vue b/src/views/system/tenant/index.vue index df97b649..975b3586 100644 --- a/src/views/system/tenant/index.vue +++ b/src/views/system/tenant/index.vue @@ -140,6 +140,8 @@ + + @@ -161,6 +163,7 @@ import { TenantPkgVO } from '@/api/system/tenantPackage/types'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; +const exportSelector = ref(null); const userStore = useUserStore(); const userId = ref(userStore.userId); const tenantList = ref([]); @@ -349,13 +352,13 @@ const handleSyncTenantPackage = async (row: TenantVO) => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/tenant/export', - { - ...queryParams.value - }, - `tenant_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; + +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/tenant/export', params, `tenant_${new Date().getTime()}.xlsx`); }; /**同步租户字典*/ diff --git a/src/views/system/tenantPackage/index.vue b/src/views/system/tenantPackage/index.vue index f97bb352..3b368c0d 100644 --- a/src/views/system/tenantPackage/index.vue +++ b/src/views/system/tenantPackage/index.vue @@ -96,6 +96,8 @@ + + @@ -115,6 +117,7 @@ import to from 'await-to-js'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; +const exportSelector = ref(null); const tenantPackageList = ref([]); const buttonLoading = ref(false); const loading = ref(true); @@ -320,13 +323,13 @@ const handleDelete = async (row?: TenantPkgVO) => { /** 导出按钮操作 */ const handleExport = () => { - proxy?.download( - 'system/tenant/package/export', - { - ...queryParams.value - }, - `tenantPackage_${new Date().getTime()}.xlsx` - ); + exportSelector.value.init(); +}; + +/** 导出动态列回调 */ +const exportCallback = (columnNames: string[]) => { + const params = proxy?.addExportClassNameAndColumnNames(queryParams.value, columnNames); + proxy?.download('system/tenant/package/export', params, `tenantPackage_${new Date().getTime()}.xlsx`); }; onMounted(() => { diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 430c55aa..1f5793cb 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -282,6 +282,8 @@ + +