@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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "",
5
5
  "scripts": {
6
- "dev": "rollup -c -w",
7
- "build": "rollup -c && npm run build:types",
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.3",
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"
@@ -1,11 +1,12 @@
1
- import { globalOptions } from './install'
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 = login.getUser()
8
- const envname = await login.getEnvname()
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 login from './login'
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' | 'apaas' = 'spu', options: SPUWebPluginOptions) => {
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' | 'apaas' = 'spu', options: SPUWebPlugi
35
35
 
36
36
  const isSendToken = get(config, 'isSendToken', true)
37
37
  if (isSendToken) {
38
- const token = login.getToken()
38
+ const token = getToken()
39
39
  if (config?.headers && token) {
40
40
  config.headers.token = token
41
41
  }
@@ -88,7 +88,7 @@ const createAxiosInstance = (type: 'spu' | 'apaas' = 'spu', options: SPUWebPlugi
88
88
  }
89
89
  return Promise.reject(realRes) as any
90
90
  }
91
- } else if (type === 'apaas') {
91
+ } else if (type === 'normal') {
92
92
  realRes = {
93
93
  code: res.status || 200,
94
94
  data: res.data?.resp_data || res.data,
@@ -118,7 +118,7 @@ const createAxiosInstance = (type: 'spu' | 'apaas' = 'spu', options: SPUWebPlugi
118
118
  } else {
119
119
  return false
120
120
  }
121
- } else if (type === 'apaas') {
121
+ } else if (type === 'normal') {
122
122
  if (msg.indexOf('token is invalid(decode).') !== -1 || msg.indexOf('token is invalid(null).') !== -1 || msg === 'token无效,请重新登录' || msg === 'jwt token无效') {
123
123
  return true
124
124
  } else {
@@ -139,19 +139,16 @@ const createAxiosInstance = (type: 'spu' | 'apaas' = 'spu', options: SPUWebPlugi
139
139
  return axiosInstance
140
140
  }
141
141
 
142
- // const spuAxios: AxiosInstance = createAxiosInstance('spu')
143
- // const apaasAxios: AxiosInstance = createAxiosInstance('apaas')
144
-
145
142
  let spuAxios: any = null
146
- let apaasAxios: any = null
143
+ let normalAxios: any = null
147
144
 
148
- function initAxios (options: SPUWebPluginOptions) {
145
+ function initAxios (options: any) {
149
146
  spuAxios = createAxiosInstance('spu', options)
150
- apaasAxios = createAxiosInstance('apaas', options)
147
+ normalAxios = createAxiosInstance('normal', options)
151
148
  }
152
149
 
153
150
  export {
154
151
  initAxios,
155
152
  spuAxios,
156
- apaasAxios
153
+ normalAxios as axios
157
154
  }
package/src/cloudServ.ts CHANGED
@@ -1,63 +1,5 @@
1
1
  import { lsProxy } from './storageProxy'
2
2
 
3
- // let cacheStorage: NormalizedCloudServ | null = null
4
-
5
- // const CLOUDSERVE = 'cloudserv'
6
-
7
- // const set = (storage: NormalizedCloudServ | string) => {
8
- // if (typeof storage === 'object') {
9
- // cacheStorage = storage
10
- // storage = JSON.stringify(storage)
11
- // }
12
- // lsProxy.setItem(CLOUDSERVE, storage)
13
- // }
14
-
15
- // const get = (key: StorageType = 'storage'): NormalizedCloudServItem | null => {
16
- // if (cacheStorage) {
17
- // return cacheStorage[key as StorageType] || null
18
- // }
19
- // const storageStr = lsProxy.getItem(CLOUDSERVE)
20
- // if (!storageStr) {
21
- // return null
22
- // }
23
- // const storage = JSON.parse(storageStr)
24
- // cacheStorage = storage
25
- // return storage[key]
26
- // }
27
-
28
- // const getProvider = (sign: StorageType = 'storage') => {
29
- // const storage: NormalizedCloudServItem | null = get(sign)
30
- // if (!storage) {
31
- // return false
32
- // }
33
- // return storage.cloudserv_storage_provider
34
- // }
35
-
36
- // const isAliyun = (sign: StorageType = 'storage') => {
37
- // return getProvider(sign) === 'aliyun'
38
- // }
39
-
40
- // const isAzure = (sign: StorageType = 'storage') => {
41
- // return getProvider(sign) === 'azure'
42
- // }
43
-
44
- // const isAwss3 = (sign: StorageType = 'storage') => {
45
- // return getProvider(sign) === 'awss3'
46
- // }
47
-
48
- // const isHuawei = (sign: StorageType = 'storage') => {
49
- // return getProvider(sign) === 'huawei'
50
- // }
51
-
52
- // export default {
53
- // set,
54
- // get,
55
- // isAliyun,
56
- // isAzure,
57
- // isAwss3,
58
- // isHuawei
59
- // }
60
-
61
3
  class CloudServ {
62
4
  CLOUD_SERVE_KEY = 'cloudserv'
63
5
 
@@ -1,13 +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 { apaasAxios } from '../../axios'
7
- import core, { Module } from '../../core'
8
- import login from '../../login'
9
- import { downloadService } from '../../oss'
10
- import { apaasSpuTrackSendLog } from '../../apaasSpuTrack'
11
9
 
12
10
  export default class SpuExpandexp extends HTMLElement {
13
11
 
@@ -67,9 +65,10 @@ export default class SpuExpandexp extends HTMLElement {
67
65
  fileName: '',
68
66
  fileSize: '',
69
67
  runningTaskCount: 0,
70
- isOldVersionService: false
68
+ isOldVersionService: false,
69
+ isWxworkSuiteTenant: wxworkSuite.isWxworkSuiteTenant()
71
70
  }, (key: string, value: any) => {
72
- const { exportConfigInit, stepName, stepText, exportcontentArray, exportcontent, isOldVersionService, runningTaskCount, fileName, filetype, fileSize, exportDataItem, percentage, resultMessage } = this.data
71
+ const { exportConfigInit, stepName, stepText, exportcontentArray, exportcontent, isOldVersionService, runningTaskCount, fileName, filetype, fileSize, exportDataItem, percentage, resultMessage, isWxworkSuiteTenant } = this.data
73
72
 
74
73
  // debugger
75
74
  const $exportSel = this.shadow.querySelector('.export-sel') as any
@@ -89,6 +88,12 @@ export default class SpuExpandexp extends HTMLElement {
89
88
  const $filesize = this.shadow.querySelector('.export-file-l-filesize') as any
90
89
  const $wait = this.shadow.querySelector('.export-wait') as any
91
90
  const $waitSpan = this.shadow.querySelector('.export-wait span') as any
91
+ const $exportWxworkTip = this.shadow.querySelector('.export-wxwork-tip') as any
92
+
93
+
94
+ if (key === 'isWxworkSuiteTenant' || key === 'stepName') {
95
+ this.vIf($exportWxworkTip, isWxworkSuiteTenant && stepName === 'initial')
96
+ }
92
97
 
93
98
  if (key === 'exportConfigInit') {
94
99
  this.vIf($exportSelCon, exportConfigInit)
@@ -324,8 +329,6 @@ export default class SpuExpandexp extends HTMLElement {
324
329
  this.handleCencel()
325
330
  })
326
331
 
327
-
328
-
329
332
  this.shadow.querySelector('.export-btn')!.addEventListener('click', () => {
330
333
  // console.log('导出')
331
334
  this.handleExport()
@@ -338,7 +341,7 @@ export default class SpuExpandexp extends HTMLElement {
338
341
  }
339
342
 
340
343
  async getExpandexpConfig () {
341
- let isInstallexpandexp = await core.checkModule('expandexp')
344
+ let isInstallexpandexp = await Module.checkModule('expandexp')
342
345
  // isInstallexpandexp = false
343
346
  console.log('isInstallexpandexp', isInstallexpandexp)
344
347
 
@@ -348,42 +351,46 @@ export default class SpuExpandexp extends HTMLElement {
348
351
  this.data.iscompress = '1'
349
352
 
350
353
  // 这个单个查询接口返回的filewatermark已经结合了全局水印开关 因此不需要查询全局水印
351
- Module.apiRequest({
352
- modulekey: 'expandexp',
353
- apitag: 'imageConfig-getByPageCode',
354
- body: {
355
- pagecode: this.props.pagecode
356
- },
357
- complete: (code: any, data: any, msg: any) => {
354
+ spuAxios
355
+ .post(
356
+ '/imageConfig/getByPageCode',
357
+ {
358
+ pagecode: this.props.pagecode
359
+ },
360
+ {
361
+ modulekey: 'expandexp'
362
+ }
363
+ )
364
+ .then((res: any) => {
358
365
  // console.log('imageConfig', code, data, msg)
359
- if (code === 200) {
360
- this.data.exportcontentArray = data.exportcontent
366
+ if (res.code === 200 && res.data) {
367
+ this.data.exportcontentArray = res.data.exportcontent
361
368
  // this.data.exportcontentArray = ['photo']
362
369
  if (this.data.exportcontentArray?.length > 0) {
363
370
  this.data.exportcontent = this.data.exportcontentArray[0]
364
371
  } else {
365
372
  this.data.exportcontent = 'excel'
366
373
  }
367
- this.data.filewatermarkGlobalConfig = data.filewatermark.toString()
368
- this.data.filewatermark = data.filewatermark.toString()
369
- this.data.iscompress = data.iscompress.toString()
370
- this.data.imagesizepercolumn = data.imagesizepercolumn.toString()
371
- 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()
372
379
 
373
380
  this.data.exportConfigInit = true
374
381
  }
375
- }
376
- })
382
+ })
383
+
377
384
  this.sendLog({
378
385
  types: 'exportopenmodal',
379
386
  event: 'exportopenmodal'
380
387
  })
381
388
  } else {
382
- apaasAxios
389
+ axios
383
390
  .post('/api/expandexp/global/searchExpGloConfig', {
384
391
  key: 'export-config-switch',
385
- tenantcode: login.getUser('tenantcode'),
386
- productcode: login.getUser('productcode')
392
+ tenantcode: getUser('tenantcode'),
393
+ productcode: getUser('productcode')
387
394
  }, {}, {
388
395
  isShowLoading: false
389
396
  })
@@ -416,7 +423,7 @@ export default class SpuExpandexp extends HTMLElement {
416
423
  this.data.iscompress = '1'
417
424
 
418
425
  // 获取文件水印开关
419
- apaasAxios
426
+ axios
420
427
  .post('/api/expandexp/global/searchWatermarkConfig', '', {
421
428
  isShowLoading: false
422
429
  })
@@ -486,7 +493,7 @@ export default class SpuExpandexp extends HTMLElement {
486
493
  }
487
494
  }
488
495
  const finallyPost = mergedata ? merge(mergedata, post) : post
489
- apaasAxios
496
+ axios
490
497
  .post(this.props.exportapi, finallyPost)
491
498
  .then((res: any) => {
492
499
  // console.log(res)
@@ -606,7 +613,7 @@ export default class SpuExpandexp extends HTMLElement {
606
613
  // console.log(this.data)
607
614
  // console.log(this.data.exportDataItem)
608
615
 
609
- apaasAxios
616
+ axios
610
617
  .post('/api/teapi/queue/impexp/cancel', {
611
618
  dynamicid: this.data.exportId
612
619
  })
@@ -653,7 +660,7 @@ export default class SpuExpandexp extends HTMLElement {
653
660
  }
654
661
 
655
662
  async updateStatus () {
656
- apaasAxios
663
+ axios
657
664
  .post(`/api/teapi/queue/impexp/expStatus?dynamicid=${this.data.exportId}`, {}, {
658
665
  isShowLoading: false
659
666
  })
@@ -173,6 +173,11 @@ export default (ele: SpuExpandexp) => {
173
173
  height: 32px;
174
174
  }
175
175
 
176
+ .export-wxwork-tip {
177
+ margin-bottom: 12px;
178
+ font-size: 14px;
179
+ }
180
+
176
181
  .export-sel {
177
182
  margin-bottom: 12px;
178
183
  }
@@ -420,6 +425,8 @@ export default (ele: SpuExpandexp) => {
420
425
  导出等待队列中:还有<span></span>位,请耐心稍等...
421
426
  </div>
422
427
 
428
+ <div class="export-wxwork-tip hide">提醒:导出前请联系管理员确认已在人员管理模块进行了同步企微端人员和组织名称的操作,否则导出字段将会显示异常!</div>
429
+
423
430
  <div class="export-sel hide">
424
431
  <div class="export-sel-title">请选择导出内容</div>
425
432
  <div class="export-sel-con hide"></div>
package/src/core.js CHANGED
@@ -1,7 +1,5 @@
1
- import { globalOptions } from './install'
2
- import { get, cloneDeep } from 'lodash-es'
3
- import { apaasAxios as 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 login.getEnvname()
57
- const nowTenantCode = login.getUser('tenantcode') || ''
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 = get(res, 'data.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 login.getEnvname()
139
- const nowTenantCode = login.getUser('tenantcode') || ''
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
-