From 3f354eae5833b2aa676996e86db4f90da67ac10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Wed, 13 Aug 2025 17:20:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E9=83=A8=E5=88=86htable?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/menu.ts | 7 ++ src/components/hTable/hTable.ts | 5 +- src/components/hTable/hTableEdit.vue | 4 +- src/components/hTable/index.vue | 11 ++- src/utils/auth.ts | 5 +- src/utils/roles.ts | 20 +++++ src/views/admin/index.vue | 15 +++- src/views/admin/role.vue | 13 ++- src/views/class/index.vue | 109 ++++++++++++++++++++++++++ src/views/menu/index.vue | 78 +++++++++++++----- src/views/permission/button/index.vue | 99 ----------------------- src/views/permission/button/perms.vue | 109 -------------------------- src/views/permission/page/index.vue | 66 ---------------- 13 files changed, 236 insertions(+), 305 deletions(-) create mode 100644 src/utils/roles.ts create mode 100644 src/views/class/index.vue delete mode 100644 src/views/permission/button/index.vue delete mode 100644 src/views/permission/button/perms.vue delete mode 100644 src/views/permission/page/index.vue diff --git a/src/api/menu.ts b/src/api/menu.ts index e6db80f..17ba631 100644 --- a/src/api/menu.ts +++ b/src/api/menu.ts @@ -30,3 +30,10 @@ export function MenuAll() { export function Edit(info: MenuItem) { return http.request>("post", `Menu/Edit`, { data: info }); } +/** + * @description 获取所有的菜单 + * @return {object} + */ +export function Del(ids: number[]) { + return http.request>("post", `Menu/Del`, { data: ids }); +} diff --git a/src/components/hTable/hTable.ts b/src/components/hTable/hTable.ts index 95bf2a1..26dcada 100644 --- a/src/components/hTable/hTable.ts +++ b/src/components/hTable/hTable.ts @@ -50,6 +50,8 @@ export interface ButtonCustomConfig { export interface OperationButton { /* 是否为头部按钮 */ topBtn: boolean; + /** 按钮权限码 */ + perms?: string; /* 是否显示 */ show?: boolean; /* 按钮文本 */ @@ -57,7 +59,7 @@ export interface OperationButton { /* 按钮类型 */ btnType: "add" | "edit" | "del" | "custom"; /* 按钮样式 */ - btnStyle?: "success" | "danger"; + btnStyle?: "success" | "info" | "primary" | "danger" | "warning"; /* 自定义按钮配置 */ custom?: ButtonCustomConfig; } @@ -112,6 +114,7 @@ export interface TableColumn { multiple?: boolean; /** 编辑时显示列 */ editShow?: boolean; + /**校验规则 */ rules?: any | Array; /** 显示列 */ show?: boolean; diff --git a/src/components/hTable/hTableEdit.vue b/src/components/hTable/hTableEdit.vue index b0cc80a..3a9bb75 100644 --- a/src/components/hTable/hTableEdit.vue +++ b/src/components/hTable/hTableEdit.vue @@ -116,8 +116,8 @@ function handleResetForm() { function fetchInitData() {} function fetchFormData() { editData.value.loading = false; - handleResetForm(); if (editData.value.isedit) { + handleResetForm(); Api.Info({ id: props.id }).then(res => { if (res.code === 200) { editData.value.frorm = res.data; @@ -192,7 +192,7 @@ function fetchFormData() {
) { permissions }); } - - if (data.userName && data.roles) { + if (data.userName && data.permissions) { const { userName, roles } = data; setUserKey({ avatar: data?.avatar ?? "", @@ -129,7 +128,7 @@ export const formatToken = (token: string): string => { /** 是否有按钮级别的权限(根据登录接口返回的`permissions`字段进行判断)*/ export const hasPerms = (value: string | Array): boolean => { - if (!value) return false; + if (!value) return true; const allPerms = "*:*:*"; const { permissions } = useUserStoreHook(); if (!permissions) return false; diff --git a/src/utils/roles.ts b/src/utils/roles.ts new file mode 100644 index 0000000..6f7566d --- /dev/null +++ b/src/utils/roles.ts @@ -0,0 +1,20 @@ +export const ruleRequired = [ + { required: true, message: "不能为空", trigger: "blur" } +]; +export const rulePassword = [ + { required: true, message: "不能为空", trigger: "blur" }, + { min: 6, message: "长度必须大于5", trigger: "blur" } +]; +export const ruleAccount = [ + { required: true, message: "不能为空", trigger: "blur" }, + { min: 13, message: "长度必须大于12", trigger: "blur" } +]; + +export const rulePhone = [ + { required: true, message: "手机号不能为空", trigger: "blur" }, + { + pattern: /^1[3-9]\d{9}$/, + message: "请输入正确的手机号", + trigger: "blur" + } +]; diff --git a/src/views/admin/index.vue b/src/views/admin/index.vue index db4fa4f..0f1c91e 100644 --- a/src/views/admin/index.vue +++ b/src/views/admin/index.vue @@ -4,6 +4,12 @@ import { TableConfig } from "@/components/hTable/hTable"; import { onMounted, ref } from "vue"; import { fa } from "element-plus/es/locales.mjs"; import { hTableAPI } from "@/api/hTable"; +import { + ruleAccount, + rulePassword, + rulePhone, + ruleRequired +} from "@/utils/roles"; const ControllerName = "Admin"; defineOptions({ @@ -71,6 +77,7 @@ const tableData: TableConfig = { name: { label: "名称", width: "180px", + rules: ruleRequired, search: true, searchType: "Like", add: true, // 字段允许添加 @@ -78,6 +85,7 @@ const tableData: TableConfig = { }, Phone: { label: "手机号", + rules: rulePhone, width: "200px", search: true, add: true, // 字段允许添加 @@ -85,6 +93,7 @@ const tableData: TableConfig = { }, account: { label: "账号", + rules: ruleAccount, search: true, add: true, // 字段允许添加 edit: false // 字段允许修改 @@ -92,6 +101,8 @@ const tableData: TableConfig = { password: { label: "密码", show: false, + /**长度必须大于6 */ + rules: rulePassword, search: false, add: true, // 字段允许添加 edit: false // 字段允许修改 @@ -100,13 +111,15 @@ const tableData: TableConfig = { label: "启用", type: "switch", search: false, - add: false, // 字段允许添加 + + add: true, // 字段允许添加 edit: true, // 字段允许修改 valueE: true // 编辑时的默认值 }, roleId: { label: "角色", type: "dropdown", + rules: ruleRequired, search: true, add: true, // 字段允许添加 edit: false, // 字段允许修改 diff --git a/src/views/admin/role.vue b/src/views/admin/role.vue index fc16386..11e281e 100644 --- a/src/views/admin/role.vue +++ b/src/views/admin/role.vue @@ -11,7 +11,6 @@ defineOptions({ }); function searchCallback(data) {} -const RoleApi = new hTableAPI("AdminRole"); const table = ref<{ initTable: (config: TableConfig) => void }>(null); const tableData: TableConfig = { apiUrl: ControllerName, @@ -29,6 +28,14 @@ const tableData: TableConfig = { }, operationColumn: true, // 显示操作按钮 operationColumnData: [ + { + topBtn: false, // 头部按钮 + show: true, + label: "角色授权", + perms: "角色授权", //按钮显示需要的权限码 + btnType: "custom", // 按钮类型 add edit del 不设置则 自定义按钮 + btnStyle: "success" // topBtn: true才生效 success danger + }, { // 操作按钮 topBtn: false, // 是头部按钮 @@ -71,7 +78,7 @@ const tableData: TableConfig = { label: "启用", type: "switch", search: false, - add: false, // 字段允许添加 + add: true, // 字段允许添加 edit: true, // 字段允许修改 valueE: true // 编辑时的默认值 }, @@ -84,6 +91,8 @@ const tableData: TableConfig = { }, remark: { label: "备注", + type: "textarea", + editRows: 3, search: false, add: true, // 字段允许添加 edit: true // 字段允许修改 diff --git a/src/views/class/index.vue b/src/views/class/index.vue new file mode 100644 index 0000000..2aab196 --- /dev/null +++ b/src/views/class/index.vue @@ -0,0 +1,109 @@ + + + diff --git a/src/views/menu/index.vue b/src/views/menu/index.vue index 91a83c7..6f09a21 100644 --- a/src/views/menu/index.vue +++ b/src/views/menu/index.vue @@ -17,26 +17,47 @@ class="menu-tree" > @@ -57,7 +78,7 @@ - - diff --git a/src/views/permission/button/perms.vue b/src/views/permission/button/perms.vue deleted file mode 100644 index 8fce6da..0000000 --- a/src/views/permission/button/perms.vue +++ /dev/null @@ -1,109 +0,0 @@ - - - diff --git a/src/views/permission/page/index.vue b/src/views/permission/page/index.vue deleted file mode 100644 index d65d03f..0000000 --- a/src/views/permission/page/index.vue +++ /dev/null @@ -1,66 +0,0 @@ - - -