@smart100/spu-web-plugin 0.0.23 → 0.0.25
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/dist/index.d.ts +28 -25
- package/dist/spu-web-plugin.mjs +24564 -24737
- package/package.json +6 -4
- package/src/apaasSpuTrack.ts +5 -4
- package/src/axios.ts +9 -12
- package/src/cloudServ.ts +0 -58
- package/src/components/expandexp/index.ts +41 -34
- package/src/components/expandexp/template.ts +7 -0
- package/src/core.js +7 -230
- package/src/index.ts +118 -10
- package/src/login.ts +243 -63
- package/src/oss/downloadService.ts +7 -7
- package/src/oss/servtoken.ts +2 -2
- package/src/oss/uploadService.ts +7 -6
- package/src/package/ali-oss/aliyun-oss-sdk.js +25121 -25121
- package/src/package/ali-oss/aliyun-oss-sdk.min.js +14 -14
- package/src/package/ali-oss/package.json +162 -162
- package/src/spuConfig.ts +2 -2
- package/src/storageProxy.ts +2 -4
- package/src/test.ts +4 -2
- package/src/types/global.d.ts +0 -7
- package/src/types/index.d.ts +95 -0
- package/src/types/shims-lib.d.ts +1 -0
- package/src/utils.ts +2 -20
- package/src/install.ts +0 -79
- package/src/tenantInfo.ts +0 -74
package/src/index.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { version } from '../package.json'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { merge } from 'lodash-es'
|
|
3
|
+
import { WxworksuitePluginInstall, jssdk, isWxworkSuiteTenant, isWxwork, isWxworkPc, isWxworkApp } from '@smart100/wxworksuite-plugin'
|
|
4
|
+
import { v4 as getUuid } from 'uuid'
|
|
5
|
+
|
|
6
|
+
import { initStorageProxy, lsProxy, ssProxy } from './storageProxy'
|
|
4
7
|
import { getLocation, getDistance } from './location'
|
|
5
|
-
import { spuAxios,
|
|
6
|
-
import { spuConfig } from './spuConfig'
|
|
8
|
+
import { initAxios, spuAxios, axios } from './axios'
|
|
9
|
+
import { initSpuConfig, spuConfig } from './spuConfig'
|
|
7
10
|
import { downloadService, uploadService } from './oss'
|
|
8
|
-
import { getUniqueid, functionCheck
|
|
11
|
+
import { getUniqueid, functionCheck } from './utils'
|
|
12
|
+
import urlquery from './urlquery'
|
|
9
13
|
import AMapLoader from './AMapLoader'
|
|
10
14
|
import login from './login'
|
|
11
|
-
import
|
|
12
|
-
import { Module } from './core'
|
|
15
|
+
import core from './core'
|
|
13
16
|
import components from './components'
|
|
14
17
|
import { expandexp } from './components/expandexp'
|
|
15
|
-
import {
|
|
18
|
+
import { initApaasSpuTrack } from './apaasSpuTrack'
|
|
19
|
+
import { initTest } from './test'
|
|
20
|
+
|
|
16
21
|
|
|
17
22
|
|
|
18
23
|
// class SPUWebPlugin {
|
|
@@ -22,32 +27,133 @@ import { jssdk } from '@smart100/wxworksuite-plugin'
|
|
|
22
27
|
// // SPUWebPlugin.install = install
|
|
23
28
|
// // SPUWebPlugin.version = version
|
|
24
29
|
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const globalOptions: any = {
|
|
33
|
+
modulekey: 'demospu',
|
|
34
|
+
modulename: 'demospu',
|
|
35
|
+
moduleversion: 'v1.0',
|
|
36
|
+
storageproxyprefix: '',
|
|
37
|
+
router: null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const install = (app: any, options: any) => {
|
|
41
|
+
// console.log(app)
|
|
42
|
+
// console.log(app.version)
|
|
43
|
+
merge(globalOptions, options)
|
|
44
|
+
console.log('@smart100/spu-web-plugin start!')
|
|
45
|
+
console.log('@smart100/spu-web-plugin userOptions: ', options)
|
|
46
|
+
console.log('@smart100/spu-web-plugin globalOptions: ', globalOptions)
|
|
47
|
+
// console.error('test')
|
|
48
|
+
|
|
49
|
+
// if (install.installed) return
|
|
50
|
+
// install.installed = true
|
|
51
|
+
// debugger
|
|
52
|
+
|
|
53
|
+
// if (app) {
|
|
54
|
+
// const version = Number(app.version.split('.')[0])
|
|
55
|
+
// if (version < 3) {
|
|
56
|
+
// console.error('This plugin requires Vue 3')
|
|
57
|
+
// return false
|
|
58
|
+
// }
|
|
59
|
+
// } else {
|
|
60
|
+
// console.error('This plugin requires Vue App Instance')
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
initStorageProxy(globalOptions)
|
|
64
|
+
|
|
65
|
+
initAxios(globalOptions)
|
|
66
|
+
initSpuConfig(globalOptions)
|
|
67
|
+
urlquery.init()
|
|
68
|
+
|
|
69
|
+
// 安装企微第三方应用插件
|
|
70
|
+
WxworksuitePluginInstall({
|
|
71
|
+
getToken: login.getToken.bind(login)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
login.startRefreshtoken()
|
|
75
|
+
|
|
76
|
+
if (globalOptions.router) {
|
|
77
|
+
globalOptions.router.beforeEach(async (to: any, from: any, next: any) => {
|
|
78
|
+
// console.log(from)
|
|
79
|
+
// console.log(to)
|
|
80
|
+
// const isInitVisit = from.path === '/' && from.name === undefined // 路由初始化访问
|
|
81
|
+
// console.log('isInitVisit', isInitVisit)
|
|
82
|
+
|
|
83
|
+
// 自动登录
|
|
84
|
+
if (to.query.token) {
|
|
85
|
+
const singleLoginRes = await login.singleLogin(to.query)
|
|
86
|
+
if (singleLoginRes.flag) {
|
|
87
|
+
// debugger
|
|
88
|
+
// next()
|
|
89
|
+
next({
|
|
90
|
+
path: to.path,
|
|
91
|
+
params: to.params,
|
|
92
|
+
query: singleLoginRes.query
|
|
93
|
+
})
|
|
94
|
+
} else {
|
|
95
|
+
console.error('单点登录失败,请检查链接所传 token 是否非法或过期。')
|
|
96
|
+
next()
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
next()
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
} else {
|
|
103
|
+
console.warn('@smart100/spu-web-plugin 需要传入一个 vue-router 实例以便执行单点登录逻辑,如果您没传 vue-router 实例则需要自行在合适的位置执行单点登录代码。')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
initApaasSpuTrack()
|
|
108
|
+
|
|
109
|
+
initTest(globalOptions)
|
|
110
|
+
}
|
|
111
|
+
|
|
25
112
|
const SPUWebPlugin = {
|
|
26
113
|
install,
|
|
27
114
|
version
|
|
28
115
|
}
|
|
29
116
|
|
|
117
|
+
|
|
118
|
+
|
|
30
119
|
const getToken = login.getToken.bind(login)
|
|
31
120
|
const getTokenExpires = login.getTokenExpires.bind(login)
|
|
32
121
|
const getRefreshToken = login.getRefreshToken.bind(login)
|
|
33
122
|
const getUser = login.getUser.bind(login)
|
|
34
123
|
const checkLogin = login.checkLogin.bind(login)
|
|
124
|
+
const singleLogin = login.singleLogin.bind(login)
|
|
125
|
+
const startRefreshtoken = login.startRefreshtoken.bind(login)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
35
129
|
const wxworkSuite = {
|
|
36
130
|
JSSDK: jssdk,
|
|
37
|
-
isWxworkSuiteTenant
|
|
131
|
+
isWxworkSuiteTenant,
|
|
38
132
|
isWxwork,
|
|
39
133
|
isWxworkPc,
|
|
40
134
|
isWxworkApp
|
|
41
135
|
}
|
|
42
136
|
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const Module = {
|
|
140
|
+
getModuleData: core.getModuleData.bind(core),
|
|
141
|
+
getEnvname: login.getEnvname.bind(login),
|
|
142
|
+
getEnvData: core.getEnvData.bind(core),
|
|
143
|
+
checkModule: core.checkModule.bind(core)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
43
147
|
export {
|
|
44
148
|
SPUWebPlugin as default,
|
|
149
|
+
globalOptions,
|
|
45
150
|
lsProxy,
|
|
46
151
|
ssProxy,
|
|
47
152
|
getLocation,
|
|
48
153
|
getDistance,
|
|
49
154
|
spuAxios,
|
|
50
|
-
|
|
155
|
+
axios,
|
|
156
|
+
axios as apaasAxios,
|
|
51
157
|
spuConfig,
|
|
52
158
|
downloadService,
|
|
53
159
|
uploadService,
|
|
@@ -60,6 +166,8 @@ export {
|
|
|
60
166
|
getRefreshToken,
|
|
61
167
|
getUser,
|
|
62
168
|
checkLogin,
|
|
169
|
+
singleLogin,
|
|
170
|
+
startRefreshtoken,
|
|
63
171
|
Module,
|
|
64
172
|
components,
|
|
65
173
|
expandexp,
|
package/src/login.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { cloneDeep } from 'lodash-es'
|
|
2
2
|
import jwtDecode from 'jwt-decode'
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { lsProxy } from './storageProxy'
|
|
3
|
+
import { lsProxy, axios } from './index'
|
|
4
|
+
import cloudServ from './cloudServ'
|
|
6
5
|
// import { functionCheck } from './utils'
|
|
7
6
|
|
|
8
7
|
|
|
@@ -45,11 +44,19 @@ class Login {
|
|
|
45
44
|
|
|
46
45
|
async getEnvname (): Promise<string> {
|
|
47
46
|
let envname = ''
|
|
48
|
-
|
|
47
|
+
|
|
48
|
+
// web 查 context 的 envname
|
|
49
49
|
let context: any = lsProxy.getItem('context')
|
|
50
50
|
context && (context = JSON.parse(context))
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const contextEnvname = context?.envname || ''
|
|
52
|
+
|
|
53
|
+
// 链接有些spu可能会传 envname
|
|
54
|
+
const queryEnvname = this.getQueryEnvname()
|
|
55
|
+
|
|
56
|
+
if (contextEnvname) {
|
|
57
|
+
envname = contextEnvname
|
|
58
|
+
} else if (queryEnvname) {
|
|
59
|
+
envname = queryEnvname
|
|
53
60
|
} else if (window?.aPaaS?.getWebInitParams && window?.Native?.setNavigationBarReturnButton) {
|
|
54
61
|
// 手机端 查 envname
|
|
55
62
|
// 只有手机端有 setNavigationBarReturnButton 方法
|
|
@@ -59,9 +66,22 @@ class Login {
|
|
|
59
66
|
})
|
|
60
67
|
})
|
|
61
68
|
}
|
|
69
|
+
|
|
62
70
|
return envname
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
setQueryEnvname (value: string) {
|
|
74
|
+
this.setData('envname', value)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getQueryEnvname () {
|
|
78
|
+
return this.getData('envname') || ''
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
removeQueryEnvname () {
|
|
82
|
+
this.removeData('envname')
|
|
83
|
+
}
|
|
84
|
+
|
|
65
85
|
getToken () {
|
|
66
86
|
return this.getData('token')
|
|
67
87
|
}
|
|
@@ -99,7 +119,7 @@ class Login {
|
|
|
99
119
|
}
|
|
100
120
|
|
|
101
121
|
private updateToken () {
|
|
102
|
-
return
|
|
122
|
+
return axios.get('/api/auth/refreshtoken', {
|
|
103
123
|
params: {
|
|
104
124
|
refreshtoken: this.getRefreshToken()
|
|
105
125
|
},
|
|
@@ -190,15 +210,112 @@ class Login {
|
|
|
190
210
|
}
|
|
191
211
|
}
|
|
192
212
|
|
|
193
|
-
//
|
|
213
|
+
// // 产品运营中心token
|
|
214
|
+
// {
|
|
215
|
+
// "LoginUser": {
|
|
216
|
+
// "appId": "100",
|
|
217
|
+
// "tenantCode": "1656652",
|
|
218
|
+
// "productCode": "100000000000000000",
|
|
219
|
+
// "productVersionCode": null,
|
|
220
|
+
// "clientTypeCode": null,
|
|
221
|
+
// "userCode": "6",
|
|
222
|
+
// "accountCode": "6",
|
|
223
|
+
// "username": "庄焕滨",
|
|
224
|
+
// "tokenId": "bd69b4a4-5376-47cd-91c3-f1e1576440e5",
|
|
225
|
+
// "appCodes": null,
|
|
226
|
+
// "appCode": null,
|
|
227
|
+
// "platRoleCodes": ["1637696814759153664"],
|
|
228
|
+
// "metamodeltype": 2,
|
|
229
|
+
// "orgCode": "1751852081616130048",
|
|
230
|
+
// "centerRole": true
|
|
231
|
+
// },
|
|
232
|
+
// "TwoFactorAuthCode": "6f56da978dffe31a3b03a56c446f9467",
|
|
233
|
+
// "exp": 1751694745
|
|
234
|
+
// }
|
|
235
|
+
|
|
236
|
+
// // 租户token
|
|
237
|
+
// {
|
|
238
|
+
// "exp": 1720161305,
|
|
239
|
+
// "LoginUser": {
|
|
240
|
+
// "accountInfoCode": "1803686723986010112",
|
|
241
|
+
// "accountCode": "1803686724107644928",
|
|
242
|
+
// "tenantCode": "3000911",
|
|
243
|
+
// "productCode": "100000000000000000",
|
|
244
|
+
// "productVersionCode": "30000000000000911",
|
|
245
|
+
// "clientTypeCode": 1,
|
|
246
|
+
// "tokenId": "8614059e-69a5-4e1e-a948-f2ef680d0dd5",
|
|
247
|
+
// "orgCode": "1803686397149065216",
|
|
248
|
+
// "userInfoId": "1806591894588108800",
|
|
249
|
+
// "userInfoName": "woOUQJEAAAn4r5-7jffaxad6yotbEZ5A",
|
|
250
|
+
// "positionCode": "1803686397304254473",
|
|
251
|
+
// "positionName": "系统管理员-勿删",
|
|
252
|
+
// "memberCode": "1806591894659411968",
|
|
253
|
+
// "refPositionCode": "1300728614534385664",
|
|
254
|
+
// "categoryCode": "",
|
|
255
|
+
// "orgStructTypeId": "1",
|
|
256
|
+
// "userName": null,
|
|
257
|
+
// "userName1": "woOUQJEAAAn4r5-7jffaxad6yotbEZ5A",
|
|
258
|
+
// "userName2": null,
|
|
259
|
+
// "userName3": null,
|
|
260
|
+
// "tenantName": "智慧100-企微版-V9.1.1开发租户",
|
|
261
|
+
// "appCode": "sales",
|
|
262
|
+
// "appCodes": [
|
|
263
|
+
// "promotion",
|
|
264
|
+
// "distribution",
|
|
265
|
+
// "sales"
|
|
266
|
+
// ],
|
|
267
|
+
// "subPdCodes": [
|
|
268
|
+
// "sfa",
|
|
269
|
+
// "dms",
|
|
270
|
+
// "pmm",
|
|
271
|
+
// "tpm",
|
|
272
|
+
// "ai"
|
|
273
|
+
// ],
|
|
274
|
+
// "codepath": "1.1803686395634921472.1803686397149065216.",
|
|
275
|
+
// "isleaforg": "true",
|
|
276
|
+
// "metamodeltype": 1,
|
|
277
|
+
// "isSmsLogin": false
|
|
278
|
+
// }
|
|
279
|
+
// }
|
|
280
|
+
// 查询token所属登录角色
|
|
281
|
+
// tenant: 普通租户登录 默认
|
|
282
|
+
// center: 产品运营中心登录 单点登录时只带 token 没带 refreshtoken 和 tokenexpires
|
|
283
|
+
getLoginRole (token?: string) {
|
|
284
|
+
let loginRole: 'center' | 'tenant' = 'tenant' // center | tenant
|
|
285
|
+
if (token) {
|
|
286
|
+
const jwtInfo = this.jwtDecode(token)
|
|
287
|
+
if (jwtInfo?.LoginUser?.centerRole || jwtInfo?.LoginUser?.appId === '100') {
|
|
288
|
+
// 产品运营中心登录
|
|
289
|
+
loginRole = 'center'
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return loginRole
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 检测当前用户是否登录状态
|
|
194
296
|
checkLogin () {
|
|
195
297
|
let haslogged = false
|
|
196
298
|
const token = this.getToken()
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
299
|
+
if (token) {
|
|
300
|
+
if (this.getLoginRole(token) === 'center') {
|
|
301
|
+
haslogged = this.checkTokenLogin(token)
|
|
302
|
+
} else {
|
|
303
|
+
const refreshtoken = this.getRefreshToken()
|
|
304
|
+
const tokenexpires = this.getTokenExpires()
|
|
305
|
+
const now = Date.now()
|
|
306
|
+
if (token && refreshtoken && tokenexpires && Number(tokenexpires) > now) {
|
|
307
|
+
haslogged = this.checkTokenLogin(token)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return haslogged
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// 检测token是否过期
|
|
315
|
+
checkTokenLogin (token?: string) {
|
|
316
|
+
let haslogged = false
|
|
317
|
+
if (token) {
|
|
318
|
+
const now = Date.now()
|
|
202
319
|
const jwtInfo = this.jwtDecode(token)
|
|
203
320
|
if (jwtInfo?.exp) {
|
|
204
321
|
haslogged = Number(jwtInfo.exp + '000') > now
|
|
@@ -210,26 +327,11 @@ class Login {
|
|
|
210
327
|
}
|
|
211
328
|
|
|
212
329
|
// 接口请求回来的 userInfo 有 functioncodes 以便做权限校验
|
|
330
|
+
// 有可能是中心角色请求失败 兼容不报错
|
|
213
331
|
async getAndSetUserInfo () {
|
|
214
|
-
// return apaasAxios.post('/api/teapi/rolepermission/account/getaccountinfo', {
|
|
215
|
-
// positionid: this.getUser('positioncode'),
|
|
216
|
-
// deviceinfo: '',
|
|
217
|
-
// sysversion: '',
|
|
218
|
-
// clientversion: ''
|
|
219
|
-
// }).then((res: any) => {
|
|
220
|
-
// // console.log(res)
|
|
221
|
-
// // debugger
|
|
222
|
-
// if (res.code === 200 && res.data) {
|
|
223
|
-
// this.setUser(res.data)
|
|
224
|
-
// }
|
|
225
|
-
// }).catch((err: Error) => {
|
|
226
|
-
// console.error(22)
|
|
227
|
-
// console.error(err)
|
|
228
|
-
// })
|
|
229
|
-
|
|
230
332
|
try {
|
|
231
|
-
const accountinfo
|
|
232
|
-
positionid: this.getUser('positioncode'),
|
|
333
|
+
const accountinfo = await axios.post('/api/teapi/rolepermission/account/getaccountinfo', {
|
|
334
|
+
positionid: this.getUser('positioncode') || '',
|
|
233
335
|
deviceinfo: '',
|
|
234
336
|
sysversion: '',
|
|
235
337
|
clientversion: ''
|
|
@@ -245,57 +347,135 @@ class Login {
|
|
|
245
347
|
}
|
|
246
348
|
} catch (e) {
|
|
247
349
|
console.error(e)
|
|
350
|
+
console.warn('获取用户信息失败,当前您登录的帐号可能为非标准租户帐号。')
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
formatTenant (tenant: ITenantInfo) {
|
|
355
|
+
if (!tenant) {
|
|
356
|
+
return null
|
|
357
|
+
}
|
|
358
|
+
const cloundTagMap = ['storage', 'storage-1d', 'storage-1y', 'storage-3m']
|
|
359
|
+
const result: NormalizedCloudServ = {}
|
|
360
|
+
for (const keyItem of cloundTagMap) {
|
|
361
|
+
const cloudServ = tenant.cloudserv[keyItem as StorageEnum]
|
|
362
|
+
if (cloudServ) {
|
|
363
|
+
result[keyItem as StorageEnum] = {
|
|
364
|
+
cloudserv_storage_provider: cloudServ.provider,
|
|
365
|
+
cloudserv_storage_storagebucket: cloudServ.storagebucket,
|
|
366
|
+
cloudserv_storage_storageendpoint: cloudServ.storageendpoint,
|
|
367
|
+
cloudserv_storage_storageurl: cloudServ.storageurl,
|
|
368
|
+
cloudserv_storage_accesskeyid: cloudServ.accesskeyid,
|
|
369
|
+
cloudserv_storage_region: cloudServ.region
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (Object.keys(result).length === 0) {
|
|
374
|
+
return null
|
|
375
|
+
}
|
|
376
|
+
return result
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async getAndSetTenant (tenantcode?: string) {
|
|
380
|
+
try {
|
|
381
|
+
const tenantsRes: null | ITenantInfo[] = await axios.get('/api/auth/tenantlist', {}).then((res: any) => {
|
|
382
|
+
return res?.data?.tenants
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
let tenant: ITenantInfo | null = null
|
|
386
|
+
if (tenantsRes?.length) {
|
|
387
|
+
if (!tenantcode) {
|
|
388
|
+
tenant = tenantsRes[0]
|
|
389
|
+
} else {
|
|
390
|
+
tenant = tenantsRes.find((item) => item.code === tenantcode) || null
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (!tenant) {
|
|
395
|
+
lsProxy.removeItem('tenant')
|
|
396
|
+
cloudServ.remove()
|
|
397
|
+
} else {
|
|
398
|
+
lsProxy.setItem('tenant', JSON.stringify(tenant))
|
|
399
|
+
const normalizedTenant = this.formatTenant(tenant)
|
|
400
|
+
if (normalizedTenant) {
|
|
401
|
+
cloudServ.set(normalizedTenant)
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
} catch (e) {
|
|
405
|
+
console.error(e)
|
|
406
|
+
console.warn('获取租户信息失败,当前您登录的帐号可能为非标准租户帐号。')
|
|
248
407
|
}
|
|
249
408
|
}
|
|
250
409
|
|
|
251
410
|
// 单点登录
|
|
252
411
|
async singleLogin (query: IAny) {
|
|
253
|
-
// 自动登录
|
|
254
412
|
query = cloneDeep(query)
|
|
255
|
-
const token = query.token
|
|
256
|
-
// 之所以不强制校验 refreshtoken tokenexpires 是因为安装卸载配置页面有可能放在产品运营中心 没有这两字段
|
|
257
|
-
if (token) {
|
|
258
|
-
this.setToken(token)
|
|
259
|
-
this.setUserByToken(token) // 解析token为用户信息存入
|
|
260
413
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
414
|
+
let flag = false // 是否登录成功
|
|
415
|
+
const token = query.token
|
|
416
|
+
const refreshtoken = query.refreshtoken
|
|
417
|
+
const tokenexpires = query.tokenexpires
|
|
418
|
+
const envname = query.envname
|
|
419
|
+
const context = query.context
|
|
420
|
+
|
|
421
|
+
if (this.checkTokenLogin(token)) {
|
|
422
|
+
let isneedlogin = true // 是否需要走单点登录流程
|
|
423
|
+
const loginRole = this.getLoginRole(token)
|
|
424
|
+
|
|
425
|
+
if (loginRole === 'center') {
|
|
426
|
+
// 如果本地已经登录 且 query 登录参数与本地一致 说明是刚登录没多久【token也没刷新过】 视为已经登录 不需再走单点登录流程
|
|
427
|
+
// 之所以不强制校验 refreshtoken tokenexpires 是因为安装卸载配置页面有可能放在产品运营中心 没有这两字段
|
|
428
|
+
if (this.checkLogin() && token === this.getToken()) {
|
|
429
|
+
isneedlogin = false
|
|
430
|
+
flag = true
|
|
431
|
+
}
|
|
270
432
|
} else {
|
|
271
|
-
|
|
433
|
+
// 如果本地已经登录 且 query 登录参数与本地一致 说明是刚登录没多久【token也没刷新过】 视为已经登录 不需再走单点登录流程
|
|
434
|
+
if (this.checkLogin() && token === this.getToken() && refreshtoken === this.getRefreshToken() && tokenexpires === this.getTokenExpires()) {
|
|
435
|
+
isneedlogin = false
|
|
436
|
+
flag = true
|
|
437
|
+
}
|
|
272
438
|
}
|
|
273
439
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
440
|
+
if (isneedlogin) {
|
|
441
|
+
this.setToken(token)
|
|
442
|
+
this.setUserByToken(token) // 解析token为用户信息存入
|
|
443
|
+
|
|
444
|
+
refreshtoken ? this.setRefreshToken(refreshtoken) : this.removeRefreshToken()
|
|
445
|
+
tokenexpires ? this.setTokenExpires(tokenexpires) : this.removeTokenExpires()
|
|
446
|
+
envname ? this.setQueryEnvname(envname) : this.removeQueryEnvname()
|
|
281
447
|
|
|
282
|
-
|
|
283
|
-
|
|
448
|
+
// context 上下文字段 产品运营中心安装 卸载 配置 和 产品配置中心业务配置 页面需要用到
|
|
449
|
+
// web 端有传 app没传 需要做兼容
|
|
450
|
+
context && lsProxy.setItem('context', decodeURIComponent(context))
|
|
284
451
|
|
|
285
|
-
|
|
286
|
-
|
|
452
|
+
// 这里兼容报错
|
|
453
|
+
await this.getAndSetTenant()
|
|
454
|
+
await this.getAndSetUserInfo()
|
|
455
|
+
|
|
456
|
+
flag = true
|
|
457
|
+
}
|
|
287
458
|
} else {
|
|
288
|
-
|
|
459
|
+
flag = false
|
|
460
|
+
console.error('没传 token 或所传 token 已过期,无法单点登录。')
|
|
289
461
|
}
|
|
462
|
+
|
|
290
463
|
// 单点登录后 无论是否成功 都需要删除 query 中相关参数
|
|
291
|
-
delete query.token
|
|
292
|
-
delete query.refreshtoken
|
|
293
|
-
delete query.tokenexpires
|
|
464
|
+
token && delete query.token
|
|
465
|
+
refreshtoken && delete query.refreshtoken
|
|
466
|
+
tokenexpires && delete query.tokenexpires
|
|
467
|
+
envname && delete query.envname
|
|
468
|
+
context && delete query.context
|
|
469
|
+
|
|
294
470
|
// debugger
|
|
471
|
+
|
|
295
472
|
return {
|
|
473
|
+
flag,
|
|
296
474
|
query
|
|
297
475
|
}
|
|
298
476
|
}
|
|
299
477
|
}
|
|
300
478
|
|
|
301
|
-
|
|
479
|
+
const login = new Login()
|
|
480
|
+
|
|
481
|
+
export default login
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import CloudServ from '../cloudServ'
|
|
2
|
-
import { initServToken } from './servtoken'
|
|
3
1
|
import OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
|
|
4
2
|
// import * as OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
|
|
5
3
|
// const OSS = require('../package/ali-oss/aliyun-oss-sdk.apaas.min.js')
|
|
6
4
|
import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
|
|
7
5
|
// import * as ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
|
|
8
6
|
// const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
|
|
7
|
+
|
|
9
8
|
import dayjs from 'dayjs'
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
9
|
+
import CloudServ from '../cloudServ'
|
|
10
|
+
import { initServToken } from './servtoken'
|
|
11
|
+
import { axios, getUser } from '../index'
|
|
12
12
|
// import { get } from 'lodash-es'
|
|
13
13
|
// import qs from 'qs'
|
|
14
14
|
|
|
@@ -108,7 +108,7 @@ const getUrl = async ({
|
|
|
108
108
|
|
|
109
109
|
const isAliYun = CloudServ.isAliyun(storagetype)
|
|
110
110
|
const isHuawei = CloudServ.isHuawei(storagetype)
|
|
111
|
-
const tenantCode =
|
|
111
|
+
const tenantCode = getUser('tenantcode')
|
|
112
112
|
|
|
113
113
|
if (!filename) {
|
|
114
114
|
filename = source
|
|
@@ -245,7 +245,7 @@ const downloadFile = async ({
|
|
|
245
245
|
filename: realFilename,
|
|
246
246
|
cope
|
|
247
247
|
})
|
|
248
|
-
//
|
|
248
|
+
// axios.get(url, {
|
|
249
249
|
// responseType: 'blob',
|
|
250
250
|
// isSendToken: false,
|
|
251
251
|
// isShowErrorMessage: false
|
|
@@ -263,7 +263,7 @@ const downloadFile = async ({
|
|
|
263
263
|
if (isAliYun) {
|
|
264
264
|
downloadFileByUrl(url, filename)
|
|
265
265
|
} else {
|
|
266
|
-
|
|
266
|
+
axios.get(url, {
|
|
267
267
|
responseType: 'blob',
|
|
268
268
|
isSendToken: false,
|
|
269
269
|
isShowErrorMessage: false
|
package/src/oss/servtoken.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import { noBaseRequest } from '@/service/http'
|
|
2
|
-
import {
|
|
2
|
+
import { axios } from '../index'
|
|
3
3
|
|
|
4
4
|
export type ServToken = {
|
|
5
5
|
accesskeyid: string
|
|
@@ -21,7 +21,7 @@ let xhr: Promise<ServToken> | null = null
|
|
|
21
21
|
|
|
22
22
|
const getServToken = async () => {
|
|
23
23
|
try {
|
|
24
|
-
const response: ServToken = await
|
|
24
|
+
const response: ServToken = await axios.get('/api/teapi/auth/servtoken', {}).then((res: any) => res.data)
|
|
25
25
|
// debugger
|
|
26
26
|
return response
|
|
27
27
|
} catch (e) {
|
package/src/oss/uploadService.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import CloudServ from '../cloudServ'
|
|
2
|
-
import { initServToken } from './servtoken'
|
|
3
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
4
1
|
import OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
|
|
5
2
|
// const OSS = require('../package/ali-oss/aliyun-oss-sdk.apaas.min.js')
|
|
6
3
|
import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
|
|
7
4
|
// const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
|
|
5
|
+
|
|
6
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
8
7
|
import dayjs from 'dayjs'
|
|
9
8
|
import co from 'co'
|
|
10
|
-
import login from '../login'
|
|
11
|
-
import { obsMultiUpload } from './multiUpload'
|
|
12
9
|
|
|
10
|
+
import { getUser } from '../index'
|
|
11
|
+
import CloudServ from '../cloudServ'
|
|
12
|
+
import { initServToken } from './servtoken'
|
|
13
|
+
import { obsMultiUpload } from './multiUpload'
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
interface IUpload {
|
|
@@ -37,7 +38,7 @@ const upload = async ({
|
|
|
37
38
|
|
|
38
39
|
const isAliYun = CloudServ.isAliyun(storagetype)
|
|
39
40
|
const isHuawei = CloudServ.isHuawei(storagetype)
|
|
40
|
-
const tenantCode =
|
|
41
|
+
const tenantCode = getUser('tenantcode')
|
|
41
42
|
const suffix = '.' + file.name.substring(file.name.lastIndexOf('.') + 1)
|
|
42
43
|
source = source ? source : (uuidv4() + suffix)
|
|
43
44
|
datetime = datetime ? datetime : Date.now()
|