Commit 67962f1deea31d695d20ae0ea7fc39b39c1eea47

Authored by Vben
1 parent 8360b1d6

fix(v-auth): ensure the background mode is correct close #330

build/config/themeConfig.ts
@@ -38,22 +38,22 @@ export function generateColors({ @@ -38,22 +38,22 @@ export function generateColors({
38 tinycolor, 38 tinycolor,
39 }: GenerateColorsParams) { 39 }: GenerateColorsParams) {
40 const arr = new Array(19).fill(0); 40 const arr = new Array(19).fill(0);
41 - const lightens = arr.map((t, i) => { 41 + const lightens = arr.map((_t, i) => {
42 return mixLighten(color, i / 5); 42 return mixLighten(color, i / 5);
43 }); 43 });
44 44
45 - const darkens = arr.map((t, i) => { 45 + const darkens = arr.map((_t, i) => {
46 return mixDarken(color, i / 5); 46 return mixDarken(color, i / 5);
47 }); 47 });
48 48
49 - const alphaColors = arr.map((t, i) => { 49 + const alphaColors = arr.map((_t, i) => {
50 return tinycolor(color) 50 return tinycolor(color)
51 .setAlpha(i / 20) 51 .setAlpha(i / 20)
52 .toRgbString(); 52 .toRgbString();
53 }); 53 });
54 54
55 const tinycolorLightens = arr 55 const tinycolorLightens = arr
56 - .map((t, i) => { 56 + .map((_t, i) => {
57 return tinycolor(color) 57 return tinycolor(color)
58 .lighten(i * 5) 58 .lighten(i * 5)
59 .toHexString(); 59 .toHexString();
@@ -61,7 +61,7 @@ export function generateColors({ @@ -61,7 +61,7 @@ export function generateColors({
61 .filter((item) => item !== '#ffffff'); 61 .filter((item) => item !== '#ffffff');
62 62
63 const tinycolorDarkens = arr 63 const tinycolorDarkens = arr
64 - .map((t, i) => { 64 + .map((_t, i) => {
65 return tinycolor(color) 65 return tinycolor(color)
66 .darken(i * 5) 66 .darken(i * 5)
67 .toHexString(); 67 .toHexString();
src/components/SimpleMenu/src/components/menu.less
@@ -111,7 +111,6 @@ @@ -111,7 +111,6 @@
111 111
112 .@{menu-prefix-cls}-submenu-active { 112 .@{menu-prefix-cls}-submenu-active {
113 color: @primary-color !important; 113 color: @primary-color !important;
114 - // background: fade(@primary-color, 8);  
115 114
116 &-border { 115 &-border {
117 .light-border(); 116 .light-border();
@@ -120,8 +119,6 @@ @@ -120,8 +119,6 @@
120 } 119 }
121 120
122 &-dark { 121 &-dark {
123 - // background: @menu-dark;  
124 -  
125 .@{menu-prefix-cls}-submenu-active { 122 .@{menu-prefix-cls}-submenu-active {
126 color: #fff !important; 123 color: #fff !important;
127 } 124 }
@@ -137,7 +134,6 @@ @@ -137,7 +134,6 @@
137 cursor: pointer; 134 cursor: pointer;
138 outline: none; 135 outline: none;
139 align-items: center; 136 align-items: center;
140 - // transition: all @transition-time @ease-in-out;  
141 137
142 &:hover, 138 &:hover,
143 &:active { 139 &:active {
@@ -264,12 +260,7 @@ @@ -264,12 +260,7 @@
264 260
265 &:hover { 261 &:hover {
266 color: #fff; 262 color: #fff;
267 - // background: @menu-dark;  
268 } 263 }
269 -  
270 - // &-active:not(.@{menu-prefix-cls}-submenu) {  
271 - // color: @primary-color;  
272 - // }  
273 } 264 }
274 265
275 &-dark&-vertical&-collapse { 266 &-dark&-vertical&-collapse {
@@ -296,11 +287,6 @@ @@ -296,11 +287,6 @@
296 } 287 }
297 288
298 &-dark&-vertical &-submenu &-item { 289 &-dark&-vertical &-submenu &-item {
299 - // &:hover {  
300 - // color: #fff;  
301 - // background: transparent;  
302 - // }  
303 -  
304 &-active, 290 &-active,
305 &-active:hover { 291 &-active:hover {
306 color: #fff; 292 color: #fff;
@@ -313,11 +299,6 @@ @@ -313,11 +299,6 @@
313 } 299 }
314 300
315 &-dark&-vertical &-opened { 301 &-dark&-vertical &-opened {
316 - // background: @menu-dark-active-bg;  
317 - // .@{menu-prefix-cls}-submenu-title {  
318 - // background: @menu-dark;  
319 - // }  
320 -  
321 .@{menu-prefix-cls}-submenu-has-parent-submenu { 302 .@{menu-prefix-cls}-submenu-has-parent-submenu {
322 .@{menu-prefix-cls}-submenu-title { 303 .@{menu-prefix-cls}-submenu-title {
323 background: transparent; 304 background: transparent;
src/design/var/index.less
@@ -32,9 +32,6 @@ @@ -32,9 +32,6 @@
32 32
33 @page-footer-z-index: 99; 33 @page-footer-z-index: 99;
34 34
35 -// left-menu  
36 -@app-menu-item-height: 42px;  
37 -  
38 .bem(@n; @content) { 35 .bem(@n; @content) {
39 @{namespace}-@{n} { 36 @{namespace}-@{n} {
40 @content(); 37 @content();
src/directives/permission.ts
@@ -5,9 +5,7 @@ @@ -5,9 +5,7 @@
5 */ 5 */
6 import type { App, Directive, DirectiveBinding } from 'vue'; 6 import type { App, Directive, DirectiveBinding } from 'vue';
7 7
8 -import projectSetting from '/@/settings/projectSetting';  
9 import { usePermission } from '/@/hooks/web/usePermission'; 8 import { usePermission } from '/@/hooks/web/usePermission';
10 -import { PermissionModeEnum } from '/@/enums/appEnum';  
11 9
12 function isAuth(el: Element, binding: any) { 10 function isAuth(el: Element, binding: any) {
13 const { hasPermission } = usePermission(); 11 const { hasPermission } = usePermission();
@@ -19,23 +17,12 @@ function isAuth(el: Element, binding: any) { @@ -19,23 +17,12 @@ function isAuth(el: Element, binding: any) {
19 } 17 }
20 } 18 }
21 19
22 -function isBackMode() {  
23 - return projectSetting.permissionMode === PermissionModeEnum.BACK;  
24 -}  
25 -  
26 const mounted = (el: Element, binding: DirectiveBinding<any>) => { 20 const mounted = (el: Element, binding: DirectiveBinding<any>) => {
27 - if (isBackMode()) return;  
28 - isAuth(el, binding);  
29 -};  
30 -  
31 -const updated = (el: Element, binding: DirectiveBinding<any>) => {  
32 - if (!isBackMode()) return;  
33 isAuth(el, binding); 21 isAuth(el, binding);
34 }; 22 };
35 23
36 const authDirective: Directive = { 24 const authDirective: Directive = {
37 mounted, 25 mounted,
38 - updated,  
39 }; 26 };
40 27
41 export function setupPermissionDirective(app: App) { 28 export function setupPermissionDirective(app: App) {
src/layouts/default/header/index.less
@@ -175,6 +175,11 @@ @@ -175,6 +175,11 @@
175 175
176 .@{header-prefix-cls}-action { 176 .@{header-prefix-cls}-action {
177 &__item { 177 &__item {
  178 + .app-iconify {
  179 + padding: 0 10px;
  180 + font-size: 16px !important;
  181 + }
  182 +
178 &:hover { 183 &:hover {
179 background: @header-dark-bg-hover-color; 184 background: @header-dark-bg-hover-color;
180 } 185 }
src/store/modules/permission.ts
@@ -13,6 +13,7 @@ import { asyncRoutes } from &#39;/@/router/routes&#39;; @@ -13,6 +13,7 @@ import { asyncRoutes } from &#39;/@/router/routes&#39;;
13 import { filter } from '/@/utils/helper/treeHelper'; 13 import { filter } from '/@/utils/helper/treeHelper';
14 import { toRaw } from 'vue'; 14 import { toRaw } from 'vue';
15 import { getMenuListById } from '/@/api/sys/menu'; 15 import { getMenuListById } from '/@/api/sys/menu';
  16 +import { getPermCodeByUserId } from '/@/api/sys/user';
16 17
17 import { transformObjToRoute, flatRoutes } from '/@/router/helper/routeHelper'; 18 import { transformObjToRoute, flatRoutes } from '/@/router/helper/routeHelper';
18 import { transformRouteToMenu } from '/@/router/helper/menuHelper'; 19 import { transformRouteToMenu } from '/@/router/helper/menuHelper';
@@ -83,6 +84,12 @@ class Permission extends VuexModule { @@ -83,6 +84,12 @@ class Permission extends VuexModule {
83 } 84 }
84 85
85 @Action 86 @Action
  87 + async changePermissionCode(userId: string) {
  88 + const codeList = await getPermCodeByUserId({ userId });
  89 + this.commitPermCodeListState(codeList);
  90 + }
  91 +
  92 + @Action
86 async buildRoutesAction(id?: number | string): Promise<AppRouteRecordRaw[]> { 93 async buildRoutesAction(id?: number | string): Promise<AppRouteRecordRaw[]> {
87 const { t } = useI18n(); 94 const { t } = useI18n();
88 let routes: AppRouteRecordRaw[] = []; 95 let routes: AppRouteRecordRaw[] = [];
@@ -106,6 +113,10 @@ class Permission extends VuexModule { @@ -106,6 +113,10 @@ class Permission extends VuexModule {
106 }); 113 });
107 // Here to get the background routing menu logic to modify by yourself 114 // Here to get the background routing menu logic to modify by yourself
108 const paramId = id || userStore.getUserInfoState.userId; 115 const paramId = id || userStore.getUserInfoState.userId;
  116 +
  117 + // !Simulate to obtain permission codes from the background,
  118 + // this function may only need to be executed once, and the actual project can be put at the right time by itself
  119 + this.changePermissionCode('1');
109 if (!paramId) { 120 if (!paramId) {
110 throw new Error('paramId is undefined!'); 121 throw new Error('paramId is undefined!');
111 } 122 }
src/views/demo/permission/back/Btn.vue
@@ -59,7 +59,6 @@ @@ -59,7 +59,6 @@
59 import CurrentPermissionMode from '../CurrentPermissionMode.vue'; 59 import CurrentPermissionMode from '../CurrentPermissionMode.vue';
60 import { usePermission } from '/@/hooks/web/usePermission'; 60 import { usePermission } from '/@/hooks/web/usePermission';
61 import { Authority } from '/@/components/Authority'; 61 import { Authority } from '/@/components/Authority';
62 - import { getPermCodeByUserId } from '/@/api/sys/user';  
63 import { permissionStore } from '/@/store/modules/permission'; 62 import { permissionStore } from '/@/store/modules/permission';
64 import { PermissionModeEnum } from '/@/enums/appEnum'; 63 import { PermissionModeEnum } from '/@/enums/appEnum';
65 import { PageWrapper } from '/@/components/Page'; 64 import { PageWrapper } from '/@/components/Page';
@@ -69,13 +68,10 @@ @@ -69,13 +68,10 @@
69 setup() { 68 setup() {
70 const { hasPermission } = usePermission(); 69 const { hasPermission } = usePermission();
71 70
72 - // !模拟从后台获取权限编码, 该函数可能只需要执行一次,实际项目可以自行放到合适的时机  
73 - async function changePermissionCode(userId: string) {  
74 - const codeList = await getPermCodeByUserId({ userId });  
75 - permissionStore.commitPermCodeListState(codeList); 71 + function changePermissionCode(userId: string) {
  72 + permissionStore.changePermissionCode(userId);
76 } 73 }
77 - // 默认初始化为1  
78 - changePermissionCode('1'); 74 +
79 return { 75 return {
80 hasPermission, 76 hasPermission,
81 permissionStore, 77 permissionStore,