From d5dfcb978ea9e2da23effcdd5083c8b9a7c942af Mon Sep 17 00:00:00 2001 From: hxr <1490493387@qq.com> Date: Mon, 24 Jun 2024 08:21:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=8C=E7=B3=BB=E7=BB=9F=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- mock/dict.mock.ts | 18 +- mock/menu.mock.ts | 12 +- src/api/auth.ts | 72 ++++ src/api/auth/index.ts | 54 --- src/api/auth/model.ts | 59 --- src/api/{dept/index.ts => dept.ts} | 53 ++- src/api/dept/model.ts | 71 ---- src/api/dict.ts | 183 +++++++++ src/api/dict/index.ts | 166 -------- src/api/dict/model.ts | 142 ------- src/api/{file/index.ts => file.ts} | 11 +- src/api/file/model.ts | 7 - src/api/menu.ts | 209 ++++++++++ src/api/menu/index.ts | 101 ----- src/api/menu/model.ts | 188 --------- src/api/{role/index.ts => role.ts} | 73 ++-- src/api/role/model.ts | 78 ---- src/api/{user/index.ts => user.ts} | 113 +++++- src/api/user/model.ts | 115 ------ src/components/Dictionary/index.vue | 17 +- src/store/modules/permission.ts | 2 +- src/store/modules/user.ts | 4 +- src/{typings => types}/auto-imports.d.ts | 0 src/{typings => types}/components.d.ts | 1 + src/{typings => types}/env.d.ts | 0 src/{typings => types}/global.d.ts | 0 src/{typings => types}/router.d.ts | 0 src/{typings => types}/socket.d.ts | 0 src/views/demo/curd/config/add.ts | 3 +- src/views/demo/curd/config/content.ts | 4 +- src/views/demo/curd/config/edit.ts | 2 +- src/views/demo/curd/index.vue | 4 +- src/views/demo/dict.vue | 4 +- src/views/login/index.vue | 2 +- src/views/system/dept/index.vue | 68 ++-- .../system/dict/components/dict-item.vue | 308 --------------- src/views/system/dict/index.vue | 361 ++++++++++-------- src/views/system/menu/index.vue | 76 ++-- src/views/system/role/index.vue | 23 +- .../system/user/components/user-import.vue | 145 +++++++ src/views/system/user/index.vue | 308 +++++---------- tsconfig.json | 3 +- 43 files changed, 1243 insertions(+), 1821 deletions(-) create mode 100644 src/api/auth.ts delete mode 100644 src/api/auth/index.ts delete mode 100644 src/api/auth/model.ts rename src/api/{dept/index.ts => dept.ts} (63%) delete mode 100644 src/api/dept/model.ts create mode 100644 src/api/dict.ts delete mode 100644 src/api/dict/index.ts delete mode 100644 src/api/dict/model.ts rename src/api/{file/index.ts => file.ts} (83%) delete mode 100644 src/api/file/model.ts create mode 100644 src/api/menu.ts delete mode 100644 src/api/menu/index.ts delete mode 100644 src/api/menu/model.ts rename src/api/{role/index.ts => role.ts} (64%) delete mode 100644 src/api/role/model.ts rename src/api/{user/index.ts => user.ts} (58%) delete mode 100644 src/api/user/model.ts rename src/{typings => types}/auto-imports.d.ts (100%) rename src/{typings => types}/components.d.ts (98%) rename src/{typings => types}/env.d.ts (100%) rename src/{typings => types}/global.d.ts (100%) rename src/{typings => types}/router.d.ts (100%) rename src/{typings => types}/socket.d.ts (100%) delete mode 100644 src/views/system/dict/components/dict-item.vue create mode 100644 src/views/system/user/components/user-import.vue diff --git a/.env.development b/.env.development index 548fc857..6268a702 100644 --- a/.env.development +++ b/.env.development @@ -5,9 +5,9 @@ VITE_APP_PORT = 3000 VITE_APP_BASE_API = '/dev-api' # 线上接口地址 -VITE_APP_API_URL = http://vapi.youlai.tech +# VITE_APP_API_URL = http://vapi.youlai.tech # 开发接口地址 -# VITE_APP_API_URL = http://localhost:8989 +VITE_APP_API_URL = http://localhost:8989 # 是否启用 Mock 服务 VITE_MOCK_DEV_SERVER = false diff --git a/mock/dict.mock.ts b/mock/dict.mock.ts index 178a75a2..ebaef2ec 100644 --- a/mock/dict.mock.ts +++ b/mock/dict.mock.ts @@ -92,7 +92,7 @@ export default defineMock([ }, }, - // 新增字典类型 + // 新增字典 { url: "dict/types", method: ["POST"], @@ -100,12 +100,12 @@ export default defineMock([ return { code: "00000", data: null, - msg: "新增字典类型" + body.name + "成功", + msg: "新增字典" + body.name + "成功", }; }, }, - // 获取字典类型表单数据 + // 获取字典表单数据 { url: "dict/types/:id/form", method: ["GET"], @@ -118,7 +118,7 @@ export default defineMock([ }, }, - // 修改字典类型 + // 修改字典 { url: "dict/types/:id", method: ["PUT"], @@ -126,12 +126,12 @@ export default defineMock([ return { code: "00000", data: null, - msg: "修改字典类型" + body.name + "成功", + msg: "修改字典" + body.name + "成功", }; }, }, - // 删除字典类型 + // 删除字典 { url: "dict/types/:id", method: ["DELETE"], @@ -139,7 +139,7 @@ export default defineMock([ return { code: "00000", data: null, - msg: "删除字典类型" + params.id + "成功", + msg: "删除字典" + params.id + "成功", }; }, }, @@ -178,7 +178,7 @@ export default defineMock([ return { code: "00000", data: null, - msg: "修改字典类型" + body.name + "成功", + msg: "修改字典" + body.name + "成功", }; }, }, @@ -197,7 +197,7 @@ export default defineMock([ }, ]); -// 字典类型映射表数据 +// 字典映射表数据 const dictTypeMap: Record = { 1: { id: 1, diff --git a/mock/menu.mock.ts b/mock/menu.mock.ts index 1e552cfe..59c3b918 100644 --- a/mock/menu.mock.ts +++ b/mock/menu.mock.ts @@ -720,7 +720,7 @@ export default defineMock([ { id: 79, parentId: 6, - name: "字典类型新增", + name: "字典新增", type: "BUTTON", path: "", component: null, @@ -734,7 +734,7 @@ export default defineMock([ { id: 81, parentId: 6, - name: "字典类型编辑", + name: "字典编辑", type: "BUTTON", path: "", component: null, @@ -748,7 +748,7 @@ export default defineMock([ { id: 84, parentId: 6, - name: "字典类型删除", + name: "字典删除", type: "BUTTON", path: "", component: null, @@ -1231,15 +1231,15 @@ export default defineMock([ children: [ { value: 79, - label: "字典类型新增", + label: "字典新增", }, { value: 81, - label: "字典类型编辑", + label: "字典编辑", }, { value: 84, - label: "字典类型删除", + label: "字典删除", }, { value: 85, diff --git a/src/api/auth.ts b/src/api/auth.ts new file mode 100644 index 00000000..eb904d87 --- /dev/null +++ b/src/api/auth.ts @@ -0,0 +1,72 @@ +import request from "@/utils/request"; + +const AUTH_BASE_URL = "/api/v1/auth"; + +class AuthAPI { + /** 登录 接口*/ + static login(data: LoginData) { + const formData = new FormData(); + formData.append("username", data.username); + formData.append("password", data.password); + formData.append("captchaKey", data.captchaKey); + formData.append("captchaCode", data.captchaCode); + return request({ + url: `${AUTH_BASE_URL}/login`, + method: "post", + data: formData, + headers: { + "Content-Type": "multipart/form-data", + }, + }); + } + + /** 注销 接口*/ + static logout() { + return request({ + url: `${AUTH_BASE_URL}/logout`, + method: "delete", + }); + } + + /** 获取验证码 接口*/ + static getCaptcha() { + return request({ + url: `${AUTH_BASE_URL}/captcha`, + method: "get", + }); + } +} + +export default AuthAPI; + +/** 登录请求参数 */ +export interface LoginData { + /** 用户名 */ + username: string; + /** 密码 */ + password: string; + /** 验证码缓存key */ + captchaKey: string; + /** 验证码 */ + captchaCode: string; +} + +/** 登录响应 */ +export interface LoginResult { + /** 访问token */ + accessToken?: string; + /** 过期时间(单位:毫秒) */ + expires?: number; + /** 刷新token */ + refreshToken?: string; + /** token 类型 */ + tokenType?: string; +} + +/** 验证码响应 */ +export interface CaptchaResult { + /** 验证码缓存key */ + captchaKey: string; + /** 验证码图片Base64字符串 */ + captchaBase64: string; +} diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts deleted file mode 100644 index b8875c6b..00000000 --- a/src/api/auth/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import request from "@/utils/request"; -import { CaptchaResult, LoginData, LoginResult } from "./model"; - -const AUTH_BASE_URL = "/api/v1/auth"; - -class AuthAPI { - /** - * 登录API - * - * @param data 登录数据 - * @returns 登录结果 - */ - static login(data: LoginData) { - const formData = new FormData(); - formData.append("username", data.username); - formData.append("password", data.password); - formData.append("captchaKey", data.captchaKey || ""); - formData.append("captchaCode", data.captchaCode || ""); - return request({ - url: `${AUTH_BASE_URL}/login`, - method: "post", - data: formData, - headers: { - "Content-Type": "multipart/form-data", - }, - }); - } - - /** - * 注销API - * - * @returns 请求结果 - */ - static logout() { - return request({ - url: `${AUTH_BASE_URL}/logout`, - method: "delete", - }); - } - - /** - * 获取验证码 - * - * @returns 验证码结果 - */ - static getCaptcha() { - return request({ - url: `${AUTH_BASE_URL}/captcha`, - method: "get", - }); - } -} - -export default AuthAPI; diff --git a/src/api/auth/model.ts b/src/api/auth/model.ts deleted file mode 100644 index 0da661ed..00000000 --- a/src/api/auth/model.ts +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 登录请求参数 - */ -export interface LoginData { - /** - * 用户名 - */ - username: string; - /** - * 密码 - */ - password: string; - - /** - * 验证码缓存key - */ - captchaKey?: string; - - /** - * 验证码 - */ - captchaCode?: string; -} - -/** - * 登录响应 - */ -export interface LoginResult { - /** - * 访问token - */ - accessToken?: string; - /** - * 过期时间(单位:毫秒) - */ - expires?: number; - /** - * 刷新token - */ - refreshToken?: string; - /** - * token 类型 - */ - tokenType?: string; -} - -/** - * 验证码响应 - */ -export interface CaptchaResult { - /** - * 验证码缓存key - */ - captchaKey: string; - /** - * 验证码图片Base64字符串 - */ - captchaBase64: string; -} diff --git a/src/api/dept/index.ts b/src/api/dept.ts similarity index 63% rename from src/api/dept/index.ts rename to src/api/dept.ts index a4eff9b5..b650c24c 100644 --- a/src/api/dept/index.ts +++ b/src/api/dept.ts @@ -1,11 +1,10 @@ import request from "@/utils/request"; -import { DeptForm, DeptQuery, DeptVO } from "./model"; const DEPT_BASE_URL = "/api/v1/dept"; class DeptAPI { /** - * 获取部门树形表格列表 + * 获取部门列表 * * @param queryParams 查询参数(可选) * @returns 部门树形表格数据 @@ -18,11 +17,7 @@ class DeptAPI { }); } - /** - * 获取部门下拉列表选项 - * - * @returns 部门下拉列表选项 - */ + /** 获取部门下拉列表 */ static getOptions() { return request({ url: `${DEPT_BASE_URL}/options`, @@ -87,3 +82,47 @@ class DeptAPI { } export default DeptAPI; + +/** 部门查询参数 */ +export interface DeptQuery { + /** 搜索关键字 */ + keywords?: string; + /** 状态 */ + status?: number; +} + +/** 部门类型 */ +export interface DeptVO { + /** 子部门 */ + children?: DeptVO[]; + /** 创建时间 */ + createTime?: Date; + /** 部门ID */ + id?: number; + /** 部门名称 */ + name?: string; + /** 部门编号 */ + code?: string; + /** 父部门ID */ + parentId?: number; + /** 排序 */ + sort?: number; + /** 状态(1:启用;0:禁用) */ + status?: number; + /** 修改时间 */ + updateTime?: Date; +} + +/** 部门表单类型 */ +export interface DeptForm { + /** 部门ID(新增不填) */ + id?: number; + /** 部门名称 */ + name?: string; + /** 父部门ID */ + parentId: number; + /** 排序 */ + sort?: number; + /** 状态(1:启用;0:禁用) */ + status?: number; +} diff --git a/src/api/dept/model.ts b/src/api/dept/model.ts deleted file mode 100644 index 408c39c4..00000000 --- a/src/api/dept/model.ts +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 部门查询参数 - */ -export interface DeptQuery { - keywords?: string; - status?: number; -} - -/** - * 部门类型 - */ -export interface DeptVO { - /** - * 子部门 - */ - children?: DeptVO[]; - /** - * 创建时间 - */ - createTime?: Date; - /** - * 部门ID - */ - id?: number; - /** - * 部门名称 - */ - name?: string; - /** - * 父部门ID - */ - parentId?: number; - /** - * 排序 - */ - sort?: number; - /** - * 状态(1:启用;0:禁用) - */ - status?: number; - /** - * 修改时间 - */ - updateTime?: Date; -} - -/** - * 部门表单类型 - */ -export interface DeptForm { - /** - * 部门ID(新增不填) - */ - id?: number; - /** - * 部门名称 - */ - name?: string; - /** - * 父部门ID - */ - parentId: number; - /** - * 排序 - */ - sort?: number; - /** - * 状态(1:启用;0:禁用) - */ - status?: number; -} diff --git a/src/api/dict.ts b/src/api/dict.ts new file mode 100644 index 00000000..b9512005 --- /dev/null +++ b/src/api/dict.ts @@ -0,0 +1,183 @@ +import request from "@/utils/request"; + +const DICT_BASE_URL = "/api/v1/dict"; + +class DictAPI { + /** + * 获取字典分页列表 + * + * @param queryParams 查询参数 + * @returns 字典分页结果 + */ + static getPage(queryParams: DictPageQuery) { + return request>({ + url: `${DICT_BASE_URL}/page`, + method: "get", + params: queryParams, + }); + } + + /** + * 获取字典表单数据 + * + * @param id 字典ID + * @returns 字典表单数据 + */ + static getFormData(id: number) { + return request>({ + url: `${DICT_BASE_URL}/${id}/form`, + method: "get", + }); + } + + /** + * 新增字典 + * + * @param data 字典表单数据 + * @returns 请求结果 + */ + static add(data: DictForm) { + return request({ + url: `${DICT_BASE_URL}`, + method: "post", + data: data, + }); + } + + /** + * 修改字典 + * + * @param id 字典ID + * @param data 字典表单数据 + * @returns 请求结果 + */ + static update(id: number, data: DictForm) { + return request({ + url: `${DICT_BASE_URL}/${id}`, + method: "put", + data: data, + }); + } + + /** + * 删除字典 + * + * @param ids 字典ID,多个以英文逗号(,)分隔 + * @returns 请求结果 + */ + static deleteByIds(ids: string) { + return request({ + url: `${DICT_BASE_URL}/${ids}`, + method: "delete", + }); + } + + /** + * 获取字典的数据项 + * + * @param typeCode 字典编码 + * @returns 字典数据项 + */ + static getOptions(code: string) { + return request({ + url: `${DICT_BASE_URL}/${code}/options`, + method: "get", + }); + } +} + +export default DictAPI; + +/** + * 字典查询参数 + */ +export interface DictPageQuery extends PageQuery { + /** + * 关键字(字典名称/编码) + */ + keywords?: string; +} + +/** + * 字典分页对象 + */ +export interface DictPageVO { + /** + * 字典ID + */ + id: number; + /** + * 字典名称 + */ + name: string; + /** + * 字典编码 + */ + code: string; + /** + * 字典状态(1-启用,0-禁用) + */ + status: number; + /** + * 字典项列表 + */ + dictItems: DictItem[]; +} + +/** + * 字典项 + */ +export interface DictItem { + /** + * 字典项ID + */ + id?: number; + /** + * 字典项名称 + */ + name?: string; + /** + * 字典项值 + */ + value?: string; + /** + * 排序 + */ + sort?: number; + /** + * 状态(1-启用,0-禁用) + */ + status?: number; +} + +// TypeScript 类型声明 + +/** + * 字典 + */ +export interface DictForm { + /** + * 字典ID + */ + id?: number; + /** + * 字典名称 + */ + name?: string; + /** + * 字典编码 + */ + code?: string; + /** + * 字典状态(1-启用,0-禁用) + */ + status?: number; + /** + * 备注 + */ + remark?: string; + /** + * 字典数据项列表 + */ + dictItems?: DictItem[]; +} diff --git a/src/api/dict/index.ts b/src/api/dict/index.ts deleted file mode 100644 index a31c9c52..00000000 --- a/src/api/dict/index.ts +++ /dev/null @@ -1,166 +0,0 @@ -import request from "@/utils/request"; -import { - DictTypeQuery, - DictTypePageResult, - DictTypeForm, - DictQuery, - DictForm, - DictPageResult, -} from "./model"; - -const DICT_BASE_URL = "/api/v1/dict"; - -class DictAPI { - /** - * 获取字典类型分页列表 - * - * @param queryParams 查询参数 - * @returns 字典类型分页结果 - */ - static getDictTypePage(queryParams: DictTypeQuery) { - return request({ - url: `${DICT_BASE_URL}/types/page`, - method: "get", - params: queryParams, - }); - } - - /** - * 获取字典类型表单数据 - * - * @param id 字典类型ID - * @returns 字典类型表单数据 - */ - static getDictTypeForm(id: number) { - return request>({ - url: `${DICT_BASE_URL}/types/${id}/form`, - method: "get", - }); - } - - /** - * 新增字典类型 - * - * @param data 字典类型表单数据 - * @returns 请求结果 - */ - static addDictType(data: DictTypeForm) { - return request({ - url: `${DICT_BASE_URL}/types`, - method: "post", - data: data, - }); - } - - /** - * 修改字典类型 - * - * @param id 字典类型ID - * @param data 字典类型表单数据 - * @returns 请求结果 - */ - static updateDictType(id: number, data: DictTypeForm) { - return request({ - url: `${DICT_BASE_URL}/types/${id}`, - method: "put", - data: data, - }); - } - - /** - * 删除字典类型 - * - * @param ids 字典类型ID,多个以英文逗号(,)分隔 - * @returns 请求结果 - */ - static deleteDictTypes(ids: string) { - return request({ - url: `${DICT_BASE_URL}/types/${ids}`, - method: "delete", - }); - } - - /** - * 获取字典类型的数据项 - * - * @param typeCode 字典类型编码 - * @returns 字典类型的数据项 - */ - static getDictOptions(typeCode: string) { - return request({ - url: `${DICT_BASE_URL}/${typeCode}/options`, - method: "get", - }); - } - - /** - * 获取字典分页列表 - * - * @param queryParams 查询参数 - * @returns 字典分页结果 - */ - static getDictPage(queryParams: DictQuery) { - return request({ - url: `${DICT_BASE_URL}/page`, - method: "get", - params: queryParams, - }); - } - - /** - * 获取字典表单数据 - * - * @param id 字典项ID - * @returns 字典表单数据 - */ - static getDictFormData(id: number) { - return request({ - url: `${DICT_BASE_URL}/${id}/form`, - method: "get", - }); - } - - /** - * 新增字典 - * - * @param data 字典表单数据 - * @returns 请求结果 - */ - static addDict(data: DictForm) { - return request({ - url: `${DICT_BASE_URL}`, - method: "post", - data: data, - }); - } - - /** - * 修改字典项 - * - * @param id 字典项ID - * @param data 字典表单数据 - * @returns 请求结果 - */ - static updateDict(id: number, data: DictForm) { - return request({ - url: `${DICT_BASE_URL}/${id}`, - method: "put", - data: data, - }); - } - - /** - * 删除字典 - * - * @param ids 字典项ID,多个以英文逗号(,)分隔 - * @returns 请求结果 - */ - static deleteDictByIds(ids: string) { - return request({ - url: `${DICT_BASE_URL}/${ids}`, - method: "delete", - }); - } -} - -export default DictAPI; diff --git a/src/api/dict/model.ts b/src/api/dict/model.ts deleted file mode 100644 index 315da6d7..00000000 --- a/src/api/dict/model.ts +++ /dev/null @@ -1,142 +0,0 @@ -/** - * 字典类型查询参数 - */ -export interface DictTypeQuery extends PageQuery { - /** - * 关键字(字典类型名称/编码) - */ - keywords?: string; -} - -/** - * 字典类型分页对象 - */ -export interface DictTypePageVO { - /** - * 字典类型ID - */ - id: number; - /** - * 类型编码 - */ - code: string; - /** - * 类型名称 - */ - name: string; - /** - * 状态(1:启用;0:禁用) - */ - status?: number; - /** - * 备注 - */ - remark?: string; -} - -/** - * 字典分页项类型声明 - */ -export type DictTypePageResult = PageResult; - -/** - * 字典表单类型声明 - */ -export interface DictTypeForm { - /** - * 字典类型ID - */ - id?: number; - /** - * 类型名称 - */ - name?: string; - /** - * 类型编码 - */ - code?: string; - /** - * 类型状态:1:启用;0:禁用 - */ - status: number; - /** - * 备注 - */ - remark?: string; -} - -/** - * 字典查询参数 - */ -export interface DictQuery extends PageQuery { - /** - * 字典项名称 - */ - name?: string; - /** - * 字典类型编码 - */ - typeCode?: string; -} - -/** - * 字典分页对象 - */ -export interface DictPageVO { - /** - * 字典ID - */ - id?: number; - /** - * 字典名称 - */ - name?: string; - /** - * 状态(1:启用;0:禁用) - */ - status?: number; - /** - * 字典值 - */ - value?: string; -} - -/** - * 字典分页 - */ -export type DictPageResult = PageResult; - -/** - * 字典表单 - */ -export interface DictForm { - /** - * 字典ID - */ - id?: number; - /** - * 字典名称 - */ - name?: string; - /** - * 排序 - */ - sort?: number; - /** - * 状态(1:启用;0:禁用) - */ - status?: number; - /** - * 类型编码 - */ - typeCode?: string; - /** - * 值 - */ - value?: string; - - /** - * 备注 - */ - remark?: string; -} diff --git a/src/api/file/index.ts b/src/api/file.ts similarity index 83% rename from src/api/file/index.ts rename to src/api/file.ts index 82364624..3203195b 100644 --- a/src/api/file/index.ts +++ b/src/api/file.ts @@ -1,5 +1,4 @@ import request from "@/utils/request"; -import { FileInfo } from "./model"; class FileAPI { /** @@ -35,3 +34,13 @@ class FileAPI { } export default FileAPI; + +/** + * 文件API类型声明 + */ +export interface FileInfo { + /** 文件名 */ + name: string; + /** 文件路径 */ + url: string; +} diff --git a/src/api/file/model.ts b/src/api/file/model.ts deleted file mode 100644 index 22b2be55..00000000 --- a/src/api/file/model.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * 文件API类型声明 - */ -export interface FileInfo { - name: string; - url: string; -} diff --git a/src/api/menu.ts b/src/api/menu.ts new file mode 100644 index 00000000..31065f16 --- /dev/null +++ b/src/api/menu.ts @@ -0,0 +1,209 @@ +import request from "@/utils/request"; +// 菜单基础URL +const MENU_BASE_URL = "/api/v1/menus"; + +class MenuAPI { + /** + * 获取路由列表 + * + * @returns 路由列表 + */ + static getRoutes() { + return request({ + url: `${MENU_BASE_URL}/routes`, + method: "get", + }); + } + + /** + * 获取菜单树形列表 + * + * @param queryParams 查询参数 + * @returns 菜单树形列表 + */ + static getList(queryParams: MenuQuery) { + return request({ + url: `${MENU_BASE_URL}`, + method: "get", + params: queryParams, + }); + } + + /** + * 获取菜单下拉数据源 + * + * @returns 菜单下拉数据源 + */ + static getOptions() { + return request({ + url: `${MENU_BASE_URL}/options`, + method: "get", + }); + } + + /** + * 获取菜单表单数据 + * + * @param id 菜单ID + * @returns 菜单表单数据 + */ + static getFormData(id: number) { + return request({ + url: `${MENU_BASE_URL}/${id}/form`, + method: "get", + }); + } + + /** + * 添加菜单 + * + * @param data 菜单表单数据 + * @returns 请求结果 + */ + static add(data: MenuForm) { + return request({ + url: `${MENU_BASE_URL}`, + method: "post", + data: data, + }); + } + + /** + * 修改菜单 + * + * @param id 菜单ID + * @param data 菜单表单数据 + * @returns 请求结果 + */ + static update(id: string, data: MenuForm) { + return request({ + url: `${MENU_BASE_URL}/${id}`, + method: "put", + data: data, + }); + } + + /** + * 删除菜单 + * + * @param id 菜单ID + * @returns 请求结果 + */ + static deleteById(id: number) { + return request({ + url: `${MENU_BASE_URL}/${id}`, + method: "delete", + }); + } +} + +export default MenuAPI; + +import { MenuTypeEnum } from "@/enums/MenuTypeEnum"; + +/** 菜单查询参数 */ +export interface MenuQuery { + /** 搜索关键字 */ + keywords?: string; +} + +/** 菜单视图对象 */ +export interface MenuVO { + /** 子菜单 */ + children?: MenuVO[]; + /** 组件路径 */ + component?: string; + /** ICON */ + icon?: string; + /** 菜单ID */ + id?: number; + /** 菜单名称 */ + name?: string; + /** 父菜单ID */ + parentId?: number; + /** 按钮权限标识 */ + perm?: string; + /** 跳转路径 */ + redirect?: string; + /** 路由名称 */ + routeName?: string; + /** 路由相对路径 */ + routePath?: string; + /** 菜单排序(数字越小排名越靠前) */ + sort?: number; + /** 菜单 */ + type?: MenuTypeEnum; + /** 菜单是否可见(1:显示;0:隐藏) */ + visible?: number; +} + +/** 菜单表单对象 */ +export interface MenuForm { + /** 菜单ID */ + id?: string; + /** 父菜单ID */ + parentId?: number; + /** 菜单名称 */ + name?: string; + /** 菜单是否可见(1-是 0-否) */ + visible: number; + /** ICON */ + icon?: string; + /** 排序 */ + sort?: number; + /** 路由名称 */ + routeName?: string; + /** 路由路径 */ + routePath?: string; + /** 组件路径 */ + component?: string; + /** 跳转路由路径 */ + redirect?: string; + /** 菜单 */ + type?: MenuTypeEnum; + /** 权限标识 */ + perm?: string; + /** 【菜单】是否开启页面缓存 */ + keepAlive?: number; + /** 【目录】只有一个子路由是否始终显示 */ + alwaysShow?: number; + /** 参数 */ + params?: KeyValue[]; +} + +interface KeyValue { + key: string; + value: string; +} + +/** RouteVO,路由对象 */ +export interface RouteVO { + /** 子路由列表 */ + children: RouteVO[]; + /** 组件路径 */ + component?: string; + /** 路由属性 */ + meta?: Meta; + /** 路由名称 */ + name?: string; + /** 路由路径 */ + path?: string; + /** 跳转链接 */ + redirect?: string; +} + +/** Meta,路由属性 */ +export interface Meta { + /** 【目录】只有一个子路由是否始终显示 */ + alwaysShow?: boolean; + /** 是否隐藏(true-是 false-否) */ + hidden?: boolean; + /** ICON */ + icon?: string; + /** 【菜单】是否开启页面缓存 */ + keepAlive?: boolean; + /** 拥有路由权限的角色编码 */ + roles?: string[]; + /** 路由title */ + title?: string; +} diff --git a/src/api/menu/index.ts b/src/api/menu/index.ts deleted file mode 100644 index 9a26294a..00000000 --- a/src/api/menu/index.ts +++ /dev/null @@ -1,101 +0,0 @@ -import request from "@/utils/request"; -import { MenuQuery, MenuVO, MenuForm, RouteVO } from "./model"; - -const MENU_BASE_URL = "/api/v1/menus"; - -class MenuAPI { - /** - * 获取路由列表 - * - * @returns 路由列表 - */ - static getRoutes() { - return request({ - url: `${MENU_BASE_URL}/routes`, - method: "get", - }); - } - - /** - * 获取菜单树形列表 - * - * @param queryParams 查询参数 - * @returns 菜单树形列表 - */ - static getList(queryParams: MenuQuery) { - return request({ - url: `${MENU_BASE_URL}`, - method: "get", - params: queryParams, - }); - } - - /** - * 获取菜单下拉数据源 - * - * @returns 菜单下拉数据源 - */ - static getOptions() { - return request({ - url: `${MENU_BASE_URL}/options`, - method: "get", - }); - } - - /** - * 获取菜单表单数据 - * - * @param id 菜单ID - * @returns 菜单表单数据 - */ - static getFormData(id: number) { - return request({ - url: `${MENU_BASE_URL}/${id}/form`, - method: "get", - }); - } - - /** - * 添加菜单 - * - * @param data 菜单表单数据 - * @returns 请求结果 - */ - static add(data: MenuForm) { - return request({ - url: `${MENU_BASE_URL}`, - method: "post", - data: data, - }); - } - - /** - * 修改菜单 - * - * @param id 菜单ID - * @param data 菜单表单数据 - * @returns 请求结果 - */ - static update(id: string, data: MenuForm) { - return request({ - url: `${MENU_BASE_URL}/${id}`, - method: "put", - data: data, - }); - } - - /** - * 删除菜单 - * - * @param id 菜单ID - * @returns 请求结果 - */ - static deleteById(id: number) { - return request({ - url: `${MENU_BASE_URL}/${id}`, - method: "delete", - }); - } -} - -export default MenuAPI; diff --git a/src/api/menu/model.ts b/src/api/menu/model.ts deleted file mode 100644 index a9e846f5..00000000 --- a/src/api/menu/model.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { MenuTypeEnum } from "@/enums/MenuTypeEnum"; - -/** - * 菜单查询参数类型 - */ -export interface MenuQuery { - keywords?: string; -} - -/** - * 菜单视图对象类型 - */ -export interface MenuVO { - /** - * 子菜单 - */ - children?: MenuVO[]; - /** - * 组件路径 - */ - component?: string; - /** - * ICON - */ - icon?: string; - /** - * 菜单ID - */ - id?: number; - /** - * 菜单名称 - */ - name?: string; - /** - * 父菜单ID - */ - parentId?: number; - /** - * 按钮权限标识 - */ - perm?: string; - /** - * 跳转路径 - */ - redirect?: string; - /** - * 路由名称 - */ - routeName?: string; - /** - * 路由相对路径 - */ - routePath?: string; - /** - * 菜单排序(数字越小排名越靠前) - */ - sort?: number; - /** - * 菜单类型 - */ - type?: MenuTypeEnum; - /** - * 菜单是否可见(1:显示;0:隐藏) - */ - visible?: number; -} - -/** - * 菜单表单对象类型 - */ -export interface MenuForm { - /** - * 菜单ID - */ - id?: string; - /** - * 父菜单ID - */ - parentId?: number; - /** - * 菜单名称 - */ - name?: string; - /** - * 菜单是否可见(1:是;0:否;) - */ - visible: number; - icon?: string; - /** - * 排序 - */ - sort?: number; - /** - * 组件路径 - */ - component?: string; - /** - * 路由路径 - */ - path?: string; - /** - * 跳转路由路径 - */ - redirect?: string; - - /** - * 菜单类型 - */ - type?: MenuTypeEnum; - - /** - * 权限标识 - */ - perm?: string; - /** - * 【菜单】是否开启页面缓存 - */ - keepAlive?: number; - - /** - * 【目录】只有一个子路由是否始终显示 - */ - alwaysShow?: number; - - params?: KeyValue[]; -} - -interface KeyValue { - key: string; - value: string; -} - -/** - * RouteVO,路由对象 - */ -export interface RouteVO { - /** - * 子路由列表 - */ - children: RouteVO[]; - /** - * 组件路径 - */ - component?: string; - meta?: Meta; - /** - * 路由名称 - */ - name?: string; - /** - * 路由路径 - */ - path?: string; - /** - * 跳转链接 - */ - redirect?: string; -} - -/** - * Meta,路由属性类型 - */ -export interface Meta { - /** - * 【目录】只有一个子路由是否始终显示 - */ - alwaysShow?: boolean; - /** - * 是否隐藏(true-是 false-否) - */ - hidden?: boolean; - /** - * ICON - */ - icon?: string; - /** - * 【菜单】是否开启页面缓存 - */ - keepAlive?: boolean; - /** - * 拥有路由权限的角色编码 - */ - roles?: string[]; - /** - * 路由title - */ - title?: string; -} diff --git a/src/api/role/index.ts b/src/api/role.ts similarity index 64% rename from src/api/role/index.ts rename to src/api/role.ts index 00d79ab2..bfbbac21 100644 --- a/src/api/role/index.ts +++ b/src/api/role.ts @@ -1,34 +1,22 @@ import request from "@/utils/request"; -import { RoleQuery, RolePageResult, RoleForm } from "./model"; const ROLE_BASE_URL = "/api/v1/roles"; class RoleAPI { - /** - * 获取角色分页数据 - * - * @param queryParams 查询参数 - * @returns 角色分页数据 - */ - static getPage(queryParams?: RoleQuery) { - return request({ + /** 获取角色分页数据 */ + static getPage(queryParams?: RolePageQuery) { + return request>({ url: `${ROLE_BASE_URL}/page`, method: "get", params: queryParams, }); } - /** - * 获取角色下拉数据源 - * - * @param queryParams 查询参数(可选) - * @returns 角色下拉数据源 - */ - static getOptions(queryParams?: RoleQuery) { + /** 获取角色下拉数据源 */ + static getOptions() { return request({ url: `${ROLE_BASE_URL}/options`, method: "get", - params: queryParams, }); } @@ -46,7 +34,7 @@ class RoleAPI { } /** - * 分配菜单权限给角色 + * 分配菜单权限 * * @param roleId 角色ID * @param data 菜单ID集合 @@ -73,12 +61,7 @@ class RoleAPI { }); } - /** - * 添加角色 - * - * @param data 角色表单数据 - * @returns 请求结果 - */ + /** 添加角色 */ static add(data: RoleForm) { return request({ url: `${ROLE_BASE_URL}`, @@ -92,7 +75,6 @@ class RoleAPI { * * @param id 角色ID * @param data 角色表单数据 - * @returns 请求结果 */ static update(id: number, data: RoleForm) { return request({ @@ -106,7 +88,6 @@ class RoleAPI { * 批量删除角色,多个以英文逗号(,)分割 * * @param ids 角色ID字符串,多个以英文逗号(,)分割 - * @returns 请求结果 */ static deleteByIds(ids: string) { return request({ @@ -117,3 +98,43 @@ class RoleAPI { } export default RoleAPI; + +/** 角色分页查询参数 */ +export interface RolePageQuery extends PageQuery { + /** 搜索关键字 */ + keywords?: string; +} + +/** 角色分页对象 */ +export interface RolePageVO { + /** 角色编码 */ + code?: string; + /** 角色ID */ + id?: number; + /** 角色名称 */ + name?: string; + /** 排序 */ + sort?: number; + /** 角色状态 */ + status?: number; + /** 创建时间 */ + createTime?: Date; + /** 修改时间 */ + updateTime?: Date; +} + +/** 角色表单对象 */ +export interface RoleForm { + /** 角色ID */ + id?: number; + /** 角色编码 */ + code: string; + /** 数据权限 */ + dataScope?: number; + /** 角色名称 */ + name: string; + /** 排序 */ + sort?: number; + /** 角色状态(1-正常;0-停用) */ + status?: number; +} diff --git a/src/api/role/model.ts b/src/api/role/model.ts deleted file mode 100644 index 2d259c7f..00000000 --- a/src/api/role/model.ts +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 角色查询参数 - */ -export interface RoleQuery extends PageQuery { - keywords?: string; -} - -/** - * 角色分页对象 - */ -export interface RolePageVO { - /** - * 角色编码 - */ - code?: string; - - /** - * 角色ID - */ - id?: number; - /** - * 角色名称 - */ - name?: string; - /** - * 排序 - */ - sort?: number; - /** - * 角色状态 - */ - status?: number; - /** - * 创建时间 - */ - createTime?: Date; - /** - * 修改时间 - */ - updateTime?: Date; -} - -/** - * 角色分页 - */ -export type RolePageResult = PageResult; - -/** - * 角色表单对象 - */ -export interface RoleForm { - /** - * 角色ID - */ - id?: number; - - /** - * 角色编码 - */ - code: string; - /** - * 数据权限 - */ - dataScope?: number; - - /** - * 角色名称 - */ - name: string; - /** - * 排序 - */ - sort?: number; - /** - * 角色状态(1-正常;0-停用) - */ - status?: number; -} diff --git a/src/api/user/index.ts b/src/api/user.ts similarity index 58% rename from src/api/user/index.ts rename to src/api/user.ts index 37f64488..e4d29d55 100644 --- a/src/api/user/index.ts +++ b/src/api/user.ts @@ -1,13 +1,12 @@ import request from "@/utils/request"; -import { UserForm, UserInfo, UserPageVO, UserQuery } from "./model"; const USER_BASE_URL = "/api/v1/users"; class UserAPI { /** - * 登录成功后获取用户信息(昵称、头像、权限集合和角色集合) + * 获取当前登录用户信息 * - * @returns 用户信息 + * @returns 登录用户昵称、头像信息,包括角色和权限 */ static getInfo() { return request({ @@ -20,9 +19,8 @@ class UserAPI { * 获取用户分页列表 * * @param queryParams 查询参数 - * @returns 用户分页列表 */ - static getPage(queryParams: UserQuery) { + static getPage(queryParams: UserPageQuery) { return request>({ url: `${USER_BASE_URL}/page`, method: "get", @@ -47,7 +45,6 @@ class UserAPI { * 添加用户 * * @param data 用户表单数据 - * @returns 请求结果 */ static add(data: UserForm) { return request({ @@ -62,7 +59,6 @@ class UserAPI { * * @param id 用户ID * @param data 用户表单数据 - * @returns 请求结果 */ static update(id: number, data: UserForm) { return request({ @@ -77,7 +73,6 @@ class UserAPI { * * @param id 用户ID * @param password 新密码 - * @returns 请求结果 */ static updatePassword(id: number, password: string) { return request({ @@ -91,7 +86,6 @@ class UserAPI { * 批量删除用户,多个以英文逗号(,)分割 * * @param ids 用户ID字符串,多个以英文逗号(,)分割 - * @returns 请求结果 */ static deleteByIds(ids: string) { return request({ @@ -100,11 +94,7 @@ class UserAPI { }); } - /** - * 下载用户导入模板 - * - * @returns 用户导入模板文件 - */ + /** 下载用户导入模板 */ static downloadTemplate() { return request({ url: `${USER_BASE_URL}/template`, @@ -117,9 +107,8 @@ class UserAPI { * 导出用户 * * @param queryParams 查询参数 - * @returns 导出文件 */ - static export(queryParams: UserQuery) { + static export(queryParams: UserPageQuery) { return request({ url: `${USER_BASE_URL}/export`, method: "get", @@ -133,7 +122,6 @@ class UserAPI { * * @param deptId 部门ID * @param file 导入文件 - * @returns 请求结果 */ static import(deptId: number, file: File) { const formData = new FormData(); @@ -151,3 +139,94 @@ class UserAPI { } export default UserAPI; + +/** 登录用户信息 */ +export interface UserInfo { + /** 用户ID */ + userId?: number; + + /** 用户名 */ + username?: string; + + /** 昵称 */ + nickname?: string; + + /** 头像URL */ + avatar?: string; + + /** 角色 */ + roles: string[]; + + /** 权限 */ + perms: string[]; +} + +/** + * 用户分页查询对象 + */ +export interface UserPageQuery extends PageQuery { + /** 搜索关键字 */ + keywords?: string; + + /** 用户状态 */ + status?: number; + + /** 部门ID */ + deptId?: number; + + /** 开始时间 */ + startTime?: string; + + /** 结束时间 */ + endTime?: string; +} + +/** 用户分页对象 */ +export interface UserPageVO { + /** 用户头像URL */ + avatar?: string; + /** 创建时间 */ + createTime?: Date; + /** 部门名称 */ + deptName?: string; + /** 用户邮箱 */ + email?: string; + /** 性别 */ + genderLabel?: string; + /** 用户ID */ + id?: number; + /** 手机号 */ + mobile?: string; + /** 用户昵称 */ + nickname?: string; + /** 角色名称,多个使用英文逗号(,)分割 */ + roleNames?: string; + /** 用户状态(1:启用;0:禁用) */ + status?: number; + /** 用户名 */ + username?: string; +} + +/** 用户表单类型 */ +export interface UserForm { + /** 用户头像 */ + avatar?: string; + /** 部门ID */ + deptId?: number; + /** 邮箱 */ + email?: string; + /** 性别 */ + gender?: number; + /** 用户ID */ + id?: number; + /** 手机号 */ + mobile?: string; + /** 昵称 */ + nickname?: string; + /** 角色ID集合 */ + roleIds?: number[]; + /** 用户状态(1:正常;0:禁用) */ + status?: number; + /** 用户名 */ + username?: string; +} diff --git a/src/api/user/model.ts b/src/api/user/model.ts deleted file mode 100644 index c0060f27..00000000 --- a/src/api/user/model.ts +++ /dev/null @@ -1,115 +0,0 @@ -/** - * 登录用户信息 - */ -export interface UserInfo { - userId?: number; - username?: string; - nickname?: string; - avatar?: string; - roles: string[]; - perms: string[]; -} - -/** - * 用户查询对象类型 - */ -export interface UserQuery extends PageQuery { - keywords?: string; - status?: number; - deptId?: number; - startTime?: string; - endTime?: string; -} - -/** - * 用户分页对象 - */ -export interface UserPageVO { - /** - * 用户头像地址 - */ - avatar?: string; - /** - * 创建时间 - */ - createTime?: Date; - /** - * 部门名称 - */ - deptName?: string; - /** - * 用户邮箱 - */ - email?: string; - /** - * 性别 - */ - genderLabel?: string; - /** - * 用户ID - */ - id?: number; - /** - * 手机号 - */ - mobile?: string; - /** - * 用户昵称 - */ - nickname?: string; - /** - * 角色名称,多个使用英文逗号(,)分割 - */ - roleNames?: string; - /** - * 用户状态(1:启用;0:禁用) - */ - status?: number; - /** - * 用户名 - */ - username?: string; -} - -/** - * 用户表单类型 - */ -export interface UserForm { - /** - * 用户头像 - */ - avatar?: string; - /** - * 部门ID - */ - deptId?: number; - /** - * 邮箱 - */ - email?: string; - /** - * 性别 - */ - gender?: number; - /** - * 用户ID - */ - id?: number; - mobile?: string; - /** - * 昵称 - */ - nickname?: string; - /** - * 角色ID集合 - */ - roleIds?: number[]; - /** - * 用户状态(1:正常;0:禁用) - */ - status?: number; - /** - * 用户名 - */ - username?: string; -} diff --git a/src/components/Dictionary/index.vue b/src/components/Dictionary/index.vue index a3804ff3..763c2c6f 100644 --- a/src/components/Dictionary/index.vue +++ b/src/components/Dictionary/index.vue @@ -20,9 +20,9 @@ import DictAPI from "@/api/dict"; const props = defineProps({ /** - * 字典类型编码(eg: 性别-gender) + * 字典编码(eg: 性别-gender) */ - typeCode: { + code: { type: String, required: true, }, @@ -39,14 +39,17 @@ const props = defineProps({ }, }); -const emits = defineEmits(["update:modelValue"]); // 父组件监听事件,同步子组件值的变化给父组件 +const emits = defineEmits(["update:modelValue"]); -const options: Ref = ref([]); // 字典下拉数据源 +const options: Ref = ref([]); const selectedValue = ref(); watch([options, () => props.modelValue], ([newOptions, newModelValue]) => { - if (newOptions.length === 0) return; // 下拉数据源加载未完成不回显 + if (newOptions.length === 0) { + // 下拉数据源加载未完成不回显 + return; + } if (newModelValue == undefined) { selectedValue.value = undefined; return; @@ -65,8 +68,8 @@ function handleChange(val?: string | number | undefined) { } onBeforeMount(() => { - // 根据字典类型编码(typeCode)获取字典选项 - DictAPI.getDictOptions(props.typeCode).then((data) => { + // 根据字典编码获取字典项 + DictAPI.getOptions(props.code).then((data) => { options.value = data; }); }); diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 9ed99d7e..f2e6f932 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -2,7 +2,7 @@ import { RouteRecordRaw } from "vue-router"; import { constantRoutes } from "@/router"; import { store } from "@/store"; import MenuAPI from "@/api/menu"; -import { RouteVO } from "@/api/menu/model"; +import { RouteVO } from "@/api/menu/types"; const modules = import.meta.glob("../../views/**/**.vue"); const Layout = () => import("@/layout/index.vue"); diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index abdbcb38..cdbecf5b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -3,8 +3,8 @@ import UserAPI from "@/api/user"; import { resetRouter } from "@/router"; import { store } from "@/store"; -import { LoginData } from "@/api/auth/model"; -import { UserInfo } from "@/api/user/model"; +import { LoginData } from "@/api/auth"; +import { UserInfo } from "@/api/user"; import { TOKEN_KEY } from "@/enums/CacheEnum"; export const useUserStore = defineStore("user", () => { diff --git a/src/typings/auto-imports.d.ts b/src/types/auto-imports.d.ts similarity index 100% rename from src/typings/auto-imports.d.ts rename to src/types/auto-imports.d.ts diff --git a/src/typings/components.d.ts b/src/types/components.d.ts similarity index 98% rename from src/typings/components.d.ts rename to src/types/components.d.ts index 80a3a983..03f1fe22 100644 --- a/src/typings/components.d.ts +++ b/src/types/components.d.ts @@ -13,6 +13,7 @@ declare module "vue" { Breadcrumb: (typeof import("./../components/Breadcrumb/index.vue"))["default"]; CURD: (typeof import("./../components/CURD/index.vue"))["default"]; DeptTree: (typeof import("./../views/system/user/components/dept-tree.vue"))["default"]; + UserImport: (typeof import("./../views/system/user/components/user-import.vue"))["default"]; Dictionary: (typeof import("./../components/Dictionary/index.vue"))["default"]; DictItem: (typeof import("./../views/system/dict/components/dict-item.vue"))["default"]; ElBacktop: (typeof import("element-plus/es"))["ElBacktop"]; diff --git a/src/typings/env.d.ts b/src/types/env.d.ts similarity index 100% rename from src/typings/env.d.ts rename to src/types/env.d.ts diff --git a/src/typings/global.d.ts b/src/types/global.d.ts similarity index 100% rename from src/typings/global.d.ts rename to src/types/global.d.ts diff --git a/src/typings/router.d.ts b/src/types/router.d.ts similarity index 100% rename from src/typings/router.d.ts rename to src/types/router.d.ts diff --git a/src/typings/socket.d.ts b/src/types/socket.d.ts similarity index 100% rename from src/typings/socket.d.ts rename to src/types/socket.d.ts diff --git a/src/views/demo/curd/config/add.ts b/src/views/demo/curd/config/add.ts index ea1438bd..023548c4 100644 --- a/src/views/demo/curd/config/add.ts +++ b/src/views/demo/curd/config/add.ts @@ -1,7 +1,6 @@ import DeptAPI from "@/api/dept"; import RoleAPI from "@/api/role"; -import UserAPI from "@/api/user"; -import type { UserForm } from "@/api/user/model"; +import UserAPI, { UserForm } from "@/api/user"; import type { IModalConfig } from "@/components/CURD/types"; const modalConfig: IModalConfig = { diff --git a/src/views/demo/curd/config/content.ts b/src/views/demo/curd/config/content.ts index 8a79fecb..9416c50b 100644 --- a/src/views/demo/curd/config/content.ts +++ b/src/views/demo/curd/config/content.ts @@ -1,9 +1,9 @@ import UserAPI from "@/api/user"; import RoleAPI from "@/api/role"; -import type { UserQuery } from "@/api/user/model"; +import type { UserPageQuery } from "@/api/user"; import type { IContentConfig } from "@/components/CURD/types"; -const contentConfig: IContentConfig = { +const contentConfig: IContentConfig = { pageName: "sys:user", table: { border: true, diff --git a/src/views/demo/curd/config/edit.ts b/src/views/demo/curd/config/edit.ts index 20550f47..983546a4 100644 --- a/src/views/demo/curd/config/edit.ts +++ b/src/views/demo/curd/config/edit.ts @@ -1,7 +1,7 @@ import DeptAPI from "@/api/dept"; import RoleAPI from "@/api/role"; import UserAPI from "@/api/user"; -import type { UserForm } from "@/api/user/model"; +import type { UserForm } from "@/api/user"; import type { IModalConfig } from "@/components/CURD/types"; import { DeviceEnum } from "@/enums/DeviceEnum"; import { useAppStore } from "@/store"; diff --git a/src/views/demo/curd/index.vue b/src/views/demo/curd/index.vue index 9060c666..66433559 100644 --- a/src/views/demo/curd/index.vue +++ b/src/views/demo/curd/index.vue @@ -49,7 +49,7 @@ @submit-click="handleSubmitClick" > @@ -60,7 +60,7 @@ @submit-click="handleSubmitClick" > diff --git a/src/views/demo/dict.vue b/src/views/demo/dict.vue index fcb6e060..eed01000 100644 --- a/src/views/demo/dict.vue +++ b/src/views/demo/dict.vue @@ -15,14 +15,14 @@ const numberValue = ref(1); // 性别(值为Number) > - + 值为String: const value = ref("1"); - + 值为Number: const value = ref(1); diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 34952d2b..42561365 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -116,7 +116,7 @@ diff --git a/src/views/system/dict/index.vue b/src/views/system/dict/index.vue index 65cfd16d..2b0a91e4 100644 --- a/src/views/system/dict/index.vue +++ b/src/views/system/dict/index.vue @@ -1,5 +1,4 @@ - - + - + @@ -418,8 +447,7 @@ defineOptions({ inheritAttrs: false, }); -import MenuAPI from "@/api/menu"; -import { MenuQuery, MenuForm, MenuVO } from "@/api/menu/model"; +import MenuAPI, { MenuQuery, MenuForm, MenuVO } from "@/api/menu"; import { MenuTypeEnum } from "@/enums/MenuTypeEnum"; const queryFormRef = ref(ElForm); @@ -458,7 +486,7 @@ const rules = reactive({ parentId: [{ required: true, message: "请选择顶级菜单", trigger: "blur" }], name: [{ required: true, message: "请输入菜单名称", trigger: "blur" }], type: [{ required: true, message: "请选择菜单类型", trigger: "blur" }], - path: [{ required: true, message: "请输入路由路径", trigger: "blur" }], + routePath: [{ required: true, message: "请输入路由路径", trigger: "blur" }], component: [{ required: true, message: "请输入组件路径", trigger: "blur" }], visible: [{ required: true, message: "请输入路由路径", trigger: "blur" }], }); @@ -496,7 +524,7 @@ function handleRowClick(row: MenuVO) { * @param parentId 父菜单ID * @param menuId 菜单ID */ -function handleDialogOpen(parentId?: number, menuId?: number) { +function handleOpenDialog(parentId?: number, menuId?: number) { MenuAPI.getOptions() .then((data) => { menuOptions.value = [{ value: 0, label: "顶级菜单", children: data }]; @@ -541,13 +569,13 @@ function submitForm() { if (menuId) { MenuAPI.update(menuId, formData.value).then(() => { ElMessage.success("修改成功"); - closeDialog(); + handleCloseDialog(); handleQuery(); }); } else { MenuAPI.add(formData.value).then(() => { ElMessage.success("新增成功"); - closeDialog(); + handleCloseDialog(); handleQuery(); }); } @@ -577,7 +605,7 @@ function handleDelete(menuId: number) { } // 关闭弹窗 -function closeDialog() { +function handleCloseDialog() { dialog.visible = false; menuFormRef.value.resetFields(); menuFormRef.value.clearValidate(); diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue index e62b10ea..d332e135 100644 --- a/src/views/system/role/index.vue +++ b/src/views/system/role/index.vue @@ -195,7 +195,6 @@ :data="menuPermOptions" :filter-node-method="handlePermFilter" :default-expand-all="true" - :check-on-click-node="true" :check-strictly="!parentChildLinked" class="mt-5" > @@ -222,11 +221,9 @@ defineOptions({ inheritAttrs: false, }); -import RoleAPI from "@/api/role"; +import RoleAPI, { RolePageVO, RoleForm, RolePageQuery } from "@/api/role"; import MenuAPI from "@/api/menu"; -import { RolePageVO, RoleForm, RoleQuery } from "@/api/role/model"; - const queryFormRef = ref(ElForm); const roleFormRef = ref(ElForm); const permTreeRef = ref>(); @@ -235,7 +232,7 @@ const loading = ref(false); const ids = ref([]); const total = ref(0); -const queryParams = reactive({ +const queryParams = reactive({ pageNum: 1, pageSize: 10, }); @@ -315,7 +312,7 @@ function handleOpenDialog(roleId?: number) { } } -// 角色保存提交 +/** 提交角色表单 */ function handleSubmit() { roleFormRef.value.validate((valid: any) => { if (valid) { @@ -342,7 +339,7 @@ function handleSubmit() { }); } -// 关闭表单弹窗 +/** 关闭表单弹窗 */ function handleCloseDialog() { dialog.visible = false; @@ -354,7 +351,7 @@ function handleCloseDialog() { formData.status = 1; } -// 删除角色 +/** 删除角色 */ function handleDelete(roleId?: number) { const roleIds = [roleId || ids.value].join(","); if (!roleIds) { @@ -377,7 +374,7 @@ function handleDelete(roleId?: number) { }); } -// 打开分配权限 +/** 打开分配菜单权限弹窗 */ async function handleOpenAssignPermDialog(row: RolePageVO) { const roleId = row.id; if (roleId) { @@ -404,7 +401,7 @@ async function handleOpenAssignPermDialog(row: RolePageVO) { } } -// 分配权限提交 +/** 分配菜单权限提交 */ function handleAssignPermSubmit() { const roleId = checkedRole.value.id; if (roleId) { @@ -425,7 +422,7 @@ function handleAssignPermSubmit() { } } -// 切换菜单树展开状态 +/** 展开/收缩 菜单权限树 */ function togglePermTree() { isExpanded.value = !isExpanded.value; if (permTreeRef.value) { @@ -438,11 +435,12 @@ function togglePermTree() { }); } } +// 菜单权限筛选 watch(permKeywords, (val) => { permTreeRef.value!.filter(val); }); -// 权限筛选 +/** 权限筛选 */ function handlePermFilter( value: string, data: { @@ -453,6 +451,7 @@ function handlePermFilter( return data.label.includes(value); } +/** 父子菜单节点是否联动 change*/ function handleparentChildLinkedChange(val: any) { parentChildLinked.value = val; } diff --git a/src/views/system/user/components/user-import.vue b/src/views/system/user/components/user-import.vue new file mode 100644 index 00000000..016dac52 --- /dev/null +++ b/src/views/system/user/components/user-import.vue @@ -0,0 +1,145 @@ + + + diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index f337f7a1..6124a205 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -59,12 +59,12 @@ @@ -332,30 +285,28 @@ defineOptions({ inheritAttrs: false, }); -import UserAPI from "@/api/user"; +import UserAPI, { UserForm, UserPageQuery, UserPageVO } from "@/api/user"; import DeptAPI from "@/api/dept"; import RoleAPI from "@/api/role"; -import { UserForm, UserQuery, UserPageVO } from "@/api/user/model"; -import type { UploadInstance } from "element-plus"; -import { genFileId } from "element-plus"; +const queryFormRef = ref(ElForm); +const userFormRef = ref(ElForm); -const queryFormRef = ref(ElForm); // 查询表单 -const userFormRef = ref(ElForm); // 用户表单 -const uploadRef = ref(); // 上传组件 - -const loading = ref(false); // 加载状态 -const removeIds = ref([]); // 删除用户ID集合 用于批量删除 -const queryParams = reactive({ +const loading = ref(false); +const removeIds = ref([]); +const total = ref(0); +const pageData = ref(); +/** 部门下拉选项 */ +const deptOptions = ref(); +/** 角色下拉选项 */ +const roleOptions = ref(); +/** 用户查询参数 */ +const queryParams = reactive({ pageNum: 1, pageSize: 10, }); -const dateTimeRange = ref(""); -const total = ref(0); // 数据总数 -const pageData = ref(); // 用户分页数据 -const deptList = ref(); // 部门下拉数据源 -const roleList = ref(); // 角色下拉数据源 +const dateTimeRange = ref(""); watch(dateTimeRange, (newVal) => { if (newVal) { queryParams.startTime = newVal[0]; @@ -363,27 +314,21 @@ watch(dateTimeRange, (newVal) => { } }); -// 弹窗对象 +/** 用户弹窗对象 */ const dialog = reactive({ visible: false, - type: "user-form", - width: 800, title: "", }); +/** 导入弹窗显示状态 */ +const importDialogVisible = ref(false); + // 用户表单数据 const formData = reactive({ status: 1, }); -// 用户导入数据 -const importData = reactive({ - deptId: undefined, - file: undefined, - fileList: [], -}); - -// 校验规则 +/** 用户表单校验规则 */ const rules = reactive({ username: [{ required: true, message: "用户名不能为空", trigger: "blur" }], nickname: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }], @@ -436,7 +381,7 @@ function handleSelectionChange(selection: any) { } /** 重置密码 */ -function resetPassword(row: { [key: string]: any }) { +function hancleResetPassword(row: { [key: string]: any }) { ElMessageBox.prompt( "请输入用户「" + row.username + "」的新密码", "重置密码", @@ -456,110 +401,63 @@ function resetPassword(row: { [key: string]: any }) { }); } -/** 加载角色下拉数据源 */ -async function loadRoleOptions() { - RoleAPI.getOptions().then((data) => { - roleList.value = data; - }); -} - -/** 加载部门下拉数据源 */ -async function loadDeptOptions() { - DeptAPI.getOptions().then((data) => { - deptList.value = data; - }); -} - /** * 打开弹窗 * - * @param type 弹窗类型 用户表单:user-form | 用户导入:user-import * @param id 用户ID */ -async function openDialog(type: string, id?: number) { +async function handleOpenDialog(id?: number) { dialog.visible = true; - dialog.type = type; + // 加载角色下拉数据源 + roleOptions.value = await RoleAPI.getOptions(); + // 加载部门下拉数据源 + deptOptions.value = await DeptAPI.getOptions(); - if (dialog.type === "user-form") { - // 用户表单弹窗 - await loadDeptOptions(); - await loadRoleOptions(); - if (id) { - dialog.title = "修改用户"; - UserAPI.getFormData(id).then((data) => { - Object.assign(formData, { ...data }); - }); - } else { - dialog.title = "新增用户"; - } - } else if (dialog.type === "user-import") { - // 用户导入弹窗 - dialog.title = "导入用户"; - dialog.width = 600; - loadDeptOptions(); + if (id) { + dialog.title = "修改用户"; + UserAPI.getFormData(id).then((data) => { + Object.assign(formData, { ...data }); + }); + } else { + dialog.title = "新增用户"; } } -/** - * 关闭弹窗 - * - * @param type 弹窗类型 用户表单:user-form | 用户导入:user-import - */ -function closeDialog() { +/** 关闭弹窗 */ +function handleCloseDialog() { dialog.visible = false; - if (dialog.type === "user-form") { - userFormRef.value.resetFields(); - userFormRef.value.clearValidate(); + userFormRef.value.resetFields(); + userFormRef.value.clearValidate(); - formData.id = undefined; - formData.status = 1; - } else if (dialog.type === "user-import") { - importData.file = undefined; - importData.fileList = []; - } + formData.id = undefined; + formData.status = 1; } /** 表单提交 */ const handleSubmit = useThrottleFn(() => { - if (dialog.type === "user-form") { - userFormRef.value.validate((valid: any) => { - if (valid) { - const userId = formData.id; - loading.value = true; - if (userId) { - UserAPI.update(userId, formData) - .then(() => { - ElMessage.success("修改用户成功"); - closeDialog(); - handleResetQuery(); - }) - .finally(() => (loading.value = false)); - } else { - UserAPI.add(formData) - .then(() => { - ElMessage.success("新增用户成功"); - closeDialog(); - handleResetQuery(); - }) - .finally(() => (loading.value = false)); - } + userFormRef.value.validate((valid: any) => { + if (valid) { + const userId = formData.id; + loading.value = true; + if (userId) { + UserAPI.update(userId, formData) + .then(() => { + ElMessage.success("修改用户成功"); + handleCloseDialog(); + handleResetQuery(); + }) + .finally(() => (loading.value = false)); + } else { + UserAPI.add(formData) + .then(() => { + ElMessage.success("新增用户成功"); + handleCloseDialog(); + handleResetQuery(); + }) + .finally(() => (loading.value = false)); } - }); - } else if (dialog.type === "user-import") { - if (!importData?.deptId) { - ElMessage.warning("请选择部门"); - return false; } - if (!importData?.file) { - ElMessage.warning("上传Excel文件不能为空"); - return false; - } - UserAPI.import(importData?.deptId, importData?.file).then((data) => { - ElMessage.success("导入用户成功"); - closeDialog(); - handleResetQuery(); - }); - } + }); }, 3000); /** 删除用户 */ @@ -581,44 +479,14 @@ function handleDelete(id?: number) { }); }); } - -/** 下载导入模板 */ -function downloadTemplate() { - UserAPI.downloadTemplate().then((response: any) => { - const fileData = response.data; - const fileName = decodeURI( - response.headers["content-disposition"].split(";")[1].split("=")[1] - ); - const fileType = - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"; - - const blob = new Blob([fileData], { type: fileType }); - const downloadUrl = window.URL.createObjectURL(blob); - - const downloadLink = document.createElement("a"); - downloadLink.href = downloadUrl; - downloadLink.download = fileName; - - document.body.appendChild(downloadLink); - downloadLink.click(); - - document.body.removeChild(downloadLink); - window.URL.revokeObjectURL(downloadUrl); - }); +/** 打开导入弹窗 */ +function handleOpenImportDialog() { + importDialogVisible.value = true; } -/** Excel文件 Change */ -function handleFileChange(file: any) { - importData.file = file.raw; -} - -/** Excel文件 Exceed */ -function handleFileExceed(files: any) { - uploadRef.value!.clearFiles(); - const file = files[0]; - file.uid = genFileId(); - uploadRef.value!.handleStart(file); - importData.file = file; +/** 导入用户成功 */ +function handleOpenImportDialogSuccess() { + handleQuery(); } /** 导出用户 */ diff --git a/tsconfig.json b/tsconfig.json index 6d1e993c..9acc1fad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,9 +25,8 @@ "jsxFragmentFactory": "Fragment" }, "include": [ - "src/**/*.ts", "src/**/*.vue", - "src/typings/**/*.d.ts", + "src/types/**/*.d.ts", "mock/**/*.ts", "vite.config.ts" ],