@smart100/spu-web-plugin 1.0.0 → 1.0.4
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/README.md +1 -0
- package/dist/index.d.ts +13 -15
- package/dist/spu-web-plugin.mjs +19354 -19345
- package/package.json +2 -2
- package/src/apaasSpuTrack.ts +42 -72
- package/src/axios.ts +136 -132
- package/src/cloudServ.ts +4 -4
- package/src/components/expandexp/index.ts +260 -205
- package/src/core.js +120 -59
- package/src/globalConfig.ts +5 -7
- package/src/index.ts +48 -111
- package/src/location.ts +20 -23
- package/src/login.ts +534 -428
- package/src/nativeApi.ts +7 -10
- package/src/oss/OSSClient.ts +20 -0
- package/src/oss/downloadService.ts +73 -73
- package/src/oss/index.ts +1 -5
- package/src/oss/multiUpload.ts +7 -4
- package/src/oss/servtoken.ts +2 -52
- package/src/oss/uploadService.ts +64 -78
- package/src/spuConfig.ts +7 -10
- package/src/storageProxy.ts +11 -13
- package/src/test.ts +3 -17
- package/src/types/global.d.ts +1 -1
- package/src/types/index.d.ts +13 -15
- package/src/types/shims-lib.d.ts +4 -10
- package/src/urlquery.ts +37 -5
- package/src/utils.ts +15 -31
- package/src/wxworksuitePlugin.ts +25 -0
package/src/location.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import AMapLoader from './AMapLoader'
|
|
2
1
|
import { cloneDeep } from 'lodash-es'
|
|
3
|
-
import
|
|
2
|
+
import AMapLoader from './AMapLoader'
|
|
3
|
+
import { urlquery } from './urlquery'
|
|
4
4
|
|
|
5
5
|
type Location = {
|
|
6
|
-
longitude: string
|
|
7
|
-
latitude: string
|
|
8
|
-
address: string
|
|
9
|
-
[propName: string]: any
|
|
6
|
+
longitude: string
|
|
7
|
+
latitude: string
|
|
8
|
+
address: string
|
|
9
|
+
[propName: string]: any
|
|
10
10
|
} | null
|
|
11
11
|
|
|
12
12
|
let AMap: any = null
|
|
@@ -17,7 +17,7 @@ let lastLocation: Location = null
|
|
|
17
17
|
let runing = false
|
|
18
18
|
let locationPromise: Promise<Location>
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
async function init() {
|
|
21
21
|
if (!AMap) {
|
|
22
22
|
AMap = await AMapLoader.load({
|
|
23
23
|
plugins: ['AMap.Geolocation', 'AMap.Geocoder']
|
|
@@ -33,10 +33,12 @@ const init = async () => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
async function getAmapLocation(): Promise<Location> {
|
|
37
37
|
await init()
|
|
38
38
|
return new Promise((resolve, reject) => {
|
|
39
|
+
// https://blog.csdn.net/Liu331013/article/details/115423749
|
|
39
40
|
geolocation.getCurrentPosition((status: string, result: any) => {
|
|
41
|
+
console.log(status, result)
|
|
40
42
|
if (status === 'complete') {
|
|
41
43
|
const { lng, lat } = result.position
|
|
42
44
|
// console.log('getAmapLocation success')
|
|
@@ -54,15 +56,15 @@ const getAmapLocation = async (): Promise<Location> => {
|
|
|
54
56
|
})
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
async function getSpuLocation(): Promise<Location> {
|
|
58
60
|
return new Promise((resolve, reject) => {
|
|
59
61
|
let isload = false
|
|
60
62
|
setTimeout(() => {
|
|
61
63
|
if (!isload) {
|
|
62
|
-
console.error('getSpuLocation timeout
|
|
64
|
+
console.error('getSpuLocation timeout 30000')
|
|
63
65
|
resolve(null)
|
|
64
66
|
}
|
|
65
|
-
},
|
|
67
|
+
}, 30000)
|
|
66
68
|
window.Native.getLocation((result: any, error: any, status: any) => {
|
|
67
69
|
isload = true
|
|
68
70
|
// console.log('getLocation result', result)
|
|
@@ -82,7 +84,7 @@ const getSpuLocation = async (): Promise<Location> => {
|
|
|
82
84
|
})
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
async function getAmapCityLocation(): Promise<Location> {
|
|
86
88
|
await init()
|
|
87
89
|
return new Promise((resolve, reject) => {
|
|
88
90
|
geolocation.getCityInfo((status: string, result: any) => {
|
|
@@ -105,7 +107,7 @@ const getAmapCityLocation = async (): Promise<Location> => {
|
|
|
105
107
|
})
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
async function getAddress(position: Location): Promise<string> {
|
|
109
111
|
await init()
|
|
110
112
|
return new Promise((resolve, reject) => {
|
|
111
113
|
if (position) {
|
|
@@ -123,7 +125,7 @@ const getAddress = async (position: Location): Promise<string> => {
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
// 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 高德地图高精度定位 > 百度地图定位 > 高德城市定位
|
|
126
|
-
|
|
128
|
+
async function getLocationPromise(): Promise<Location> {
|
|
127
129
|
let location: Location = null
|
|
128
130
|
|
|
129
131
|
// 在 SPU 容器里使用 Native-API 的定位
|
|
@@ -152,14 +154,13 @@ const getLocationPromise = async (): Promise<Location> => {
|
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
if (location && !location.address) {
|
|
155
|
-
location.address = await getAddress(location) || '经纬度获取成功,但地址获取失败。'
|
|
157
|
+
location.address = (await getAddress(location)) || '经纬度获取成功,但地址获取失败。'
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
return location
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
|
|
162
|
-
const getLocation = async () => {
|
|
163
|
+
async function getLocation() {
|
|
163
164
|
// debugger
|
|
164
165
|
// 缓存30秒
|
|
165
166
|
if (datetime && Date.now() - datetime <= 30000 && lastLocation && !runing) {
|
|
@@ -181,12 +182,11 @@ const getLocation = async () => {
|
|
|
181
182
|
return locationRes
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
|
|
185
|
+
async function getDistance(p1: [number, number], p2: [number, number]) {
|
|
185
186
|
await init()
|
|
186
187
|
return AMap.GeometryUtil.distance(p1, p2)
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
|
|
190
190
|
// // 两个经纬度距离计算
|
|
191
191
|
// function getDistance (latlng1, latlng2) {
|
|
192
192
|
// console.log(latlng1)
|
|
@@ -205,7 +205,4 @@ const getDistance = async (p1: [number, number], p2: [number, number]) => {
|
|
|
205
205
|
// return s * 1000
|
|
206
206
|
// }
|
|
207
207
|
|
|
208
|
-
export {
|
|
209
|
-
getLocation,
|
|
210
|
-
getDistance
|
|
211
|
-
}
|
|
208
|
+
export { getLocation, getDistance }
|