Commit d971016c0434f0f17c497dc46e28f4e7ec9e78fa
Merge branch 'perf/main_dev' into 'main_dev'
Perf/main dev See merge request yunteng/thingskit-scada!161
Showing
12 changed files
with
122 additions
and
3 deletions
... | ... | @@ -4289,6 +4289,7 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) { |
4289 | 4289 | // TODO Thingskit 从服务器请求 load file |
4290 | 4290 | async function getRemoteData() { |
4291 | 4291 | const { doGetConfigurationContent } = useContentData() |
4292 | + const { getAuthInfo } = useAuth?.() || {} | |
4292 | 4293 | |
4293 | 4294 | const platformInfo = getPlatformInfo() |
4294 | 4295 | document.getElementById('first-text-animation-text').querySelector('text').innerHTML = platformInfo?.name || window.PROJECT_ENV?.shortName |
... | ... | @@ -4313,10 +4314,27 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) { |
4313 | 4314 | */ |
4314 | 4315 | |
4315 | 4316 | /** |
4317 | + * @typedef PermissionInfo | |
4318 | + * @property {string[]} permissions | |
4319 | + * @property {string} hasPreview | |
4320 | + * @property {string} platform | |
4321 | + * @property {ConfigurationContentListItemType[]} configurationContentList | |
4322 | + */ | |
4323 | + | |
4324 | + /** | |
4316 | 4325 | * @type {ConfigurationContentType} |
4317 | 4326 | */ |
4318 | 4327 | const result = await doGetConfigurationContent() |
4319 | 4328 | const { configurationContentList, configurationId, configurationName, platform, isTemplate } = result |
4329 | + | |
4330 | + | |
4331 | + /** | |
4332 | + * @type {PermissionInfo} | |
4333 | + */ | |
4334 | + const permissionInfo = await getAuthInfo?.() || {} | |
4335 | + | |
4336 | + this.permissionInfo = permissionInfo | |
4337 | + | |
4320 | 4338 | const firstContent = configurationContentList?.[0] |
4321 | 4339 | this.configurationContentId = firstContent?.id |
4322 | 4340 | this.isTemplateConfiguration = !!isTemplate |
... | ... | @@ -5137,6 +5155,9 @@ App.prototype.addPreviewButton = function () { |
5137 | 5155 | switchLightboxMode?.() |
5138 | 5156 | })) |
5139 | 5157 | |
5158 | + if (this.permissionInfo && !this.permissionInfo.hasPreviewAuth) this.previewButton.style.display = 'none' | |
5159 | + | |
5160 | + | |
5140 | 5161 | this.buttonContainer.appendChild(this.previewButton) |
5141 | 5162 | } |
5142 | 5163 | } |
... | ... | @@ -5375,6 +5396,8 @@ App.prototype.addSaveButton = function () { |
5375 | 5396 | .funct(); |
5376 | 5397 | })) |
5377 | 5398 | |
5399 | + if (this.permissionInfo && !this.permissionInfo.hasDesignAuth) this.saveButton.style.display = 'none' | |
5400 | + | |
5378 | 5401 | this.buttonContainer.appendChild(this.saveButton) |
5379 | 5402 | } |
5380 | 5403 | } | ... | ... |
... | ... | @@ -343,7 +343,7 @@ Format.prototype.immediateRefresh = function () { |
343 | 343 | var cells = ss.cells || [] |
344 | 344 | var currentCell = cells[0] |
345 | 345 | var { COMPONENT_KEY } = window.CellAttributeKeyEnum |
346 | - var hasDataSourceBindPanel = !!(cells.length === 1 && currentCell && currentCell.getValue() && currentCell.getAttribute(COMPONENT_KEY)) | |
346 | + var hasDataSourceBindPanel = !!(cells.length === 1 && currentCell && currentCell.getValue() && currentCell.getAttribute(COMPONENT_KEY)) && this.editorUi?.permissionInfo?.hasDesignAuth !== false | |
347 | 347 | |
348 | 348 | label.style.backgroundColor = Format.inactiveTabBackgroundColor; |
349 | 349 | label.style.borderLeftWidth = '1px'; | ... | ... |
... | ... | @@ -9,6 +9,7 @@ enum Api { |
9 | 9 | REFRESH_TOKEN = '/auth/token', |
10 | 10 | GET_DICT = '/dict_item/find', |
11 | 11 | UPLOAD_FILE = '/oss/upload', |
12 | + GET_PERMISSIONS = '/role/me/permissions', | |
12 | 13 | } |
13 | 14 | export const getPlatformInfo = () => { |
14 | 15 | return defHttp.get<PlatformInfo>({ |
... | ... | @@ -44,3 +45,9 @@ export function doUploadFile(file: FormData) { |
44 | 45 | }, |
45 | 46 | }) |
46 | 47 | } |
48 | + | |
49 | +export function getCurrentRolePermission() { | |
50 | + return defHttp.get<string[]>({ | |
51 | + url: Api.GET_PERMISSIONS, | |
52 | + }) | |
53 | +} | ... | ... |
... | ... | @@ -4,6 +4,9 @@ import { useParseParams } from '@/core/LoadData' |
4 | 4 | import type { MxCell } from '@/fitCore/types' |
5 | 5 | import type { BasicNodeBindType, NodeDataActJsonType, NodeDataDataSourceJsonType, NodeDataEventJsonType, NodeDataType, SaveNodeDataParamsType } from '@/api/node/model' |
6 | 6 | import { CellAttributeKeyEnum } from '@/enums/cellAttributeEnum' |
7 | +import { useContentDataStoreWithOut } from '@/store/modules/contentData' | |
8 | +import { useMessage } from '@/hooks/web/useMessage' | |
9 | +import { MessageEnum } from '@/enums/messageEnum' | |
7 | 10 | |
8 | 11 | interface UseNodeDataParamsType { |
9 | 12 | cell: MxCell |
... | ... | @@ -29,8 +32,11 @@ function removeCellSourceAttribute(cell: MxCell) { |
29 | 32 | } |
30 | 33 | |
31 | 34 | export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) { |
35 | + const { createMessage } = useMessage() | |
36 | + | |
32 | 37 | const nodeData = ref<NodeDataType>() |
33 | 38 | |
39 | + const contentDataStore = useContentDataStoreWithOut() | |
34 | 40 | // const contentId = window.DrawApp.configurationContentId! |
35 | 41 | const { configurationId } = useParseParams() |
36 | 42 | |
... | ... | @@ -65,6 +71,11 @@ export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) { |
65 | 71 | } |
66 | 72 | |
67 | 73 | const saveNodeAllData = async (data: Partial<SaveNodeDataParamsType>) => { |
74 | + if (!contentDataStore.hasDesignAuth) { | |
75 | + createMessage.error(MessageEnum.NO_AUTH) | |
76 | + throw new Error(MessageEnum.NO_AUTH) | |
77 | + } | |
78 | + | |
68 | 79 | const result = await doSaveNodeAllData(Object.assign(data, basicNodeBindData(ActionType.SAVE))) |
69 | 80 | removeCellSourceAttribute(cell) |
70 | 81 | nodeData.value = result || getDefaultNodeData() |
... | ... | @@ -72,6 +83,11 @@ export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) { |
72 | 83 | } |
73 | 84 | |
74 | 85 | const saveNodeDataSourceData = async (data: NodeDataDataSourceJsonType) => { |
86 | + if (!contentDataStore.hasDesignAuth) { | |
87 | + createMessage.error(MessageEnum.NO_AUTH) | |
88 | + throw new Error(MessageEnum.NO_AUTH) | |
89 | + } | |
90 | + | |
75 | 91 | const result = await doSaveNodeDataSource({ ...basicNodeBindData(ActionType.SAVE), data }) |
76 | 92 | removeCellSourceAttribute(cell) |
77 | 93 | if (unref(nodeData)?.dataSourceJson) |
... | ... | @@ -81,12 +97,22 @@ export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) { |
81 | 97 | } |
82 | 98 | |
83 | 99 | const saveNodeEventData = async (data: NodeDataEventJsonType) => { |
100 | + if (!contentDataStore.hasDesignAuth) { | |
101 | + createMessage.error(MessageEnum.NO_AUTH) | |
102 | + throw new Error(MessageEnum.NO_AUTH) | |
103 | + } | |
104 | + | |
84 | 105 | const result = await doSaveNodeEvent({ ...basicNodeBindData(ActionType.SAVE), data }) |
85 | 106 | removeCellSourceAttribute(cell) |
86 | 107 | return result |
87 | 108 | } |
88 | 109 | |
89 | 110 | const saveNodeActData = async (data: NodeDataActJsonType) => { |
111 | + if (!contentDataStore.hasDesignAuth) { | |
112 | + createMessage.error(MessageEnum.NO_AUTH) | |
113 | + throw new Error(MessageEnum.NO_AUTH) | |
114 | + } | |
115 | + | |
90 | 116 | const result = await doSaveNodeAct({ ...basicNodeBindData(ActionType.SAVE), data }) |
91 | 117 | removeCellSourceAttribute(cell) |
92 | 118 | return result | ... | ... |
... | ... | @@ -49,8 +49,8 @@ const [register, { getFieldsValue, validate, setFieldsValue }] = useForm({ |
49 | 49 | return { |
50 | 50 | api: getVideoList, |
51 | 51 | params: formModel[ContentDataFieldsEnum.ORG_ID], |
52 | - valueField: 'id', | |
53 | - labelField: 'name', | |
52 | + | |
53 | + fieldNames: { label: 'name', value: 'id' }, | |
54 | 54 | resultField: 'items', |
55 | 55 | onSelect(value: string, option: any) { |
56 | 56 | formModel[ContentDataFieldsEnum.ACCESS_MODE] = value && option ? option.accessMode : null | ... | ... |
... | ... | @@ -2,3 +2,4 @@ export { usePlatform, getPlatformInfo, setPlatformInfo } from './module/usePlatf |
2 | 2 | export { useContentData } from './module/useContentData' |
3 | 3 | export { useParseParams } from './module/useParseParams' |
4 | 4 | export { useLightboxModeService } from './module/useLightboxModeService' |
5 | +export { useAuth } from './module/useAuth' | ... | ... |
src/core/LoadData/module/useAuth.ts
0 → 100644
1 | +import { getCurrentRolePermission } from '@/api/sys' | |
2 | +import { useContentDataStoreWithOut } from '@/store/modules/contentData' | |
3 | +import { isShareMode } from '@/utils/env' | |
4 | + | |
5 | +export function useAuth() { | |
6 | + const contentDataStore = useContentDataStoreWithOut() | |
7 | + const getAuthInfo = async () => { | |
8 | + const result = { permissions: [] as string[], hasPreview: true, hasDesign: true } | |
9 | + if (isShareMode()) return result | |
10 | + | |
11 | + const permissions = await getCurrentRolePermission() | |
12 | + result.permissions = permissions | |
13 | + const ret = contentDataStore.setPermissions(permissions) | |
14 | + return { | |
15 | + permissions, | |
16 | + ...ret, | |
17 | + } | |
18 | + } | |
19 | + | |
20 | + return { | |
21 | + getAuthInfo, | |
22 | + } | |
23 | +} | |
24 | + | |
25 | +window.useAuth = useAuth | ... | ... |
... | ... | @@ -6,11 +6,14 @@ import { ShareLoginModal } from '@/core/Share' |
6 | 6 | import { PageModeEnum } from '@/enums/modeEnum' |
7 | 7 | import { useContentDataStoreWithOut } from '@/store/modules/contentData' |
8 | 8 | import { useUserStoreWithOut } from '@/store/modules/user' |
9 | +import { useMessage } from '@/hooks/web/useMessage' | |
10 | +import { MessageEnum } from '@/enums/messageEnum' | |
9 | 11 | |
10 | 12 | export function useContentData() { |
11 | 13 | const contentDataStore = useContentDataStoreWithOut() |
12 | 14 | const { mode, publicId, configurationId } = useParseParams() |
13 | 15 | const userStore = useUserStoreWithOut() |
16 | + const { createMessage } = useMessage() | |
14 | 17 | |
15 | 18 | const shareModeBootstrap = async () => { |
16 | 19 | if (!publicId) return |
... | ... | @@ -46,6 +49,10 @@ export function useContentData() { |
46 | 49 | } |
47 | 50 | |
48 | 51 | const doSaveConfigurationContent = async (params: ConfigurationContentType) => { |
52 | + if (!contentDataStore.hasDesignAuth) { | |
53 | + createMessage.error(MessageEnum.NO_AUTH) | |
54 | + return | |
55 | + } | |
49 | 56 | return saveData(params) |
50 | 57 | } |
51 | 58 | ... | ... |
src/enums/authEnum.ts
0 → 100644
1 | +export enum ConfigurationAuthEnum { | |
2 | + DESIGN = 'api:yt:configuration:center:get_configuration_info:design', | |
3 | + PREVIEW = 'api:yt:configuration:center:get_configuration_info:preview', | |
4 | +} | |
5 | + | |
6 | +export enum ConfigurationTemplateAuthEnum { | |
7 | + DESIGN = 'api:yt:configuration:template:center:get_configuration_info:design', | |
8 | + PREVIEW = 'api:yt:configuration:template:center:get_configuration_info:preview', | |
9 | +} | ... | ... |
src/enums/messageEnum.ts
0 → 100644
... | ... | @@ -4,6 +4,8 @@ import { store } from '..' |
4 | 4 | import type { NodeDataType } from '@/api/node/model' |
5 | 5 | import type { ProductAndDevice } from '@/api/content/model' |
6 | 6 | import type { CreateComponentType } from '@/core/Library/types' |
7 | +import { isShareMode } from '@/utils/env' | |
8 | +import { ConfigurationAuthEnum, ConfigurationTemplateAuthEnum } from '@/enums/authEnum' | |
7 | 9 | |
8 | 10 | interface DeviceList { |
9 | 11 | deviceId: string |
... | ... | @@ -19,6 +21,8 @@ interface ContentDataStoreType { |
19 | 21 | configurationContentList?: any |
20 | 22 | configurationContentId: Nullable<string> |
21 | 23 | diveceDetailMap: Record<string, DeviceList> |
24 | + hasDesignAuth?: boolean | |
25 | + hasPerviewAuth?: boolean | |
22 | 26 | } |
23 | 27 | |
24 | 28 | export const useContentDataStore = defineStore('app-content-data', { |
... | ... | @@ -30,6 +34,8 @@ export const useContentDataStore = defineStore('app-content-data', { |
30 | 34 | configurationContentList: [], |
31 | 35 | configurationContentId: null, |
32 | 36 | diveceDetailMap: {}, |
37 | + hasDesignAuth: true, | |
38 | + hasPerviewAuth: true, | |
33 | 39 | }), |
34 | 40 | actions: { |
35 | 41 | |
... | ... | @@ -74,6 +80,16 @@ export const useContentDataStore = defineStore('app-content-data', { |
74 | 80 | if (!id) return null |
75 | 81 | return this.contentData.find(item => item.id === id) || null |
76 | 82 | }, |
83 | + | |
84 | + setPermissions(string: string[]) { | |
85 | + if (isShareMode()) return | |
86 | + this.hasDesignAuth = string.includes((this.isTemplate ? ConfigurationTemplateAuthEnum : ConfigurationAuthEnum).DESIGN) | |
87 | + this.hasPerviewAuth = string.includes((this.isTemplate ? ConfigurationTemplateAuthEnum : ConfigurationAuthEnum).PREVIEW) | |
88 | + return { | |
89 | + hasDesignAuth: toRaw(this.hasDesignAuth), | |
90 | + hasPreviewAuth: toRaw(this.hasPerviewAuth), | |
91 | + } | |
92 | + }, | |
77 | 93 | }, |
78 | 94 | |
79 | 95 | getters: { | ... | ... |