help.js
1.21 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
import config from '../../../../config/baseUrl.js'
import {
atob,
btoa
} from './weapp.atob.js'
const getRandomString = () => Number(Math.random().toString().substring(2)).toString(36);
export const ScadaModeEnum = {
PRIVATE_VIEW: 'PRIVATE_VIEW',
PUBLIC_VIEW: 'PUBLIC_VIEW',
}
export const encode = (record) => {
let hash = JSON.stringify(record);
const mixinString = getRandomString()
.slice(0, 10)
.padEnd(10, getRandomString())
.split('')
.map((item) => (Math.random() > 0.5 ? item.toUpperCase() : item))
.join('');
hash = btoa(hash);
hash = hash.substring(0, 6) + mixinString + hash.substring(6);
hash = btoa(hash);
return hash;
};
export const createScadaPageLink = (
record,
mode = ScadaModeEnum.PRIVATE_VIEW,
open = false
) => {
const userInfo = uni.getStorageSync('userInfo')
const params = {
configurationId: record?.id,
organizationId: record?.organizationId,
mode: record?.viewType === ScadaModeEnum.PRIVATE_VIEW ? 'lightbox' : 'share',
platform: record?.platform,
userId: userInfo.userId
};
if (record?.viewType === ScadaModeEnum.PUBLIC_VIEW) {
params.publicId = record.publicId;
}
const hash = encode(params);
const href = `${config.baseDrawioUrl}#${hash}`
return href
};