@tmsfe/tms-core 0.0.194 → 0.0.196
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/package.json +1 -1
- package/src/location/utils.ts +20 -21
- package/src/wxApi.ts +38 -0
package/package.json
CHANGED
package/src/location/utils.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import EventDispatcher from '../eventDispatcher';
|
|
6
|
+
import { getWxSetting } from '../wxApi';
|
|
6
7
|
|
|
7
8
|
const event = new EventDispatcher();
|
|
8
9
|
|
|
@@ -80,27 +81,25 @@ export function getSetting(scopeKey: string = LocationScopeKey) {
|
|
|
80
81
|
return getSettingPromise;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
});
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
85
|
+
getSettingPromise = new Promise(async (resolve, reject) => {
|
|
86
|
+
// 历史逻辑:这里需要每次调用都获取最新的setting —— 后续评估优化
|
|
87
|
+
const settingRes = await getWxSetting(true);
|
|
88
|
+
const { success, errMsg = '', authSetting } = settingRes;
|
|
89
|
+
if (success) {
|
|
90
|
+
resolve((authSetting as any)?.[scopeKey]);
|
|
91
|
+
getSettingPromise = null;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
getSettingPromise = null;
|
|
95
|
+
// wx.getSetting接口没有响应时errMsg
|
|
96
|
+
const reason = 'getSetting:fail data no response';
|
|
97
|
+
// 部分机型上,wx.getSetting接口没有响应,此时,当做位置开关是打开的来处理
|
|
98
|
+
if (errMsg.indexOf(reason) > -1) {
|
|
99
|
+
resolve(true);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
reject(settingRes);
|
|
104
103
|
});
|
|
105
104
|
|
|
106
105
|
return getSettingPromise;
|
package/src/wxApi.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 微信API工具类
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* getSetting
|
|
7
|
+
* @param forceRefresh 是否强制刷新
|
|
8
|
+
*/
|
|
9
|
+
async function getWxSetting(forceRefresh = false): Promise<{
|
|
10
|
+
success: boolean; // 是否成功
|
|
11
|
+
errMsg?: string, // message
|
|
12
|
+
authSetting?: { // 用户设置
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
};
|
|
15
|
+
subscriptionsSetting?: {
|
|
16
|
+
mainSwitch: boolean; // 订阅消息总开关
|
|
17
|
+
itemSettings?: { // 每一项开关
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}> {
|
|
22
|
+
if (wx.tmsGetWxSetting && !forceRefresh) {
|
|
23
|
+
return wx.tmsGetWxSetting;
|
|
24
|
+
}
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
const cacheData = (data, success) => {
|
|
27
|
+
wx.tmsGetWxSetting = { ...(data || {}), success };
|
|
28
|
+
resolve(wx.tmsGetWxSetting);
|
|
29
|
+
};
|
|
30
|
+
wx.getSetting({
|
|
31
|
+
withSubscriptions: true,
|
|
32
|
+
success: res => cacheData(res, true),
|
|
33
|
+
fail: err => cacheData(err, false),
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { getWxSetting };
|