From 8a139153464124f58e2cd3400ed80780ef7041e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Fri, 10 Oct 2025 23:17:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(cms):=20=E6=B7=BB=E5=8A=A0=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增导航数据批量导入接口- 实现管理员专属的备份与恢复按钮- 增加搜索组件中的导出逻辑及弹窗控制 - 调整按钮布局并移除旧有功能入口 x- 引入lsx 库支持 Excel 文件读写操作 - 添加权限判断以限制敏感操作访问 --- src/api/cms/cmsNavigation/index.ts | 15 ++ .../cms/cmsNavigation/components/search.vue | 139 +++++++++++++++--- 2 files changed, 134 insertions(+), 20 deletions(-) diff --git a/src/api/cms/cmsNavigation/index.ts b/src/api/cms/cmsNavigation/index.ts index 9f00bba..1ebb173 100644 --- a/src/api/cms/cmsNavigation/index.ts +++ b/src/api/cms/cmsNavigation/index.ts @@ -134,3 +134,18 @@ export async function getByCode(code: string) { return Promise.reject(new Error(res.data.message)); } +/** + * 导航批量导入 + */ +export async function importCmsNavigation(file: File) { + const formData = new FormData(); + formData.append('file', file); + const res = await request.post>( + MODULES_API_URL + '/cms/cms-navigation/import', + formData + ); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} \ No newline at end of file diff --git a/src/views/cms/cmsNavigation/components/search.vue b/src/views/cms/cmsNavigation/components/search.vue index 259696d..190409e 100644 --- a/src/views/cms/cmsNavigation/components/search.vue +++ b/src/views/cms/cmsNavigation/components/search.vue @@ -1,24 +1,16 @@ + +// 表单数据 +const where = ref({ + keywords: '', + model: '', + position: 0 +}); + +const position = ref(0); + +const reload = () => { + // 更新搜索关键词 + where.value.keywords = searchText.value; + emit('search', where.value); +}; + +/* 打开编辑弹窗 */ +const openImport = () => { + showImport.value = true; +}; + +// 导出 +const handleExport = async () => { + const array: (string | number)[][] = [ + [ + '上级id', + '菜单名称', + '模型', + '标识', + '菜单路由地址', + '菜单组件地址', + '打开位置', + '菜单图标', + 'banner图片', + '图标颜色', + '是否隐藏', + '可见类型', + '访问密码', + '位置', + '仅在顶部显示', + '仅在底部显示', + '菜单侧栏选中的path', + '其它路由元信息', + 'css样式', + '是否推荐', + '排序', + '备注', + '状态' + ] + ]; + + // 按搜索结果导出 + await listCmsNavigation(where.value) + .then((list) => { + list?.forEach((d) => { + array.push([ + `${d.parentId || ''}`, + `${d.title || ''}`, + `${d.model || ''}`, + `${d.code || ''}`, + `${d.path || ''}`, + `${d.component || ''}`, + `${d.target || ''}`, + `${d.icon || ''}`, + `${d.banner || ''}`, + `${d.color || ''}`, + `${d.hide || 0}`, + `${d.permission || 0}`, + `${d.password || ''}`, + `${d.position || 0}`, + `${d.top || 0}`, + `${d.bottom || 0}`, + `${d.active || ''}`, + `${d.meta || ''}`, + `${d.style || ''}`, + `${d.recommend ? 1 : 0}`, + `${d.sortNumber || 0}`, + `${d.comments || ''}`, + `${d.status || 0}` + ]); + }); + const sheetName = `bak_navigation_${getTenantId()}`; + const workbook = { + SheetNames: [sheetName], + Sheets: {} + }; + const sheet = utils.aoa_to_sheet(array); + workbook.Sheets[sheetName] = sheet; + // 设置列宽 + sheet['!cols'] = []; + message.loading('正在导出...'); + setTimeout(() => { + writeFile( + workbook, + `${sheetName}.xlsx` + ); + }, 1000); + }) + .catch((msg) => { + message.error(msg); + }); +}; + \ No newline at end of file