@smart100/spu-web-plugin 0.0.6 → 0.0.8

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,14 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "rollup -c -w",
7
7
  "build": "rollup -c && npm run build:types",
8
- "build:types": "node script/build-types.js"
8
+ "build:types": "node script/build-types.js",
9
+ "docs": "cd ./docs && npm run docs"
9
10
  },
10
- "author": "tarymee",
11
+ "author": "tarymee <tarymee@qq.com>",
11
12
  "type": "module",
12
13
  "browser1": "dist/spu-web-plugin.umd.js",
13
14
  "main1": "dist/spu-web-plugin.cjs",
package/src/index.ts CHANGED
@@ -3,8 +3,9 @@ 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
- import { getUniqueid } from './utils'
8
+ import { getUniqueid, functionCheck } from './utils'
8
9
  import AMapLoader from './AMapLoader'
9
10
  import login from './login'
10
11
  import { v4 as getUuid } from 'uuid'
@@ -38,10 +39,12 @@ export {
38
39
  getDistance,
39
40
  spuAxios,
40
41
  apaasAxios,
42
+ spuConfig,
41
43
  downloadService,
42
44
  uploadService,
43
45
  getUniqueid,
44
46
  getUuid,
47
+ functionCheck,
45
48
  AMapLoader,
46
49
  getToken,
47
50
  getTokenExpires,
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,12 +23,10 @@ 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
 
28
-
29
-
30
-
31
30
  // setTimeout(async () => {
32
31
  // const a = await downloadService.getUrl({
33
32
  // // source: 'a1b9954a-fb39-4bb2-aa0b-501f4af0d99e.jpeg',
package/src/login.ts CHANGED
@@ -3,6 +3,7 @@ import jwtDecode from 'jwt-decode'
3
3
  import { apaasAxios } from './axios'
4
4
  import tenantInfo from './tenantInfo'
5
5
  import { lsProxy } from './storageProxy'
6
+ // import { functionCheck } from './utils'
6
7
 
7
8
  type JwtResult = {
8
9
  LoginUser: IAny
@@ -191,6 +192,22 @@ class Login {
191
192
  return haslogged
192
193
  }
193
194
 
195
+ // 接口请求回来的 userInfo 有 functioncodes 以便做权限校验
196
+ async getAndSetUserInfo () {
197
+ return apaasAxios.post('/api/teapi/rolepermission/account/getaccountinfo', {
198
+ positionid: this.getUser('positioncode'),
199
+ deviceinfo: 'h5',
200
+ sysversion: 'h5',
201
+ clientversion: 'h5'
202
+ }).then((res: any) => {
203
+ // console.log(res)
204
+ // debugger
205
+ if (res.code === 200 && res.data) {
206
+ this.setUser(res.data)
207
+ }
208
+ })
209
+ }
210
+
194
211
  // 单点登录
195
212
  async singleLogin (query: IAny) {
196
213
  // 自动登录
@@ -219,18 +236,11 @@ class Login {
219
236
  delete query.context
220
237
  }
221
238
 
222
- // const tenant = await apassRequest.get('/api/auth/tenantlist', {}).then((res) => {
223
- // return res?.data?.tenants?.[0]
224
- // })
225
- // if (tenant) {
226
- // lsProxy.setItem('tenant', JSON.stringify(tenant))
227
- // const normalizedTenant = tenantInfoApi.format(tenant as Tenant)
228
- // normalizedTenant && tenantInfoApi.save(normalizedTenant)
229
- // }
230
- // console.log(tenant)
231
-
232
239
  await tenantInfo.getAndSave()
233
- // debugger
240
+ await this.getAndSetUserInfo()
241
+
242
+ // const ischeck = functionCheck('1429379220684842752')
243
+ // console.log(ischeck)
234
244
  } else {
235
245
  console.error('query 中没有 token,无法单点登录。')
236
246
  }
@@ -238,7 +248,7 @@ class Login {
238
248
  delete query.token
239
249
  delete query.refreshtoken
240
250
  delete query.tokenexpires
241
- delete query.context
251
+ // debugger
242
252
  return {
243
253
  query
244
254
  }
@@ -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
+ }
package/src/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import login from './login'
2
+
1
3
  const isIOS = () => {
2
4
  const ua = navigator.userAgent
3
5
  return /(iPhone|iPad|iPod|IOS)/i.test(ua)
@@ -27,10 +29,20 @@ const getUniqueid = () => {
27
29
  }
28
30
 
29
31
 
32
+ const functionCheck = (functioncode?: string): boolean => {
33
+ if (!functioncode) return false
34
+ const functioncodes = login.getUser('functioncodes') || []
35
+ // console.log(functioncodes)
36
+ // debugger
37
+ const check = functioncodes.includes(functioncode)
38
+ return !!check
39
+ }
40
+
30
41
  export {
31
42
  isIOS,
32
43
  isInWxwork,
33
44
  isInPcWxwork,
34
45
  isInAppWxwork,
35
- getUniqueid
46
+ getUniqueid,
47
+ functionCheck
36
48
  }