@tarojs/taro-h5 3.4.6 → 3.4.7
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/api/device/scan.js +8 -4
- package/dist/api/location/getLocation.js +64 -0
- package/dist/api/location/index.js +6 -3
- package/dist/api/utils/index.js +30 -25
- package/dist/dist/api/device/scan.d.ts +3 -1
- package/dist/dist/api/location/getLocation.d.ts +2 -0
- package/dist/dist/api/location/index.d.ts +5 -3
- package/dist/dist/api/utils/index.d.ts +8 -1
- package/dist/index.cjs.js +105 -31
- package/dist/index.cjs.js.map +1 -1
- package/package.json +7 -7
- package/src/api/device/scan.ts +8 -4
- package/src/api/location/getLocation.ts +80 -0
- package/src/api/location/index.ts +6 -3
- package/src/api/utils/index.ts +39 -23
package/dist/api/device/scan.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { processOpenApi } from '../utils';
|
|
2
2
|
// 扫码
|
|
3
|
-
export const scanCode = processOpenApi(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export const scanCode = processOpenApi({
|
|
4
|
+
name: 'scanQRCode',
|
|
5
|
+
defaultOptions: { needResult: 1 },
|
|
6
|
+
formatResult: res => ({
|
|
7
|
+
errMsg: res.errMsg === 'scanQRCode:ok' ? 'scanCode:ok' : res.errMsg,
|
|
8
|
+
result: res.resultStr
|
|
9
|
+
})
|
|
10
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { processOpenApi, shouldBeObject } from '../utils';
|
|
2
|
+
import { MethodHandler } from '../utils/handler';
|
|
3
|
+
const getLocationByW3CApi = (options) => {
|
|
4
|
+
var _a;
|
|
5
|
+
// 断言 options 必须是 Object
|
|
6
|
+
const isObject = shouldBeObject(options);
|
|
7
|
+
if (!isObject.flag) {
|
|
8
|
+
const res = { errMsg: `getLocation:fail ${isObject.msg}` };
|
|
9
|
+
console.error(res.errMsg);
|
|
10
|
+
return Promise.reject(res);
|
|
11
|
+
}
|
|
12
|
+
// 解构回调函数
|
|
13
|
+
const { success, fail, complete } = options;
|
|
14
|
+
const handle = new MethodHandler({ name: 'getLocation', success, fail, complete });
|
|
15
|
+
// const defaultMaximumAge = 5 * 1000
|
|
16
|
+
const positionOptions = {
|
|
17
|
+
enableHighAccuracy: options.isHighAccuracy || (options.altitude != null),
|
|
18
|
+
// maximumAge: defaultMaximumAge, // 允许取多久以内的缓存位置
|
|
19
|
+
timeout: options.highAccuracyExpireTime // 高精度定位超时时间
|
|
20
|
+
};
|
|
21
|
+
// Web端API实现暂时仅支持GPS坐标系
|
|
22
|
+
if (((_a = options.type) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== 'WGS84') {
|
|
23
|
+
return handle.fail({
|
|
24
|
+
errMsg: 'This coordinate system type is not temporarily supported'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// 判断当前浏览器是否支持位置API
|
|
28
|
+
const geolocationSupported = navigator.geolocation;
|
|
29
|
+
if (!geolocationSupported) {
|
|
30
|
+
return handle.fail({
|
|
31
|
+
errMsg: 'The current browser does not support this feature'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// 开始获取位置
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
navigator.geolocation.getCurrentPosition((position) => {
|
|
37
|
+
const result = {
|
|
38
|
+
/** 位置的精确度 */
|
|
39
|
+
accuracy: position.coords.accuracy,
|
|
40
|
+
/** 高度,单位 m */
|
|
41
|
+
altitude: position.coords.altitude,
|
|
42
|
+
/** 水平精度,单位 m */
|
|
43
|
+
horizontalAccuracy: position.coords.accuracy,
|
|
44
|
+
/** 纬度,范围为 -90~90,负数表示南纬 */
|
|
45
|
+
latitude: position.coords.latitude,
|
|
46
|
+
/** 经度,范围为 -180~180,负数表示西经 */
|
|
47
|
+
longitude: position.coords.longitude,
|
|
48
|
+
/** 速度,单位 m/s */
|
|
49
|
+
speed: position.coords.speed,
|
|
50
|
+
/** 垂直精度,单位 m(Android 无法获取,返回 0) */
|
|
51
|
+
verticalAccuracy: position.coords.altitudeAccuracy || 0,
|
|
52
|
+
/** 调用结果,自动补充 */
|
|
53
|
+
errMsg: ''
|
|
54
|
+
};
|
|
55
|
+
handle.success(result, resolve);
|
|
56
|
+
}, (error) => {
|
|
57
|
+
handle.fail({ errMsg: error.message }, reject);
|
|
58
|
+
}, positionOptions);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export const getLocation = processOpenApi({
|
|
62
|
+
name: 'getLocation',
|
|
63
|
+
standardMethod: getLocationByW3CApi
|
|
64
|
+
});
|
|
@@ -3,11 +3,14 @@ import { processOpenApi, temporarilyNotSupport } from '../utils/index';
|
|
|
3
3
|
export const stopLocationUpdate = temporarilyNotSupport('stopLocationUpdate');
|
|
4
4
|
export const startLocationUpdateBackground = temporarilyNotSupport('startLocationUpdateBackground');
|
|
5
5
|
export const startLocationUpdate = temporarilyNotSupport('startLocationUpdate');
|
|
6
|
-
export const openLocation = processOpenApi(
|
|
6
|
+
export const openLocation = processOpenApi({
|
|
7
|
+
name: 'openLocation',
|
|
8
|
+
defaultOptions: { scale: 18 }
|
|
9
|
+
});
|
|
7
10
|
export const onLocationChangeError = temporarilyNotSupport('onLocationChangeError');
|
|
8
11
|
export const onLocationChange = temporarilyNotSupport('onLocationChange');
|
|
9
12
|
export const offLocationChangeError = temporarilyNotSupport('offLocationChangeError');
|
|
10
13
|
export const offLocationChange = temporarilyNotSupport('offLocationChange');
|
|
11
|
-
export
|
|
14
|
+
export { getLocation } from './getLocation';
|
|
12
15
|
export const choosePoi = temporarilyNotSupport('choosePoi');
|
|
13
|
-
export
|
|
16
|
+
export { chooseLocation } from './chooseLocation';
|
package/dist/api/utils/index.js
CHANGED
|
@@ -90,7 +90,7 @@ export function temporarilyNotSupport(apiName) {
|
|
|
90
90
|
}
|
|
91
91
|
export function weixinCorpSupport(apiName) {
|
|
92
92
|
return () => {
|
|
93
|
-
const errMsg = `h5
|
|
93
|
+
const errMsg = `h5端当前仅在微信公众号JS-SDK环境下支持此 API ${apiName}`;
|
|
94
94
|
if (process.env.NODE_ENV !== 'production') {
|
|
95
95
|
console.error(errMsg);
|
|
96
96
|
return Promise.reject({
|
|
@@ -129,31 +129,36 @@ const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
|
|
|
129
129
|
export const isValidColor = (color) => {
|
|
130
130
|
return VALID_COLOR_REG.test(color);
|
|
131
131
|
};
|
|
132
|
-
export function processOpenApi(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
132
|
+
export function processOpenApi({ name, defaultOptions, standardMethod, formatOptions = options => options, formatResult = res => res }) {
|
|
133
|
+
const notSupported = weixinCorpSupport(name);
|
|
134
|
+
return (options = {}) => {
|
|
135
|
+
var _a;
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
const targetApi = (_a = window === null || window === void 0 ? void 0 : window.wx) === null || _a === void 0 ? void 0 : _a[name];
|
|
138
|
+
const opts = formatOptions(Object.assign({}, defaultOptions, options));
|
|
139
|
+
if (typeof targetApi === 'function') {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
['fail', 'success', 'complete'].forEach(k => {
|
|
142
|
+
opts[k] = preRef => {
|
|
143
|
+
const res = formatResult(preRef);
|
|
144
|
+
options[k] && options[k](res);
|
|
145
|
+
if (k === 'success') {
|
|
146
|
+
resolve(res);
|
|
147
|
+
}
|
|
148
|
+
else if (k === 'fail') {
|
|
149
|
+
reject(res);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
return targetApi(opts);
|
|
153
|
+
});
|
|
152
154
|
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
}
|
|
156
|
+
else if (typeof standardMethod === 'function') {
|
|
157
|
+
return standardMethod(opts);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return notSupported();
|
|
161
|
+
}
|
|
157
162
|
};
|
|
158
163
|
}
|
|
159
164
|
/**
|
|
@@ -7,7 +7,9 @@ export declare const startLocationUpdateBackground: () => Promise<{
|
|
|
7
7
|
export declare const startLocationUpdate: () => Promise<{
|
|
8
8
|
errMsg: string;
|
|
9
9
|
}>;
|
|
10
|
-
export declare const openLocation: (options
|
|
10
|
+
export declare const openLocation: (options?: Partial<{
|
|
11
|
+
scale: number;
|
|
12
|
+
}>) => Promise<any>;
|
|
11
13
|
export declare const onLocationChangeError: () => Promise<{
|
|
12
14
|
errMsg: string;
|
|
13
15
|
}>;
|
|
@@ -20,8 +22,8 @@ export declare const offLocationChangeError: () => Promise<{
|
|
|
20
22
|
export declare const offLocationChange: () => Promise<{
|
|
21
23
|
errMsg: string;
|
|
22
24
|
}>;
|
|
23
|
-
export
|
|
25
|
+
export { getLocation } from './getLocation';
|
|
24
26
|
export declare const choosePoi: () => Promise<{
|
|
25
27
|
errMsg: string;
|
|
26
28
|
}>;
|
|
27
|
-
export
|
|
29
|
+
export { chooseLocation } from './chooseLocation';
|
|
@@ -28,7 +28,14 @@ export declare function permanentlyNotSupport(apiName: any): () => Promise<{
|
|
|
28
28
|
}>;
|
|
29
29
|
export declare function isFunction(obj: any): boolean;
|
|
30
30
|
export declare const isValidColor: (color: any) => boolean;
|
|
31
|
-
|
|
31
|
+
interface IProcessOpenApi<TOptions = Record<string, unknown>, TResult extends TaroGeneral.CallbackResult = any> {
|
|
32
|
+
name: string;
|
|
33
|
+
defaultOptions?: TOptions;
|
|
34
|
+
standardMethod?: (opts: TOptions) => Promise<TResult>;
|
|
35
|
+
formatOptions?: (opts: TOptions) => TOptions;
|
|
36
|
+
formatResult?: (res: TResult) => TResult;
|
|
37
|
+
}
|
|
38
|
+
export declare function processOpenApi<TOptions = Record<string, unknown>, TResult extends TaroGeneral.CallbackResult = any>({ name, defaultOptions, standardMethod, formatOptions, formatResult }: IProcessOpenApi<TOptions, TResult>): (options?: Partial<TOptions>) => Promise<TResult>;
|
|
32
39
|
/**
|
|
33
40
|
* ease-in-out的函数
|
|
34
41
|
* @param t 0-1的数字
|
package/dist/index.cjs.js
CHANGED
|
@@ -108,7 +108,7 @@ function temporarilyNotSupport(apiName) {
|
|
|
108
108
|
}
|
|
109
109
|
function weixinCorpSupport(apiName) {
|
|
110
110
|
return () => {
|
|
111
|
-
const errMsg = `h5
|
|
111
|
+
const errMsg = `h5端当前仅在微信公众号JS-SDK环境下支持此 API ${apiName}`;
|
|
112
112
|
if (process.env.NODE_ENV !== 'production') {
|
|
113
113
|
console.error(errMsg);
|
|
114
114
|
return Promise.reject({
|
|
@@ -147,31 +147,36 @@ const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
|
|
|
147
147
|
const isValidColor = (color) => {
|
|
148
148
|
return VALID_COLOR_REG.test(color);
|
|
149
149
|
};
|
|
150
|
-
function processOpenApi(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
150
|
+
function processOpenApi({ name, defaultOptions, standardMethod, formatOptions = options => options, formatResult = res => res }) {
|
|
151
|
+
const notSupported = weixinCorpSupport(name);
|
|
152
|
+
return (options = {}) => {
|
|
153
|
+
var _a;
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
const targetApi = (_a = window === null || window === void 0 ? void 0 : window.wx) === null || _a === void 0 ? void 0 : _a[name];
|
|
156
|
+
const opts = formatOptions(Object.assign({}, defaultOptions, options));
|
|
157
|
+
if (typeof targetApi === 'function') {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
['fail', 'success', 'complete'].forEach(k => {
|
|
160
|
+
opts[k] = preRef => {
|
|
161
|
+
const res = formatResult(preRef);
|
|
162
|
+
options[k] && options[k](res);
|
|
163
|
+
if (k === 'success') {
|
|
164
|
+
resolve(res);
|
|
165
|
+
}
|
|
166
|
+
else if (k === 'fail') {
|
|
167
|
+
reject(res);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return targetApi(opts);
|
|
171
|
+
});
|
|
170
172
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
}
|
|
174
|
+
else if (typeof standardMethod === 'function') {
|
|
175
|
+
return standardMethod(opts);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return notSupported();
|
|
179
|
+
}
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
182
|
/**
|
|
@@ -1478,10 +1483,14 @@ const makePhoneCall = (options) => {
|
|
|
1478
1483
|
};
|
|
1479
1484
|
|
|
1480
1485
|
// 扫码
|
|
1481
|
-
const scanCode = processOpenApi(
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1486
|
+
const scanCode = processOpenApi({
|
|
1487
|
+
name: 'scanQRCode',
|
|
1488
|
+
defaultOptions: { needResult: 1 },
|
|
1489
|
+
formatResult: res => ({
|
|
1490
|
+
errMsg: res.errMsg === 'scanQRCode:ok' ? 'scanCode:ok' : res.errMsg,
|
|
1491
|
+
result: res.resultStr
|
|
1492
|
+
})
|
|
1493
|
+
});
|
|
1485
1494
|
|
|
1486
1495
|
// 屏幕
|
|
1487
1496
|
const setVisualEffectOnCapture = temporarilyNotSupport('setVisualEffectOnCapture');
|
|
@@ -1559,6 +1568,69 @@ const getApp = function () {
|
|
|
1559
1568
|
// 自定义组件
|
|
1560
1569
|
const getCurrentInstance = Taro__default["default"].getCurrentInstance;
|
|
1561
1570
|
|
|
1571
|
+
const getLocationByW3CApi = (options) => {
|
|
1572
|
+
var _a;
|
|
1573
|
+
// 断言 options 必须是 Object
|
|
1574
|
+
const isObject = shouldBeObject(options);
|
|
1575
|
+
if (!isObject.flag) {
|
|
1576
|
+
const res = { errMsg: `getLocation:fail ${isObject.msg}` };
|
|
1577
|
+
console.error(res.errMsg);
|
|
1578
|
+
return Promise.reject(res);
|
|
1579
|
+
}
|
|
1580
|
+
// 解构回调函数
|
|
1581
|
+
const { success, fail, complete } = options;
|
|
1582
|
+
const handle = new MethodHandler({ name: 'getLocation', success, fail, complete });
|
|
1583
|
+
// const defaultMaximumAge = 5 * 1000
|
|
1584
|
+
const positionOptions = {
|
|
1585
|
+
enableHighAccuracy: options.isHighAccuracy || (options.altitude != null),
|
|
1586
|
+
// maximumAge: defaultMaximumAge, // 允许取多久以内的缓存位置
|
|
1587
|
+
timeout: options.highAccuracyExpireTime // 高精度定位超时时间
|
|
1588
|
+
};
|
|
1589
|
+
// Web端API实现暂时仅支持GPS坐标系
|
|
1590
|
+
if (((_a = options.type) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== 'WGS84') {
|
|
1591
|
+
return handle.fail({
|
|
1592
|
+
errMsg: 'This coordinate system type is not temporarily supported'
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
// 判断当前浏览器是否支持位置API
|
|
1596
|
+
const geolocationSupported = navigator.geolocation;
|
|
1597
|
+
if (!geolocationSupported) {
|
|
1598
|
+
return handle.fail({
|
|
1599
|
+
errMsg: 'The current browser does not support this feature'
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
// 开始获取位置
|
|
1603
|
+
return new Promise((resolve, reject) => {
|
|
1604
|
+
navigator.geolocation.getCurrentPosition((position) => {
|
|
1605
|
+
const result = {
|
|
1606
|
+
/** 位置的精确度 */
|
|
1607
|
+
accuracy: position.coords.accuracy,
|
|
1608
|
+
/** 高度,单位 m */
|
|
1609
|
+
altitude: position.coords.altitude,
|
|
1610
|
+
/** 水平精度,单位 m */
|
|
1611
|
+
horizontalAccuracy: position.coords.accuracy,
|
|
1612
|
+
/** 纬度,范围为 -90~90,负数表示南纬 */
|
|
1613
|
+
latitude: position.coords.latitude,
|
|
1614
|
+
/** 经度,范围为 -180~180,负数表示西经 */
|
|
1615
|
+
longitude: position.coords.longitude,
|
|
1616
|
+
/** 速度,单位 m/s */
|
|
1617
|
+
speed: position.coords.speed,
|
|
1618
|
+
/** 垂直精度,单位 m(Android 无法获取,返回 0) */
|
|
1619
|
+
verticalAccuracy: position.coords.altitudeAccuracy || 0,
|
|
1620
|
+
/** 调用结果,自动补充 */
|
|
1621
|
+
errMsg: ''
|
|
1622
|
+
};
|
|
1623
|
+
handle.success(result, resolve);
|
|
1624
|
+
}, (error) => {
|
|
1625
|
+
handle.fail({ errMsg: error.message }, reject);
|
|
1626
|
+
}, positionOptions);
|
|
1627
|
+
});
|
|
1628
|
+
};
|
|
1629
|
+
const getLocation = processOpenApi({
|
|
1630
|
+
name: 'getLocation',
|
|
1631
|
+
standardMethod: getLocationByW3CApi
|
|
1632
|
+
});
|
|
1633
|
+
|
|
1562
1634
|
function styleInject(css, ref) {
|
|
1563
1635
|
if ( ref === void 0 ) ref = {};
|
|
1564
1636
|
var insertAt = ref.insertAt;
|
|
@@ -1694,12 +1766,14 @@ const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
|
|
|
1694
1766
|
const stopLocationUpdate = temporarilyNotSupport('stopLocationUpdate');
|
|
1695
1767
|
const startLocationUpdateBackground = temporarilyNotSupport('startLocationUpdateBackground');
|
|
1696
1768
|
const startLocationUpdate = temporarilyNotSupport('startLocationUpdate');
|
|
1697
|
-
const openLocation = processOpenApi(
|
|
1769
|
+
const openLocation = processOpenApi({
|
|
1770
|
+
name: 'openLocation',
|
|
1771
|
+
defaultOptions: { scale: 18 }
|
|
1772
|
+
});
|
|
1698
1773
|
const onLocationChangeError = temporarilyNotSupport('onLocationChangeError');
|
|
1699
1774
|
const onLocationChange = temporarilyNotSupport('onLocationChange');
|
|
1700
1775
|
const offLocationChangeError = temporarilyNotSupport('offLocationChangeError');
|
|
1701
1776
|
const offLocationChange = temporarilyNotSupport('offLocationChange');
|
|
1702
|
-
const getLocation = processOpenApi('getLocation');
|
|
1703
1777
|
const choosePoi = temporarilyNotSupport('choosePoi');
|
|
1704
1778
|
|
|
1705
1779
|
class InnerAudioContext {
|