|
|
@@ -1,13 +1,40 @@
|
|
|
import { localST_UserInfo } from '../../base/storage';
|
|
|
|
|
|
function hasPermissionDirective(el, binding) {
|
|
|
- // 获取用户权限
|
|
|
- const { permissions } = JSON.parse(localST_UserInfo.getItem());
|
|
|
+ try {
|
|
|
+ // 确保 localST_UserInfo 和 getItem 方法存在
|
|
|
+ if (typeof localST_UserInfo === 'undefined' || typeof localST_UserInfo.getItem !== 'function') {
|
|
|
+ console.error('localST_UserInfo 或 getItem 方法未定义');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // 获取按钮权限
|
|
|
- const btnPermission = binding.value;
|
|
|
- if (!permissions.includes('*:*:*') && !permissions.includes(btnPermission)) {
|
|
|
- el.style.display = 'none';
|
|
|
+ // 尝试解析用户权限
|
|
|
+ const userPermissions = localST_UserInfo.getItem();
|
|
|
+ if (typeof userPermissions !== 'string') {
|
|
|
+ console.error('用户权限不是字符串格式');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const permissions = JSON.parse(userPermissions);
|
|
|
+
|
|
|
+ // 确保 permissions 是数组类型
|
|
|
+ if (!Array.isArray(permissions)) {
|
|
|
+ console.error('权限不是数组格式');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取按钮权限
|
|
|
+ const btnPermission = binding.value;
|
|
|
+ if (btnPermission === undefined) {
|
|
|
+ console.error('按钮权限未定义');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查权限
|
|
|
+ if (!permissions.includes('*:*:*') && !permissions.includes(btnPermission)) {
|
|
|
+ el.style.display = 'none';
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('hasPermissionDirective 中发生错误:', error);
|
|
|
}
|
|
|
}
|
|
|
|