const.js
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const isShareMode = (() => {
const urlParams = Array.from(new URLSearchParams(window.location.href)).reduce((prev, [key, value]) => ({ ...prev, [key]: value }), {})
return urlParams.share && urlParams.share === 'SCADA'
})()
const GLOBAL_STORAGE_KEY = (() => {
const isDEV = location.href.includes('dev=1')
const DEVELOPMENT = 'DEVELOPMENT'
const PRODUCTION = 'PRODUCTION'
return `UNDEFINED__${isDEV ? DEVELOPMENT : PRODUCTION}__2.7.1__COMMON__LOCAL__KEY__`
})()
const GLOBAL_PLATFORM_INFO_KEY = (() => {
const isDEV = location.href.includes('dev=1')
const DEVELOPMENT = 'DEVELOPMENT'
const PRODUCTION = 'PRODUCTION'
return `UNDEFINED__${isDEV ? DEVELOPMENT : PRODUCTION}__2.7.1__PLATFORMINFO`
})()
const GLOBAL_TOKEN = (() => {
const ls = createStorage({ storage: localStorage })
/**
* @description user info
* @type {{JWT_TOKEN: {value: string}}}
*/
const common = ls.get(GLOBAL_STORAGE_KEY)
return isShareMode
? {
token: common && common.SHARE_JWT_TOKEN && common.SHARE_JWT_TOKEN.value,
refreshToken: common && common.SHARE_REFRESH_TOKEN && common.SHARE_REFRESH_TOKEN.value,
}
: {
token: common && common.JWT_TOKEN && common.JWT_TOKEN.value,
refreshToken: common && common.REFRESH_TOKEN && common.REFRESH_TOKEN.value,
}
})()
const GLOBAL_PLATFORM_INFO = (() => {
const ls = createStorage({ storage: localStorage })
/**
* @description user info
* @type {{JWT_TOKEN: {value: string}}}
*/
const common = ls.get(GLOBAL_PLATFORM_INFO_KEY) || {}
return common
})()
/**
* @description 写权限 key
*/
const CAN_WRITE = 'api:yt:configuration:center:get_configuration_info:design'
const USER_PERMISSION = {
permission: []
}
const IS_CUSTOMER_USER = (() => {
const ls = createStorage({ storage: localStorage })
const common = ls.get(GLOBAL_STORAGE_KEY) || { USER__INFO__: {} }
const userInfo = ((common || {}).USER__INFO__ || {}).value || {}
return (((userInfo || {})).roles || [])[0] === 'CUSTOMER_USER'
})()
const hasSavePermission = () => {
return USER_PERMISSION.permission.includes(CAN_WRITE) && !IS_CUSTOMER_USER
}
const GLOBAL_WS_URL = () => {
const { host, href } = location
const reg = /^https/
return `${reg.test(href) ? 'wss' : 'ws'}://${host}/api/ws/plugins/telemetry?token=${GLOBAL_TOKEN.token}`
}