crh-jssdk 0.10.30 → 0.10.31
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.
|
@@ -243,22 +243,14 @@ exports.default = {
|
|
|
243
243
|
/**
|
|
244
244
|
* 跳转个股详情页
|
|
245
245
|
*/
|
|
246
|
-
goStockDetail: function (params
|
|
247
|
-
|
|
248
|
-
var code = params.code, market = params.market;
|
|
249
|
-
var instanceId = "hxqRequestBridge" + Math.floor(Math.random() * 999 + 1);
|
|
250
|
-
var data = {
|
|
251
|
-
instanceId: instanceId,
|
|
252
|
-
type: type,
|
|
253
|
-
params: {
|
|
254
|
-
stockCode: code,
|
|
255
|
-
stockmarket: market,
|
|
256
|
-
},
|
|
257
|
-
cancel: "",
|
|
258
|
-
subscribe: ""
|
|
259
|
-
};
|
|
246
|
+
goStockDetail: function (params) {
|
|
247
|
+
var stockcode = params.stockcode, stockmarket = params.stockmarket;
|
|
260
248
|
try {
|
|
261
|
-
|
|
249
|
+
console.error("跳转个股详情数据:", stockcode, stockmarket);
|
|
250
|
+
utils_1.globalBridge.bridgeCallHandler("Promise", "HXJumpToStockFenshi", {
|
|
251
|
+
stockcode: stockcode,
|
|
252
|
+
stockmarket: stockmarket,
|
|
253
|
+
});
|
|
262
254
|
}
|
|
263
255
|
catch (error) {
|
|
264
256
|
console.error("跳转个股详情失败:", error);
|
package/dist/business/index.js
CHANGED
|
@@ -146,11 +146,19 @@ var BUSINESS = /** @class */ (function () {
|
|
|
146
146
|
this.isApp = this.sdkObj.isApp();
|
|
147
147
|
this.webviewType = this.sdkObj.webviewType();
|
|
148
148
|
// 异步等待Bridge准备就绪,但不阻塞初始化
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
// 使用 try-catch 包裹,避免未捕获的 Promise 错误
|
|
150
|
+
try {
|
|
151
|
+
this.bridge.waitForReady(5000).then(function () {
|
|
152
|
+
console.log("Bridge通信已准备就绪");
|
|
153
|
+
}).catch(function (error) {
|
|
154
|
+
// 静默处理超时错误,不影响SDK初始化流程
|
|
155
|
+
console.warn("Bridge初始化超时或失败:", error);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// 捕获同步错误
|
|
160
|
+
console.warn("Bridge waitForReady调用异常:", error);
|
|
161
|
+
}
|
|
154
162
|
_l.label = 11;
|
|
155
163
|
case 11:
|
|
156
164
|
// 设置Bridge实例到sdkObj中,供各模块使用
|
|
@@ -122,23 +122,30 @@ exports.default = {
|
|
|
122
122
|
},
|
|
123
123
|
/**
|
|
124
124
|
* 获取交易登录Token(会弹出登录框)
|
|
125
|
-
* @param
|
|
125
|
+
* @param appidOrOptions 应用ID字符串,或包含appId和accountType的对象
|
|
126
126
|
*/
|
|
127
|
-
getTradeLoginToken: function () {
|
|
128
|
-
return __awaiter(this,
|
|
129
|
-
var params, response, error_2;
|
|
130
|
-
if (appid === void 0) { appid = APPID; }
|
|
127
|
+
getTradeLoginToken: function (appidOrOptions) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var appId, params, response, error_2;
|
|
131
130
|
return __generator(this, function (_a) {
|
|
132
131
|
switch (_a.label) {
|
|
133
132
|
case 0:
|
|
134
133
|
_a.trys.push([0, 2, , 3]);
|
|
134
|
+
appId = APPID;
|
|
135
|
+
if (typeof appidOrOptions === 'string') {
|
|
136
|
+
appId = appidOrOptions;
|
|
137
|
+
}
|
|
138
|
+
else if (appidOrOptions && typeof appidOrOptions === 'object') {
|
|
139
|
+
appId = appidOrOptions.appId || APPID;
|
|
140
|
+
// accountType 参数暂时保留,但当前Bridge版本可能不支持,需要根据实际需求调整
|
|
141
|
+
}
|
|
135
142
|
params = {
|
|
136
143
|
info_type: "wt",
|
|
137
144
|
call_type: "callback_after_login", // 强制登录
|
|
138
145
|
info_complete_check: "0",
|
|
139
146
|
key_type: "lccommon",
|
|
140
147
|
needEncryptTraceInfo: true,
|
|
141
|
-
appId:
|
|
148
|
+
appId: appId,
|
|
142
149
|
};
|
|
143
150
|
console.log('获取交易登录Token,参数:', params);
|
|
144
151
|
return [4 /*yield*/, utils_1.globalBridge.bridgeCallHandler('Promise', 'getUserInfoByRsa', params)];
|
|
@@ -9,6 +9,7 @@ var Bridge = /** @class */ (function () {
|
|
|
9
9
|
function Bridge() {
|
|
10
10
|
this.bridge = null;
|
|
11
11
|
this.initPromise = null;
|
|
12
|
+
this.isConnecting = false; // 标记是否正在连接,避免重复添加监听器
|
|
12
13
|
this.initPromise = this.init();
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
@@ -19,25 +20,70 @@ var Bridge = /** @class */ (function () {
|
|
|
19
20
|
return new Promise(function (resolve) {
|
|
20
21
|
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
21
22
|
_this.bridge = bridge;
|
|
22
|
-
bridge.init
|
|
23
|
-
|
|
23
|
+
// 确保bridge.init存在且是函数
|
|
24
|
+
if (bridge && typeof bridge.init === 'function') {
|
|
25
|
+
bridge.init(function () {
|
|
26
|
+
console.log('Bridge初始化完成');
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// 如果bridge已经初始化过,直接resolve
|
|
32
|
+
console.log('Bridge已存在,跳过初始化');
|
|
24
33
|
resolve();
|
|
25
|
-
}
|
|
34
|
+
}
|
|
26
35
|
});
|
|
27
36
|
});
|
|
28
37
|
};
|
|
29
38
|
/**
|
|
30
39
|
* 连接WebViewJavascriptBridge
|
|
40
|
+
* 避免重复添加事件监听器
|
|
31
41
|
*/
|
|
32
42
|
Bridge.prototype.connectWebViewJavascriptBridge = function (callback) {
|
|
43
|
+
var _this = this;
|
|
44
|
+
// 如果Bridge已经存在,直接使用
|
|
33
45
|
if (window.WebViewJavascriptBridge) {
|
|
34
46
|
callback(window.WebViewJavascriptBridge);
|
|
47
|
+
return;
|
|
35
48
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
// 如果正在连接中,等待连接完成
|
|
50
|
+
if (this.isConnecting) {
|
|
51
|
+
// 等待Bridge准备就绪
|
|
52
|
+
var checkBridge_1 = function () {
|
|
53
|
+
if (window.WebViewJavascriptBridge) {
|
|
54
|
+
callback(window.WebViewJavascriptBridge);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// 继续等待
|
|
58
|
+
setTimeout(checkBridge_1, 100);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
checkBridge_1();
|
|
62
|
+
return;
|
|
40
63
|
}
|
|
64
|
+
// 标记为正在连接
|
|
65
|
+
this.isConnecting = true;
|
|
66
|
+
// 添加事件监听器(只添加一次)
|
|
67
|
+
var bridgeReadyHandler = function () {
|
|
68
|
+
_this.isConnecting = false;
|
|
69
|
+
if (window.WebViewJavascriptBridge) {
|
|
70
|
+
callback(window.WebViewJavascriptBridge);
|
|
71
|
+
}
|
|
72
|
+
// 移除监听器,避免重复调用
|
|
73
|
+
document.removeEventListener('WebViewJavascriptBridgeReady', bridgeReadyHandler);
|
|
74
|
+
};
|
|
75
|
+
document.addEventListener('WebViewJavascriptBridgeReady', bridgeReadyHandler, false);
|
|
76
|
+
// 设置超时,避免永久等待
|
|
77
|
+
setTimeout(function () {
|
|
78
|
+
if (_this.isConnecting) {
|
|
79
|
+
_this.isConnecting = false;
|
|
80
|
+
document.removeEventListener('WebViewJavascriptBridgeReady', bridgeReadyHandler);
|
|
81
|
+
// 如果超时后Bridge仍然不存在,尝试直接调用callback(可能Bridge已经通过其他方式加载)
|
|
82
|
+
if (window.WebViewJavascriptBridge) {
|
|
83
|
+
callback(window.WebViewJavascriptBridge);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, 10000); // 10秒超时
|
|
41
87
|
};
|
|
42
88
|
/**
|
|
43
89
|
* 调用App方法(Promise版本)
|
|
@@ -53,7 +99,12 @@ var Bridge = /** @class */ (function () {
|
|
|
53
99
|
if (type === 'Promise') {
|
|
54
100
|
return new Promise(function (resolve, reject) {
|
|
55
101
|
try {
|
|
56
|
-
|
|
102
|
+
// 如果Bridge已初始化,直接使用;否则等待初始化完成
|
|
103
|
+
var useBridge_1 = function (bridge) {
|
|
104
|
+
if (!bridge || typeof bridge.callHandler !== 'function') {
|
|
105
|
+
reject(new Error("Bridge\u672A\u6B63\u786E\u521D\u59CB\u5316\u6216callHandler\u65B9\u6CD5\u4E0D\u5B58\u5728"));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
57
108
|
bridge.callHandler(name, params, function (response) {
|
|
58
109
|
if (response) {
|
|
59
110
|
resolve(response);
|
|
@@ -62,7 +113,39 @@ var Bridge = /** @class */ (function () {
|
|
|
62
113
|
reject(new Error("\u8C03\u7528".concat(name, "\u65B9\u6CD5\u5931\u8D25\u4E86!")));
|
|
63
114
|
}
|
|
64
115
|
});
|
|
65
|
-
}
|
|
116
|
+
};
|
|
117
|
+
if (_this.bridge) {
|
|
118
|
+
// Bridge已初始化,直接使用
|
|
119
|
+
useBridge_1(_this.bridge);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Bridge未初始化,等待初始化完成
|
|
123
|
+
_this.waitForReady(5000)
|
|
124
|
+
.then(function () {
|
|
125
|
+
if (_this.bridge) {
|
|
126
|
+
useBridge_1(_this.bridge);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// 如果等待后仍然没有bridge,尝试重新连接(可能是动态加载的情况)
|
|
130
|
+
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
131
|
+
_this.bridge = bridge;
|
|
132
|
+
useBridge_1(bridge);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
.catch(function (error) {
|
|
137
|
+
// 如果等待超时,尝试直接连接(可能是Bridge已经存在但未初始化)
|
|
138
|
+
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
139
|
+
if (bridge) {
|
|
140
|
+
_this.bridge = bridge;
|
|
141
|
+
useBridge_1(bridge);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
reject(new Error("Bridge\u521D\u59CB\u5316\u5931\u8D25: ".concat(error.message)));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
66
149
|
}
|
|
67
150
|
catch (e) {
|
|
68
151
|
reject(e);
|
|
@@ -71,11 +154,37 @@ var Bridge = /** @class */ (function () {
|
|
|
71
154
|
}
|
|
72
155
|
// 不需要回调,只需要执行
|
|
73
156
|
try {
|
|
74
|
-
|
|
75
|
-
bridge.callHandler
|
|
76
|
-
|
|
157
|
+
var useBridge_2 = function (bridge) {
|
|
158
|
+
if (bridge && typeof bridge.callHandler === 'function') {
|
|
159
|
+
bridge.callHandler(name, params, function () {
|
|
160
|
+
// dosomething
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
if (this.bridge) {
|
|
165
|
+
useBridge_2(this.bridge);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// 等待初始化或直接连接
|
|
169
|
+
this.waitForReady(3000)
|
|
170
|
+
.then(function () {
|
|
171
|
+
if (_this.bridge) {
|
|
172
|
+
useBridge_2(_this.bridge);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
176
|
+
_this.bridge = bridge;
|
|
177
|
+
useBridge_2(bridge);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
.catch(function () {
|
|
182
|
+
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
183
|
+
_this.bridge = bridge;
|
|
184
|
+
useBridge_2(bridge);
|
|
185
|
+
});
|
|
77
186
|
});
|
|
78
|
-
}
|
|
187
|
+
}
|
|
79
188
|
}
|
|
80
189
|
catch (e) {
|
|
81
190
|
// dosomething
|
|
@@ -88,15 +197,42 @@ var Bridge = /** @class */ (function () {
|
|
|
88
197
|
* @param callback 回调函数
|
|
89
198
|
*/
|
|
90
199
|
Bridge.prototype.registerHandler = function (name, callback) {
|
|
200
|
+
var _this = this;
|
|
91
201
|
if (name === void 0) { name = ''; }
|
|
92
202
|
if (callback === void 0) { callback = function () { }; }
|
|
93
203
|
try {
|
|
94
|
-
|
|
95
|
-
bridge.registerHandler
|
|
96
|
-
|
|
97
|
-
|
|
204
|
+
var useBridge_3 = function (bridge) {
|
|
205
|
+
if (bridge && typeof bridge.registerHandler === 'function') {
|
|
206
|
+
bridge.registerHandler(name, function (data, responseCallback) {
|
|
207
|
+
callback(data);
|
|
208
|
+
responseCallback(data);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
if (this.bridge) {
|
|
213
|
+
useBridge_3(this.bridge);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// 等待初始化或直接连接
|
|
217
|
+
this.waitForReady(3000)
|
|
218
|
+
.then(function () {
|
|
219
|
+
if (_this.bridge) {
|
|
220
|
+
useBridge_3(_this.bridge);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
224
|
+
_this.bridge = bridge;
|
|
225
|
+
useBridge_3(bridge);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
.catch(function () {
|
|
230
|
+
_this.connectWebViewJavascriptBridge(function (bridge) {
|
|
231
|
+
_this.bridge = bridge;
|
|
232
|
+
useBridge_3(bridge);
|
|
233
|
+
});
|
|
98
234
|
});
|
|
99
|
-
}
|
|
235
|
+
}
|
|
100
236
|
}
|
|
101
237
|
catch (e) {
|
|
102
238
|
// dosomething
|
|
@@ -114,9 +250,11 @@ var Bridge = /** @class */ (function () {
|
|
|
114
250
|
*/
|
|
115
251
|
Bridge.prototype.waitForReady = function (timeout) {
|
|
116
252
|
if (timeout === void 0) { timeout = 5000; }
|
|
253
|
+
// 如果Bridge已经初始化,直接返回成功
|
|
117
254
|
if (this.bridge) {
|
|
118
255
|
return Promise.resolve();
|
|
119
256
|
}
|
|
257
|
+
// 如果正在初始化,等待初始化完成
|
|
120
258
|
if (this.initPromise) {
|
|
121
259
|
return Promise.race([
|
|
122
260
|
this.initPromise,
|
|
@@ -125,7 +263,16 @@ var Bridge = /** @class */ (function () {
|
|
|
125
263
|
})
|
|
126
264
|
]);
|
|
127
265
|
}
|
|
128
|
-
|
|
266
|
+
// 如果初始化Promise不存在,尝试重新初始化
|
|
267
|
+
// 这可能是Bridge实例创建后,初始化还没有开始的情况
|
|
268
|
+
console.warn('Bridge未开始初始化,尝试重新初始化...');
|
|
269
|
+
this.initPromise = this.init();
|
|
270
|
+
return Promise.race([
|
|
271
|
+
this.initPromise,
|
|
272
|
+
new Promise(function (_, reject) {
|
|
273
|
+
setTimeout(function () { return reject(new Error('Bridge初始化超时')); }, timeout);
|
|
274
|
+
})
|
|
275
|
+
]);
|
|
129
276
|
};
|
|
130
277
|
return Bridge;
|
|
131
278
|
}());
|
package/package.json
CHANGED
package/dist/package.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "crh-jssdk",
|
|
3
|
-
"version": "0.10.28",
|
|
4
|
-
"description": "crh-jssdk",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "node build.js"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"typescript"
|
|
11
|
-
],
|
|
12
|
-
"publishConfig": {
|
|
13
|
-
"access": "public"
|
|
14
|
-
},
|
|
15
|
-
"author": "crh-fe",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"typescript": "^5.5.2"
|
|
19
|
-
}
|
|
20
|
-
}
|