@smart100/spu-web-plugin 1.0.8 → 1.0.10
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 +30 -0
- package/dist/spu-web-plugin.mjs +1346 -367
- package/package.json +1 -1
- package/src/index.ts +4 -2
- package/src/login.ts +5 -43
- package/src/map/AMapKey.ts +31 -0
- package/src/map/AMapLoader.ts +43 -0
- package/src/map/MapService.ts +186 -0
- package/src/map/index.ts +564 -0
- package/src/map/utils.ts +98 -0
- package/src/tenantSetting.ts +86 -0
- package/src/types/global.d.ts +0 -4
- package/src/types/index.d.ts +30 -0
- package/src/types/shims-lib.d.ts +14 -3
- package/src/utils.ts +41 -1
- package/src/AMapLoader.ts +0 -46
- package/src/location.ts +0 -208
package/package.json
CHANGED
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 './
|
|
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
|
|
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,186 @@
|
|
|
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
|
+
private 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
|
+
AMap: any = null
|
|
57
|
+
TMap: any = null
|
|
58
|
+
BMap: any = null
|
|
59
|
+
MapCore: any = null
|
|
60
|
+
|
|
61
|
+
// get AMap() {
|
|
62
|
+
// if (!this.isInit || this.type !== 'amap') {
|
|
63
|
+
// return null
|
|
64
|
+
// }
|
|
65
|
+
// return window.AMap
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
// get TMap() {
|
|
69
|
+
// if (!this.isInit || this.type !== 'tencent') {
|
|
70
|
+
// return null
|
|
71
|
+
// }
|
|
72
|
+
// return window.TMap
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
// get BMap() {
|
|
76
|
+
// if (!this.isInit || this.type !== 'baidu') {
|
|
77
|
+
// return null
|
|
78
|
+
// }
|
|
79
|
+
// return window.BMap
|
|
80
|
+
// }
|
|
81
|
+
|
|
82
|
+
// get MapCore() {
|
|
83
|
+
// if (!this.isInit) {
|
|
84
|
+
// return null
|
|
85
|
+
// }
|
|
86
|
+
// return window.BMap
|
|
87
|
+
// }
|
|
88
|
+
|
|
89
|
+
async init() {
|
|
90
|
+
if (this.isInit) return
|
|
91
|
+
|
|
92
|
+
this.isInit = true
|
|
93
|
+
|
|
94
|
+
const type = this.type
|
|
95
|
+
|
|
96
|
+
// if (process.env.NODE_ENV === 'development') {
|
|
97
|
+
// type = 'baidu'
|
|
98
|
+
// }
|
|
99
|
+
if (type === 'tencent') {
|
|
100
|
+
await this.initTecent()
|
|
101
|
+
} else if (type === 'amap') {
|
|
102
|
+
await this.initAmap()
|
|
103
|
+
} else if (type === 'baidu') {
|
|
104
|
+
await this.initBaidu()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// reset() {
|
|
109
|
+
// this.isInit = false
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
private async initTecent() {
|
|
113
|
+
await importJS(
|
|
114
|
+
`https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=${this.key}`,
|
|
115
|
+
// `https://map.qq.com/api/gljs?v=1.exp&key=${this.key}`,
|
|
116
|
+
'TMap'
|
|
117
|
+
)
|
|
118
|
+
this.TMap = window.TMap
|
|
119
|
+
this.MapCore = window.TMap
|
|
120
|
+
await delay(300)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private async initAmap() {
|
|
124
|
+
// if (this.secretkey) {
|
|
125
|
+
// window._AMapSecurityConfig = {
|
|
126
|
+
// securityJsCode: this.secretkey
|
|
127
|
+
// }
|
|
128
|
+
// }
|
|
129
|
+
|
|
130
|
+
const plugin = ['AMap.Geolocation']
|
|
131
|
+
// plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
|
|
132
|
+
|
|
133
|
+
const AMap = await AMapLoader.load({
|
|
134
|
+
key: this.key,
|
|
135
|
+
version: '2.0',
|
|
136
|
+
plugins: plugin,
|
|
137
|
+
AMapUI: {
|
|
138
|
+
version: '1.1',
|
|
139
|
+
plugins: []
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
window.AMap = AMap
|
|
143
|
+
this.AMap = AMap
|
|
144
|
+
this.MapCore = window.AMap
|
|
145
|
+
// console.log(window)
|
|
146
|
+
// console.log(window.AMap)
|
|
147
|
+
// console.log(window.AMapUI)
|
|
148
|
+
// console.log(window.AMapLoader)
|
|
149
|
+
// console.log(window.AMap === aaaa)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private async initBaidu() {
|
|
153
|
+
// await importJS(
|
|
154
|
+
// `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}`,
|
|
155
|
+
// 'BMap'
|
|
156
|
+
// )
|
|
157
|
+
// await delay(300)
|
|
158
|
+
// function initialize() {
|
|
159
|
+
// const mp = new BMap.Map('map')
|
|
160
|
+
// mp.centerAndZoom(new BMap.Point(121.491, 31.233), 11)
|
|
161
|
+
// }
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
window.BMAP_INITIAL_CALLBACK = () => {
|
|
164
|
+
this.BMap = window.BMap
|
|
165
|
+
this.MapCore = window.BMap
|
|
166
|
+
// debugger
|
|
167
|
+
// 启用google标准坐标体系
|
|
168
|
+
// coordsType 指定输入输出的坐标类型,BMAP_COORD_GCJ02为gcj02坐标,BMAP_COORD_BD09为bd0ll坐标,默认为BMAP_COORD_BD09。
|
|
169
|
+
window.BMap.coordType = 'BMAP_COORD_GCJ02'
|
|
170
|
+
resolve(null)
|
|
171
|
+
}
|
|
172
|
+
const script = document.createElement('script')
|
|
173
|
+
// 使用最新 3.0 api https://lbsyun.baidu.com/index.php?title=jspopular3.0
|
|
174
|
+
script.src = `https://api.map.baidu.com/api?v=3.0&ak=${this.key}&callback=BMAP_INITIAL_CALLBACK`
|
|
175
|
+
// script.src = `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}&callback=BMAP_INITIAL_CALLBACK`
|
|
176
|
+
script.onerror = (err) => {
|
|
177
|
+
reject(err)
|
|
178
|
+
}
|
|
179
|
+
document.body.appendChild(script)
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const mapService = new MapService()
|
|
185
|
+
|
|
186
|
+
export { mapService }
|