forked from opentiny/tiny-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseEditorInfo.js
More file actions
71 lines (66 loc) · 1.81 KB
/
Copy pathuseEditorInfo.js
File metadata and controls
71 lines (66 loc) · 1.81 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
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { useHttp } from '@opentiny/tiny-engine-http'
import useModal from './useModal'
// web版获取配置信息: 从url中获取
const _getWebData = () => {
const paramsMap = new URLSearchParams(location.search)
const id = paramsMap.get('id')
const blockId = paramsMap.get('blockid')
const pageId = paramsMap.get('pageid')
const type = paramsMap.get('type')
const version = paramsMap.get('version')
return {
type: type || 'app',
id,
pageId,
blockId,
version
}
}
let userInfo = {}
const getUserInfo = () => {
// 获取登录用户信息
useHttp()
.get('/platform-center/api/user/me')
.then((data) => {
if (data) {
userInfo = data
}
})
.catch((error) => {
useModal().message({ message: error.message, status: 'error' })
})
}
const isAdmin = () => userInfo.resetPasswordToken === 'p_webcenter'
/**
* 1、是否是VSCode插件: 通过是否有全局变量window.vscodeBridge判断
*
* 2、vscode中类型和id
* window.vscodeInjectData
* type: app 应用管理 block 区块管理
* id: 应用id/blockid
* ...其他详细信息
*
* 3、web版中,通过url参数判断
* type: app 应用管理 block 区块管理
* id: 应用id/blockid
*
*/
export default () => {
return {
useInfo: _getWebData,
getUserInfo,
userInfo,
isAdmin
}
}