@smart100/spu-web-plugin 1.0.16 → 1.0.18

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.16",
3
+ "version": "1.0.18",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
package/src/envService.ts CHANGED
@@ -22,7 +22,7 @@ async function getEnvname(): Promise<string> {
22
22
  envname = queryEnvname
23
23
  } else if (window?.aPaaS?.getWebInitParams && window?.Native?.setNavigationBarReturnButton) {
24
24
  // 手机端 查 envname
25
- // 只有手机端有 setNavigationBarReturnButton 方法
25
+ // 只有手机端有 setNavigationBarReturnButton 和 getWebInitParams 方法
26
26
  envname = await new Promise((resolve, reject) => {
27
27
  window.aPaaS.getWebInitParams((params: any) => {
28
28
  resolve(params?.envname || '')
package/src/index.ts CHANGED
@@ -9,7 +9,15 @@ import { globalConfig } from './globalConfig'
9
9
  import { downloadService, uploadService } from './oss'
10
10
  import { getServToken } from './oss/servtoken'
11
11
  import { getCloudServ } from './oss/cloudServ'
12
- import { getUniqueid, functionCheck, setTitle, isInApp, isdebugger, isvirtuallocation } from './utils'
12
+ import {
13
+ getUniqueid,
14
+ functionCheck,
15
+ setTitle,
16
+ isInApp,
17
+ isdebugger,
18
+ isvirtuallocation,
19
+ getServerTime
20
+ } from './utils'
13
21
  import { installUrlquery } from './urlquery'
14
22
  import { mapService } from './map/MapService'
15
23
  import AMapLoader from './map/AMapLoader'
@@ -73,7 +81,7 @@ const install = (app: any, options: any) => {
73
81
  console.log(globalOptions)
74
82
 
75
83
  // setTimeout(() => {
76
- // console.error('5416546544')
84
+ // console.error('9999')
77
85
  // }, 1000)
78
86
 
79
87
  // if (install.installed) return
@@ -116,6 +124,7 @@ export {
116
124
  getUniqueid,
117
125
  getUuid,
118
126
  functionCheck,
127
+ getServerTime,
119
128
  setTitle,
120
129
  isInApp,
121
130
  AMapLoader,
package/src/login.ts CHANGED
@@ -3,7 +3,7 @@ import jwtDecode from 'jwt-decode'
3
3
  import { lsProxy } from './storageProxy'
4
4
  import { axios } from './axios'
5
5
  import cloudServ from './oss/cloudServ'
6
- import core from './core'
6
+ import core, { Module } from './core'
7
7
  import { urlquery } from './urlquery'
8
8
  import { getData, setData, removeData } from './storageCache'
9
9
  import {
@@ -24,11 +24,14 @@ type JwtResult = {
24
24
  } | null
25
25
 
26
26
  function getToken() {
27
- return getData('token')
28
- // return lsProxy.getItem('token') as string
27
+ const token = getData('token')
28
+ // const token = lsProxy.getItem('token') as string
29
+ return token
29
30
  }
30
31
 
31
32
  function setToken(value: string) {
33
+ // console.log('setToken', value)
34
+ // debugger
32
35
  setData('token', value)
33
36
  }
34
37
 
@@ -110,6 +113,7 @@ function removeUser() {
110
113
  }
111
114
 
112
115
  function parseToken(token?: string) {
116
+ // debugger
113
117
  if (!token) {
114
118
  console.error('token为空 jwt解析token出错')
115
119
  return null
@@ -328,9 +332,11 @@ function formatTenant(tenant: ITenantInfo) {
328
332
 
329
333
  async function getAndSetTenant(tenantcode?: string) {
330
334
  try {
331
- const tenantsRes: null | ITenantInfo[] = await axios.get('/api/auth/tenantlist', {}).then((res: any) => {
332
- return res?.data?.tenants
333
- })
335
+ const tenantsRes: null | ITenantInfo[] = await axios
336
+ .get('/api/auth/tenantlist', {})
337
+ .then((res: any) => {
338
+ return res?.data?.tenants
339
+ })
334
340
 
335
341
  let tenant: ITenantInfo | null = null
336
342
  if (tenantsRes?.length) {
@@ -445,9 +451,89 @@ function startRefreshtoken() {
445
451
  }, time)
446
452
  }
447
453
 
454
+ // 获取 spu 容器 token
455
+ const getSPUContainerToken = (): Promise<any> => {
456
+ return new Promise((resolve, reject) => {
457
+ if (window.aPaaS?.getToken) {
458
+ window.aPaaS.getToken((res: any) => {
459
+ console.log('window.aPaaS.getToken success', res)
460
+ // 安卓返回 token tokenExpires refreshToken
461
+ // ios返回 token tokenexpires refreshtoken
462
+ // 改好按安卓
463
+
464
+ const token = res?.token
465
+ const tokenexpires = res?.tokenExpires || res?.tokenexpires
466
+ const refreshtoken = res?.refreshToken || res?.refreshtoken
467
+
468
+ if (token && tokenexpires && refreshtoken) {
469
+ resolve({
470
+ token,
471
+ tokenexpires,
472
+ refreshtoken
473
+ })
474
+ } else {
475
+ console.error('window.aPaaS.getToken fail')
476
+ resolve(null)
477
+ }
478
+ })
479
+ } else {
480
+ console.warn('window.aPaaS.getToken fail: not in SPU container')
481
+ resolve(null)
482
+ }
483
+ })
484
+ }
485
+
486
+ // 如果APP端在SPU页面切到后台 然后又切回前台 有可能发生
487
+ // 1、切后台时间过长导致 token 过期
488
+ // 2、切后台后打开太多别的应用 导致切回前台时内存不足 从而导致 SPU 的 webview reload
489
+ // 如果 1 2 同时发生 那么当前SPU页面重走单点登录流程 而url上的token已经过期 会导致单点登录失败
490
+ // 因此 在APP端 单点登录不使用url上的token 而是直接拿App端的 App端能保证拿到的token一直不过期
491
+ const fixLoginQuery = async (query: IAny) => {
492
+ const newQuery = cloneDeep(query)
493
+ const type = await Module.getSpuContainerType()
494
+ if (type === 'app' && window.aPaaS?.getToken) {
495
+ console.log('SPU is in App, singleLogin use App token.')
496
+ const tokenData = await getSPUContainerToken()
497
+ if (tokenData) {
498
+ newQuery.token = tokenData.token
499
+ newQuery.tokenexpires = tokenData.tokenexpires
500
+ newQuery.refreshtoken = tokenData.refreshtoken
501
+ }
502
+ } else {
503
+ console.log('SPU is not in App, singleLogin use query token.')
504
+ }
505
+ return newQuery
506
+ }
507
+
508
+ // 修复 App 切到后台时间过长导致 token 过期
509
+ // 监听 App 切换到前台 判断token是否过期 如果过期就调用获取tokne方法更新token
510
+ const fixAppTokenExpired = () => {
511
+ if (window.Native?.onHostEnterForceground) {
512
+ console.log('listen App enter forceground')
513
+ window.Native.onHostEnterForceground(async () => {
514
+ console.log('App enter forceground')
515
+ const loginState = getLoginState()
516
+ if (!loginState.islogin && loginState.type === 2 && loginState.role !== 'center') {
517
+ const tokenData = await getSPUContainerToken()
518
+ if (tokenData) {
519
+ setToken(tokenData.token)
520
+ setRefreshToken(tokenData.refreshtoken)
521
+ setTokenExpires(tokenData.tokenexpires)
522
+ } else {
523
+ try {
524
+ await updateToken()
525
+ } catch (err) {
526
+ console.error(err)
527
+ }
528
+ }
529
+ }
530
+ })
531
+ }
532
+ }
533
+
448
534
  // 单点登录
449
535
  async function singleLogin(query: IAny) {
450
- query = cloneDeep(query)
536
+ query = await fixLoginQuery(query)
451
537
 
452
538
  let flag = false // 是否登录成功
453
539
  const token = query.token
@@ -572,6 +658,7 @@ async function singleLogin(query: IAny) {
572
658
 
573
659
  function installAuth(options: any) {
574
660
  startRefreshtoken()
661
+ fixAppTokenExpired()
575
662
  if (options.router) {
576
663
  options.router.beforeEach(async (to: any, from: any, next: any) => {
577
664
  // console.log(from)
@@ -583,6 +670,7 @@ function installAuth(options: any) {
583
670
  if (to.query.token) {
584
671
  const singleLoginRes = await singleLogin(to.query)
585
672
  if (singleLoginRes.flag) {
673
+ // next()
586
674
  next({
587
675
  path: to.path,
588
676
  params: to.params,
@@ -598,7 +686,7 @@ function installAuth(options: any) {
598
686
  })
599
687
  } else {
600
688
  console.warn(
601
- '@smart100/spu-web-plugin 需要传入一个 vue-router 实例以便执行单点登录逻辑,如果您没传 vue-router 实例则需要自行在合适的位置执行单点登录代码。'
689
+ '@smart100/spu-web-plugin 需要传入一个 vue-router 实例以便执行单点登录逻辑,如果您没传 vue-router 实例则需要自行在合适的位置执行单点登录代码,如果您已自行实现,请忽略该提示。'
602
690
  )
603
691
  }
604
692
 
@@ -22,12 +22,51 @@ class MapService {
22
22
  private isInit = false
23
23
  private initPromise: any = null
24
24
 
25
+ get lbssetting(): ILbsSettingData | undefined {
26
+ return tenantSetting.get('lbssetting')
27
+ // const lbssetting: any = {
28
+ // enable: '1',
29
+ // setting: {
30
+ // type: '',
31
+ // key: {
32
+ // web: '',
33
+ // android: '',
34
+ // ios: '',
35
+ // harmony: ''
36
+ // },
37
+ // secretkey: {
38
+ // web: '',
39
+ // android: '',
40
+ // ios: '',
41
+ // harmony: ''
42
+ // }
43
+ // }
44
+ // }
45
+ // // // 高德地图公司key
46
+ // // lbssetting.setting.type = 'amap'
47
+ // // lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
48
+ // // lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
49
+ // // 高德地图个人key
50
+ // lbssetting.setting.type = 'amap'
51
+ // lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
52
+ // lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
53
+ // // // 腾讯地图
54
+ // // lbssetting.setting.type = 'tencent'
55
+ // // lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
56
+ // // lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
57
+ // // // 百度地图
58
+ // // lbssetting.setting.type = 'baidu'
59
+ // // lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
60
+ // // lbssetting.setting.secretkey.web = ''
61
+ // return lbssetting
62
+ }
63
+
25
64
  get isLbssettingEnable() {
26
- return tenantSetting.get('lbssetting')?.enable === '1'
65
+ return this.lbssetting?.enable === '1'
27
66
  }
28
67
 
29
68
  private get setting(): ILbsSetting | undefined {
30
- return tenantSetting.get('lbssetting')?.setting
69
+ return this.lbssetting?.setting
31
70
  }
32
71
 
33
72
  get key() {
@@ -57,35 +96,6 @@ class MapService {
57
96
  AMap: any = null
58
97
  TMap: any = null
59
98
  BMap: any = null
60
- MapCore: any = null
61
-
62
- // get AMap() {
63
- // if (!this.isInit || this.type !== 'amap') {
64
- // return null
65
- // }
66
- // return window.AMap
67
- // }
68
-
69
- // get TMap() {
70
- // if (!this.isInit || this.type !== 'tencent') {
71
- // return null
72
- // }
73
- // return window.TMap
74
- // }
75
-
76
- // get BMap() {
77
- // if (!this.isInit || this.type !== 'baidu') {
78
- // return null
79
- // }
80
- // return window.BMap
81
- // }
82
-
83
- // get MapCore() {
84
- // if (!this.isInit) {
85
- // return null
86
- // }
87
- // return window.BMap
88
- // }
89
99
 
90
100
  async init() {
91
101
  if (this.isInit) return
@@ -134,10 +144,11 @@ class MapService {
134
144
  this.isInit = true
135
145
  }
136
146
 
137
- // reset() {
138
- // this.isInit = false
139
- // }
140
-
147
+ // 腾讯地图 key 配置错误
148
+ // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
149
+ // 2 如果是调用 api 会返回 catch 和详细的错误信息
150
+ // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
151
+ // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
141
152
  private async initTecent() {
142
153
  await importJS(
143
154
  `https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=${this.key}`,
@@ -145,10 +156,12 @@ class MapService {
145
156
  'TMap'
146
157
  )
147
158
  this.TMap = window.TMap
148
- this.MapCore = window.TMap
149
159
  await delay(300)
150
160
  }
151
161
 
162
+ // 高德地图 key 配置错误
163
+ // 1 如果是 key 格式不对 那么没返回 promise 连 window.AMap 都拿不到 地图和都不能用
164
+ // 1 如果是 key 格式对 但 key 不对 有返回 window.AMap 但 api 定位调用失败 地图可以渲染空白地图
152
165
  private async initAmap() {
153
166
  return new Promise(async (resolve, reject) => {
154
167
  // 高德地图api初始化失败 没有返回reject 因此用超时机制检测
@@ -180,7 +193,6 @@ class MapService {
180
193
 
181
194
  window.AMap = AMap
182
195
  this.AMap = window.AMap
183
- this.MapCore = window.AMap
184
196
  // console.log(window)
185
197
  // console.log(window.AMap)
186
198
  // console.log(window.AMapUI)
@@ -190,13 +202,14 @@ class MapService {
190
202
  })
191
203
  }
192
204
 
205
+ // 百度地图 key 配置错误
206
+ // alert以下信息: 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
193
207
  private async initBaidu() {
194
208
  return new Promise((resolve, reject) => {
195
209
  window.BMAP_INITIAL_CALLBACK = (e: any) => {
196
210
  // console.log(e)
197
211
  // debugger
198
212
  this.BMap = window.BMap
199
- this.MapCore = window.BMap
200
213
  // debugger
201
214
  // 启用google标准坐标体系
202
215
  // coordsType 指定输入输出的坐标类型,BMAP_COORD_GCJ02为gcj02坐标,BMAP_COORD_BD09为bd0ll坐标,默认为BMAP_COORD_BD09。
package/src/map/index.ts CHANGED
@@ -95,20 +95,19 @@ const getLocationByNavigator = async (): Promise<Location> => {
95
95
  }
96
96
 
97
97
  // ipaas ip 定位
98
- const getIPLocationByIpaas = async (
99
- ip?: string
100
- ): Promise<Location> => {
98
+ const getIPLocationByIpaas = async (ip?: string): Promise<Location> => {
101
99
  console.log('getIPLocationByIpaas start...')
102
100
  return new Promise((resolve, reject) => {
103
101
  const AMapKey = getAMapKey()
104
102
 
105
- axios.post(
106
- 'https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001815271',
107
- {
108
- key: AMapKey.key, // 好像不传也没问题 因为key是在ipaas那边设置的
109
- ip: ip || ''
110
- }
111
- )
103
+ axios
104
+ .post(
105
+ 'https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001815271',
106
+ {
107
+ key: AMapKey.key, // 好像不传也没问题 因为key是在ipaas那边设置的
108
+ ip: ip || ''
109
+ }
110
+ )
112
111
  .then((res: any) => {
113
112
  // console.log(res)
114
113
  // debugger
@@ -134,7 +133,8 @@ const getIPLocationByIpaas = async (
134
133
  console.error('getIPLocationByIpaas fail')
135
134
  resolve(null)
136
135
  }
137
- }).catch((err: any) => {
136
+ })
137
+ .catch((err: any) => {
138
138
  console.error(err)
139
139
  console.error('getIPLocationByIpaas fail')
140
140
  resolve(null)
@@ -150,12 +150,15 @@ const getAddressByIpaas = async (position: Location): Promise<string> => {
150
150
  if (position) {
151
151
  try {
152
152
  const AMapKey = getAMapKey()
153
- const result = await axios.post('https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001809906', {
154
- longitude: position.longitude,
155
- latitude: position.latitude,
156
- key: AMapKey.key
157
- // extensions: 'all'
158
- })
153
+ const result = await axios.post(
154
+ 'https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001809906',
155
+ {
156
+ longitude: position.longitude,
157
+ latitude: position.latitude,
158
+ key: AMapKey.key
159
+ // extensions: 'all'
160
+ }
161
+ )
159
162
  // console.log(result)
160
163
  const address = result?.data?.formatted_address
161
164
  if (address) {
@@ -476,7 +479,7 @@ const getAddressByBmap = async (position: Location): Promise<string> => {
476
479
  })
477
480
  }
478
481
 
479
- const getLocationPromise = async (isuseiplocarion = false): Promise<Location> => {
482
+ const getLocationPromise = async (isuseiplocation = false): Promise<Location> => {
480
483
  let location: Location = null
481
484
 
482
485
  // 在 SPU 容器里使用 Native-API 的定位
@@ -484,31 +487,31 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
484
487
  location = await getLocationByNative()
485
488
  }
486
489
 
487
- if (!location) {
488
- location = await getLocationByNavigator()
489
- }
490
- // location = null
491
-
492
490
  if (!location) {
493
491
  if (mapService.type === 'amap') {
494
492
  location = await getLocationByAMap()
495
- if (!location && isuseiplocarion) {
493
+ if (!location && isuseiplocation) {
496
494
  location = await getCityLocationByAMap()
497
495
  }
498
496
  // 改成不使用ipaas了
499
- // if (!location && isuseiplocarion) {
497
+ // if (!location && isuseiplocation) {
500
498
  // location = await getIPLocationByIpaas()
501
499
  // }
502
- } else if (mapService.type === 'tencent' && isuseiplocarion) {
500
+ } else if (mapService.type === 'tencent' && isuseiplocation) {
503
501
  location = await getIPLocationByTMap()
504
502
  } else if (mapService.type === 'baidu') {
505
503
  location = await getLocationByBMap()
506
- if (!location && isuseiplocarion) {
504
+ if (!location && isuseiplocation) {
507
505
  location = await getCityLocationByBMap()
508
506
  }
509
507
  }
510
508
  }
511
509
 
510
+ if (!location) {
511
+ location = await getLocationByNavigator()
512
+ }
513
+ // location = null
514
+
512
515
  // 开发模式下为了方便测试提供虚拟定位
513
516
  if (!location && urlquery.isvirtuallocation) {
514
517
  location = {
@@ -541,7 +544,7 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
541
544
  // WGS84 GCJ-02 BD-09 坐标系
542
545
  // https://www.jianshu.com/p/559029832a67
543
546
  // 不能精确定位的情况下是否启用ip城市定位,ip定位用于不需要精确定位的场景
544
- async function getLocation(isuseiplocarion = false) {
547
+ async function getLocation(isuseiplocation = false) {
545
548
  await mapService.init()
546
549
  // debugger
547
550
  // 缓存30秒
@@ -554,7 +557,7 @@ async function getLocation(isuseiplocarion = false) {
554
557
  }
555
558
  // console.log('runing')
556
559
  runing = true
557
- locationPromise = getLocationPromise(isuseiplocarion)
560
+ locationPromise = getLocationPromise(isuseiplocation)
558
561
  const locationRes = await locationPromise
559
562
  runing = false
560
563
  if (locationRes) {
@@ -39,64 +39,6 @@ class TenantSetting {
39
39
  }
40
40
 
41
41
  get(key: string) {
42
- // const tenantsetting = {
43
- // lbssetting: {
44
- // enable: '1',
45
- // setting: {
46
- // type: '',
47
- // key: {
48
- // web: '',
49
- // android: '',
50
- // ios: '',
51
- // harmony: ''
52
- // },
53
- // secretkey: {
54
- // web: '',
55
- // android: '',
56
- // ios: '',
57
- // harmony: ''
58
- // }
59
- // }
60
- // }
61
- // }
62
-
63
- // 高德地图key配置错误
64
- // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
65
- // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
66
-
67
- // // 高德地图公司key
68
- // tenantsetting.lbssetting.setting.type = 'amap'
69
- // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
70
- // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
71
-
72
- // // 高德地图个人key
73
- // tenantsetting.lbssetting.setting.type = 'amap'
74
- // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
75
- // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
76
-
77
- // tencent地图key配置错误
78
- // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
79
- // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
80
- // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
81
- // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
82
- // tenantsetting.lbssetting.setting.type = 'tencent'
83
- // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
84
- // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
85
-
86
- // 百度地图key配置错误alert以下信息
87
- // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
88
- // tenantsetting.lbssetting.setting.type = 'baidu'
89
- // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
90
-
91
-
92
-
93
- // tenantsetting.lbssetting.setting.type = 'tencent'
94
- // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT是的是的'
95
- // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0对对对'
96
-
97
- // lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
98
-
99
-
100
42
  let tenantsettingStr = lsProxy.getItem('tenantsetting')
101
43
  if (tenantsettingStr) {
102
44
  const tenantsetting = JSON.parse(tenantsettingStr)
@@ -31,12 +31,11 @@ interface IAMapLoader {
31
31
  }
32
32
 
33
33
  interface IMapService {
34
- init: () => Promise<any>
34
+ init: () => Promise<void>
35
35
  type: 'amap' | 'tencent' | 'baidu'
36
36
  AMap: any
37
37
  BMap: any
38
38
  TMap: any
39
- MapCore: any
40
39
  }
41
40
 
42
41
  type StorageType = 'storage' | 'storage-1d' | 'storage-3m' | 'storage-1y'
@@ -98,18 +97,14 @@ export default SPUWebPlugin
98
97
  export const globalOptions: any
99
98
  export const lsProxy: any
100
99
  export const ssProxy: any
101
- export const getLocation: () => Promise<{
100
+ export const getLocation: (isuseiplocation?: boolean) => Promise<{
102
101
  longitude: string
103
102
  latitude: string
104
103
  address: string
105
104
  [propName: string]: any
106
105
  } | null>
107
106
  export const getDistance: (p1: [number, number], p2: [number, number]) => Promise<any>
108
- export const getAddress: (location: {
109
- longitude: string
110
- latitude: string
111
- [propName: string]: any
112
- }) => Promise<string>
107
+ export const getAddress: (location: { longitude: string; latitude: string; [propName: string]: any }) => Promise<string>
113
108
  export const spuAxios: any
114
109
  export const apaasAxios: any
115
110
  export const axios: any
@@ -123,10 +118,11 @@ export const getServToken: () => Promise<{
123
118
  securitytoken: string
124
119
  expiration: string
125
120
  }>
126
- export const getCloudServ: () => any
121
+ export const getCloudServ: (type?: StorageType) => any
127
122
  export const getUniqueid: () => string
128
123
  export const getUuid: () => string
129
124
  export const functionCheck: (functioncode?: string) => boolean
125
+ export const getServerTime: () => Promise<string>
130
126
  export const setTitle: (pagetitle?: string) => void
131
127
  export const isInApp: () => boolean
132
128
  export const AMapLoader: IAMapLoader
package/src/utils.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { getUser } from './login'
2
2
  import { urlquery } from './urlquery'
3
3
  import { get } from 'lodash-es'
4
+ import { axios } from './axios'
4
5
 
5
6
  function isIOS() {
6
7
  const ua = navigator.userAgent
@@ -128,6 +129,40 @@ const delay = (timeout = 1000) => {
128
129
  })
129
130
  }
130
131
 
132
+ const getServerTime = () => {
133
+ return new Promise((resolve, reject) => {
134
+ if (window?.Native?.getServerTime) {
135
+ window.Native.getServerTime((res: any) => {
136
+ if (res) {
137
+ resolve(res.toString())
138
+ } else {
139
+ resolve(Date.now().toString())
140
+ }
141
+ })
142
+ } else {
143
+ axios
144
+ .get(
145
+ '/api/teapi/offline/servertime',
146
+ {},
147
+ {
148
+ isShowLoading: false
149
+ }
150
+ )
151
+ .then((res: any) => {
152
+ if (res.data) {
153
+ resolve(res.data.toString())
154
+ } else {
155
+ resolve(Date.now().toString())
156
+ }
157
+ })
158
+ .catch((err: any) => {
159
+ resolve(Date.now().toString())
160
+ })
161
+ }
162
+ })
163
+ }
164
+
165
+
131
166
  export {
132
167
  isIOS,
133
168
  isMobile,
@@ -139,5 +174,6 @@ export {
139
174
  isvirtuallocation,
140
175
  toggleHttpOrHttps,
141
176
  importJS,
142
- delay
177
+ delay,
178
+ getServerTime
143
179
  }