mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 18:49:06 +08:00 
			
		
		
		
	refactor: vue3 axios api ...
This commit is contained in:
		
							
								
								
									
										27
									
								
								yudao-ui-admin-vue3/src/directives/permission/hasPermi.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								yudao-ui-admin-vue3/src/directives/permission/hasPermi.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| import type { App } from 'vue' | ||||
| import { useCache } from '@/hooks/web/useCache' | ||||
| import { useI18n } from '@/hooks/web/useI18n' | ||||
| const { t } = useI18n() // 国际化 | ||||
|  | ||||
| export function hasPermi(app: App<Element>) { | ||||
|   app.directive('hasPermi', (el, binding) => { | ||||
|     const { wsCache } = useCache() | ||||
|     const { value } = binding | ||||
|     const all_permission = '*:*:*' | ||||
|     const permissions = wsCache.get('user').permissions | ||||
|  | ||||
|     if (value && value instanceof Array && value.length > 0) { | ||||
|       const permissionFlag = value | ||||
|  | ||||
|       const hasPermissions = permissions.some((permission: string) => { | ||||
|         return all_permission === permission || permissionFlag.includes(permission) | ||||
|       }) | ||||
|  | ||||
|       if (!hasPermissions) { | ||||
|         el.parentNode && el.parentNode.removeChild(el) | ||||
|       } | ||||
|     } else { | ||||
|       throw new Error(t('permission.hasPermission')) | ||||
|     } | ||||
|   }) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 xingyu
					xingyu