@smart100/spu-web-plugin 0.0.24 → 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 +27 -25
- package/dist/spu-web-plugin.mjs +26236 -17151
- package/package.json +6 -4
- package/src/apaasSpuTrack.ts +5 -4
- package/src/axios.ts +4 -4
- package/src/components/expandexp/index.ts +30 -29
- package/src/core.js +7 -230
- package/src/index.ts +115 -7
- package/src/login.ts +242 -62
- package/src/oss/downloadService.ts +5 -5
- package/src/oss/servtoken.ts +1 -1
- 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 +1 -3
- package/src/test.ts +4 -2
- package/src/types/global.d.ts +0 -8
- package/src/types/index.d.ts +95 -0
- package/src/types/shims-lib.d.ts +1 -0
- package/src/utils.ts +2 -2
- package/src/install.ts +0 -80
- package/src/tenantInfo.ts +0 -74
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart100/spu-web-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "rollup -c -w",
|
|
7
|
-
"build": "
|
|
6
|
+
"dev": "npm run build:types && rollup -c -w",
|
|
7
|
+
"build": "npm run build:types && rollup -c",
|
|
8
8
|
"build:types": "node script/build-types.js",
|
|
9
9
|
"docs": "cd ./docs && npm run docs"
|
|
10
10
|
},
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/core": "^7.23.2",
|
|
23
23
|
"@babel/preset-env": "^7.23.2",
|
|
24
|
+
"@rollup/plugin-alias": "^5.1.0",
|
|
24
25
|
"@rollup/plugin-babel": "^6.0.4",
|
|
25
26
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
26
27
|
"@rollup/plugin-image": "^3.0.3",
|
|
@@ -37,11 +38,12 @@
|
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@amap/amap-jsapi-loader": "^1.0.1",
|
|
40
|
-
"@smart100/wxworksuite-plugin": "^0.0.
|
|
41
|
+
"@smart100/wxworksuite-plugin": "^0.0.5",
|
|
41
42
|
"axios": "^1.6.0",
|
|
42
43
|
"co": "^4.6.0",
|
|
43
44
|
"dayjs": "^1.11.10",
|
|
44
45
|
"jwt-decode": "^3.1.2",
|
|
46
|
+
"lit": "^3.1.4",
|
|
45
47
|
"lodash-es": "^4.17.21",
|
|
46
48
|
"uuid": "^9.0.1",
|
|
47
49
|
"vconsole": "^3.15.1"
|
package/src/apaasSpuTrack.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { globalOptions } from './
|
|
1
|
+
import { globalOptions, getUser, Module } from './index'
|
|
2
2
|
import { cloneDeep, merge } from 'lodash-es'
|
|
3
|
+
|
|
4
|
+
// @ts-ignore
|
|
3
5
|
import ApaasSpuTrack from './package/apaas-track/apaas-spu/index.umd.js'
|
|
4
|
-
import login from './login'
|
|
5
6
|
|
|
6
7
|
const getWebInitParams = async () => {
|
|
7
|
-
const user =
|
|
8
|
-
const envname = await
|
|
8
|
+
const user = getUser()
|
|
9
|
+
const envname = await Module.getEnvname()
|
|
9
10
|
return {
|
|
10
11
|
project: globalOptions.modulename,
|
|
11
12
|
appid: globalOptions.modulekey,
|
package/src/axios.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import { get } from 'lodash-es'
|
|
8
8
|
// import { Message } from 'element-ui'
|
|
9
9
|
import { loadding } from './components/loadding'
|
|
10
|
-
import
|
|
10
|
+
import { getUser, getToken } from './index'
|
|
11
11
|
import core from './core'
|
|
12
12
|
|
|
13
13
|
interface Response {
|
|
@@ -16,7 +16,7 @@ interface Response {
|
|
|
16
16
|
msg: string
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const createAxiosInstance = (type: 'spu' | 'normal' = 'spu', options:
|
|
19
|
+
const createAxiosInstance = (type: 'spu' | 'normal' = 'spu', options: any) => {
|
|
20
20
|
const axiosInstance: AxiosInstance = axios.create({
|
|
21
21
|
baseURL: type === 'spu' ? `/api/${options.modulekey}/${options.moduleversion}` : '',
|
|
22
22
|
// baseURL: '',
|
|
@@ -35,7 +35,7 @@ const createAxiosInstance = (type: 'spu' | 'normal' = 'spu', options: SPUWebPlug
|
|
|
35
35
|
|
|
36
36
|
const isSendToken = get(config, 'isSendToken', true)
|
|
37
37
|
if (isSendToken) {
|
|
38
|
-
const token =
|
|
38
|
+
const token = getToken()
|
|
39
39
|
if (config?.headers && token) {
|
|
40
40
|
config.headers.token = token
|
|
41
41
|
}
|
|
@@ -142,7 +142,7 @@ const createAxiosInstance = (type: 'spu' | 'normal' = 'spu', options: SPUWebPlug
|
|
|
142
142
|
let spuAxios: any = null
|
|
143
143
|
let normalAxios: any = null
|
|
144
144
|
|
|
145
|
-
function initAxios (options:
|
|
145
|
+
function initAxios (options: any) {
|
|
146
146
|
spuAxios = createAxiosInstance('spu', options)
|
|
147
147
|
normalAxios = createAxiosInstance('normal', options)
|
|
148
148
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
+
import { Module, axios, getUser, wxworkSuite, spuAxios } from '../../index'
|
|
2
|
+
import { cloneDeep, merge } from 'lodash-es'
|
|
3
|
+
import { downloadService } from '../../oss'
|
|
4
|
+
import { apaasSpuTrackSendLog } from '../../apaasSpuTrack'
|
|
1
5
|
import { getAttributes } from '../common/index'
|
|
2
6
|
import renderTemplate from './template'
|
|
3
7
|
import { Step } from './step'
|
|
4
|
-
import { cloneDeep, merge } from 'lodash-es'
|
|
5
8
|
import { fixFileName, dealFileSize, dealResultMessage } from './util'
|
|
6
|
-
import { axios } from '../../axios'
|
|
7
|
-
import core, { Module } from '../../core'
|
|
8
|
-
import login from '../../login'
|
|
9
|
-
import { downloadService } from '../../oss'
|
|
10
|
-
import { apaasSpuTrackSendLog } from '../../apaasSpuTrack'
|
|
11
|
-
import { isWxworkSuiteTenant } from '@smart100/wxworksuite-plugin'
|
|
12
9
|
|
|
13
10
|
export default class SpuExpandexp extends HTMLElement {
|
|
14
11
|
|
|
@@ -69,7 +66,7 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
69
66
|
fileSize: '',
|
|
70
67
|
runningTaskCount: 0,
|
|
71
68
|
isOldVersionService: false,
|
|
72
|
-
isWxworkSuiteTenant: isWxworkSuiteTenant()
|
|
69
|
+
isWxworkSuiteTenant: wxworkSuite.isWxworkSuiteTenant()
|
|
73
70
|
}, (key: string, value: any) => {
|
|
74
71
|
const { exportConfigInit, stepName, stepText, exportcontentArray, exportcontent, isOldVersionService, runningTaskCount, fileName, filetype, fileSize, exportDataItem, percentage, resultMessage, isWxworkSuiteTenant } = this.data
|
|
75
72
|
|
|
@@ -94,8 +91,8 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
94
91
|
const $exportWxworkTip = this.shadow.querySelector('.export-wxwork-tip') as any
|
|
95
92
|
|
|
96
93
|
|
|
97
|
-
if (key === 'isWxworkSuiteTenant') {
|
|
98
|
-
this.vIf($exportWxworkTip, isWxworkSuiteTenant)
|
|
94
|
+
if (key === 'isWxworkSuiteTenant' || key === 'stepName') {
|
|
95
|
+
this.vIf($exportWxworkTip, isWxworkSuiteTenant && stepName === 'initial')
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
if (key === 'exportConfigInit') {
|
|
@@ -344,7 +341,7 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
344
341
|
}
|
|
345
342
|
|
|
346
343
|
async getExpandexpConfig () {
|
|
347
|
-
let isInstallexpandexp = await
|
|
344
|
+
let isInstallexpandexp = await Module.checkModule('expandexp')
|
|
348
345
|
// isInstallexpandexp = false
|
|
349
346
|
console.log('isInstallexpandexp', isInstallexpandexp)
|
|
350
347
|
|
|
@@ -354,32 +351,36 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
354
351
|
this.data.iscompress = '1'
|
|
355
352
|
|
|
356
353
|
// 这个单个查询接口返回的filewatermark已经结合了全局水印开关 因此不需要查询全局水印
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
354
|
+
spuAxios
|
|
355
|
+
.post(
|
|
356
|
+
'/imageConfig/getByPageCode',
|
|
357
|
+
{
|
|
358
|
+
pagecode: this.props.pagecode
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
modulekey: 'expandexp'
|
|
362
|
+
}
|
|
363
|
+
)
|
|
364
|
+
.then((res: any) => {
|
|
364
365
|
// console.log('imageConfig', code, data, msg)
|
|
365
|
-
if (code === 200) {
|
|
366
|
-
this.data.exportcontentArray = data.exportcontent
|
|
366
|
+
if (res.code === 200 && res.data) {
|
|
367
|
+
this.data.exportcontentArray = res.data.exportcontent
|
|
367
368
|
// this.data.exportcontentArray = ['photo']
|
|
368
369
|
if (this.data.exportcontentArray?.length > 0) {
|
|
369
370
|
this.data.exportcontent = this.data.exportcontentArray[0]
|
|
370
371
|
} else {
|
|
371
372
|
this.data.exportcontent = 'excel'
|
|
372
373
|
}
|
|
373
|
-
this.data.filewatermarkGlobalConfig = data.filewatermark.toString()
|
|
374
|
-
this.data.filewatermark = data.filewatermark.toString()
|
|
375
|
-
this.data.iscompress = data.iscompress.toString()
|
|
376
|
-
this.data.imagesizepercolumn = data.imagesizepercolumn.toString()
|
|
377
|
-
this.data.imageheightcm = data.imageheightcm.toString()
|
|
374
|
+
this.data.filewatermarkGlobalConfig = res.data.filewatermark.toString()
|
|
375
|
+
this.data.filewatermark = res.data.filewatermark.toString()
|
|
376
|
+
this.data.iscompress = res.data.iscompress.toString()
|
|
377
|
+
this.data.imagesizepercolumn = res.data.imagesizepercolumn.toString()
|
|
378
|
+
this.data.imageheightcm = res.data.imageheightcm.toString()
|
|
378
379
|
|
|
379
380
|
this.data.exportConfigInit = true
|
|
380
381
|
}
|
|
381
|
-
}
|
|
382
|
-
|
|
382
|
+
})
|
|
383
|
+
|
|
383
384
|
this.sendLog({
|
|
384
385
|
types: 'exportopenmodal',
|
|
385
386
|
event: 'exportopenmodal'
|
|
@@ -388,8 +389,8 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
388
389
|
axios
|
|
389
390
|
.post('/api/expandexp/global/searchExpGloConfig', {
|
|
390
391
|
key: 'export-config-switch',
|
|
391
|
-
tenantcode:
|
|
392
|
-
productcode:
|
|
392
|
+
tenantcode: getUser('tenantcode'),
|
|
393
|
+
productcode: getUser('productcode')
|
|
393
394
|
}, {}, {
|
|
394
395
|
isShowLoading: false
|
|
395
396
|
})
|
package/src/core.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { globalOptions } from './
|
|
2
|
-
import { get
|
|
3
|
-
import { axios } from './axios'
|
|
4
|
-
import login from './login'
|
|
1
|
+
import { globalOptions, axios, getUser, Module } from './index'
|
|
2
|
+
import { get } from 'lodash-es'
|
|
5
3
|
|
|
6
4
|
const urlIsIp = (url) => {
|
|
7
5
|
const hostname = url.split('://')[1].split(':')[0].split('/')[0]
|
|
@@ -53,8 +51,8 @@ class Core {
|
|
|
53
51
|
|
|
54
52
|
// 请求实时G3数据
|
|
55
53
|
async requestData () {
|
|
56
|
-
const nowEnvname = await
|
|
57
|
-
const nowTenantCode =
|
|
54
|
+
const nowEnvname = await Module.getEnvname()
|
|
55
|
+
const nowTenantCode = getUser('tenantcode') || ''
|
|
58
56
|
this.cache.envName = nowEnvname
|
|
59
57
|
this.cache.tenantCode = nowTenantCode
|
|
60
58
|
this.cache.envData = await this.requestEnvData(nowEnvname)
|
|
@@ -107,7 +105,7 @@ class Core {
|
|
|
107
105
|
}
|
|
108
106
|
// console.log(res)
|
|
109
107
|
// debugger
|
|
110
|
-
const list =
|
|
108
|
+
const list = res?.data?.list || []
|
|
111
109
|
if (list && list.length) {
|
|
112
110
|
const usedList = list.filter((item) => item.status === 1)
|
|
113
111
|
usedList.forEach((item) => {
|
|
@@ -132,11 +130,10 @@ class Core {
|
|
|
132
130
|
return result
|
|
133
131
|
}
|
|
134
132
|
|
|
135
|
-
|
|
136
133
|
requestDataPromise = null
|
|
137
134
|
async getData () {
|
|
138
|
-
const nowEnvname = await
|
|
139
|
-
const nowTenantCode =
|
|
135
|
+
const nowEnvname = await Module.getEnvname()
|
|
136
|
+
const nowTenantCode = getUser('tenantcode') || ''
|
|
140
137
|
// console.log(tenantCode)
|
|
141
138
|
if (this.cache.envName === nowEnvname && this.cache.tenantCode === nowTenantCode && this.loadStatus === 2) {
|
|
142
139
|
return this.cache
|
|
@@ -249,228 +246,8 @@ class Core {
|
|
|
249
246
|
const moduleData = await this.getModuleData(modulekey)
|
|
250
247
|
return !!moduleData.data
|
|
251
248
|
}
|
|
252
|
-
|
|
253
|
-
// pagecode: 'modulekey:indextag'
|
|
254
|
-
async createWebUrl (modulekey, indextag, queryvalue = {}) {
|
|
255
|
-
let url = ''
|
|
256
|
-
let errorMsg = ''
|
|
257
|
-
let indextagData
|
|
258
|
-
|
|
259
|
-
const moduleData = await this.getModuleData(modulekey)
|
|
260
|
-
if (moduleData.data) {
|
|
261
|
-
if (!indextag) {
|
|
262
|
-
errorMsg = '缺少 indextag,请检查。'
|
|
263
|
-
} else {
|
|
264
|
-
indextagData = (moduleData.data.protocol.indexs || []).find((item) => item.indextag === indextag)
|
|
265
|
-
if (indextagData) {
|
|
266
|
-
const queryUrl = await this.getQueryUrl(indextagData.query || [], queryvalue)
|
|
267
|
-
const context = await this.getContext(modulekey)
|
|
268
|
-
const moduleBusiness = await this.getModuleBusiness(modulekey)
|
|
269
|
-
if (indextagData.externalurl) {
|
|
270
|
-
url = `${indextagData.externalurl}`
|
|
271
|
-
} else if (indextagData.url) {
|
|
272
|
-
url = `${moduleBusiness}/${indextagData.url}`
|
|
273
|
-
} else {
|
|
274
|
-
url = `${moduleBusiness}/${moduleData.data.modulekey}/${moduleData.data.moduleversion}/${indextagData.path}${indextagData.location}`
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (url.indexOf('?') === -1) {
|
|
278
|
-
url += `?${queryUrl}indextag=${indextag}&context=${encodeURIComponent(JSON.stringify(context))}`
|
|
279
|
-
} else {
|
|
280
|
-
url += `&${queryUrl}indextag=${indextag}&context=${encodeURIComponent(JSON.stringify(context))}`
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
errorMsg = `找不到 indextag = ${indextag} 的页面信息。`
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
errorMsg = moduleData.errorMsg
|
|
288
|
-
}
|
|
289
|
-
return {
|
|
290
|
-
url,
|
|
291
|
-
indextagData,
|
|
292
|
-
errorMsg
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// pagecode: 'modulekey:indextag'
|
|
297
|
-
async createRouteUrl (modulekey, indextag, queryvalue) {
|
|
298
|
-
// &moduletype=${category === '1000' ? 'scene' : 'spu'}
|
|
299
|
-
// console.log(modulekey, indextag, queryvalue)
|
|
300
|
-
// debugger
|
|
301
|
-
if (!queryvalue) {
|
|
302
|
-
return `/module?modulekey=${modulekey}&indextag=${indextag}`
|
|
303
|
-
} else {
|
|
304
|
-
return `/module?modulekey=${modulekey}&indextag=${indextag}&queryvalue=${encodeURIComponent(JSON.stringify(queryvalue))}`
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
async getQueryUrl (query, queryvalue = {}) {
|
|
309
|
-
const data = await this.getData()
|
|
310
|
-
const buildInMap = {
|
|
311
|
-
'${token}': login.getToken(), // eslint-disable-line no-template-curly-in-string
|
|
312
|
-
'${refreshtoken}': login.getRefreshToken(), // eslint-disable-line no-template-curly-in-string
|
|
313
|
-
'${tokenexpires}': login.getTokenExpires(), // eslint-disable-line no-template-curly-in-string
|
|
314
|
-
'${envname}': data.envName || '' // eslint-disable-line no-template-curly-in-string
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (queryvalue) {
|
|
318
|
-
queryvalue = cloneDeep(queryvalue)
|
|
319
|
-
for (const x in queryvalue) {
|
|
320
|
-
if (x.indexOf('${') === 0) {
|
|
321
|
-
buildInMap[x] = queryvalue[x]
|
|
322
|
-
delete queryvalue[x]
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
let url = ''
|
|
328
|
-
query && query.length && query.forEach((item) => {
|
|
329
|
-
let value = ''
|
|
330
|
-
if (item.value.indexOf('${') === 0) {
|
|
331
|
-
const buildInValue = buildInMap[item.value]
|
|
332
|
-
value = typeof buildInValue !== 'undefined' ? buildInValue : ''
|
|
333
|
-
} else {
|
|
334
|
-
value = typeof item.value !== 'undefined' ? item.value : ''
|
|
335
|
-
}
|
|
336
|
-
if (queryvalue && typeof queryvalue[item.key] !== 'undefined') {
|
|
337
|
-
value = queryvalue[item.key]
|
|
338
|
-
}
|
|
339
|
-
url += `${item.key}=${value}&`
|
|
340
|
-
})
|
|
341
|
-
return url
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
async createApi (modulekey, apitag) {
|
|
345
|
-
let apiUrl = ''
|
|
346
|
-
let errorMsg = ''
|
|
347
|
-
let apitagData
|
|
348
|
-
|
|
349
|
-
const moduleData = await this.getModuleData(modulekey)
|
|
350
|
-
if (moduleData.data) {
|
|
351
|
-
if (!apitag) {
|
|
352
|
-
errorMsg = '缺少 apitag,请检查。'
|
|
353
|
-
} else {
|
|
354
|
-
apitagData = (moduleData.data.apiprotocol.apis || []).find((item) => item.apitag === apitag)
|
|
355
|
-
if (apitagData) {
|
|
356
|
-
if (apitagData.status === '1') {
|
|
357
|
-
const moduleBusiness = await this.getModuleBusiness(modulekey)
|
|
358
|
-
apiUrl = `${moduleBusiness}/api/${moduleData.data.modulekey}/${moduleData.data.moduleversion}/${apitagData.path}`
|
|
359
|
-
} else {
|
|
360
|
-
errorMsg = `apitag = ${apitag} 的 api 已停用。`
|
|
361
|
-
}
|
|
362
|
-
} else {
|
|
363
|
-
errorMsg = `找不到 apitag = ${apitag} 的 api 信息。`
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
} else {
|
|
367
|
-
errorMsg = moduleData.errorMsg
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return {
|
|
371
|
-
apiUrl,
|
|
372
|
-
apitagData,
|
|
373
|
-
errorMsg
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// async getApiOrigin (modulekey) {
|
|
378
|
-
// let apiOrigin = ''
|
|
379
|
-
// let errorMsg = ''
|
|
380
|
-
// const moduleData = await this.getModuleData(modulekey)
|
|
381
|
-
// if (moduleData.data) {
|
|
382
|
-
// const moduleBusiness = await this.getModuleBusiness(modulekey)
|
|
383
|
-
// apiOrigin = `${moduleBusiness}/api/${moduleData.data.modulekey}/${moduleData.data.moduleversion}/`
|
|
384
|
-
// } else {
|
|
385
|
-
// errorMsg = moduleData.errorMsg
|
|
386
|
-
// }
|
|
387
|
-
// return {
|
|
388
|
-
// apiOrigin,
|
|
389
|
-
// errorMsg
|
|
390
|
-
// }
|
|
391
|
-
// }
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
// Module.apiRequest({
|
|
395
|
-
// modulekey: 'demospu',
|
|
396
|
-
// apitag: 'pagelist',
|
|
397
|
-
// body: {
|
|
398
|
-
// pageindex: '1',
|
|
399
|
-
// pagesize: '1',
|
|
400
|
-
// status: '',
|
|
401
|
-
// name: ''
|
|
402
|
-
// },
|
|
403
|
-
// complete: (code, data, msg) => {
|
|
404
|
-
// if (code === 200) {
|
|
405
|
-
// console.log(data)
|
|
406
|
-
// } else {
|
|
407
|
-
// throw Error(msg)
|
|
408
|
-
// }
|
|
409
|
-
// }
|
|
410
|
-
// })
|
|
411
|
-
async apiRequest (params) {
|
|
412
|
-
// debugger
|
|
413
|
-
// params.modulekey = 'ss'
|
|
414
|
-
|
|
415
|
-
const result = {
|
|
416
|
-
code: '',
|
|
417
|
-
msg: '',
|
|
418
|
-
data: null
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const apiData = await this.createApi(params.modulekey, params.apitag)
|
|
422
|
-
// if (apiData.errorMsg) throw new Error(apiData.errorMsg)
|
|
423
|
-
if (apiData.errorMsg) {
|
|
424
|
-
result.code = 404
|
|
425
|
-
result.msg = apiData.errorMsg
|
|
426
|
-
} else {
|
|
427
|
-
if (apiData.apitagData.method === 'POST') {
|
|
428
|
-
// todo 校验 body
|
|
429
|
-
try {
|
|
430
|
-
const res = await axios.post(`${apiData.apiUrl}`, params.body, {
|
|
431
|
-
isShowErrorMessage: false
|
|
432
|
-
})
|
|
433
|
-
if (res?.data?.code === 200) {
|
|
434
|
-
result.code = 200
|
|
435
|
-
result.msg = res?.data?.msg || '请求成功。'
|
|
436
|
-
result.data = res?.data?.data
|
|
437
|
-
} else {
|
|
438
|
-
result.code = res?.data?.code || 404
|
|
439
|
-
result.msg = res?.data?.msg || '网络异常,请稍后重试。'
|
|
440
|
-
}
|
|
441
|
-
} catch (err) {
|
|
442
|
-
result.code = err?.response?.data?.code || err?.response?.status || 404
|
|
443
|
-
result.msg = err?.response?.data?.msg || err?.response?.statusText || '网络异常,请稍后重试。'
|
|
444
|
-
}
|
|
445
|
-
} else {
|
|
446
|
-
result.code = 404
|
|
447
|
-
result.msg = '暂不支持除了 POST 以外的其他方法'
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
params.complete && params.complete(result.code, result.data, result.msg)
|
|
452
|
-
return result
|
|
453
|
-
}
|
|
454
249
|
}
|
|
455
250
|
|
|
456
251
|
const core = new Core()
|
|
457
252
|
|
|
458
|
-
const Module = {
|
|
459
|
-
// getContextSync () {
|
|
460
|
-
// return core.getContext(modulekey)
|
|
461
|
-
// },
|
|
462
|
-
// linkToPage: core.linkToPage.bind(core),
|
|
463
|
-
// linkToModule: core.linkToModule.bind(core),
|
|
464
|
-
getModuleData: core.getModuleData.bind(core),
|
|
465
|
-
// getContext: core.getContext.bind(core),
|
|
466
|
-
getEnvData: core.getEnvData.bind(core),
|
|
467
|
-
apiRequest: core.apiRequest.bind(core),
|
|
468
|
-
checkModule: core.checkModule.bind(core)
|
|
469
|
-
}
|
|
470
|
-
|
|
471
253
|
export default core
|
|
472
|
-
|
|
473
|
-
export {
|
|
474
|
-
Module
|
|
475
|
-
}
|
|
476
|
-
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
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, axios } from './axios'
|
|
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
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
|
+
|
|
21
|
+
|
|
16
22
|
|
|
17
23
|
// class SPUWebPlugin {
|
|
18
24
|
// static install = install
|
|
@@ -21,16 +27,105 @@ import { jssdk, isWxworkSuiteTenant, isWxwork, isWxworkPc, isWxworkApp } from '@
|
|
|
21
27
|
// // SPUWebPlugin.install = install
|
|
22
28
|
// // SPUWebPlugin.version = version
|
|
23
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
|
+
|
|
24
112
|
const SPUWebPlugin = {
|
|
25
113
|
install,
|
|
26
114
|
version
|
|
27
115
|
}
|
|
28
116
|
|
|
117
|
+
|
|
118
|
+
|
|
29
119
|
const getToken = login.getToken.bind(login)
|
|
30
120
|
const getTokenExpires = login.getTokenExpires.bind(login)
|
|
31
121
|
const getRefreshToken = login.getRefreshToken.bind(login)
|
|
32
122
|
const getUser = login.getUser.bind(login)
|
|
33
123
|
const checkLogin = login.checkLogin.bind(login)
|
|
124
|
+
const singleLogin = login.singleLogin.bind(login)
|
|
125
|
+
const startRefreshtoken = login.startRefreshtoken.bind(login)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
34
129
|
const wxworkSuite = {
|
|
35
130
|
JSSDK: jssdk,
|
|
36
131
|
isWxworkSuiteTenant,
|
|
@@ -39,8 +134,19 @@ const wxworkSuite = {
|
|
|
39
134
|
isWxworkApp
|
|
40
135
|
}
|
|
41
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
|
+
|
|
42
147
|
export {
|
|
43
148
|
SPUWebPlugin as default,
|
|
149
|
+
globalOptions,
|
|
44
150
|
lsProxy,
|
|
45
151
|
ssProxy,
|
|
46
152
|
getLocation,
|
|
@@ -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,
|