Commit 4488b4c2031c3a088dbb36e47f2783e61bd116cb

Authored by xp.Huang
2 parents 83e269fe bc2a43c9

Merge branch 'ww' into 'main_dev'

fix: 修复bug

See merge request yunteng/thingskit-front!560
... ... @@ -30,6 +30,38 @@ export const getMenuList = (args?: number) => {
30 30 } catch (e) {}
31 31 };
32 32
  33 +/**
  34 + * @description 获取自身的权限
  35 + * @param args
  36 + * @returns
  37 + */
  38 +export const getMeMenuList = (args?: number) => {
  39 + try {
  40 + return defHttp.get<getMenuListResultModel>({
  41 + url: Api.GetMenuList,
  42 + params: {
  43 + needButton: args == 1 ? false : null,
  44 + },
  45 + });
  46 + } catch (e) {}
  47 +};
  48 +
  49 +/**
  50 + * @description 获取超级管理员菜单
  51 + * @param args
  52 + * @returns
  53 + */
  54 +export const getAdminMenuList = (args?: number) => {
  55 + try {
  56 + return defHttp.get<getMenuListResultModel>({
  57 + url: Api.SysAdminMenuList,
  58 + params: {
  59 + needButton: args == 1 ? false : null,
  60 + },
  61 + });
  62 + } catch (e) {}
  63 +};
  64 +
33 65 export const delMenu = (menuIds: string[]) => {
34 66 const url = Api.BaseMenuUrl;
35 67 return defHttp.delete({ url: url, data: menuIds });
... ...
... ... @@ -31,6 +31,6 @@
31 31 <Icon
32 32 v-bind="getBindProps"
33 33 class="justify-center items-center"
34   - :class="getHasPermission ? '' : '!cursor-not-allowed !text-gray-200'"
  34 + :class="getHasPermission ? '' : '!cursor-not-allowed !text-gray-200 !dark:text-gray-700'"
35 35 />
36 36 </template>
... ...
... ... @@ -9,6 +9,8 @@ export enum DictEnum {
9 9 DEVICE_TYPE = 'device_type',
10 10 // 平台管理员启用的权限
11 11 ENABLED_PLATFORM_ADMIN_AUTH = 'enabled_platform_admin_auth',
  12 + // 平台管理员禁用的权限
  13 + DISABLED_PLATFORM_ADMIN_AUTH = 'disabled_platform_admin_auth',
12 14 // 系统管理员启用的权限
13 15 ENABLED_SYSADMIN_AUTH = 'enabled_sysadmin_auth',
14 16 // 租户禁用的权限
... ...
  1 +import { computed, unref } from 'vue';
  2 +import { useUserStore } from '/@/store/modules/user';
  3 +import { RoleEnum } from '/@/enums/roleEnum';
  4 +
  5 +export const useRole = () => {
  6 + const userStore = useUserStore();
  7 +
  8 + const getRole = computed(() => {
  9 + return userStore.userInfo?.roles![0] as RoleEnum;
  10 + });
  11 +
  12 + const isPlatformAdmin = computed(() => {
  13 + return unref(getRole) === RoleEnum.PLATFORM_ADMIN;
  14 + });
  15 +
  16 + const isCustomerUser = computed(() => {
  17 + return unref(getRole) === RoleEnum.CUSTOMER_USER;
  18 + });
  19 +
  20 + const isTenantAdmin = computed(() => {
  21 + return unref(getRole) === RoleEnum.TENANT_ADMIN;
  22 + });
  23 +
  24 + const isSysadmin = computed(() => {
  25 + return unref(getRole) === RoleEnum.SYS_ADMIN;
  26 + });
  27 +
  28 + return { getRole, isPlatformAdmin, isCustomerUser, isTenantAdmin, isSysadmin };
  29 +};
... ...
... ... @@ -29,11 +29,14 @@
29 29 import { useModal } from '/@/components/Modal';
30 30 import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
31 31 import { ViewType } from '../../visual/board/config/panelDetail';
  32 + import { useRole } from '/@/hooks/business/useRole';
32 33
33 34 const listColumn = ref(5);
34 35
35 36 const { createMessage } = useMessage();
36 37
  38 + const { isCustomerUser } = useRole();
  39 +
37 40 const organizationId = ref<Nullable<number>>(null);
38 41
39 42 const pagination = reactive<PaginationProps>({
... ... @@ -219,7 +222,7 @@
219 222 >
220 223 <template #header>
221 224 <div class="flex gap-3 justify-end">
222   - <Authority :value="ConfigurationPermission.CREATE">
  225 + <Authority v-if="!isCustomerUser" :value="ConfigurationPermission.CREATE">
223 226 <Button type="primary" @click="handleCreateOrUpdate()">新增组态</Button>
224 227 </Authority>
225 228 <CardLayoutButton v-model:value="listColumn" @change="handleCardLayoutChange" />
... ... @@ -265,7 +268,7 @@
265 268 @click="handlePreview(item)"
266 269 />
267 270 </Tooltip>
268   - <Tooltip title="设计">
  271 + <Tooltip v-if="!isCustomerUser" title="设计">
269 272 <AuthIcon
270 273 :auth="ConfigurationPermission.DESIGN"
271 274 class="!text-lg"
... ... @@ -283,6 +286,7 @@
283 286 />
284 287 </Tooltip>
285 288 <AuthDropDown
  289 + v-if="!isCustomerUser"
286 290 :dropMenuList="[
287 291 {
288 292 text: '分享',
... ...
... ... @@ -32,6 +32,7 @@
32 32 import { ViewType } from '../visual/board/config/panelDetail';
33 33 import { useUserStore } from '/@/store/modules/user';
34 34 import { RoleEnum } from '/@/enums/roleEnum';
  35 + import { useRole } from '/@/hooks/business/useRole';
35 36
36 37 const listColumn = ref(5);
37 38
... ... @@ -51,6 +52,7 @@
51 52 });
52 53
53 54 const loading = ref(false);
  55 + const { isCustomerUser } = useRole();
54 56
55 57 const dataSource = ref<BigScreenCenterItemsModel[]>([]);
56 58
... ... @@ -218,8 +220,8 @@
218 220 >
219 221 <template #header>
220 222 <div class="flex gap-3 justify-end">
221   - <Authority :value="ConfigurationPermission.CREATE">
222   - <Button type="primary" @click="handleCreateOrUpdate()">新增大屏</Button>
  223 + <Authority v-if="!isCustomerUser" :value="ConfigurationPermission.CREATE">
  224 + <Button type="primary" @click="handleCreateOrUpdate()"> 新增大屏 </Button>
223 225 </Authority>
224 226 <Authority v-if="hasPublicInterfacePermission" :value="ConfigurationPermission.CREATE">
225 227 <Button type="primary" @click="handleCreateOrUpdatePublicApi()">公共接口管理</Button>
... ... @@ -281,7 +283,7 @@
281 283 @click="handlePreview(item)"
282 284 />
283 285 </Tooltip>
284   - <Tooltip title="设计">
  286 + <Tooltip v-if="!isCustomerUser" title="设计">
285 287 <AuthIcon
286 288 :disabled="item.state === 1"
287 289 icon="ant-design:edit-outlined"
... ... @@ -298,6 +300,7 @@
298 300 />
299 301 </Tooltip>
300 302 <AuthDropDown
  303 + v-if="!isCustomerUser"
301 304 :dropMenuList="[
302 305 {
303 306 text: '分享',
... ...
... ... @@ -35,14 +35,15 @@
35 35 import { useMessage } from '/@/hooks/web/useMessage';
36 36 const { t } = useI18n(); //加载国际化
37 37 // 加载菜单数据
38   - import { getMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu';
  38 + import { getMeMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu';
39 39 import { useI18n } from '/@/hooks/web/useI18n';
40 40 import { MenuRecord } from '/@/api/sys/model/menuModel';
41 41 import { saveOrUpdateRoleInfoWithMenu } from '/@/api/system/system';
42 42 import { findDictItemByCode } from '/@/api/system/dict';
43 43 import { RoleEnum } from '/@/enums/roleEnum';
44 44 import { Spin } from 'ant-design-vue';
45   - import { useUserStore } from '/@/store/modules/user';
  45 + import { useRole } from '/@/hooks/business/useRole';
  46 + import { RoleListItem } from '/@/api/system/model/systemModel';
46 47
47 48 type TreeData = MenuRecord & TreeItem;
48 49
... ... @@ -76,56 +77,72 @@
76 77 });
77 78 };
78 79
79   - const userStore = useUserStore();
80   - const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
81   - allCheckedKeys.value = [];
82   - resetFields();
83   - roleId.value = '';
84   - // 在打开弹窗时清除所有选择的菜单
85   - treeRef.value && treeRef.value?.setCheckedKeys([]);
86   - isUpdate.value = data.isUpdate;
87   - let roleType = (userStore.getUserInfo.roles![0] as RoleEnum) || RoleEnum.SYS_ADMIN;
88   - // 租户管理员创建角色时 菜单分配为客户菜单
89   - if (roleType === RoleEnum.TENANT_ADMIN) {
90   - roleType = RoleEnum.CUSTOMER_USER;
91   - }
92   - try {
93   - spinning.value = true;
94   - // 需要在setFieldsValue之前先填充treeData,否则Tree组件可能会报key not exist警告
  80 + const { isTenantAdmin, isSysadmin, getRole } = useRole();
  81 + const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(
  82 + async (data: { isUpdate: boolean; record: RoleListItem }) => {
  83 + allCheckedKeys.value = [];
  84 + resetFields();
  85 + roleId.value = '';
  86 + // 在打开弹窗时清除所有选择的菜单
  87 + treeRef.value && treeRef.value?.setCheckedKeys([]);
  88 + isUpdate.value = data.isUpdate;
  89 + let roleType = unref(getRole) || RoleEnum.SYS_ADMIN;
  90 +
  91 + // 租户管理员创建角色时 菜单分配为客户菜单
  92 + if (unref(isTenantAdmin)) {
  93 + roleType = RoleEnum.CUSTOMER_USER;
  94 + }
  95 +
  96 + try {
  97 + spinning.value = true;
  98 + // 需要在setFieldsValue之前先填充treeData,否则Tree组件可能会报key not exist警告
95 99
96   - if (!unref(treeData).length) {
  100 + // if (!unref(treeData).length) {
97 101 // 获取全部的菜单
98   - const menuListModel = await getMenuList();
  102 + const menuListModel = await getMeMenuList();
99 103 treeData.value = transformName(menuListModel as unknown as TreeData[]);
100   - }
  104 + // }
101 105
102   - const keys = await getPermissionByRole(roleType);
103   - const { keyType } = RoleMenuDictEnum[roleType];
104   - treeData.value = filterPermissionTreeData(
105   - unref(treeData) as unknown as TreeData[],
106   - keys,
107   - keyType
108   - );
  106 + const keys = await getPermissionByRole(roleType);
  107 + const { keyType } = RoleMenuDictEnum[roleType];
  108 + treeData.value = filterPermissionTreeData(
  109 + unref(treeData) as unknown as TreeData[],
  110 + keys,
  111 + keyType
  112 + );
109 113
110   - // 更新
111   - if (unref(isUpdate)) {
112   - checked.value = [];
113   - roleId.value = data.record.id;
  114 + // 如果编辑的是超级管理员 则不再过滤平台管理员禁用的权限
  115 + // 如果是超级管理员创建角色 创建角色属于平台管理员 因此过滤平台管理员禁用的权限
  116 + if (data?.record?.roleType !== RoleEnum.SYS_ADMIN && unref(isSysadmin)) {
  117 + const keys = await getPermissionByRole(RoleEnum.PLATFORM_ADMIN);
  118 + const { keyType } = RoleMenuDictEnum[RoleEnum.PLATFORM_ADMIN];
  119 + treeData.value = filterPermissionTreeData(
  120 + unref(treeData) as unknown as TreeData[],
  121 + keys,
  122 + keyType
  123 + );
  124 + }
  125 +
  126 + // 更新
  127 + if (unref(isUpdate)) {
  128 + checked.value = [];
  129 + roleId.value = data.record.id;
114 130
115   - //通过角色id去获取角色对应的菜单的ids
116   - allCheckedKeys.value = roleMenus.value = await getMenusIdsByRoleId(data.record.id);
117   - excludeHalfCheckedKeys(unref(treeData));
118   - await nextTick();
119   - treeRef.value.setCheckedKeys(roleMenus.value);
120   - setFieldsValue(data.record);
121   - } else {
  131 + //通过角色id去获取角色对应的菜单的ids
  132 + allCheckedKeys.value = roleMenus.value = await getMenusIdsByRoleId(data.record.id);
  133 + excludeHalfCheckedKeys(unref(treeData));
  134 + await nextTick();
  135 + treeRef.value.setCheckedKeys(roleMenus.value);
  136 + setFieldsValue(data.record);
  137 + } else {
  138 + }
  139 + } catch (error) {
  140 + throw error;
  141 + } finally {
  142 + spinning.value = false;
122 143 }
123   - } catch (error) {
124   - throw error;
125   - } finally {
126   - spinning.value = false;
127 144 }
128   - });
  145 + );
129 146
130 147 const getTitle = computed(() => (!unref(isUpdate) ? '新增角色' : '编辑角色'));
131 148
... ...
... ... @@ -10,8 +10,8 @@ export enum KeysTypeEnum {
10 10
11 11 export const RoleMenuDictEnum: Recordable<{ key: string; keyType: KeysTypeEnum }> = {
12 12 [RoleEnum.PLATFORM_ADMIN]: {
13   - key: DictEnum.ENABLED_PLATFORM_ADMIN_AUTH,
14   - keyType: KeysTypeEnum.ENABLED,
  13 + key: DictEnum.DISABLED_PLATFORM_ADMIN_AUTH,
  14 + keyType: KeysTypeEnum.DISABLED,
15 15 },
16 16 [RoleEnum.SYS_ADMIN]: { key: DictEnum.ENABLED_SYSADMIN_AUTH, keyType: KeysTypeEnum.ENABLED },
17 17 [RoleEnum.TENANT_ADMIN]: { key: DictEnum.DISABLED_TENANT_AUTH, keyType: KeysTypeEnum.DISABLED },
... ...
... ... @@ -34,7 +34,7 @@
34 34 import { BasicTree, TreeItem } from '/@/components/Tree';
35 35 const { t } = useI18n(); //加载国际化
36 36 // 加载菜单数据
37   - import { getMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu';
  37 + import { getAdminMenuList, getMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu';
38 38 import { useI18n } from '/@/hooks/web/useI18n';
39 39 import { MenuRecord } from '/@/api/sys/model/menuModel';
40 40 import { saveOrUpdateRoleInfoWithMenu } from '/@/api/system/system';
... ... @@ -43,7 +43,7 @@
43 43 import { KeysTypeEnum, RoleMenuDictEnum } from '../../system/role/role.data';
44 44 import { findDictItemByCode } from '/@/api/system/dict';
45 45 import { Spin } from 'ant-design-vue';
46   - import { useUserStore } from '/@/store/modules/user';
  46 + import { useRole } from '/@/hooks/business/useRole';
47 47
48 48 type TreeData = MenuRecord & TreeItem;
49 49
... ... @@ -77,7 +77,7 @@
77 77 });
78 78 };
79 79
80   - const userStore = useUserStore();
  80 + const { isPlatformAdmin } = useRole();
81 81 const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
82 82 allCheckedKeys.value = [];
83 83 resetFields();
... ... @@ -85,18 +85,16 @@
85 85 // 在打开弹窗时清除所有选择的菜单
86 86 treeRef.value && treeRef.value?.setCheckedKeys([]);
87 87 isUpdate.value = data.isUpdate;
88   - let roleType = (userStore.getUserInfo.roles![0] as RoleEnum) || RoleEnum.SYS_ADMIN;
89   - // 平台管理员创建角色时 菜单分配为租户管理员可分配的菜单
90   - if (roleType === RoleEnum.PLATFORM_ADMIN) {
91   - roleType = RoleEnum.TENANT_ADMIN;
92   - }
  88 + const roleType = RoleEnum.TENANT_ADMIN;
93 89 try {
94 90 spinning.value = true;
95 91 // 需要在setFieldsValue之前先填充treeData,否则Tree组件可能会报key not exist警告
96 92
97 93 if (!unref(treeData).length) {
98 94 // 获取全部的菜单
99   - const menuListModel = await getMenuList();
  95 + const menuListModel = unref(isPlatformAdmin)
  96 + ? await getAdminMenuList()
  97 + : await getMenuList();
100 98 treeData.value = transformName(menuListModel as unknown as TreeData[]);
101 99 }
102 100 const keys = await getPermissionByRole(roleType);
... ...
... ... @@ -12,6 +12,7 @@
12 12 import { usePermission } from '/@/hooks/web/usePermission';
13 13 import { DataSource } from '/@/api/dataBoard/model';
14 14 import { useRoute } from 'vue-router';
  15 + import { useRole } from '/@/hooks/business/useRole';
15 16
16 17 const emit = defineEmits(['action']);
17 18 const props = defineProps<{
... ... @@ -19,6 +20,7 @@
19 20 record: DataSource[];
20 21 panelName?: string;
21 22 }>();
  23 + const { isCustomerUser } = useRole();
22 24 const { hasPermission } = usePermission();
23 25 const dropMenuList = computed<DropMenu[]>(() => {
24 26 const basicMenu: DropMenu[] = [];
... ... @@ -82,7 +84,7 @@
82 84 <div class="flex items-center gap-5">
83 85 <slot name="moreAction"></slot>
84 86 <Dropdown
85   - v-if="dropMenuList.length"
  87 + v-if="!isCustomerUser && dropMenuList.length"
86 88 :drop-menu-list="dropMenuList"
87 89 :trigger="['click']"
88 90 @menu-event="handleMenuEvent"
... ...
... ... @@ -337,7 +337,7 @@
337 337 v-for="item in dataSource"
338 338 :data-id="item.id"
339 339 :key="item.id"
340   - class="flex bg-neutral-100 dark:text-gray-300 dark:bg-dark-700"
  340 + class="flex bg-light-50 dark:text-gray-300 dark:bg-dark-700"
341 341 >
342 342 <div class="w-24 text-right flex justify-end" style="flex: 0 0 96px"> 选择设备 </div>
343 343 <div class="pl-2 flex-auto">
... ...
... ... @@ -47,6 +47,7 @@
47 47 import { useScript } from '/@/hooks/web/useScript';
48 48 import { BAI_DU_MAP_GL_LIB, BAI_DU_MAP_TRACK_ANIMATION } from '/@/utils/fnUtils';
49 49 import { useAppStore } from '/@/store/modules/app';
  50 + import { useRole } from '/@/hooks/business/useRole';
50 51
51 52 const userStore = useAppStore();
52 53
... ... @@ -60,6 +61,7 @@
60 61
61 62 const ROUTER = useRouter();
62 63
  64 + const { isCustomerUser } = useRole();
63 65 const { toPromise: injectBaiDuMapLib } = useScript({ src: BAI_DU_MAP_GL_LIB });
64 66 const { toPromise: injectBaiDuMapTrackAniMationLib } = useScript({
65 67 src: BAI_DU_MAP_TRACK_ANIMATION,
... ... @@ -400,7 +402,11 @@
400 402 </template>
401 403 <template #extra>
402 404 <Authority :value="VisualComponentPermission.CREATE">
403   - <Button v-if="!getIsSharePage" type="primary" @click="handleOpenCreatePanel">
  405 + <Button
  406 + v-if="!getIsSharePage && !isCustomerUser"
  407 + type="primary"
  408 + @click="handleOpenCreatePanel"
  409 + >
404 410 创建组件
405 411 </Button>
406 412 </Authority>
... ... @@ -456,7 +462,7 @@
456 462 @action="handleMoreAction"
457 463 >
458 464 <template #moreAction>
459   - <Tooltip title="趋势">
  465 + <Tooltip v-if="!isCustomerUser" title="趋势">
460 466 <img
461 467 :src="trendIcon"
462 468 v-if="!getIsSharePage && hasHistoryTrend(item)"
... ...
... ... @@ -24,6 +24,7 @@
24 24 import { ShareModal } from '/@/views/common/ShareModal';
25 25 import { ModalParamsType } from '/#/utils';
26 26 import { DataActionModeEnum } from '/@/enums/toolEnum';
  27 + import { useRole } from '/@/hooks/business/useRole';
27 28
28 29 const ListItem = List.Item;
29 30 const router = useRouter();
... ... @@ -92,6 +93,7 @@
92 93 unref(clipboardRef) ? createMessage.success('复制成功') : createMessage.error('未找到分享链接');
93 94 };
94 95
  96 + const { isCustomerUser } = useRole();
95 97 const { hasPermission } = usePermission();
96 98 const dropMenuList = computed<DropMenu[]>(() => {
97 99 const hasUpdatePermission = hasPermission(VisualBoardPermission.UPDATE);
... ... @@ -213,7 +215,9 @@
213 215 <div class="flex items-center mb-3 bg-light-100 h-78px dark:text-gray-300 dark:bg-dark-900">
214 216 <div class="text-lg ml-30px mr-9px font-bold">自定义看板</div>
215 217 <Authority value="api:yt:data_board:add:post">
216   - <Button type="primary" @click="handleOpenDetailModal">创建看板</Button>
  218 + <Button v-if="!isCustomerUser" type="primary" @click="handleOpenDetailModal"
  219 + >创建看板</Button
  220 + >
217 221 </Authority>
218 222 </div>
219 223 <div class="bg-light-100 mb-6 w-full p-3 search-form dark:text-gray-300 dark:bg-dark-900">
... ... @@ -235,7 +239,7 @@
235 239 </template>
236 240 <template #extra>
237 241 <Dropdown
238   - v-if="dropMenuList.length"
  242 + v-if="!isCustomerUser && dropMenuList.length"
239 243 :trigger="['click']"
240 244 @menu-event="(event) => handleMenuEvent(event, item)"
241 245 :drop-menu-list="dropMenuList"
... ...