Эх сурвалжийг харах

Merge pull request #119 from xingyu4j/master

添加按钮权限功能
Archer 2 жил өмнө
parent
commit
60aa653fdf

+ 2 - 2
README.md

@@ -9,7 +9,7 @@
 
 ## Introduction
 
-vue-element-plus-admin is a free and open source middle and background template based on `element-plus`. Developed using the latest mainstream technologies such as `vue3`, `vite2` and `typescript`, the out of the box middle and background front-end solution can be used as the starting template of the project and learning reference. And always pay attention to the latest technological trends and update them as soon as possible.
+vue-element-plus-admin is a free and open source middle and background template based on `element-plus`. Developed using the latest mainstream technologies such as `vue3`, `vite3` and `typescript`, the out of the box middle and background front-end solution can be used as the starting template of the project and learning reference. And always pay attention to the latest technological trends and update them as soon as possible.
 
 vue-element-plus-admin is positioned as a background integration scheme, which is not suitable for secondary development as a basic template. Because it integrates many functions that you may not use, it will cause a lot of code redundancy. If your project doesn't pay attention to this problem, you can also directly carry out secondary development based on it.
 
@@ -17,7 +17,7 @@ If you need a basic template, please switch to the `tempalte` branch. `Tempalte`
 
 ## Feature
 
-- **State of The Art Development**:Use front-end front-end technology development such as Vue3/vite2
+- **State of The Art Development**:Use front-end front-end technology development such as Vue3/vite3
 - **TypeScript**: Application-level JavaScript language
 - **Theming**: Configurable themes
 - **International**:Built-in complete internationalization program

+ 2 - 2
README.zh-CN.md

@@ -9,7 +9,7 @@
 
 ## 介绍
 
-vue-element-plus-admin 是一个基于 `element-plus` 免费开源的中后台模版。使用了最新的`vue3`,`vite2`,`TypeScript`等主流技术开发,开箱即用的中后台前端解决方案,可以用来作为项目的启动模版,也可用于学习参考。并且时刻关注着最新技术动向,尽可能的第一时间更新。
+vue-element-plus-admin 是一个基于 `element-plus` 免费开源的中后台模版。使用了最新的`vue3`,`vite3`,`TypeScript`等主流技术开发,开箱即用的中后台前端解决方案,可以用来作为项目的启动模版,也可用于学习参考。并且时刻关注着最新技术动向,尽可能的第一时间更新。
 
 vue-element-plus-admin 的定位是后台集成方案,不太适合当基础模板来进行二次开发。因为集成了很多你可能用不到的功能,会造成不少的代码冗余。如果你的项目不关注这方面的问题,也可以直接基于它进行二次开发。
 
@@ -17,7 +17,7 @@ vue-element-plus-admin 的定位是后台集成方案,不太适合当基础模
 
 ## 特性
 
-- **最新技术栈**:使用 Vue3/vite2 等前端前沿技术开发
+- **最新技术栈**:使用 Vue3/vite3 等前端前沿技术开发
 - **TypeScript**: 应用程序级 JavaScript 的语言
 - **主题**: 可配置的主题
 - **国际化**:内置完善的国际化方案

+ 5 - 2
mock/user/index.ts

@@ -10,18 +10,21 @@ const List: {
   password: string
   role: string
   roleId: string
+  permissions: string | string[]
 }[] = [
   {
     username: 'admin',
     password: 'admin',
     role: 'admin',
-    roleId: '1'
+    roleId: '1',
+    permissions: ['*.*.*']
   },
   {
     username: 'test',
     password: 'test',
     role: 'test',
-    roleId: '2'
+    roleId: '2',
+    permissions: ['example:dialog:create', 'example:dialog:delete']
   }
 ]
 

+ 11 - 13
package.json

@@ -1,7 +1,7 @@
 {
   "name": "vue-element-plus-admin",
   "version": "1.5.4",
-  "description": "一套基于vue3、element-plus、typesScript、vite2的后台集成方案。",
+  "description": "一套基于vue3、element-plus、typesScript、vite3的后台集成方案。",
   "author": "Archer <502431556@qq.com>",
   "private": false,
   "scripts": {
@@ -27,17 +27,16 @@
   },
   "dependencies": {
     "@iconify/iconify": "^2.2.1",
-    "@vueuse/core": "^8.9.3",
-    "@wangeditor/editor": "^5.1.9",
+    "@vueuse/core": "^8.9.4",
+    "@wangeditor/editor": "^5.1.10",
     "@wangeditor/editor-for-vue": "^5.1.10",
-    "@zxcvbn-ts/core": "^2.0.1",
+    "@zxcvbn-ts/core": "^2.0.3",
     "animate.css": "^4.1.1",
     "axios": "^0.27.2",
     "echarts": "^5.3.3",
     "echarts-wordcloud": "^2.0.0",
     "element-plus": "2.2.9",
     "intro.js": "^6.0.0",
-    "js-md5": "^0.7.3",
     "lodash-es": "^4.17.21",
     "mitt": "^3.0.0",
     "mockjs": "^1.1.0",
@@ -56,22 +55,21 @@
   "devDependencies": {
     "@commitlint/cli": "^17.0.3",
     "@commitlint/config-conventional": "^17.0.3",
-    "@iconify/json": "^2.1.78",
+    "@iconify/json": "^2.1.79",
     "@intlify/vite-plugin-vue-i18n": "^5.0.0",
     "@purge-icons/generated": "^0.8.1",
     "@types/intro.js": "^5.1.0",
-    "@types/js-md5": "^0.4.3",
     "@types/lodash-es": "^4.17.6",
-    "@types/node": "^18.0.5",
+    "@types/node": "^18.0.6",
     "@types/nprogress": "^0.2.0",
     "@types/qrcode": "^1.4.2",
     "@types/qs": "^6.9.7",
     "@typescript-eslint/eslint-plugin": "^5.30.6",
     "@typescript-eslint/parser": "^5.30.6",
-    "@vitejs/plugin-vue": "^3.0.0",
+    "@vitejs/plugin-vue": "^3.0.1",
     "@vitejs/plugin-vue-jsx": "^2.0.0",
     "autoprefixer": "^10.4.7",
-    "eslint": "^8.19.0",
+    "eslint": "^8.20.0",
     "eslint-config-prettier": "^8.5.0",
     "eslint-define-config": "^1.5.1",
     "eslint-plugin-prettier": "^4.2.1",
@@ -94,7 +92,7 @@
     "stylelint-order": "^5.0.0",
     "typescript": "4.7.4",
     "unplugin-vue-define-options": "^0.6.2",
-    "vite": "3.0.0",
+    "vite": "3.0.1",
     "vite-plugin-eslint": "^1.6.1",
     "vite-plugin-html": "^3.2.0",
     "vite-plugin-mock": "^2.9.6",
@@ -102,12 +100,12 @@
     "vite-plugin-style-import": "^1.4.1",
     "vite-plugin-svg-icons": "^2.0.1",
     "vite-plugin-windicss": "^1.8.7",
-    "vue-tsc": "^0.38.5",
+    "vue-tsc": "^0.38.8",
     "windicss": "^3.5.6",
     "windicss-analysis": "^0.3.5"
   },
   "engines": {
-    "node": ">= 14.0.0"
+    "node": ">= 14.18.0"
   },
   "license": "MIT",
   "repository": {

BIN
public/logo.png


+ 1 - 0
src/api/login/types.ts

@@ -8,4 +8,5 @@ export type UserType = {
   password: string
   role: string
   roleId: string
+  permissions: string | string[]
 }

BIN
src/assets/imgs/avatar.jpg


BIN
src/assets/imgs/logo.png


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 5290
src/assets/svgs/403.svg


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 5287
src/assets/svgs/404.svg


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 5389
src/assets/svgs/500.svg


+ 1 - 1
src/assets/svgs/icon.svg

@@ -1 +1 @@
-<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg"><path d="M115.147.062a13 13 0 0 1 4.94.945c1.55.63 2.907 1.526 4.069 2.688a13.148 13.148 0 0 1 2.761 4.069c.678 1.55 1.017 3.245 1.017 5.086v102.3c0 3.681-1.187 6.733-3.56 9.155-2.373 2.422-5.352 3.633-8.937 3.633H12.992c-3.875 0-7-1.26-9.373-3.779-2.373-2.518-3.56-5.667-3.56-9.445V12.704c0-3.39 1.163-6.345 3.488-8.863C5.872 1.32 8.972.062 12.847.062h102.3zM81.434 109.047c1.744 0 3.003-.412 3.778-1.235.775-.824 1.163-1.914 1.163-3.27 0-1.26-.388-2.325-1.163-3.197-.775-.872-2.034-1.307-3.778-1.307H72.57c.097-.194.145-.485.145-.872V27.09h9.01c1.743 0 2.954-.436 3.633-1.308.678-.872 1.017-1.938 1.017-3.197 0-1.26-.34-2.325-1.017-3.197-.679-.872-1.89-1.308-3.633-1.308H46.268c-1.743 0-2.954.436-3.632 1.308-.678.872-1.018 1.938-1.018 3.197 0 1.26.34 2.325 1.018 3.197.678.872 1.889 1.308 3.632 1.308h8.138v72.075c0 .193.024.339.073.436.048.096.072.242.072.436H46.56c-1.744 0-3.003.435-3.778 1.307-.775.872-1.163 1.938-1.163 3.197 0 1.356.388 2.446 1.163 3.27.775.823 2.034 1.235 3.778 1.235h34.875z"/></svg>
+<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg"><path d="M115.147.062a13 13 0 014.94.945c1.55.63 2.907 1.526 4.069 2.688a13.148 13.148 0 012.761 4.069c.678 1.55 1.017 3.245 1.017 5.086v102.3c0 3.681-1.187 6.733-3.56 9.155-2.373 2.422-5.352 3.633-8.937 3.633H12.992c-3.875 0-7-1.26-9.373-3.779-2.373-2.518-3.56-5.667-3.56-9.445V12.704c0-3.39 1.163-6.345 3.488-8.863C5.872 1.32 8.972.062 12.847.062h102.3zM81.434 109.047c1.744 0 3.003-.412 3.778-1.235.775-.824 1.163-1.914 1.163-3.27 0-1.26-.388-2.325-1.163-3.197-.775-.872-2.034-1.307-3.778-1.307H72.57c.097-.194.145-.485.145-.872V27.09h9.01c1.743 0 2.954-.436 3.633-1.308.678-.872 1.017-1.938 1.017-3.197 0-1.26-.34-2.325-1.017-3.197-.679-.872-1.89-1.308-3.633-1.308H46.268c-1.743 0-2.954.436-3.632 1.308-.678.872-1.018 1.938-1.018 3.197 0 1.26.34 2.325 1.018 3.197.678.872 1.889 1.308 3.632 1.308h8.138v72.075c0 .193.024.339.073.436.048.096.072.242.072.436H46.56c-1.744 0-3.003.435-3.778 1.307-.775.872-1.163 1.938-1.163 3.197 0 1.356.388 2.446 1.163 3.27.775.823 2.034 1.235 3.778 1.235h34.875z"/></svg>

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 47
src/assets/svgs/login-bg.svg


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 1643
src/assets/svgs/login-box-bg.svg


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
src/assets/svgs/shopping.svg


+ 10 - 0
src/directives/index.ts

@@ -0,0 +1,10 @@
+import type { App } from 'vue'
+import { setupPermissionDirective } from './permission/hasPermi'
+
+/**
+ * 导出指令:v-xxx
+ * @methods hasPermi 按钮权限,用法: v-hasPermi
+ */
+export const setupPermission = (app: App<Element>) => {
+  setupPermissionDirective(app)
+}

+ 47 - 0
src/directives/permission/hasPermi.ts

@@ -0,0 +1,47 @@
+import type { App, Directive, DirectiveBinding } from 'vue'
+import { useI18n } from '@/hooks/web/useI18n'
+import { useCache } from '@/hooks/web/useCache'
+import { intersection } from 'lodash-es'
+import { isArray } from '@/utils/is'
+import { useAppStoreWithOut } from '@/store/modules/app'
+
+const { t } = useI18n()
+const { wsCache } = useCache()
+const appStore = useAppStoreWithOut()
+
+// 全部权限
+const all_permission = ['*.*.*']
+const hasPermission = (value: string | string[]): boolean => {
+  const permissions = wsCache.get(appStore.getUserInfo).permissions as string[]
+  if (!value) {
+    throw new Error(t('permission.hasPermission'))
+  }
+  if (!isArray(value)) {
+    return permissions?.includes(value as string)
+  }
+  if (all_permission[0] === permissions[0]) {
+    return true
+  }
+  return (intersection(value, permissions) as string[]).length > 0
+}
+function hasPermi(el: Element, binding: DirectiveBinding) {
+  const value = binding.value
+
+  const flag = hasPermission(value)
+  if (!flag) {
+    el.parentNode?.removeChild(el)
+  }
+}
+const mounted = (el: Element, binding: DirectiveBinding<any>) => {
+  hasPermi(el, binding)
+}
+
+const permiDirective: Directive = {
+  mounted
+}
+
+export const setupPermissionDirective = (app: App<Element>) => {
+  app.directive('hasPermi', permiDirective)
+}
+
+export default permiDirective

+ 3 - 0
src/locales/en.ts

@@ -143,6 +143,9 @@ export default {
     inputPassword: 'InputPassword',
     sticky: 'Sticky'
   },
+  permission: {
+    hasPermission: 'Please set the operation permission value'
+  },
   analysis: {
     newUser: 'New user',
     unreadInformation: 'Unread information',

+ 3 - 0
src/locales/zh-CN.ts

@@ -143,6 +143,9 @@ export default {
     inputPassword: '密码输入框',
     sticky: '黏性'
   },
+  permission: {
+    hasPermission: '请设置操作权限值'
+  },
   analysis: {
     newUser: '新增用户',
     unreadInformation: '未读消息',

+ 5 - 0
src/main.ts

@@ -25,6 +25,9 @@ import '@/plugins/animate.css'
 // 路由
 import { setupRouter } from './router'
 
+// 权限
+import { setupPermission } from './directives'
+
 import { createApp } from 'vue'
 
 import App from './App.vue'
@@ -44,6 +47,8 @@ const setupAll = async () => {
 
   setupRouter(app)
 
+  setupPermission(app)
+
   app.mount('#app')
 }
 

+ 7 - 3
src/views/Example/Dialog/ExampleDialog.vue

@@ -231,13 +231,17 @@ const save = async () => {
       @register="register"
     >
       <template #action="{ row }">
-        <ElButton type="primary" @click="action(row, 'edit')">
+        <ElButton type="primary" v-hasPermi="['example:dialog:edit']" @click="action(row, 'edit')">
           {{ t('exampleDemo.edit') }}
         </ElButton>
-        <ElButton type="success" @click="action(row, 'detail')">
+        <ElButton
+          type="success"
+          v-hasPermi="['example:dialog:view']"
+          @click="action(row, 'detail')"
+        >
           {{ t('exampleDemo.detail') }}
         </ElButton>
-        <ElButton type="danger" @click="delData(row, false)">
+        <ElButton type="danger" v-hasPermi="['example:dialog:delete']" @click="delData(row, false)">
           {{ t('exampleDemo.del') }}
         </ElButton>
       </template>

+ 1 - 3
vite.config.ts

@@ -20,7 +20,6 @@ function pathResolve(dir: string) {
   return resolve(root, '.', dir)
 }
 
-// https://vitejs.dev/config/
 export default ({ command, mode }: ConfigEnv): UserConfig => {
   let env = {} as any
   const isBuild = command === 'build'
@@ -146,8 +145,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
         'intro.js',
         'qrcode',
         '@wangeditor/editor',
-        '@wangeditor/editor-for-vue',
-        'js-md5'
+        '@wangeditor/editor-for-vue'
       ]
     }
   }

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно