@smart100/spu-web-plugin 1.0.7 → 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.
@@ -0,0 +1,88 @@
1
+ import { axios } from './axios'
2
+ import { decrypt } from './crypt'
3
+ import { lsProxy } from './storageProxy'
4
+
5
+ class TenantSetting {
6
+ async requestAndSetTenantSetting(tenantcode?: string) {
7
+ try {
8
+ const res = await axios.post(
9
+ '/api/auth/tenantsettings',
10
+ {
11
+ tenantcode: tenantcode || ''
12
+ },
13
+ {
14
+ isSendToken: false,
15
+ isSendTecode: true,
16
+ isShowErrorMessage: false
17
+ }
18
+ )
19
+
20
+ let tenantSetting = res?.data?.econfig || ''
21
+ if (tenantSetting) {
22
+ tenantSetting = decrypt(tenantSetting)
23
+ }
24
+ // console.log(tenantSetting)
25
+ // debugger
26
+ if (tenantSetting) {
27
+ lsProxy.setItem('tenantsetting', tenantSetting)
28
+ } else {
29
+ this.removeTenantSetting()
30
+ }
31
+ } catch (err) {
32
+ console.error(err)
33
+ this.removeTenantSetting()
34
+ }
35
+ }
36
+
37
+ removeTenantSetting() {
38
+ lsProxy.removeItem('tenantsetting')
39
+ }
40
+
41
+ get(key: string) {
42
+ const tenantsettingStr = lsProxy.getItem('tenantsetting')
43
+ if (tenantsettingStr) {
44
+ const tenantsetting = JSON.parse(tenantsettingStr)
45
+
46
+
47
+ // tenantsetting.lbssetting = {
48
+ // enable: '1',
49
+ // setting: {
50
+ // type: '',
51
+ // key: {
52
+ // web: '',
53
+ // android: '',
54
+ // ios: '',
55
+ // harmony: ''
56
+ // },
57
+ // secretkey: {
58
+ // web: '',
59
+ // android: '',
60
+ // ios: '',
61
+ // harmony: ''
62
+ // }
63
+ // }
64
+ // }
65
+ // // tenantsetting.lbssetting.setting.type = 'amap'
66
+ // // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
67
+ // // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
68
+
69
+ // // tenantsetting.lbssetting.setting.type = 'tencent'
70
+ // // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
71
+
72
+ // tenantsetting.lbssetting.setting.type = 'baidu'
73
+ // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
74
+
75
+
76
+ if (key) {
77
+ return tenantsetting[key]
78
+ }
79
+ return tenantsetting
80
+ } else {
81
+ return null
82
+ }
83
+ }
84
+ }
85
+
86
+ const tenantSetting = new TenantSetting()
87
+
88
+ export { tenantSetting }
@@ -52,9 +52,5 @@ interface ITenantInfo {
52
52
  productversionlist: IProductVersion[]
53
53
  }
54
54
 
55
- interface Window {
56
- AWS: any
57
- }
58
-
59
55
  declare module 'uuid'
60
56
  declare module 'co'
@@ -10,6 +10,14 @@ interface IAMapLoader {
10
10
  }) => Promise<any>
11
11
  }
12
12
 
13
+ interface IMapService {
14
+ init: () => Promise<any>
15
+ type: 'amap' | 'tencent' | 'baidu'
16
+ AMap: any
17
+ BMap: any
18
+ TMap: any
19
+ }
20
+
13
21
  type StorageType = 'storage' | 'storage-1d' | 'storage-3m' | 'storage-1y'
14
22
 
15
23
  type Cope = { width?: number; height?: number } | string | boolean
@@ -83,6 +91,7 @@ export const functionCheck: (functioncode?: string) => boolean
83
91
  export const setTitle: (pagetitle?: string) => void
84
92
  export const isInApp: () => boolean
85
93
  export const AMapLoader: IAMapLoader
94
+ export const mapService: IMapService
86
95
  export const singleLogin: any
87
96
  export const updateToken: () => Promise<void>
88
97
  export const getToken: () => string
@@ -14,9 +14,6 @@ declare module '*.jpeg'
14
14
  declare module '*.gif'
15
15
 
16
16
  interface Window {
17
- _AMapSecurityConfig: {
18
- securityJsCode: string
19
- }
20
17
  // Native Module aPaaS 为 G3 SPU 容器注入的 Native-API
21
18
  Native: any
22
19
  Module: any
@@ -24,6 +21,20 @@ interface Window {
24
21
  // 日志插件 和 日志实例
25
22
  ApaasSpuTrack: any
26
23
  apaasSpuTrack: any
24
+ // minio 客户端
25
+ AWS: any
26
+ // 高德地图
27
+ AMapLoader: any
28
+ _AMapSecurityConfig: {
29
+ securityJsCode: string
30
+ }
31
+ AMap: any
32
+ AMapUI: IAny
33
+ // 百度地图
34
+ BMap: any
35
+ __baiduMapInitial: any
36
+ // 腾讯地图
37
+ TMap: any
27
38
  // wx: IAny;
28
39
  // AMapUI: IAny;
29
40
  // lsProxy: any;
package/src/utils.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getUser } from './login'
2
2
  import { urlquery } from './urlquery'
3
+ import { get } from 'lodash-es'
3
4
 
4
5
  function isIOS() {
5
6
  const ua = navigator.userAgent
@@ -90,6 +91,43 @@ function toggleHttpOrHttps(url: string) {
90
91
  return res
91
92
  }
92
93
 
94
+ const urlMap = new Map<string, Promise<any>>()
95
+ function importJS(url: string, attrName = ''): Promise<any> {
96
+ let p = urlMap.get(url)
97
+ if (p) {
98
+ return p.then(() => {
99
+ return Promise.resolve(attrName ? get(window, attrName) : undefined)
100
+ })
101
+ }
102
+ const script: any = document.createElement('script')
103
+ script.setAttribute('type', 'text/javascript')
104
+ script.setAttribute('src', url)
105
+ document.getElementsByTagName('head')[0].appendChild(script)
106
+
107
+ p = new Promise((resolve, reject) => {
108
+ script.onload = script.onreadystatechange = function () {
109
+ const f = script.readyState
110
+ if (f && f !== 'loaded' && f !== 'complete') return
111
+ script.onload = script.onreadystatechange = null
112
+ resolve(undefined)
113
+ }
114
+ script.onerror = () => reject(new Error('加载失败'))
115
+ })
116
+ urlMap.set(url, p)
117
+ // console.log('importJS:', url, attrName)
118
+ return p.then(() => {
119
+ return Promise.resolve(attrName ? get(window, attrName) : undefined)
120
+ })
121
+ }
122
+
123
+ const delay = (timeout = 1000) => {
124
+ return new Promise((resolve) => {
125
+ setTimeout(() => {
126
+ resolve(null)
127
+ }, timeout)
128
+ })
129
+ }
130
+
93
131
  export {
94
132
  isIOS,
95
133
  isMobile,
@@ -99,5 +137,7 @@ export {
99
137
  isInApp,
100
138
  isdebugger,
101
139
  isvirtuallocation,
102
- toggleHttpOrHttps
140
+ toggleHttpOrHttps,
141
+ importJS,
142
+ delay
103
143
  }
package/src/AMapLoader.ts DELETED
@@ -1,46 +0,0 @@
1
- import AMapLoader from '@amap/amap-jsapi-loader'
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
- // const amapkey = process.env.NODE_ENV !== 'production' ? amapKey.dev.key : amapKey.production.key
17
- // const amapsecurityjscode = process.env.NODE_ENV !== 'production' ? amapKey.dev.securityjscode : amapKey.production.securityjscode
18
-
19
- const amapkey = amapKey.production.key
20
- const amapsecurityjscode = amapKey.production.securityjscode
21
-
22
- const load = (options?: {
23
- plugins?: Array<string>
24
- AMapUI?: {
25
- plugins?: Array<string>
26
- }
27
- }) => {
28
- if (!window._AMapSecurityConfig) {
29
- window._AMapSecurityConfig = {
30
- securityJsCode: amapsecurityjscode
31
- }
32
- }
33
- return AMapLoader.load({
34
- key: amapkey,
35
- version: '2.0',
36
- plugins: options?.plugins || [],
37
- AMapUI: {
38
- version: '1.1',
39
- plugins: options?.AMapUI?.plugins || []
40
- }
41
- })
42
- }
43
-
44
- export default {
45
- load
46
- }
package/src/location.ts DELETED
@@ -1,208 +0,0 @@
1
- import { cloneDeep } from 'lodash-es'
2
- import AMapLoader from './AMapLoader'
3
- import { urlquery } from './urlquery'
4
-
5
- type Location = {
6
- longitude: string
7
- latitude: string
8
- address: string
9
- [propName: string]: any
10
- } | null
11
-
12
- let AMap: any = null
13
- let geocoder: any = null
14
- let geolocation: any = null
15
- let datetime: number | null = null
16
- let lastLocation: Location = null
17
- let runing = false
18
- let locationPromise: Promise<Location>
19
-
20
- async function init() {
21
- if (!AMap) {
22
- AMap = await AMapLoader.load({
23
- plugins: ['AMap.Geolocation', 'AMap.Geocoder']
24
- })
25
- geocoder = new AMap.Geocoder({
26
- city: '',
27
- radius: 500
28
- })
29
- geolocation = new AMap.Geolocation({
30
- enableHighAccuracy: true,
31
- timeout: 3000
32
- })
33
- }
34
- }
35
-
36
- async function getAmapLocation(): Promise<Location> {
37
- await init()
38
- return new Promise((resolve, reject) => {
39
- // https://blog.csdn.net/Liu331013/article/details/115423749
40
- geolocation.getCurrentPosition((status: string, result: any) => {
41
- console.log(status, result)
42
- if (status === 'complete') {
43
- const { lng, lat } = result.position
44
- // console.log('getAmapLocation success')
45
- resolve({
46
- longitude: lng.toString(),
47
- latitude: lat.toString(),
48
- address: ''
49
- })
50
- } else {
51
- // reject(new Error('getAmapLocation fail'))
52
- console.error('getAmapLocation fail')
53
- resolve(null)
54
- }
55
- })
56
- })
57
- }
58
-
59
- async function getSpuLocation(): Promise<Location> {
60
- return new Promise((resolve, reject) => {
61
- let isload = false
62
- setTimeout(() => {
63
- if (!isload) {
64
- console.error('getSpuLocation timeout 30000')
65
- resolve(null)
66
- }
67
- }, 30000)
68
- window.Native.getLocation((result: any, error: any, status: any) => {
69
- isload = true
70
- // console.log('getLocation result', result)
71
- // console.log('getLocation error', error)
72
- // console.log('getLocation status', status)
73
- if (result && result?.longitude && result?.latitude) {
74
- resolve({
75
- longitude: result.longitude.toString(),
76
- latitude: result.latitude.toString(),
77
- address: result.address || ''
78
- })
79
- } else {
80
- console.error('getSpuLocation fail')
81
- resolve(null)
82
- }
83
- })
84
- })
85
- }
86
-
87
- async function getAmapCityLocation(): Promise<Location> {
88
- await init()
89
- return new Promise((resolve, reject) => {
90
- geolocation.getCityInfo((status: string, result: any) => {
91
- if (status === 'complete') {
92
- const lng = result.position[0].toString()
93
- const lat = result.position[1].toString()
94
- // console.log('getAmapCityLocation success')
95
- // resolve([lng, lat])
96
- resolve({
97
- longitude: lng.toString(),
98
- latitude: lat.toString(),
99
- address: ''
100
- })
101
- } else {
102
- // reject(new Error('getAmapCityLocation fail'))
103
- console.error('getAmapCityLocation fail')
104
- resolve(null)
105
- }
106
- })
107
- })
108
- }
109
-
110
- async function getAddress(position: Location): Promise<string> {
111
- await init()
112
- return new Promise((resolve, reject) => {
113
- if (position) {
114
- geocoder.getAddress([position.longitude, position.latitude], (status: string, result: any) => {
115
- if (status === 'complete' && result.regeocode) {
116
- resolve(result.regeocode.formattedAddress)
117
- } else {
118
- // reject(new Error('getAddress fail'))
119
- console.error('getAddress fail')
120
- resolve('')
121
- }
122
- })
123
- }
124
- })
125
- }
126
-
127
- // 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 高德地图高精度定位 > 百度地图定位 > 高德城市定位
128
- async function getLocationPromise(): Promise<Location> {
129
- let location: Location = null
130
-
131
- // 在 SPU 容器里使用 Native-API 的定位
132
- if (window?.Native?.getLocation) {
133
- location = await getSpuLocation()
134
- }
135
-
136
- // 高德定位
137
- if (!location) {
138
- location = await getAmapLocation()
139
- }
140
-
141
- // 城市定位结果不精确 仅在开发模式下使用
142
- // if (!location && process.env.NODE_ENV !== 'production') {
143
- if (!location && urlquery.isvirtuallocation) {
144
- location = await getAmapCityLocation()
145
- }
146
-
147
- // 测试虚拟定位
148
- if (!location && urlquery.isvirtuallocation) {
149
- location = {
150
- longitude: '113.34331353081598',
151
- latitude: '23.105349663628473',
152
- address: ''
153
- }
154
- }
155
-
156
- if (location && !location.address) {
157
- location.address = (await getAddress(location)) || '经纬度获取成功,但地址获取失败。'
158
- }
159
-
160
- return location
161
- }
162
-
163
- async function getLocation() {
164
- // debugger
165
- // 缓存30秒
166
- if (datetime && Date.now() - datetime <= 30000 && lastLocation && !runing) {
167
- return cloneDeep(lastLocation)
168
- }
169
- // 兼容同时间发起多个
170
- if (runing && locationPromise) {
171
- return locationPromise
172
- }
173
- // console.log('runing')
174
- runing = true
175
- locationPromise = getLocationPromise()
176
- const locationRes = await locationPromise
177
- runing = false
178
- if (locationRes) {
179
- datetime = Date.now()
180
- lastLocation = locationRes
181
- }
182
- return locationRes
183
- }
184
-
185
- async function getDistance(p1: [number, number], p2: [number, number]) {
186
- await init()
187
- return AMap.GeometryUtil.distance(p1, p2)
188
- }
189
-
190
- // // 两个经纬度距离计算
191
- // function getDistance (latlng1, latlng2) {
192
- // console.log(latlng1)
193
- // console.log(latlng2)
194
- // const lng1 = Number(latlng1[0])
195
- // const lat1 = Number(latlng1[1])
196
- // const lng2 = Number(latlng2[0])
197
- // const lat2 = Number(latlng2[1])
198
- // const radLat1 = (lat1 * Math.PI) / 180.0
199
- // const radLat2 = (lat2 * Math.PI) / 180.0
200
- // const a = radLat1 - radLat2
201
- // const b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0
202
- // let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
203
- // s = s * 6378.137 // EARTH_RADIUS
204
- // s = Math.round(s * 10000) / 10000
205
- // return s * 1000
206
- // }
207
-
208
- export { getLocation, getDistance }