@tarojs/taro-h5 3.6.24 → 3.6.26-alpha.1

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.cjs.js CHANGED
@@ -113,6 +113,10 @@ class CallbackManager {
113
113
  }
114
114
  });
115
115
  };
116
+ /** 清空所有回调 */
117
+ this.clear = () => {
118
+ this.callbacks = [];
119
+ };
116
120
  }
117
121
  }
118
122
 
@@ -163,7 +167,7 @@ function findDOM(inst) {
163
167
  }
164
168
  const page = runtime.Current.page;
165
169
  const path = page === null || page === void 0 ? void 0 : page.path;
166
- const msg = '没有找到已经加载了的页面,请在页面加载完成后时候此 API。';
170
+ const msg = '没有找到已经加载了的页面,请在页面加载完成后使用此 API。';
167
171
  if (path == null) {
168
172
  throw new Error(msg);
169
173
  }
@@ -2784,6 +2788,8 @@ const getApp = function () {
2784
2788
  // 自定义组件
2785
2789
  const getCurrentInstance = Taro.getCurrentInstance;
2786
2790
 
2791
+ const isGeolocationSupported = () => !!navigator.geolocation;
2792
+
2787
2793
  const getLocationByW3CApi = (options) => {
2788
2794
  var _a;
2789
2795
  // 断言 options 必须是 Object
@@ -2809,8 +2815,7 @@ const getLocationByW3CApi = (options) => {
2809
2815
  });
2810
2816
  }
2811
2817
  // 判断当前浏览器是否支持位置API
2812
- const geolocationSupported = navigator.geolocation;
2813
- if (!geolocationSupported) {
2818
+ if (!isGeolocationSupported()) {
2814
2819
  return handle.fail({
2815
2820
  errMsg: 'The current browser does not support this feature'
2816
2821
  });
@@ -2976,18 +2981,135 @@ const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
2976
2981
  });
2977
2982
  };
2978
2983
 
2979
- // 位置
2980
- const stopLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('stopLocationUpdate');
2984
+ const _successCbManager = new CallbackManager();
2985
+ const _errorCbManager = new CallbackManager();
2986
+ let _watchID = -1;
2987
+ function onLocationChange(callback) {
2988
+ _successCbManager.add(callback);
2989
+ }
2990
+ function offLocationChange(callback) {
2991
+ if (callback && typeof callback === 'function') {
2992
+ _successCbManager.remove(callback);
2993
+ }
2994
+ else if (callback === undefined) {
2995
+ _successCbManager.clear();
2996
+ }
2997
+ else {
2998
+ console.warn('offLocationChange failed');
2999
+ }
3000
+ }
3001
+ function onLocationChangeError(callback) {
3002
+ _errorCbManager.add(callback);
3003
+ }
3004
+ function offLocationChangeError(callback) {
3005
+ if (callback && typeof callback === 'function') {
3006
+ _errorCbManager.remove(callback);
3007
+ }
3008
+ else if (callback === undefined) {
3009
+ _errorCbManager.clear();
3010
+ }
3011
+ else {
3012
+ console.warn('offLocationChangeError failed');
3013
+ }
3014
+ }
3015
+ /**
3016
+ * 开始监听位置信息
3017
+ * @param opts
3018
+ * @returns
3019
+ */
3020
+ function startLocationUpdateByW3CApi(opts) {
3021
+ // 断言 options 必须是 Object
3022
+ const isObject = shouldBeObject(opts);
3023
+ if (!isObject.flag) {
3024
+ const res = { errMsg: `startLocationUpdate:fail ${isObject.msg}` };
3025
+ console.error(res.errMsg);
3026
+ return Promise.reject(res);
3027
+ }
3028
+ const { success, fail, complete } = opts;
3029
+ const handle = new MethodHandler({ name: 'startLocationUpdate', success, fail, complete });
3030
+ // 判断当前浏览器是否支持位置API
3031
+ if (!isGeolocationSupported()) {
3032
+ return handle.fail({
3033
+ errMsg: 'The current browser does not support this feature'
3034
+ });
3035
+ }
3036
+ try {
3037
+ if (_watchID > -1) {
3038
+ console.error('startLocationUpdate:fail');
3039
+ return handle.fail();
3040
+ }
3041
+ else {
3042
+ _watchID = navigator.geolocation.watchPosition(({ coords }) => {
3043
+ const { latitude, longitude, altitude, accuracy, speed } = coords;
3044
+ _successCbManager.trigger({
3045
+ accuracy,
3046
+ altitude,
3047
+ horizontalAccuracy: 0,
3048
+ verticalAccuracy: 0,
3049
+ latitude,
3050
+ longitude,
3051
+ speed,
3052
+ });
3053
+ }, err => {
3054
+ _errorCbManager.trigger({
3055
+ errMsg: 'Watch Position error',
3056
+ err
3057
+ });
3058
+ }, {
3059
+ timeout: 10,
3060
+ maximumAge: 0,
3061
+ enableHighAccuracy: true,
3062
+ });
3063
+ return handle.success();
3064
+ }
3065
+ }
3066
+ catch (error) {
3067
+ return handle.fail();
3068
+ }
3069
+ }
3070
+ /**
3071
+ * 停止监听位置信息
3072
+ * @param opts
3073
+ * @returns
3074
+ */
3075
+ function stopLocationUpdateByW3CApi(opts) {
3076
+ const isObject = shouldBeObject(opts);
3077
+ if (!isObject.flag) {
3078
+ const res = { errMsg: `stopLocationUpdate:fail ${isObject.msg}` };
3079
+ console.error(res.errMsg);
3080
+ return Promise.reject(res);
3081
+ }
3082
+ const { success, fail, complete } = opts;
3083
+ const handle = new MethodHandler({ name: 'stopLocationUpdate', success, fail, complete });
3084
+ // 判断当前浏览器是否支持位置API
3085
+ if (!isGeolocationSupported()) {
3086
+ return handle.fail({
3087
+ errMsg: 'The current browser does not support this feature'
3088
+ });
3089
+ }
3090
+ try {
3091
+ navigator.geolocation.clearWatch(_watchID);
3092
+ _watchID = -1;
3093
+ return handle.success();
3094
+ }
3095
+ catch (error) {
3096
+ return handle.fail();
3097
+ }
3098
+ }
3099
+ const stopLocationUpdate = /* @__PURE__ */ processOpenApi({
3100
+ name: 'stopLocationUpdate',
3101
+ standardMethod: stopLocationUpdateByW3CApi
3102
+ });
3103
+ const startLocationUpdate = /* @__PURE__ */ processOpenApi({
3104
+ name: 'startLocationUpdate',
3105
+ standardMethod: startLocationUpdateByW3CApi
3106
+ });
3107
+
2981
3108
  const startLocationUpdateBackground = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdateBackground');
2982
- const startLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdate');
2983
3109
  const openLocation = /* @__PURE__ */ processOpenApi({
2984
3110
  name: 'openLocation',
2985
3111
  defaultOptions: { scale: 18 }
2986
3112
  });
2987
- const onLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('onLocationChangeError');
2988
- const onLocationChange = /* @__PURE__ */ temporarilyNotSupport('onLocationChange');
2989
- const offLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('offLocationChangeError');
2990
- const offLocationChange = /* @__PURE__ */ temporarilyNotSupport('offLocationChange');
2991
3113
  const choosePoi = /* @__PURE__ */ temporarilyNotSupport('choosePoi');
2992
3114
  const getFuzzyLocation = /* @__PURE__ */ temporarilyNotSupport('getFuzzyLocation');
2993
3115
 
@@ -3740,7 +3862,15 @@ const loadFontFace = (options) => tslib.__awaiter(void 0, void 0, void 0, functi
3740
3862
  const getMenuButtonBoundingClientRect = /* @__PURE__ */ temporarilyNotSupport('getMenuButtonBoundingClientRect');
3741
3863
 
3742
3864
  // 导航栏
3743
- const showNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('showNavigationBarLoading');
3865
+ /**
3866
+ * 展示导航栏 loading 状态
3867
+ */
3868
+ function showNavigationBarLoading(options = {}) {
3869
+ const { success, fail, complete } = options;
3870
+ const handle = new MethodHandler({ name: 'showNavigationBarLoading', success, fail, complete });
3871
+ router.setNavigationBarLoading(true);
3872
+ return handle.success();
3873
+ }
3744
3874
  function setNavigationBarTitle(options) {
3745
3875
  // options must be an Object
3746
3876
  const isObject = shouldBeObject(options);
@@ -3776,7 +3906,15 @@ const setNavigationBarColor = (options) => {
3776
3906
  router.setNavigationBarStyle({ frontColor, backgroundColor });
3777
3907
  return handle.success();
3778
3908
  };
3779
- const hideNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('hideNavigationBarLoading');
3909
+ /**
3910
+ * 隐藏导航栏 loading 状态
3911
+ */
3912
+ function hideNavigationBarLoading(options = {}) {
3913
+ const { success, fail, complete } = options;
3914
+ const handle = new MethodHandler({ name: 'hideNavigationBarLoading', success, fail, complete });
3915
+ router.setNavigationBarLoading(false);
3916
+ return handle.success();
3917
+ }
3780
3918
  const hideHomeButton = /* @__PURE__ */ temporarilyNotSupport('hideHomeButton');
3781
3919
 
3782
3920
  /**