@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.32 → 1.0.0-beta.33
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/sdk/WeComAdapter.js +34 -1
- package/src/sdk/WechatAdapter.js +47 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [1.0.0-beta.33](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.32...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.33) (2025-07-21)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
6
|
+
|
|
7
|
+
* **getLocation:** 解决在 URL 变化时,由于 wx.config 和 wx.ready 的异步特性导致的微信接口调用使用旧配置、签名失效或调用失败的问题 ([08b96b6](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/08b96b61e0fa07bc3cad53b5bb4c8025e297e12c))
|
|
8
|
+
|
|
2
9
|
## [1.0.0-beta.32](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.31...@lambo-design-mobile/lambo-js-bridge@1.0.0-beta.32) (2025-07-16)
|
|
3
10
|
|
|
4
11
|
|
package/package.json
CHANGED
package/src/sdk/WeComAdapter.js
CHANGED
|
@@ -90,7 +90,40 @@ class WeComAdapter {
|
|
|
90
90
|
|
|
91
91
|
async getLocation(options) {
|
|
92
92
|
return new Promise((resolve, reject) => {
|
|
93
|
-
wx.ready(() => {
|
|
93
|
+
wx.ready(async () => {
|
|
94
|
+
// 解决在 URL 变化时,由于 wx.config 和 wx.ready 的异步特性导致的微信接口调用使用旧配置、签名失效或调用失败的问题
|
|
95
|
+
// 新增重试机制检查接口可用性
|
|
96
|
+
let retryInterval;
|
|
97
|
+
try {
|
|
98
|
+
await new Promise((retryResolve, retryReject) => {
|
|
99
|
+
let retryCount = 0;
|
|
100
|
+
const maxRetries = 30; // 最大重试次数 (30*100ms=3秒超时)
|
|
101
|
+
retryInterval = setInterval(async () => {
|
|
102
|
+
if (retryCount++ >= maxRetries) {
|
|
103
|
+
clearInterval(retryInterval);
|
|
104
|
+
retryReject(new Error("JS-SDK接口初始化超时"));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 检查getLocation接口是否可用
|
|
109
|
+
wx.checkJsApi({
|
|
110
|
+
jsApiList: ["getLocation"],
|
|
111
|
+
success: (res) => {
|
|
112
|
+
if (res.checkResult.getLocation === true) {
|
|
113
|
+
clearInterval(retryInterval);
|
|
114
|
+
retryResolve();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
fail: () => {/* 失败不计入重试,继续轮询 */
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}, 100); // 每100ms检查一次
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
reject(new Error(`接口初始化失败: ${error.message}`));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
94
127
|
// 检查 options.type,如果为空或者不含有 'wgs84' 或 'bd09',则设置为 'gcj02'
|
|
95
128
|
let locationType = options.type;
|
|
96
129
|
if (!options.type || (options.type !== 'wgs84' && options.type !== 'bd09')) {
|
package/src/sdk/WechatAdapter.js
CHANGED
|
@@ -66,7 +66,40 @@ class WechatAdapter {
|
|
|
66
66
|
|
|
67
67
|
async getLocation(options) {
|
|
68
68
|
return new Promise((resolve, reject) => {
|
|
69
|
-
wx.ready(() => {
|
|
69
|
+
wx.ready(async () => {
|
|
70
|
+
// 解决在 URL 变化时,由于 wx.config 和 wx.ready 的异步特性导致的微信接口调用使用旧配置、签名失效或调用失败的问题
|
|
71
|
+
// 新增重试机制检查接口可用性
|
|
72
|
+
let retryInterval;
|
|
73
|
+
try {
|
|
74
|
+
await new Promise((retryResolve, retryReject) => {
|
|
75
|
+
let retryCount = 0;
|
|
76
|
+
const maxRetries = 30; // 最大重试次数 (30*100ms=3秒超时)
|
|
77
|
+
retryInterval = setInterval(async () => {
|
|
78
|
+
if (retryCount++ >= maxRetries) {
|
|
79
|
+
clearInterval(retryInterval);
|
|
80
|
+
retryReject(new Error("JS-SDK接口初始化超时"));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 检查getLocation接口是否可用
|
|
85
|
+
wx.checkJsApi({
|
|
86
|
+
jsApiList: ["getLocation"],
|
|
87
|
+
success: (res) => {
|
|
88
|
+
if (res.checkResult.getLocation === true) {
|
|
89
|
+
clearInterval(retryInterval);
|
|
90
|
+
retryResolve();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
fail: () => {/* 失败不计入重试,继续轮询 */
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}, 100); // 每100ms检查一次
|
|
97
|
+
});
|
|
98
|
+
} catch (error) {
|
|
99
|
+
reject(new Error(`接口初始化失败: ${error.message}`));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
70
103
|
// 检查 options.type,如果为空或者不含有 'wgs84' 或 'bd09',则设置为 'gcj02'
|
|
71
104
|
let locationType = options.type;
|
|
72
105
|
if (!options.type || (options.type !== 'wgs84' && options.type !== 'bd09')) {
|
|
@@ -108,18 +141,19 @@ class WechatAdapter {
|
|
|
108
141
|
};
|
|
109
142
|
|
|
110
143
|
// 先判断是否需要地理位置 如不需要 直接返回坐标
|
|
111
|
-
if(options.needAddress) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
144
|
+
if (options.needAddress) {
|
|
145
|
+
fetchLocation('gcj02'.then(unifiedLocation => {
|
|
146
|
+
const result = getAddressByType(unifiedLocation, locationType)
|
|
147
|
+
if (!result) {
|
|
148
|
+
return reject(new Error('Invalid location data'));
|
|
149
|
+
}
|
|
150
|
+
resolve(unifiedLocation);
|
|
151
|
+
}))
|
|
152
|
+
.catch(err => {
|
|
153
|
+
reject(err)
|
|
154
|
+
})
|
|
155
|
+
} else {
|
|
156
|
+
resolve(fetchLocation(locationType))
|
|
123
157
|
}
|
|
124
158
|
|
|
125
159
|
// // 先取gcj02 再根据type转成不同坐标系
|