@gm-mobile/mp-request 3.11.2-beta.0 → 3.11.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/config_private_domain.ts +67 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp-request",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.4-beta.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "zhongsink <zhongink@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@gm-mobile/c-tool": "^3.11.
|
|
24
|
-
"@gm-mobile/locales": "^3.11.
|
|
25
|
-
"@gm-mobile/mp": "^3.11.
|
|
23
|
+
"@gm-mobile/c-tool": "^3.11.4-beta.0",
|
|
24
|
+
"@gm-mobile/locales": "^3.11.4-beta.0",
|
|
25
|
+
"@gm-mobile/mp": "^3.11.4-beta.0",
|
|
26
26
|
"js-base64": "^3.6.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"taro-axios": "^1.1.1",
|
|
31
31
|
"weapp-cookie": "^1.4.6"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "b5ca25b313c10ac57e6fc12b7165785489080838"
|
|
34
34
|
}
|
|
@@ -6,40 +6,85 @@ import { LocalStorage } from '@gm-mobile/mp'
|
|
|
6
6
|
// 如果有值使用此值作为接口请求域名
|
|
7
7
|
let privateBaseUrl: string = LocalStorage.get('privateBaseUrl') || ''
|
|
8
8
|
|
|
9
|
-
/** 私有化部署实现,监测到登录后,后续所有接口的请求域名将使用group中的private_domain字段值
|
|
10
|
-
|
|
9
|
+
/** 私有化部署实现,监测到登录后,后续所有接口的请求域名将使用group中的private_domain字段值
|
|
10
|
+
* 退出登录后应该调用clearPrivateDomain恢复
|
|
11
|
+
*/
|
|
12
|
+
export async function configPrivateDomain(defaultBaseUrl: string) {
|
|
11
13
|
instance.interceptors.request.use(async (config) => {
|
|
12
14
|
const { baseURL = '', url, data = '{}' } = config
|
|
13
15
|
const fullUrl = baseURL + url
|
|
16
|
+
if (url!.indexOf('ceres') === -1) {
|
|
17
|
+
// 仅处理ceres接口
|
|
18
|
+
return config
|
|
19
|
+
}
|
|
14
20
|
const apiName = fullUrl.split('/').reverse()[0]
|
|
15
21
|
const origin = fullUrl.split('/').slice(0, 3).join('/')
|
|
16
22
|
const form: any = /^\{/.test(data) ? JSON.parse(data) : {}
|
|
17
23
|
switch (apiName) {
|
|
18
24
|
case 'Token': {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
// #region 已知目前三种登录方式:
|
|
26
|
+
// 1、group_id 使用企业id登录,如轻巧版
|
|
27
|
+
// 2、group_customized_code 使用自定义编码登录,如采购助手
|
|
28
|
+
// 3、wechat_app_id 使用绑定了企业的应用id登录,通过GetApplicationRelation取得group_id,如eshop
|
|
29
|
+
// 故以下三个一定存在一个
|
|
30
|
+
const group_id: string | undefined = form.group_id
|
|
31
|
+
const group_customized_code: string | undefined =
|
|
32
|
+
form.group_customized_code
|
|
33
|
+
const wechat_app_id: string | undefined = form.wechat_app_id
|
|
34
|
+
// #endregion
|
|
35
|
+
const getPrivateBaseUrl = async ({
|
|
36
|
+
group_id,
|
|
37
|
+
customized_code,
|
|
38
|
+
}: {
|
|
39
|
+
group_id?: string
|
|
40
|
+
customized_code?: string
|
|
41
|
+
}) => {
|
|
42
|
+
const {
|
|
43
|
+
data: { groups },
|
|
44
|
+
} = await axios.post(
|
|
45
|
+
'/ceres/enterprise/EnterpriseService/ListLoginGroup',
|
|
46
|
+
{ group_id, customized_code },
|
|
47
|
+
{ baseURL: defaultBaseUrl }
|
|
48
|
+
)
|
|
49
|
+
return get(groups, '0.private_domain_name')?.replace(/\/^/, '') || ''
|
|
50
|
+
}
|
|
51
|
+
// 登录1和登录2
|
|
52
|
+
if (group_id || group_customized_code) {
|
|
53
|
+
privateBaseUrl =
|
|
54
|
+
(await getPrivateBaseUrl({
|
|
55
|
+
group_id,
|
|
56
|
+
customized_code: group_customized_code,
|
|
57
|
+
})) || ''
|
|
58
|
+
LocalStorage.set('privateBaseUrl', privateBaseUrl)
|
|
59
|
+
} else if (wechat_app_id) {
|
|
60
|
+
// 登录3
|
|
61
|
+
const {
|
|
62
|
+
data: { group_id },
|
|
63
|
+
} = await axios.post(
|
|
64
|
+
'/ceres/preference/PreferenceService/GetApplicationRelation',
|
|
65
|
+
{
|
|
66
|
+
application_key: wechat_app_id,
|
|
67
|
+
application_type: 1,
|
|
68
|
+
},
|
|
69
|
+
{ baseURL: defaultBaseUrl }
|
|
70
|
+
)
|
|
71
|
+
privateBaseUrl = (await getPrivateBaseUrl({ group_id })) || ''
|
|
72
|
+
LocalStorage.set('privateBaseUrl', privateBaseUrl)
|
|
73
|
+
console.log('[configPrivateDomain] 启用自定义域名', privateBaseUrl)
|
|
74
|
+
} else {
|
|
75
|
+
console.warn('不该来到这里')
|
|
76
|
+
}
|
|
77
|
+
break
|
|
78
|
+
}
|
|
79
|
+
default: {
|
|
36
80
|
break
|
|
37
81
|
}
|
|
38
|
-
default:
|
|
39
82
|
}
|
|
40
|
-
config.baseURL = privateBaseUrl || defaultBaseUrl
|
|
83
|
+
config.baseURL = privateBaseUrl || defaultBaseUrl || config.baseURL
|
|
41
84
|
return Promise.resolve(config)
|
|
42
85
|
})
|
|
43
86
|
}
|
|
44
87
|
|
|
45
|
-
export
|
|
88
|
+
export function clearPrivateDomain() {
|
|
89
|
+
privateBaseUrl = ''
|
|
90
|
+
}
|