Explorar el Código

fix: 增加按钮列表权限验证功能,如果关闭验证,即使没有配置按钮和列表权限也能显示

yanglzh hace 1 año
padre
commit
90ba6b12ae
Se han modificado 3 ficheros con 11 adiciones y 2 borrados
  1. 4 2
      src/App.vue
  2. 4 0
      src/utils/authDirective.ts
  3. 3 0
      src/utils/colDirective.ts

+ 4 - 2
src/App.vue

@@ -27,6 +27,8 @@ export default defineComponent({
 	created() {
 		api.sysinfo().then((res: any) => {
 			localStorage.setItem('sysinfo', JSON.stringify(res));
+			sessionStorage.setItem('btnNoAuth', res.sysButtonSwitch ? '' : '1');
+			sessionStorage.setItem('colNoAuth', res.sysColumnSwitch ? '' : '1');
 		});
 	},
 	setup() {
@@ -80,8 +82,8 @@ export default defineComponent({
 		});
 		// 页面销毁时,关闭监听布局配置/i18n监听
 		onUnmounted(() => {
-			proxy.mittBus.off('openSetingsDrawer', () => {});
-			proxy.mittBus.off('getI18nConfig', () => {});
+			proxy.mittBus.off('openSetingsDrawer', () => { });
+			proxy.mittBus.off('getI18nConfig', () => { });
 		});
 		// 监听路由的变化,设置网站标题
 		watch(

+ 4 - 0
src/utils/authDirective.ts

@@ -13,8 +13,10 @@ export function authDirective(app: App) {
 	// 单个权限验证(v-auth="xxx")
 	app.directive('auth', {
 		mounted(el, binding) {
+			if (sessionStorage.btnNoAuth) return
 			const buttons = <string[]>router.currentRoute.value.meta.buttons
 			if (buttons.includes(allPermissions)) return
+
 			// 不显示该dom
 			if (!buttons.includes(binding.value)) el.parentNode.removeChild(el)
 			// 设置为disabled
@@ -30,6 +32,7 @@ export function authDirective(app: App) {
 	// 多个权限验证,满足一个则显示(v-auths="[xxx,xxx]")
 	app.directive('auths', {
 		mounted(el, binding) {
+			if (sessionStorage.btnNoAuth) return
 			const buttons = <string[]>router.currentRoute.value.meta.buttons
 			if (buttons.includes(allPermissions)) return
 			let flag = false;
@@ -45,6 +48,7 @@ export function authDirective(app: App) {
 	// 多个权限验证,全部满足则显示(v-auth-all="[xxx,xxx]")
 	app.directive('auth-all', {
 		mounted(el, binding) {
+			if (sessionStorage.btnNoAuth) return
 			const buttons = <string[]>router.currentRoute.value.meta.buttons
 			if (buttons.includes(allPermissions)) return
 			!smallInBig(buttons, binding.value) && el.parentNode.removeChild(el)

+ 3 - 0
src/utils/colDirective.ts

@@ -13,6 +13,7 @@ export function colDirective(app: App) {
 	// 单个权限验证(v-col="xxx")
 	app.directive('col', {
 		mounted(el, binding) {
+			if (sessionStorage.colNoAuth) return
 			const columns = <string[]>router.currentRoute.value.meta.columns
 			if (columns.includes(allPermissions)) return
 			if (!columns.includes(binding.value)) el.parentNode.removeChild(el)
@@ -21,6 +22,7 @@ export function colDirective(app: App) {
 	// 多个权限验证,满足一个则显示(v-cols="[xxx,xxx]")
 	app.directive('cols', {
 		mounted(el, binding) {
+			if (sessionStorage.colNoAuth) return
 			const columns = <string[]>router.currentRoute.value.meta.columns
 			if (columns.includes(allPermissions)) return
 			let flag = false;
@@ -35,6 +37,7 @@ export function colDirective(app: App) {
 	// 多个权限验证,全部满足则显示(v-col-all="[xxx,xxx]")
 	app.directive('col-all', {
 		mounted(el, binding) {
+			if (sessionStorage.colNoAuth) return
 			const columns = <string[]>router.currentRoute.value.meta.columns
 			if (columns.includes(allPermissions)) return
 			!smallInBig(columns, binding.value) && el.parentNode.removeChild(el)