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