@smart100/spu-web-plugin 1.0.8 → 1.0.9

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
package/src/index.ts CHANGED
@@ -2,14 +2,15 @@ import { version } from '../package.json'
2
2
  import { merge } from 'lodash-es'
3
3
  import { v4 as getUuid } from 'uuid'
4
4
  import { installStorageProxy, lsProxy, ssProxy } from './storageProxy'
5
- import { getLocation, getDistance } from './location'
5
+ import { getLocation, getDistance } from './map/index'
6
6
  import { installAxios, spuAxios, axios } from './axios'
7
7
  import { installSpuConfig, spuConfig } from './spuConfig'
8
8
  import { globalConfig } from './globalConfig'
9
9
  import { downloadService, uploadService } from './oss'
10
10
  import { getUniqueid, functionCheck, setTitle, isInApp, isdebugger, isvirtuallocation } from './utils'
11
11
  import { installUrlquery } from './urlquery'
12
- import AMapLoader from './AMapLoader'
12
+ import { mapService } from './map/MapService'
13
+ import AMapLoader from './map/AMapLoader'
13
14
  import {
14
15
  getToken,
15
16
  checkLogin,
@@ -113,6 +114,7 @@ export {
113
114
  setTitle,
114
115
  isInApp,
115
116
  AMapLoader,
117
+ mapService,
116
118
  singleLogin,
117
119
  updateToken,
118
120
  getToken,
package/src/login.ts CHANGED
@@ -5,7 +5,6 @@ import { axios } from './axios'
5
5
  import cloudServ from './cloudServ'
6
6
  import core from './core'
7
7
  import { urlquery } from './urlquery'
8
- import { decrypt } from './crypt'
9
8
  import { getData, setData, removeData } from './storageCache'
10
9
  import {
11
10
  setQueryEnvname,
@@ -15,9 +14,9 @@ import {
15
14
  removeEnvdata,
16
15
  saveEnvdata,
17
16
  setTecode,
18
- removeTecode,
19
- getTecode
17
+ removeTecode
20
18
  } from './envService'
19
+ import { tenantSetting } from './tenantSetting'
21
20
 
22
21
  type JwtResult = {
23
22
  LoginUser: IAny
@@ -358,41 +357,6 @@ async function getAndSetTenant(tenantcode?: string) {
358
357
  }
359
358
  }
360
359
 
361
- async function requestAndSetTenantSetting(tenantcode?: string) {
362
- try {
363
- const res = await axios.post(
364
- '/api/auth/tenantsettings',
365
- {
366
- tenantcode: tenantcode || ''
367
- },
368
- {
369
- isSendToken: false,
370
- isSendTecode: true,
371
- isShowErrorMessage: false
372
- }
373
- )
374
-
375
- let tenantSetting = res?.data?.resp_data?.econfig || ''
376
- if (tenantSetting) {
377
- tenantSetting = decrypt(tenantSetting)
378
- }
379
- // console.log(tenantSetting)
380
- if (tenantSetting) {
381
- lsProxy.setItem('tenantsetting', tenantSetting)
382
- } else {
383
- removeTenantSetting()
384
- }
385
- } catch (err) {
386
- console.error(err)
387
- removeTenantSetting()
388
- }
389
- }
390
-
391
- function removeTenantSetting() {
392
- lsProxy.removeItem('tenantsetting')
393
- }
394
-
395
-
396
360
  function updateToken() {
397
361
  const loginState = getLoginState()
398
362
 
@@ -468,7 +432,7 @@ function startRefreshtoken() {
468
432
  if (loginState.type === 2) {
469
433
  time = 0
470
434
  } else {
471
- console.error('未登录,10秒后尝试更新token')
435
+ // console.error('未登录,10秒后尝试更新token')
472
436
  time = 30000
473
437
  }
474
438
  }
@@ -481,8 +445,6 @@ function startRefreshtoken() {
481
445
  }, time)
482
446
  }
483
447
 
484
-
485
-
486
448
  // 单点登录
487
449
  async function singleLogin(query: IAny) {
488
450
  query = cloneDeep(query)
@@ -560,9 +522,9 @@ async function singleLogin(query: IAny) {
560
522
  if (envData.tenantcode) {
561
523
  setTecode(envData.tenantcode)
562
524
  // 租户配置
563
- await requestAndSetTenantSetting(envData.tenantcode)
525
+ await tenantSetting.requestAndSetTenantSetting(envData.tenantcode)
564
526
  } else {
565
- removeTenantSetting()
527
+ tenantSetting.removeTenantSetting()
566
528
  removeTecode()
567
529
  }
568
530
  } else {
@@ -0,0 +1,31 @@
1
+ import { mapService } from './MapService'
2
+
3
+ // 高德地图 web端key 和 安全密钥
4
+ const AMapKey = {
5
+ // 测试开发环境
6
+ dev: {
7
+ key: '38fa4702d240e1e6ee5cc8ca059b254f',
8
+ securityJsCode: '96f2af5670b7a41a56dcd2e8b63c1e06'
9
+ },
10
+ // 生产环境
11
+ production: {
12
+ key: '1993ac213d2f4675ac1bffb1b03ef1f0',
13
+ securityJsCode: '816fe46b7b7bce145940b93c1e4818fa'
14
+ }
15
+ }
16
+
17
+ const getAMapKey = () => {
18
+ if (mapService.isLbssettingEnable && mapService.type === 'amap') {
19
+ return {
20
+ key: mapService.key,
21
+ securityJsCode: mapService.secretkey
22
+ }
23
+ } else {
24
+ return {
25
+ key: AMapKey.production.key,
26
+ securityJsCode: AMapKey.production.securityJsCode
27
+ }
28
+ }
29
+ }
30
+
31
+ export { AMapKey, getAMapKey }
@@ -0,0 +1,43 @@
1
+ import AMapLoader from '@amap/amap-jsapi-loader'
2
+ import { AMapKey } from './AMapKey'
3
+ import { getAMapKey } from './AMapKey'
4
+
5
+ let isinit = false
6
+
7
+ const load = (options?: {
8
+ plugins?: Array<string>
9
+ AMapUI?: {
10
+ plugins?: Array<string>
11
+ }
12
+ }) => {
13
+ const AMapKey = getAMapKey()
14
+ if (!isinit) {
15
+ isinit = true
16
+ if (AMapKey.securityJsCode) {
17
+ // 本来想改成取消安全秘钥 但考虑到其他spu有可能用了需要安全秘钥的功能 因此不取消
18
+ // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
19
+ window._AMapSecurityConfig = {
20
+ securityJsCode: AMapKey.securityJsCode
21
+ }
22
+ }
23
+ }
24
+
25
+ // 不开放地址查询 改用ipaas
26
+ const plugin = ['AMap.Geolocation']
27
+ // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
28
+
29
+ return AMapLoader.load({
30
+ key: AMapKey.key,
31
+ version: '2.0',
32
+ plugins: options?.plugins || plugin,
33
+ AMapUI: {
34
+ version: '1.1',
35
+ plugins: options?.AMapUI?.plugins || []
36
+ }
37
+ })
38
+ }
39
+
40
+ export default {
41
+ AMapKey,
42
+ load
43
+ }
@@ -0,0 +1,167 @@
1
+ import { importJS, delay } from '../utils'
2
+ import { tenantSetting } from '../tenantSetting'
3
+ import { AMapKey } from './AMapKey'
4
+ import AMapLoader from '@amap/amap-jsapi-loader'
5
+
6
+ type MapType = 'amap' | 'tencent' | 'baidu'
7
+
8
+ type MapSupportType = 'android' | 'harmony' | 'ios' | 'web' | 'server'
9
+
10
+ interface ILbsSetting {
11
+ type: MapType
12
+ key: Record<MapSupportType, string>
13
+ secretkey: Record<MapSupportType, string>
14
+ }
15
+
16
+ interface ILbsSettingData {
17
+ enable: string
18
+ setting: ILbsSetting
19
+ }
20
+
21
+ class MapService {
22
+ isInit = false
23
+
24
+ get isLbssettingEnable() {
25
+ return tenantSetting.get('lbssetting')?.enable === '1'
26
+ }
27
+
28
+ private get setting(): ILbsSetting | undefined {
29
+ return tenantSetting.get('lbssetting')?.setting
30
+ }
31
+
32
+ get key() {
33
+ if (this.isLbssettingEnable) {
34
+ return this.setting?.key?.web || ''
35
+ } else {
36
+ return AMapKey.production.key
37
+ }
38
+ }
39
+
40
+ get secretkey() {
41
+ if (this.isLbssettingEnable) {
42
+ return this.setting?.secretkey?.web || ''
43
+ } else {
44
+ return AMapKey.production.securityJsCode
45
+ }
46
+ }
47
+
48
+ get type(): MapType {
49
+ if (this.isLbssettingEnable) {
50
+ return this.setting?.type || 'amap'
51
+ } else {
52
+ return 'amap'
53
+ }
54
+ }
55
+
56
+ get AMap() {
57
+ if (!this.isInit || this.type !== 'amap') {
58
+ return null
59
+ }
60
+ return window.AMap
61
+ }
62
+
63
+ get TMap() {
64
+ if (!this.isInit || this.type !== 'tencent') {
65
+ return null
66
+ }
67
+ return window.TMap
68
+ }
69
+
70
+ get BMap() {
71
+ if (!this.isInit || this.type !== 'baidu') {
72
+ return null
73
+ }
74
+ return window.BMap
75
+ }
76
+
77
+ async init() {
78
+ if (this.isInit) return
79
+
80
+ this.isInit = true
81
+
82
+ const type = this.type
83
+
84
+ // if (process.env.NODE_ENV === 'development') {
85
+ // type = 'baidu'
86
+ // }
87
+ if (type === 'tencent') {
88
+ await this.initTecent()
89
+ } else if (type === 'amap') {
90
+ await this.initAmap()
91
+ } else if (type === 'baidu') {
92
+ await this.initBaidu()
93
+ }
94
+ }
95
+
96
+ // reset() {
97
+ // this.isInit = false
98
+ // }
99
+
100
+ private async initTecent() {
101
+ await importJS(
102
+ `https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=${this.key}`,
103
+ // `https://map.qq.com/api/gljs?v=1.exp&key=${this.key}`,
104
+ 'TMap'
105
+ )
106
+ await delay(300)
107
+ }
108
+
109
+ private async initAmap() {
110
+ // if (this.secretkey) {
111
+ // window._AMapSecurityConfig = {
112
+ // securityJsCode: this.secretkey
113
+ // }
114
+ // }
115
+
116
+ const plugin = ['AMap.Geolocation']
117
+ // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
118
+
119
+ const AMap = await AMapLoader.load({
120
+ key: this.key,
121
+ version: '2.0',
122
+ plugins: plugin,
123
+ AMapUI: {
124
+ version: '1.1',
125
+ plugins: []
126
+ }
127
+ })
128
+ window.AMap = AMap
129
+ // console.log(window)
130
+ // console.log(window.AMap)
131
+ // console.log(window.AMapUI)
132
+ // console.log(window.AMapLoader)
133
+ // console.log(window.AMap === aaaa)
134
+ }
135
+
136
+ private async initBaidu() {
137
+ // await importJS(
138
+ // `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}`,
139
+ // 'BMap'
140
+ // )
141
+ // await delay(300)
142
+ // function initialize() {
143
+ // const mp = new BMap.Map('map')
144
+ // mp.centerAndZoom(new BMap.Point(121.491, 31.233), 11)
145
+ // }
146
+ return new Promise((resolve, reject) => {
147
+ window.__baiduMapInitial = function () {
148
+ // 启用google标准坐标体系
149
+ // coordsType 指定输入输出的坐标类型,BMAP_COORD_GCJ02为gcj02坐标,BMAP_COORD_BD09为bd0ll坐标,默认为BMAP_COORD_BD09。
150
+ window.BMap.coordType = 'BMAP_COORD_GCJ02'
151
+ resolve(null)
152
+ }
153
+ const script = document.createElement('script')
154
+ // 使用最新 3.0 api https://lbsyun.baidu.com/index.php?title=jspopular3.0
155
+ script.src = `https://api.map.baidu.com/api?v=3.0&ak=${this.key}&callback=__baiduMapInitial`
156
+ // script.src = `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}&callback=__baiduMapInitial`
157
+ script.onerror = (err) => {
158
+ reject(err)
159
+ }
160
+ document.body.appendChild(script)
161
+ })
162
+ }
163
+ }
164
+
165
+ const mapService = new MapService()
166
+
167
+ export { mapService }