@tmsfe/tms-core 0.0.12 → 0.0.13

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.js CHANGED
@@ -543,6 +543,8 @@ function getWxLocation(type = defaultLocationType) {
543
543
  });
544
544
  });
545
545
  }
546
+ // 是否开启监听位置变更
547
+ let isListenerLocation = false;
546
548
  /**
547
549
  * @class Location
548
550
  * @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
@@ -550,11 +552,14 @@ function getWxLocation(type = defaultLocationType) {
550
552
  */
551
553
  class LocationBase {
552
554
  /**
553
- * @private 构造函数
555
+ * @private 开启监听位置变更,要在授权之后才能开启
554
556
  */
555
- constructor() {
556
- wx.onLocationChange(this.subscribeLocationChnage);
557
- wx.startLocationUpdate({});
557
+ listenerLocation() {
558
+ if (!isListenerLocation) {
559
+ isListenerLocation = true;
560
+ wx.onLocationChange(this.subscribeLocationChnage);
561
+ wx.startLocationUpdate({});
562
+ }
558
563
  }
559
564
  /**
560
565
  * 获取用户当前位置(经纬度)
@@ -604,6 +609,7 @@ class LocationBase {
604
609
  getWxLocationPromise(showModalWhenCloseAuth, type, content = '', showCancel = true) {
605
610
  return new Promise((resolve, reject) => {
606
611
  getWxLocation(type).then((res) => {
612
+ this.listenerLocation();
607
613
  userLocationCache$1 = res;
608
614
  // 更新用户状态 -- todo
609
615
  updateLocStatus(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/rollup.config.js CHANGED
@@ -98,7 +98,7 @@ function createConfig(format, output, plugins = []) {
98
98
  // exclude: ['node_modules/**'],
99
99
  }),
100
100
  // terser(),
101
- // createReplacePlugin(),
101
+ createReplacePlugin(),
102
102
  ...extralPlugin,
103
103
  ...plugins,
104
104
  ],
@@ -29,6 +29,9 @@ function getWxLocation(type: string = defaultLocationType): Promise<WxPostionTyp
29
29
  });
30
30
  }
31
31
 
32
+ // 是否开启监听位置变更
33
+ let isListenerLocation = false;
34
+
32
35
  /**
33
36
  * @class Location
34
37
  * @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
@@ -36,11 +39,14 @@ function getWxLocation(type: string = defaultLocationType): Promise<WxPostionTyp
36
39
  */
37
40
  class LocationBase {
38
41
  /**
39
- * @private 构造函数
42
+ * @private 开启监听位置变更,要在授权之后才能开启
40
43
  */
41
- constructor() {
42
- wx.onLocationChange(this.subscribeLocationChnage);
43
- wx.startLocationUpdate({});
44
+ listenerLocation() {
45
+ if (!isListenerLocation) {
46
+ isListenerLocation = true;
47
+ wx.onLocationChange(this.subscribeLocationChnage);
48
+ wx.startLocationUpdate({});
49
+ }
44
50
  }
45
51
 
46
52
  /**
@@ -95,6 +101,7 @@ class LocationBase {
95
101
  public getWxLocationPromise(showModalWhenCloseAuth: boolean, type: string, content = '', showCancel = true) {
96
102
  return new Promise((resolve, reject) => {
97
103
  getWxLocation(type).then((res: WxPostionType) => {
104
+ this.listenerLocation();
98
105
  userLocationCache = res;
99
106
  // 更新用户状态 -- todo
100
107
  updateLocStatus(true);