From 3c9cf679615cff9381d75f50ba7085becfe19194 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Mon, 24 Mar 2025 08:17:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8C=89=E9=9C=80=E5=8A=A0=E8=BD=BD=EF=BC=8C?= =?UTF-8?q?api=E3=80=81store=E5=92=8C=E6=9E=9A=E4=B8=BE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/dict-data.mock.ts | 216 ------------- mock/dict.mock.ts | 300 ++++++++++++----- mock/menu.mock.ts | 36 +-- mock/user.mock.ts | 68 ++-- src/App.vue | 8 +- src/api/{auth/index.ts => auth.api.ts} | 0 src/api/{codegen/index.ts => codegen.api.ts} | 0 src/api/{file/index.ts => file.api.ts} | 0 src/api/system/{config.ts => config.api.ts} | 21 +- src/api/system/{dept.ts => dept.api.ts} | 2 +- src/api/system/dict-data.ts | 162 ---------- src/api/system/dict.api.ts | 302 ++++++++++++++++++ src/api/system/dict.ts | 180 ----------- src/api/system/{log.ts => log.api.ts} | 0 src/api/system/{menu.ts => menu.api.ts} | 4 +- src/api/system/{notice.ts => notice.api.ts} | 2 +- src/api/system/{role.ts => role.api.ts} | 2 +- src/api/system/{user.ts => user.api.ts} | 2 +- src/components/Dict/DictLabel.vue | 58 ++-- src/components/Dict/index.vue | 39 +-- src/components/Hamburger/index.vue | 10 +- src/components/LangSelect/index.vue | 4 +- src/components/NoticeDropdown/index.vue | 2 +- src/components/SizeSelect/index.vue | 10 +- src/components/Upload/FileUpload.vue | 2 +- src/components/Upload/MultiImageUpload.vue | 2 +- src/components/Upload/SingleImageUpload.vue | 2 +- src/components/WangEditor/index.vue | 2 +- src/enums/LayoutEnum.ts | 18 -- src/enums/SidebarStatusEnum.ts | 14 - src/enums/SizeEnum.ts | 19 -- .../{ResultEnum.ts => api/result.enum.ts} | 0 .../{FormTypeEnum.ts => codegen/form.enum.ts} | 0 .../query.enum.ts} | 0 src/enums/index.ts | 11 + .../device.enum.ts} | 0 src/enums/settings/layout.enum.ts | 53 +++ .../locale.enum.ts} | 0 .../{ThemeEnum.ts => settings/theme.enum.ts} | 4 +- .../{MenuTypeEnum.ts => system/menu.enum.ts} | 0 src/lang/index.ts | 2 +- src/lang/package/zh-cn.ts | 2 +- .../NavBar/components/NavbarRight.vue | 8 +- .../Settings/components/LayoutSelect.vue | 16 +- src/layout/components/Settings/index.vue | 18 +- .../Sidebar/components/SidebarMenu.vue | 12 +- .../Sidebar/components/SidebarMixTopMenu.vue | 8 +- src/layout/components/Sidebar/index.vue | 6 +- src/layout/index.vue | 8 +- src/plugins/permission.ts | 2 +- src/settings.ts | 13 +- src/store/index.ts | 12 +- src/store/modules/{app.ts => app.store.ts} | 14 +- src/store/modules/dict.store.ts | 55 ++++ src/store/modules/dict.ts | 41 --- .../{permission.ts => permission.store.ts} | 2 +- .../{settings.ts => settings.store.ts} | 12 +- .../{tags-view.ts => tags-view.store.ts} | 0 src/store/modules/{user.ts => user.store.ts} | 20 +- src/utils/request.ts | 47 ++- src/views/codegen/index.vue | 10 +- src/views/dashboard/index.vue | 4 +- src/views/demo/curd/config/add.ts | 4 +- src/views/demo/curd/config/content.ts | 6 +- src/views/demo/curd/config/edit.ts | 4 +- src/views/demo/curd/config/search.ts | 2 +- src/views/demo/curd/index.vue | 6 +- src/views/demo/signature.vue | 2 +- src/views/demo/table-select/config/select.ts | 2 +- src/views/demo/websocket.vue | 2 +- src/views/login/index.vue | 94 +++--- src/views/profile/index.vue | 4 +- src/views/system/config/index.vue | 4 +- src/views/system/dept/index.vue | 4 +- .../system/dict/{data.vue => dict-item.vue} | 45 ++- src/views/system/dict/index.vue | 13 +- src/views/system/log/index.vue | 2 +- src/views/system/menu/index.vue | 6 +- .../system/notice/components/MyNotice.vue | 2 +- src/views/system/notice/index.vue | 6 +- src/views/system/role/index.vue | 6 +- src/views/system/user/components/DeptTree.vue | 2 +- .../system/user/components/UserImport.vue | 4 +- src/views/system/user/index.vue | 10 +- 84 files changed, 989 insertions(+), 1108 deletions(-) delete mode 100644 mock/dict-data.mock.ts rename src/api/{auth/index.ts => auth.api.ts} (100%) rename src/api/{codegen/index.ts => codegen.api.ts} (100%) rename src/api/{file/index.ts => file.api.ts} (100%) rename src/api/system/{config.ts => config.api.ts} (85%) rename src/api/system/{dept.ts => dept.api.ts} (98%) delete mode 100644 src/api/system/dict-data.ts create mode 100644 src/api/system/dict.api.ts delete mode 100644 src/api/system/dict.ts rename src/api/system/{log.ts => log.api.ts} (100%) rename src/api/system/{menu.ts => menu.api.ts} (97%) rename src/api/system/{notice.ts => notice.api.ts} (99%) rename src/api/system/{role.ts => role.api.ts} (99%) rename src/api/system/{user.ts => user.api.ts} (99%) delete mode 100644 src/enums/LayoutEnum.ts delete mode 100644 src/enums/SidebarStatusEnum.ts delete mode 100644 src/enums/SizeEnum.ts rename src/enums/{ResultEnum.ts => api/result.enum.ts} (100%) rename src/enums/{FormTypeEnum.ts => codegen/form.enum.ts} (100%) rename src/enums/{QueryTypeEnum.ts => codegen/query.enum.ts} (100%) create mode 100644 src/enums/index.ts rename src/enums/{DeviceEnum.ts => settings/device.enum.ts} (100%) create mode 100644 src/enums/settings/layout.enum.ts rename src/enums/{LanguageEnum.ts => settings/locale.enum.ts} (100%) rename src/enums/{ThemeEnum.ts => settings/theme.enum.ts} (83%) rename src/enums/{MenuTypeEnum.ts => system/menu.enum.ts} (100%) rename src/store/modules/{app.ts => app.store.ts} (85%) create mode 100644 src/store/modules/dict.store.ts delete mode 100644 src/store/modules/dict.ts rename src/store/modules/{permission.ts => permission.store.ts} (98%) rename src/store/modules/{settings.ts => settings.store.ts} (84%) rename src/store/modules/{tags-view.ts => tags-view.store.ts} (100%) rename src/store/modules/{user.ts => user.store.ts} (87%) rename src/views/system/dict/{data.vue => dict-item.vue} (87%) diff --git a/mock/dict-data.mock.ts b/mock/dict-data.mock.ts deleted file mode 100644 index 9f33f2db..00000000 --- a/mock/dict-data.mock.ts +++ /dev/null @@ -1,216 +0,0 @@ -import { defineMock } from "./base"; - -export default defineMock([ - { - url: "dict-data/page", - method: ["GET"], - body: { - code: "00000", - data: { - list: [ - { - id: 1, - dictCode: "gender", - label: "男", - value: "1", - sort: 1, - status: 1, - }, - { - id: 2, - dictCode: "gender", - label: "女", - value: "2", - sort: 2, - status: 1, - }, - { - id: 3, - dictCode: "gender", - label: "保密", - value: "0", - sort: 3, - status: 1, - }, - ], - total: 3, - }, - msg: "一切ok", - }, - }, - - { - url: "dict-data/:dictCode/options", - method: ["GET"], - body: ({ params }) => { - const dictCode = params.dictCode; - - let list = null; - - if (dictCode == "gender") { - list = [ - { - value: "1", - label: "男", - }, - { - value: "2", - label: "女", - }, - { - value: "0", - label: "保密", - }, - ]; - } else if (dictCode == "notice_level") { - list = [ - { - value: "L", - label: "低", - tag: "info", - }, - { - value: "M", - label: "中", - tag: "warning", - }, - { - value: "H", - label: "高", - tag: "danger", - }, - ]; - } else if (dictCode == "notice_type") { - list = [ - { - value: "1", - label: "系统升级", - tag: "success", - }, - { - value: "2", - label: "系统维护", - tag: "primary", - }, - { - value: "3", - label: "安全警告", - tag: "danger", - }, - { - value: "4", - label: "假期通知", - tag: "success", - }, - { - value: "5", - label: "公司新闻", - tag: "primary", - }, - { - value: "99", - label: "其他", - tag: "info", - }, - ]; - } - - return { - code: "00000", - data: list, - msg: "一切ok", - }; - }, - }, - // 新增字典数据 - { - url: "dict-data", - method: ["POST"], - body({ body }) { - return { - code: "00000", - data: null, - msg: "新增字典" + body.name + "成功", - }; - }, - }, - - // 获取字典数据表单 - { - url: "dict-data/:id/form", - method: ["GET"], - body: ({ params }) => { - return { - code: "00000", - data: dictMap[params.id], - msg: "一切ok", - }; - }, - }, - - // 修改字典数据 - { - url: "dict-data/:id", - method: ["PUT"], - body({ body }) { - return { - code: "00000", - data: null, - msg: "修改字典数据" + body.name + "成功", - }; - }, - }, - - // 删除字典 - { - url: "dict-data/:id", - method: ["DELETE"], - body({ params }) { - return { - code: "00000", - data: null, - msg: "删除字典" + params.id + "成功", - }; - }, - }, -]); - -// 字典数据映射表数据 -const dictMap: Record = { - 1: { - code: "00000", - data: { - id: 1, - value: "1", - label: "男", - sort: 1, - status: 1, - tagType: "primary", - }, - msg: "一切ok", - }, - 2: { - code: "00000", - data: { - id: 2, - value: "2", - label: "女", - sort: 2, - status: 1, - tagType: "danger", - }, - msg: "一切ok", - }, - 3: { - code: "00000", - data: { - id: 3, - value: "0", - label: "保密", - sort: 3, - status: 1, - tagType: "info", - }, - msg: "一切ok", - }, -}; diff --git a/mock/dict.mock.ts b/mock/dict.mock.ts index 5f3e5f27..9eff20e7 100644 --- a/mock/dict.mock.ts +++ b/mock/dict.mock.ts @@ -2,7 +2,7 @@ import { defineMock } from "./base"; export default defineMock([ { - url: "dict/page", + url: "dicts/page", method: ["GET"], body: { code: "00000", @@ -23,7 +23,7 @@ export default defineMock([ // 新增字典 { - url: "dict", + url: "dicts", method: ["POST"], body({ body }) { return { @@ -36,7 +36,7 @@ export default defineMock([ // 获取字典表单数据 { - url: "dict/:id/form", + url: "dicts/:id/form", method: ["GET"], body: ({ params }) => { return { @@ -49,7 +49,7 @@ export default defineMock([ // 修改字典 { - url: "dict/:id", + url: "dicts/:id", method: ["PUT"], body({ body }) { return { @@ -62,108 +62,194 @@ export default defineMock([ // 删除字典 { - url: "dict/:id", + url: "dicts/:ids", method: ["DELETE"], body({ params }) { return { code: "00000", data: null, - msg: "删除字典" + params.id + "成功", + msg: "删除字典" + params.ids + "成功", }; }, }, - // 所有字典列表 + //--------------------------------------------------- + // 字典项相关接口 + //--------------------------------------------------- + + // 字典项分页列表 { - url: "dict/list", + url: "dicts/:dictCode/items/page", method: ["GET"], - body() { - return { - code: "00000", - data: [ + body: { + code: "00000", + data: { + list: [ { - name: "通知级别", - dictCode: "notice_level", - dictDataList: [ - { - value: "L", - label: "低", - tagType: "info", - }, - { - value: "M", - label: "中", - tagType: "warning", - }, - { - value: "H", - label: "高", - tagType: "danger", - }, - ], - }, - { - name: "通知类型", - dictCode: "notice_type", - dictDataList: [ - { - value: "1", - label: "系统升级", - tagType: "success", - }, - { - value: "2", - label: "系统维护", - tagType: "primary", - }, - { - value: "3", - label: "安全警告", - tagType: "danger", - }, - { - value: "4", - label: "假期通知", - tagType: "success", - }, - { - value: "5", - label: "公司新闻", - tagType: "primary", - }, - { - value: "99", - label: "其他", - tagType: "info", - }, - ], - }, - { - name: "性别", + id: 1, dictCode: "gender", - dictDataList: [ - { - value: "1", - label: "男", - tagType: "primary", - }, - { - value: "2", - label: "女", - tagType: "danger", - }, - { - value: "0", - label: "保密", - tagType: "info", - }, - ], + label: "男", + value: "1", + sort: 1, + status: 1, + }, + { + id: 2, + dictCode: "gender", + label: "女", + value: "2", + sort: 2, + status: 1, + }, + { + id: 3, + dictCode: "gender", + label: "保密", + value: "0", + sort: 3, + status: 1, }, ], + total: 3, + }, + msg: "一切ok", + }, + }, + // 字典项列表 + { + url: "dicts/:dictCode/items", + method: ["GET"], + body: ({ params }) => { + const dictCode = params.dictCode; + + let list = null; + + if (dictCode == "gender") { + list = [ + { + value: "1", + label: "男", + }, + { + value: "2", + label: "女", + }, + { + value: "0", + label: "保密", + }, + ]; + } else if (dictCode == "notice_level") { + list = [ + { + value: "L", + label: "低", + tag: "info", + }, + { + value: "M", + label: "中", + tag: "warning", + }, + { + value: "H", + label: "高", + tag: "danger", + }, + ]; + } else if (dictCode == "notice_type") { + list = [ + { + value: "1", + label: "系统升级", + tag: "success", + }, + { + value: "2", + label: "系统维护", + tag: "primary", + }, + { + value: "3", + label: "安全警告", + tag: "danger", + }, + { + value: "4", + label: "假期通知", + tag: "success", + }, + { + value: "5", + label: "公司新闻", + tag: "primary", + }, + { + value: "99", + label: "其他", + tag: "info", + }, + ]; + } + + return { + code: "00000", + data: list, msg: "一切ok", }; }, }, + // 新增字典项 + { + url: "dicts/:dictCode/items", + method: ["POST"], + body({ body }) { + return { + code: "00000", + data: null, + msg: "新增字典" + body.name + "成功", + }; + }, + }, + + // 字典项表单数据 + { + url: "dicts/:dictCode/items/:itemId/form", + method: ["GET"], + body: ({ params }) => { + return { + code: "00000", + data: dictItemMap[params.itemId], + msg: "一切ok", + }; + }, + }, + + // 修改字典项 + { + url: "dicts/:dictCode/items/:itemId", + method: ["PUT"], + body({ body }) { + return { + code: "00000", + data: null, + msg: "修改字典项" + body.name + "成功", + }; + }, + }, + + // 删除字典 + { + url: "dicts/:dictCode/items/:itemId", + method: ["DELETE"], + body({ params }) { + return { + code: "00000", + data: null, + msg: "删除字典" + params.itemId + "成功", + }; + }, + }, ]); // 字典映射表数据 @@ -179,3 +265,43 @@ const dictMap: Record = { msg: "一切ok", }, }; + +// 字典项映射表数据 +const dictItemMap: Record = { + 1: { + code: "00000", + data: { + id: 1, + value: "1", + label: "男", + sort: 1, + status: 1, + tagType: "primary", + }, + msg: "一切ok", + }, + 2: { + code: "00000", + data: { + id: 2, + value: "2", + label: "女", + sort: 2, + status: 1, + tagType: "danger", + }, + msg: "一切ok", + }, + 3: { + code: "00000", + data: { + id: 3, + value: "0", + label: "保密", + sort: 3, + status: 1, + tagType: "info", + }, + msg: "一切ok", + }, +}; diff --git a/mock/menu.mock.ts b/mock/menu.mock.ts index 06a4096c..2f2550d1 100644 --- a/mock/menu.mock.ts +++ b/mock/menu.mock.ts @@ -99,11 +99,11 @@ export default defineMock([ }, }, { - path: "dict-data", - component: "system/dict/data", - name: "DictData", + path: "dict-item", + component: "system/dict/dict-item", + name: "DictItem", meta: { - title: "字典数据", + title: "字典项", icon: "", hidden: true, keepAlive: true, @@ -880,11 +880,11 @@ export default defineMock([ { id: 135, parentId: 1, - name: "字典数据", + name: "字典项", type: "MENU", routeName: "DictData", - routePath: "dict-data", - component: "system/dict/data", + routePath: "dict-item", + component: "system/dict/dict-item", sort: 6, visible: 0, icon: "", @@ -894,7 +894,7 @@ export default defineMock([ { id: 136, parentId: 135, - name: "字典数据新增", + name: "字典项新增", type: "BUTTON", routeName: null, routePath: "", @@ -903,13 +903,13 @@ export default defineMock([ visible: 1, icon: "", redirect: null, - perm: "sys:dict-data:add", + perm: "sys:dict-item:add", children: [], }, { id: 137, parentId: 135, - name: "字典数据编辑", + name: "字典项编辑", type: "BUTTON", routeName: null, routePath: "", @@ -918,13 +918,13 @@ export default defineMock([ visible: 1, icon: "", redirect: null, - perm: "sys:dict-data:edit", + perm: "sys:dict-item:edit", children: [], }, { id: 138, parentId: 135, - name: "字典数据删除", + name: "字典项删除", type: "BUTTON", routeName: null, routePath: "", @@ -933,7 +933,7 @@ export default defineMock([ visible: 1, icon: "", redirect: null, - perm: "sys:dict-data:delete", + perm: "sys:dict-item:delete", children: [], }, ], @@ -1695,23 +1695,23 @@ export default defineMock([ }, { value: "135", - label: "字典数据", + label: "字典项", children: [ { value: "143", - label: "字典数据查询", + label: "字典项查询", }, { value: "136", - label: "字典数据新增", + label: "字典项新增", }, { value: "137", - label: "字典数据编辑", + label: "字典项编辑", }, { value: "138", - label: "字典数据删除", + label: "字典项删除", }, ], }, diff --git a/mock/user.mock.ts b/mock/user.mock.ts index 57c8482d..bf2fc988 100644 --- a/mock/user.mock.ts +++ b/mock/user.mock.ts @@ -13,38 +13,52 @@ export default defineMock([ avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", roles: ["ADMIN"], perms: [ - "sys:notice:edit", - "sys:menu:delete", - "sys:dict:edit", - "sys:notice:query", - "sys:dict:delete", - "sys:config:add", - "sys:config:refresh", - "sys:menu:add", - "sys:user:add", - "sys:user:export", - "sys:role:edit", - "sys:dept:delete", - "sys:config:update", - "sys:user:password:reset", - "sys:notice:revoke", - "sys:user:import", - "sys:user:delete", - "sys:dict_type:delete", - "sys:dict:add", - "sys:role:add", - "sys:notice:publish", - "sys:notice:delete", - "sys:dept:edit", - "sys:dict_type:edit", "sys:user:query", + "sys:user:add", "sys:user:edit", - "sys:config:delete", - "sys:dept:add", - "sys:notice:add", + "sys:user:delete", + "sys:user:import", + "sys:user:export", + "sys:user:reset-password", + + "sys:role:query", + "sys:role:add", + "sys:role:edit", "sys:role:delete", + + "sys:dept:query", + "sys:dept:add", + "sys:dept:edit", + "sys:dept:delete", + + "sys:menu:query", + "sys:menu:add", "sys:menu:edit", + "sys:menu:delete", + + "sys:dict:query", + "sys:dict:add", + "sys:dict:edit", + "sys:dict:delete", + "sys:dict:delete", + + "sys:dict-item:query", + "sys:dict-item:add", + "sys:dict-item:edit", + "sys:dict-item:delete", + + "sys:notice:query", + "sys:notice:add", + "sys:notice:edit", + "sys:notice:delete", + "sys:notice:revoke", + "sys:notice:publish", + "sys:config:query", + "sys:config:add", + "sys:config:update", + "sys:config:delete", + "sys:config:refresh", ], }, msg: "一切ok", diff --git a/src/App.vue b/src/App.vue index 6bc6d3ce..764bbf26 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,18 +15,18 @@ diff --git a/src/api/auth/index.ts b/src/api/auth.api.ts similarity index 100% rename from src/api/auth/index.ts rename to src/api/auth.api.ts diff --git a/src/api/codegen/index.ts b/src/api/codegen.api.ts similarity index 100% rename from src/api/codegen/index.ts rename to src/api/codegen.api.ts diff --git a/src/api/file/index.ts b/src/api/file.api.ts similarity index 100% rename from src/api/file/index.ts rename to src/api/file.api.ts diff --git a/src/api/system/config.ts b/src/api/system/config.api.ts similarity index 85% rename from src/api/system/config.ts rename to src/api/system/config.api.ts index 95c1bb84..d05aa81f 100644 --- a/src/api/system/config.ts +++ b/src/api/system/config.api.ts @@ -3,7 +3,7 @@ import request from "@/utils/request"; const CONFIG_BASE_URL = "/api/v1/config"; const ConfigAPI = { - /** 获取系统配置分页数据 */ + /** 系统配置分页 */ getPage(queryParams?: ConfigPageQuery) { return request>({ url: `${CONFIG_BASE_URL}/page`, @@ -11,12 +11,8 @@ const ConfigAPI = { params: queryParams, }); }, - /** - * 获取系统配置表单数据 - * - * @param id ConfigID - * @returns Config表单数据 - */ + + /** 系统配置表单数据 */ getFormData(id: number) { return request({ url: `${CONFIG_BASE_URL}/${id}/form`, @@ -24,8 +20,8 @@ const ConfigAPI = { }); }, - /** 添加系统配置*/ - add(data: ConfigForm) { + /** 新增系统配置 */ + create(data: ConfigForm) { return request({ url: `${CONFIG_BASE_URL}`, method: "post", @@ -33,12 +29,7 @@ const ConfigAPI = { }); }, - /** - * 更新系统配置 - * - * @param id ConfigID - * @param data Config表单数据 - */ + /** 更新系统配置 */ update(id: number, data: ConfigForm) { return request({ url: `${CONFIG_BASE_URL}/${id}`, diff --git a/src/api/system/dept.ts b/src/api/system/dept.api.ts similarity index 98% rename from src/api/system/dept.ts rename to src/api/system/dept.api.ts index e3e7530f..a2124e92 100644 --- a/src/api/system/dept.ts +++ b/src/api/system/dept.api.ts @@ -44,7 +44,7 @@ const DeptAPI = { * @param data 部门表单数据 * @returns 请求结果 */ - add(data: DeptForm) { + create(data: DeptForm) { return request({ url: `${DEPT_BASE_URL}`, method: "post", diff --git a/src/api/system/dict-data.ts b/src/api/system/dict-data.ts deleted file mode 100644 index 412e1fe6..00000000 --- a/src/api/system/dict-data.ts +++ /dev/null @@ -1,162 +0,0 @@ -import request from "@/utils/request"; - -const DICT_DATA_BASE_URL = "/api/v1/dict-data"; - -const DictDataAPI = { - /** - * 获取字典分页列表 - * - * @param queryParams 查询参数 - * @returns 字典分页结果 - */ - getPage(queryParams: DictDataPageQuery) { - return request>({ - url: `${DICT_DATA_BASE_URL}/page`, - method: "get", - params: queryParams, - }); - }, - - /** - * 获取字典数据表单 - * - * @param id 字典ID - * @returns 字典数据表单 - */ - getFormData(id: number) { - return request>({ - url: `${DICT_DATA_BASE_URL}/${id}/form`, - method: "get", - }); - }, - - /** - * 新增字典数据 - * - * @param data 字典数据 - */ - add(data: DictDataForm) { - return request({ - url: `${DICT_DATA_BASE_URL}`, - method: "post", - data: data, - }); - }, - - /** - * 修改字典数据 - * - * @param id 字典ID - * @param data 字典数据 - */ - update(id: number, data: DictDataForm) { - return request({ - url: `${DICT_DATA_BASE_URL}/${id}`, - method: "put", - data: data, - }); - }, - - /** - * 删除字典 - * - * @param ids 字典ID,多个以英文逗号(,)分隔 - */ - deleteByIds(ids: string) { - return request({ - url: `${DICT_DATA_BASE_URL}/${ids}`, - method: "delete", - }); - }, - - /** - * 获取字典的数据项 - * - * @param dictCode 字典编码 - * @returns 字典数据项 - */ - getOptions(dictCode: string) { - return request({ - url: `${DICT_DATA_BASE_URL}/${dictCode}/options`, - method: "get", - }); - }, -}; - -export default DictDataAPI; - -/** - * 字典查询参数 - */ -export interface DictDataPageQuery extends PageQuery { - /** 关键字(字典数据值/标签) */ - keywords?: string; - - /** 字典编码 */ - dictCode?: string; -} - -/** - * 字典分页对象 - */ -export interface DictDataPageVO { - /** - * 字典ID - */ - id: number; - /** - * 字典编码 - */ - dictCode: string; - /** - * 字典数据值 - */ - value: string; - /** - * 字典数据标签 - */ - label: string; - /** - * 状态(1:启用,0:禁用) - */ - status: number; - /** - * 字典排序 - */ - sort?: number; -} - -/** - * 字典 - */ -export interface DictDataForm { - /** - * 字典ID - */ - id?: number; - /** - * 字典编码 - */ - dictCode?: string; - /** - * 字典数据值 - */ - value?: string; - /** - * 字典数据标签 - */ - label?: string; - /** - * 状态(1:启用,0:禁用) - */ - status?: number; - /** - * 字典排序 - */ - sort?: number; - - /** - * 标签类型 - */ - tagType?: "success" | "warning" | "info" | "primary" | "danger" | undefined; -} diff --git a/src/api/system/dict.api.ts b/src/api/system/dict.api.ts new file mode 100644 index 00000000..e2024297 --- /dev/null +++ b/src/api/system/dict.api.ts @@ -0,0 +1,302 @@ +import request from "@/utils/request"; + +const DICT_BASE_URL = "/api/v1/dicts"; + +const DictAPI = { + //--------------------------------------------------- + // 字典相关接口 + //--------------------------------------------------- + + /** + * 字典分页列表 + * + * @param queryParams 查询参数 + * @returns 字典分页结果 + */ + getPage(queryParams: DictPageQuery) { + return request>({ + url: `${DICT_BASE_URL}/page`, + method: "get", + params: queryParams, + }); + }, + + /** + * 字典表单数据 + * + * @param id 字典ID + * @returns 字典表单数据 + */ + getFormData(id: number) { + return request>({ + url: `${DICT_BASE_URL}/${id}/form`, + method: "get", + }); + }, + + /** + * 新增字典 + * + * @param data 字典表单数据 + */ + create(data: DictForm) { + return request({ + url: `${DICT_BASE_URL}`, + method: "post", + data: data, + }); + }, + + /** + * 修改字典 + * + * @param id 字典ID + * @param data 字典表单数据 + */ + update(id: number, data: DictForm) { + return request({ + url: `${DICT_BASE_URL}/${id}`, + method: "put", + data: data, + }); + }, + + /** + * 删除字典 + * + * @param ids 字典ID,多个以英文逗号(,)分隔 + */ + deleteByIds(ids: string) { + return request({ + url: `${DICT_BASE_URL}/${ids}`, + method: "delete", + }); + }, + + //--------------------------------------------------- + // 字典项相关接口 + //--------------------------------------------------- + /** + * 获取字典分页列表 + * + * @param queryParams 查询参数 + * @returns 字典分页结果 + */ + getDictItemPage(dictCode: string, queryParams: DictItemPageQuery) { + return request>({ + url: `${DICT_BASE_URL}/${dictCode}/items/page`, + method: "get", + params: queryParams, + }); + }, + + /** + * 获取字典项列表 + */ + getDictItems(dictCode: string) { + return request({ + url: `${DICT_BASE_URL}/${dictCode}/items`, + method: "get", + }); + }, + + /** + * 新增字典项 + */ + createDictItem(dictCode: string, data: DictItemForm) { + return request({ + url: `${DICT_BASE_URL}/${dictCode}/items`, + method: "post", + data: data, + }); + }, + + /** + * 获取字典项表单数据 + * + * @param id 字典项ID + * @returns 字典项表单数据 + */ + getDictItemFormData(dictCode: string, id: number) { + return request>({ + url: `${DICT_BASE_URL}/${dictCode}/items/${id}/form`, + method: "get", + }); + }, + + /** + * 修改字典项 + */ + updateDictItem(dictCode: string, id: number, data: DictItemForm) { + return request({ + url: `${DICT_BASE_URL}/${dictCode}/items/${id}`, + method: "put", + data: data, + }); + }, + + /** + * 删除字典项 + */ + deleteDictItems(dictCode: string, ids: string) { + return request({ + url: `${DICT_BASE_URL}/${dictCode}/items/${ids}`, + method: "delete", + }); + }, +}; + +export default DictAPI; + +/** + * 字典查询参数 + */ +export interface DictPageQuery extends PageQuery { + /** + * 关键字(字典名称/编码) + */ + keywords?: string; + + /** + * 字典状态(1:启用,0:禁用) + */ + status?: number; +} + +/** + * 字典分页对象 + */ +export interface DictPageVO { + /** + * 字典ID + */ + id: number; + /** + * 字典名称 + */ + name: string; + /** + * 字典编码 + */ + dictCode: string; + /** + * 字典状态(1:启用,0:禁用) + */ + status: number; +} + +/** + * 字典 + */ +export interface DictForm { + /** + * 字典ID + */ + id?: number; + /** + * 字典名称 + */ + name?: string; + /** + * 字典编码 + */ + dictCode?: string; + /** + * 字典状态(1-启用,0-禁用) + */ + status?: number; + /** + * 备注 + */ + remark?: string; +} + +/** + * 字典查询参数 + */ +export interface DictItemPageQuery extends PageQuery { + /** 关键字(字典数据值/标签) */ + keywords?: string; + + /** 字典编码 */ + dictCode?: string; +} + +/** + * 字典分页对象 + */ +export interface DictItemPageVO { + /** + * 字典ID + */ + id: number; + /** + * 字典编码 + */ + dictCode: string; + /** + * 字典数据值 + */ + value: string; + /** + * 字典数据标签 + */ + label: string; + /** + * 状态(1:启用,0:禁用) + */ + status: number; + /** + * 字典排序 + */ + sort?: number; +} + +/** + * 字典 + */ +export interface DictItemForm { + /** + * 字典ID + */ + id?: number; + /** + * 字典编码 + */ + dictCode?: string; + /** + * 字典数据值 + */ + value?: string; + /** + * 字典数据标签 + */ + label?: string; + /** + * 状态(1:启用,0:禁用) + */ + status?: number; + /** + * 字典排序 + */ + sort?: number; + + /** + * 标签类型 + */ + tagType?: "success" | "warning" | "info" | "primary" | "danger" | undefined; +} + +/** + * 字典项下拉选项 + */ +export interface DictItemOption { + /** 字典数据值 */ + value: string; + + /** 字典数据标签 */ + label: string; + + /** 标签类型 */ + tagType: string; +} diff --git a/src/api/system/dict.ts b/src/api/system/dict.ts deleted file mode 100644 index ed29b7df..00000000 --- a/src/api/system/dict.ts +++ /dev/null @@ -1,180 +0,0 @@ -import request from "@/utils/request"; - -const DICT_BASE_URL = "/api/v1/dict"; - -const DictAPI = { - /** - * 获取字典分页列表 - * - * @param queryParams 查询参数 - * @returns 字典分页结果 - */ - getPage(queryParams: DictPageQuery) { - return request>({ - url: `${DICT_BASE_URL}/page`, - method: "get", - params: queryParams, - }); - }, - - /** - * 获取字典表单数据 - * - * @param id 字典ID - * @returns 字典表单数据 - */ - getFormData(id: number) { - return request>({ - url: `${DICT_BASE_URL}/${id}/form`, - method: "get", - }); - }, - - /** - * 新增字典 - * - * @param data 字典表单数据 - */ - add(data: DictForm) { - return request({ - url: `${DICT_BASE_URL}`, - method: "post", - data: data, - }); - }, - - /** - * 修改字典 - * - * @param id 字典ID - * @param data 字典表单数据 - */ - update(id: number, data: DictForm) { - return request({ - url: `${DICT_BASE_URL}/${id}`, - method: "put", - data: data, - }); - }, - - /** - * 删除字典 - * - * @param ids 字典ID,多个以英文逗号(,)分隔 - */ - deleteByIds(ids: string) { - return request({ - url: `${DICT_BASE_URL}/${ids}`, - method: "delete", - }); - }, - - /** - * 获取字典列表 - * - * @returns 字典列表 - */ - getList() { - return request({ - url: `${DICT_BASE_URL}/list`, - method: "get", - }); - }, -}; - -export default DictAPI; - -/** - * 字典查询参数 - */ -export interface DictPageQuery extends PageQuery { - /** - * 关键字(字典名称/编码) - */ - keywords?: string; - - /** - * 字典状态(1:启用,0:禁用) - */ - status?: number; -} - -/** - * 字典分页对象 - */ -export interface DictPageVO { - /** - * 字典ID - */ - id: number; - /** - * 字典名称 - */ - name: string; - /** - * 字典编码 - */ - dictCode: string; - /** - * 字典状态(1:启用,0:禁用) - */ - status: number; -} - -/** - * 字典 - */ -export interface DictForm { - /** - * 字典ID - */ - id?: number; - /** - * 字典名称 - */ - name?: string; - /** - * 字典编码 - */ - dictCode?: string; - /** - * 字典状态(1-启用,0-禁用) - */ - status?: number; - /** - * 备注 - */ - remark?: string; -} - -/** - * 字典数据项分页VO - * - * @description 字典数据分页对象 - */ -export interface DictVO { - /** 字典名称 */ - name: string; - - /** 字典编码 */ - dictCode: string; - - /** 字典数据集合 */ - dictDataList: DictData[]; -} - -/** - * 字典数据 - * - * @description 字典数据 - */ -export interface DictData { - /** 字典数据值 */ - value: string; - - /** 字典数据标签 */ - label: string; - - /** 标签类型 */ - tagType: string; -} diff --git a/src/api/system/log.ts b/src/api/system/log.api.ts similarity index 100% rename from src/api/system/log.ts rename to src/api/system/log.api.ts diff --git a/src/api/system/menu.ts b/src/api/system/menu.api.ts similarity index 97% rename from src/api/system/menu.ts rename to src/api/system/menu.api.ts index a3d9b639..65867ff5 100644 --- a/src/api/system/menu.ts +++ b/src/api/system/menu.api.ts @@ -62,7 +62,7 @@ const MenuAPI = { * @param data 菜单表单数据 * @returns 请求结果 */ - add(data: MenuForm) { + create(data: MenuForm) { return request({ url: `${MENU_BASE_URL}`, method: "post", @@ -101,7 +101,7 @@ const MenuAPI = { export default MenuAPI; -import type { MenuTypeEnum } from "@/enums/MenuTypeEnum"; +import type { MenuTypeEnum } from "@/enums/system/menu.enum"; /** 菜单查询参数 */ export interface MenuQuery { diff --git a/src/api/system/notice.ts b/src/api/system/notice.api.ts similarity index 99% rename from src/api/system/notice.ts rename to src/api/system/notice.api.ts index 17bb1ef1..0ad16107 100644 --- a/src/api/system/notice.ts +++ b/src/api/system/notice.api.ts @@ -31,7 +31,7 @@ const NoticeAPI = { * @param data Notice表单数据 * @returns */ - add(data: NoticeForm) { + create(data: NoticeForm) { return request({ url: `${NOTICE_BASE_URL}`, method: "post", diff --git a/src/api/system/role.ts b/src/api/system/role.api.ts similarity index 99% rename from src/api/system/role.ts rename to src/api/system/role.api.ts index cc21e342..44b4624a 100644 --- a/src/api/system/role.ts +++ b/src/api/system/role.api.ts @@ -60,7 +60,7 @@ const RoleAPI = { }, /** 添加角色 */ - add(data: RoleForm) { + create(data: RoleForm) { return request({ url: `${ROLE_BASE_URL}`, method: "post", diff --git a/src/api/system/user.ts b/src/api/system/user.api.ts similarity index 99% rename from src/api/system/user.ts rename to src/api/system/user.api.ts index b58e6f50..e9c69c1f 100644 --- a/src/api/system/user.ts +++ b/src/api/system/user.api.ts @@ -46,7 +46,7 @@ const UserAPI = { * * @param data 用户表单数据 */ - add(data: UserForm) { + create(data: UserForm) { return request({ url: `${USER_BASE_URL}`, method: "post", diff --git a/src/components/Dict/DictLabel.vue b/src/components/Dict/DictLabel.vue index fd051314..b68ee155 100644 --- a/src/components/Dict/DictLabel.vue +++ b/src/components/Dict/DictLabel.vue @@ -6,47 +6,55 @@ {{ label }} - diff --git a/src/components/Dict/index.vue b/src/components/Dict/index.vue index f17b38a7..14dbc9c7 100644 --- a/src/components/Dict/index.vue +++ b/src/components/Dict/index.vue @@ -100,41 +100,34 @@ const selectedValue = ref( : undefined ); -// 监听 modelValue 变化 +// 监听 modelValue 和 options 的变化 watch( - () => props.modelValue, - (newValue) => { - if (props.type === "checkbox") { - selectedValue.value = Array.isArray(newValue) ? newValue : []; + [() => props.modelValue, () => options.value], + ([newValue, newOptions]) => { + if (newOptions.length > 0 && newValue !== undefined) { + if (props.type === "checkbox") { + selectedValue.value = Array.isArray(newValue) ? newValue : []; + } else { + const matchedOption = newOptions.find( + (option) => String(option.value) === String(newValue) + ); + selectedValue.value = matchedOption?.value; + } } else { - selectedValue.value = newValue?.toString() || ""; + selectedValue.value = undefined; } }, { immediate: true } ); -// 监听 options 变化并重新匹配 selectedValue -watch( - () => options.value, - (newOptions) => { - // options 加载后,确保 selectedValue 可以正确匹配到 options - if (newOptions.length > 0 && selectedValue.value !== undefined) { - const matchedOption = newOptions.find((option) => option.value === selectedValue.value); - if (!matchedOption && props.type !== "checkbox") { - // 如果找不到匹配项,清空选中 - selectedValue.value = ""; - } - } - } -); - // 监听 selectedValue 的变化并触发 update:modelValue function handleChange(val: any) { emit("update:modelValue", val); } // 获取字典数据 -onMounted(() => { - options.value = dictStore.getDictionary(props.code); +onMounted(async () => { + await dictStore.loadDictItems(props.code); + options.value = dictStore.getDictItems(props.code); }); diff --git a/src/components/Hamburger/index.vue b/src/components/Hamburger/index.vue index dc79d96d..58d2bd10 100644 --- a/src/components/Hamburger/index.vue +++ b/src/components/Hamburger/index.vue @@ -6,8 +6,8 @@ diff --git a/src/layout/components/Settings/index.vue b/src/layout/components/Settings/index.vue index 8a5a4d98..f3fe8436 100644 --- a/src/layout/components/Settings/index.vue +++ b/src/layout/components/Settings/index.vue @@ -48,10 +48,10 @@
{{ $t("settings.sidebarColorScheme") }} - + {{ $t("settings.classicBlue") }} - + {{ $t("settings.minimalWhite") }} @@ -67,9 +67,9 @@