@smart100/spu-web-plugin 0.0.6 → 0.0.7

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,13 +1,13 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "rollup -c -w",
7
7
  "build": "rollup -c && npm run build:types",
8
8
  "build:types": "node script/build-types.js"
9
9
  },
10
- "author": "tarymee",
10
+ "author": "tarymee <tarymee@qq.com>",
11
11
  "type": "module",
12
12
  "browser1": "dist/spu-web-plugin.umd.js",
13
13
  "main1": "dist/spu-web-plugin.cjs",
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import { install } from './install'
3
3
  import { lsProxy, ssProxy } from './storageProxy'
4
4
  import { getLocation, getDistance } from './location'
5
5
  import { spuAxios, apaasAxios } from './axios'
6
+ import { spuConfig } from './spuConfig'
6
7
  import { downloadService, uploadService } from './oss'
7
8
  import { getUniqueid } from './utils'
8
9
  import AMapLoader from './AMapLoader'
@@ -38,6 +39,7 @@ export {
38
39
  getDistance,
39
40
  spuAxios,
40
41
  apaasAxios,
42
+ spuConfig,
41
43
  downloadService,
42
44
  uploadService,
43
45
  getUniqueid,
package/src/install.ts CHANGED
@@ -2,6 +2,7 @@ import { initStorageProxy } from './storageProxy'
2
2
  import login from './login'
3
3
  import { initAxios } from './axios'
4
4
  import urlquery from './urlquery'
5
+ import { initSpuConfig } from './spuConfig'
5
6
  // import tenantInfo from './tenantInfo'
6
7
  // import { downloadService } from './oss'
7
8
 
@@ -22,6 +23,7 @@ const install = (app: any, options: SPUWebPluginOptions) => {
22
23
 
23
24
  initStorageProxy(options)
24
25
  initAxios(options)
26
+ initSpuConfig(options)
25
27
  urlquery.init()
26
28
  login.startRefreshtoken()
27
29
 
@@ -0,0 +1,97 @@
1
+ import { spuAxios } from './axios'
2
+ import { cloneDeep } from 'lodash-es'
3
+
4
+ let modulekey = ''
5
+
6
+ class SpuConfig {
7
+ private isload = false
8
+
9
+ cache: any[] = []
10
+
11
+ public async get (dataid?: string | string[]): Promise<any> {
12
+ if (!this.isload) {
13
+ try {
14
+ const res = await spuAxios.post('/lifecycle/getconfigdata', {
15
+ // modulekey: 'litheformspu'
16
+ modulekey: modulekey
17
+ })
18
+ // console.log(res)
19
+ // debugger
20
+ if (res.code === 200) {
21
+ this.cache = res?.data?.configs || []
22
+ }
23
+ } catch (err) {
24
+ console.error(err)
25
+ }
26
+ this.isload = true
27
+ }
28
+
29
+ if (dataid) {
30
+ if (Array.isArray(dataid)) {
31
+ return cloneDeep(this.cache.filter((item: any) => (dataid.some((item2) => item2 === item.dataid))))
32
+ } else {
33
+ return cloneDeep(this.cache.find((item: any) => item.dataid === dataid))
34
+ }
35
+ } else {
36
+ return cloneDeep(this.cache)
37
+ }
38
+ }
39
+
40
+ // public async set (configs: any[]) {
41
+ // let isSaveSuccess = false
42
+
43
+ // configs.forEach((item: any) => {
44
+ // const index = this.cache.findIndex((item1: any) => item1.dataid === item.dataid)
45
+ // if (index >= 0) {
46
+ // this.cache[index] = item
47
+ // } else {
48
+ // this.cache.push(item)
49
+ // }
50
+ // })
51
+
52
+ // try {
53
+ // const initconfigRes = await spuAxios.post('/lifecycle/initconfig', {
54
+ // context: {
55
+ // // envid: selectEnv.conn.envid,
56
+ // // envname: selectEnv.conn.name,
57
+ // // tenantcode: tenantData.tenantcode,
58
+ // // modulecode: moduleData.modulecode,
59
+ // // modulekey: moduleData.modulekey,
60
+ // // modulename: moduleData.modulename,
61
+ // // versioncode: versionData.versioncode,
62
+ // // versionnum: versionData.versionnum,
63
+ // // serviceversion: ''
64
+ // },
65
+ // configs: this.cache,
66
+ // extend: {}
67
+ // })
68
+ // if (initconfigRes.code === 200) {
69
+ // const logRes = await spuAxios.post('/api/smartcenter/tenantModule/saveOpLog', {
70
+ // // envid: selectEnv.conn.envid,
71
+ // // tenantcode: tenantData.tenantcode,
72
+ // // versioncode: versionData.versioncode,
73
+ // // modulecode: moduleData.modulecode,
74
+ // logdatas: initconfigRes.data.logdatas,
75
+ // serviceversion: initconfigRes.data.serviceversion
76
+ // })
77
+ // if (logRes.code === 200) {
78
+ // isSaveSuccess = true
79
+ // }
80
+ // }
81
+ // } catch (err) {
82
+ // console.error(err)
83
+ // }
84
+ // return isSaveSuccess
85
+ // }
86
+ }
87
+
88
+ function initSpuConfig (options: SPUWebPluginOptions) {
89
+ modulekey = options.modulekey
90
+ }
91
+
92
+ const spuConfig = new SpuConfig()
93
+
94
+ export {
95
+ initSpuConfig,
96
+ spuConfig
97
+ }