From 06c77d53a09c55aeadd5142a43f416b234d98d76 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Tue, 20 Aug 2024 15:28:29 +0800 Subject: [PATCH] release: update `5.8.0` --- mock/asyncRoutes.ts | 35 +- mock/login.ts | 3 + package.json | 80 +- public/platform-config.json | 2 +- src/api/user.ts | 2 + src/components/ReDialog/index.vue | 22 +- src/components/ReDialog/type.ts | 15 +- src/components/RePerms/index.ts | 5 + src/components/RePerms/src/perms.tsx | 20 + src/components/RePureTableBar/src/bar.tsx | 24 +- src/directives/index.ts | 1 + src/directives/perms/index.ts | 15 + .../components/lay-sidebar/NavHorizontal.vue | 19 +- src/main.ts | 2 + src/router/utils.ts | 2 +- src/store/modules/user.ts | 8 + src/store/types.ts | 1 + src/utils/auth.ts | 33 +- src/views/permission/button/index.vue | 2 +- src/views/permission/button/perms.vue | 109 + types/directives.d.ts | 4 +- types/global-components.d.ts | 1 + yarn.lock | 2551 +++++++++-------- 23 files changed, 1662 insertions(+), 1294 deletions(-) create mode 100644 src/components/RePerms/index.ts create mode 100644 src/components/RePerms/src/perms.tsx create mode 100644 src/directives/perms/index.ts create mode 100644 src/views/permission/button/perms.vue diff --git a/mock/asyncRoutes.ts b/mock/asyncRoutes.ts index 202bf362..2a991839 100644 --- a/mock/asyncRoutes.ts +++ b/mock/asyncRoutes.ts @@ -23,17 +23,34 @@ const permissionRouter = { } }, { - path: "/permission/button/index", - name: "PermissionButton", + path: "/permission/button", meta: { title: "按钮权限", - roles: ["admin", "common"], - auths: [ - "permission:btn:add", - "permission:btn:edit", - "permission:btn:delete" - ] - } + roles: ["admin", "common"] + }, + children: [ + { + path: "/permission/button/router", + component: "permission/button/index", + name: "PermissionButtonRouter", + meta: { + title: "路由返回按钮权限", + auths: [ + "permission:btn:add", + "permission:btn:edit", + "permission:btn:delete" + ] + } + }, + { + path: "/permission/button/login", + component: "permission/button/perms", + name: "PermissionButtonLogin", + meta: { + title: "登录接口返回按钮权限" + } + } + ] } ] }; diff --git a/mock/login.ts b/mock/login.ts index a9c71b15..55897d8f 100644 --- a/mock/login.ts +++ b/mock/login.ts @@ -15,6 +15,8 @@ export default defineFakeRoute([ nickname: "小铭", // 一个用户可能有多个角色 roles: ["admin"], + // 按钮级别权限 + permissions: ["*:*:*"], accessToken: "eyJhbGciOiJIUzUxMiJ9.admin", refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh", expires: "2030/10/30 00:00:00" @@ -28,6 +30,7 @@ export default defineFakeRoute([ username: "common", nickname: "小林", roles: ["common"], + permissions: ["permission:btn:add", "permission:btn:edit"], accessToken: "eyJhbGciOiJIUzUxMiJ9.common", refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh", expires: "2030/10/30 00:00:00" diff --git a/package.json b/package.json index 9e544438..e1c9a15d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electron-pure-admin", - "version": "5.7.0", + "version": "5.8.0", "description": "electron-pure-admin", "private": true, "type": "module", @@ -54,35 +54,35 @@ }, "dependencies": { "@pureadmin/descriptions": "^1.2.1", - "@pureadmin/table": "^3.1.2", - "@pureadmin/utils": "^2.4.7", - "@vueuse/core": "^10.11.0", + "@pureadmin/table": "^3.2.0", + "@pureadmin/utils": "^2.4.8", + "@vueuse/core": "^11.0.1", "@vueuse/motion": "^2.2.3", "animate.css": "^4.1.1", - "axios": "^1.7.2", - "dayjs": "^1.11.11", + "axios": "^1.7.4", + "dayjs": "^1.11.12", "echarts": "^5.5.1", - "element-plus": "^2.7.6", + "element-plus": "^2.8.0", "js-cookie": "^3.0.5", "localforage": "^1.10.0", "mitt": "^3.0.1", "nprogress": "^0.2.0", "path": "^0.12.7", - "pinia": "^2.1.7", - "pinyin-pro": "^3.23.0", - "qs": "^6.12.2", + "pinia": "^2.2.2", + "pinyin-pro": "^3.24.2", + "qs": "^6.13.0", "responsive-storage": "^2.2.0", "sortablejs": "^1.15.2", - "vue": "^3.4.31", - "vue-router": "^4.4.0", + "vue": "^3.4.38", + "vue-router": "^4.4.3", "vue-tippy": "^6.4.4", - "vue-types": "^5.1.2" + "vue-types": "^5.1.3" }, "devDependencies": { - "@commitlint/cli": "^19.3.0", + "@commitlint/cli": "^19.4.0", "@commitlint/config-conventional": "^19.2.2", "@commitlint/types": "^19.0.3", - "@eslint/js": "^9.6.0", + "@eslint/js": "^9.9.0", "@faker-js/faker": "^8.4.1", "@iconify-icons/ep": "^1.2.12", "@iconify-icons/ri": "^1.2.10", @@ -91,61 +91,61 @@ "@types/args": "^5.0.3", "@types/gradient-string": "^1.1.6", "@types/js-cookie": "^3.0.6", - "@types/node": "^20.14.9", + "@types/node": "^22.4.1", "@types/nprogress": "^0.2.3", "@types/qs": "^6.9.15", "@types/sortablejs": "^1.15.8", - "@typescript-eslint/eslint-plugin": "^7.15.0", - "@typescript-eslint/parser": "^7.15.0", - "@vitejs/plugin-vue": "^5.0.5", - "@vitejs/plugin-vue-jsx": "^4.0.0", + "@typescript-eslint/eslint-plugin": "^7.18.0", + "@typescript-eslint/parser": "^7.18.0", + "@vitejs/plugin-vue": "^5.1.2", + "@vitejs/plugin-vue-jsx": "^4.0.1", "args": "^5.0.3", - "autoprefixer": "^10.4.19", - "boxen": "^7.1.1", + "autoprefixer": "^10.4.20", + "boxen": "^8.0.1", "cross-env": "^7.0.3", - "cssnano": "^7.0.3", + "cssnano": "^7.0.5", "electron": "^31.1.0", "electron-builder": "^24.13.3", - "eslint": "^9.6.0", + "eslint": "^9.9.0", "eslint-config-prettier": "^9.1.0", "eslint-define-config": "^2.1.0", - "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-vue": "^9.27.0", "esno": "^4.7.0", "gradient-string": "^2.0.2", - "husky": "^9.0.11", - "icon-gen": "^4.0.0", + "husky": "^9.1.4", + "icon-gen": "^5.0.0", "jimp": "^0.22.12", - "lint-staged": "^15.2.7", - "postcss": "^8.4.39", + "lint-staged": "^15.2.9", + "postcss": "^8.4.41", "postcss-html": "^1.7.0", "postcss-import": "^16.1.0", "postcss-scss": "^4.0.9", - "prettier": "^3.3.2", - "rimraf": "^5.0.7", + "prettier": "^3.3.3", + "rimraf": "^6.0.1", "rollup-plugin-visualizer": "^5.12.0", - "sass": "^1.77.6", - "stylelint": "^16.6.1", + "sass": "^1.77.8", + "stylelint": "^16.8.2", "stylelint-config-recess-order": "^5.0.1", "stylelint-config-recommended-vue": "^1.5.0", "stylelint-config-standard-scss": "^13.1.0", - "stylelint-prettier": "^5.0.0", + "stylelint-prettier": "^5.0.2", "svgo": "^3.3.2", - "tailwindcss": "^3.4.4", - "typescript": "^5.5.3", - "vite": "^5.3.2", + "tailwindcss": "^3.4.10", + "typescript": "^5.5.4", + "vite": "^5.4.1", "vite-plugin-cdn-import": "^1.0.1", - "vite-plugin-checker": "^0.7.0", + "vite-plugin-checker": "^0.7.2", "vite-plugin-compression": "^0.5.1", "vite-plugin-electron": "^0.28.7", "vite-plugin-electron-renderer": "^0.14.5", "vite-plugin-fake-server": "^2.1.1", "vite-plugin-remove-console": "^2.2.0", "vite-plugin-router-warn": "^1.0.0", - "vite-plugin-vue-inspector": "^5.1.2", + "vite-plugin-vue-inspector": "^5.1.3", "vite-svg-loader": "^5.1.0", "vue-eslint-parser": "^9.4.3", - "vue-tsc": "^2.0.24" + "vue-tsc": "^2.0.29" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/public/platform-config.json b/public/platform-config.json index 6eccc740..43b58a64 100644 --- a/public/platform-config.json +++ b/public/platform-config.json @@ -1,5 +1,5 @@ { - "Version": "5.7.0", + "Version": "5.8.0", "Title": "PureAdmin", "FixedHeader": true, "HiddenSideBar": false, diff --git a/src/api/user.ts b/src/api/user.ts index ab100b52..87184b50 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -11,6 +11,8 @@ export type UserResult = { nickname: string; /** 当前登录用户的角色 */ roles: Array; + /** 按钮级别权限 */ + permissions: Array; /** `token` */ accessToken: string; /** 用于调用刷新`accessToken`的接口时所需的`token` */ diff --git a/src/components/ReDialog/index.vue b/src/components/ReDialog/index.vue index 1db105f5..23a0106e 100644 --- a/src/components/ReDialog/index.vue +++ b/src/components/ReDialog/index.vue @@ -15,6 +15,7 @@ defineOptions({ name: "ReDialog" }); +const sureBtnMap = ref({}); const fullscreen = ref(false); const footerButtons = computed(() => { @@ -43,10 +44,26 @@ const footerButtons = computed(() => { bg: true, popconfirm: options?.popconfirm, btnClick: ({ dialog: { options, index } }) => { - const done = () => + if (options?.sureBtnLoading) { + sureBtnMap.value[index] = Object.assign( + {}, + sureBtnMap.value[index], + { + loading: true + } + ); + } + const closeLoading = () => { + if (options?.sureBtnLoading) { + sureBtnMap.value[index].loading = false; + } + }; + const done = () => { + closeLoading(); closeDialog(options, index, { command: "sure" }); + }; if (options?.beforeSure && isFunction(options?.beforeSure)) { - options.beforeSure(done, { options, index }); + options.beforeSure(done, { options, index, closeLoading }); } else { done(); } @@ -172,6 +189,7 @@ function handleClose( { + if (!slots) return null; + return hasPerms(props.value) ? ( + {slots.default?.()} + ) : null; + }; + } +}); diff --git a/src/components/RePureTableBar/src/bar.tsx b/src/components/RePureTableBar/src/bar.tsx index 29688565..8a1b7459 100644 --- a/src/components/RePureTableBar/src/bar.tsx +++ b/src/components/RePureTableBar/src/bar.tsx @@ -17,6 +17,8 @@ import { getKeyList } from "@pureadmin/utils"; +import Fullscreen from "@iconify-icons/ri/fullscreen-fill"; +import ExitFullscreen from "@iconify-icons/ri/fullscreen-exit-fill"; import DragIcon from "@/assets/table-bar/drag.svg?component"; import ExpandIcon from "@/assets/table-bar/expand.svg?component"; import RefreshIcon from "@/assets/table-bar/refresh.svg?component"; @@ -56,6 +58,7 @@ export default defineComponent({ const size = ref("default"); const loading = ref(false); const checkAll = ref(true); + const isFullscreen = ref(false); const isIndeterminate = ref(false); const instance = getCurrentInstance()!; const isExpandAll = ref(props.isExpandAll); @@ -239,7 +242,18 @@ export default defineComponent({ return () => ( <> -
+
{slots?.title ? ( slots.title() @@ -353,6 +367,14 @@ export default defineComponent({
+ + + (isFullscreen.value = !isFullscreen.value)} + />
{slots.default({ diff --git a/src/directives/index.ts b/src/directives/index.ts index 3be2c5c1..d01fe714 100644 --- a/src/directives/index.ts +++ b/src/directives/index.ts @@ -2,4 +2,5 @@ export * from "./auth"; export * from "./copy"; export * from "./longpress"; export * from "./optimize"; +export * from "./perms"; export * from "./ripple"; diff --git a/src/directives/perms/index.ts b/src/directives/perms/index.ts new file mode 100644 index 00000000..073c918b --- /dev/null +++ b/src/directives/perms/index.ts @@ -0,0 +1,15 @@ +import { hasPerms } from "@/utils/auth"; +import type { Directive, DirectiveBinding } from "vue"; + +export const perms: Directive = { + mounted(el: HTMLElement, binding: DirectiveBinding>) { + const { value } = binding; + if (value) { + !hasPerms(value) && el.parentNode?.removeChild(el); + } else { + throw new Error( + "[Directive: perms]: need perms! Like v-perms=\"['btn.add','btn.edit']\"" + ); + } + } +}; diff --git a/src/layout/components/lay-sidebar/NavHorizontal.vue b/src/layout/components/lay-sidebar/NavHorizontal.vue index 8c46d032..f5aa1b68 100644 --- a/src/layout/components/lay-sidebar/NavHorizontal.vue +++ b/src/layout/components/lay-sidebar/NavHorizontal.vue @@ -1,9 +1,11 @@