crh-jssdk 1.0.56 → 1.0.58

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.
@@ -37,24 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var utils_1 = require("../utils");
40
- /**
41
- * 规范化 hex 颜色值:转小写、补 # 前缀、3 位补 6 位
42
- * 非 hex 格式仅转小写后原样返回
43
- * @param color 颜色值,如 #FF0000、FFF、fff
44
- * @returns 规范化后的颜色值,如 #ff0000
45
- */
46
- var normalizeColor = function (color) {
47
- var c = color.trim().toLowerCase();
48
- // 匹配 #RGB / #RRGGBB 及不带 # 的形式
49
- if (/^#?[0-9a-f]{3}$/.test(c) || /^#?[0-9a-f]{6}$/.test(c)) {
50
- var hex = c.startsWith("#") ? c.slice(1) : c;
51
- if (hex.length === 3) {
52
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
53
- }
54
- return "#" + hex;
55
- }
56
- return c;
57
- };
58
40
  // webview类型
59
41
  var webviewType = (function () {
60
42
  var ua = navigator.userAgent;
@@ -93,10 +75,18 @@ exports.default = {
93
75
  },
94
76
  // 拦截Android物理返回键事件,并回调给前端 --- 仅安卓
95
77
  interceptBack: function (callback) {
96
- window.jtoJHandle.interceptBack("interceptBackCallBack");
97
- window.interceptBackCallBack = function (e) {
98
- callback && callback(e);
99
- };
78
+ if (window.jtoJHandle) {
79
+ window.jtoJHandle.interceptBack("interceptBackCallBack");
80
+ window.interceptBackCallBack = function (e) {
81
+ callback && callback(e);
82
+ };
83
+ }
84
+ else {
85
+ window.HarmonyBridge.callJsHandler('interceptBack', JSON.stringify({ callback: 'interceptBackCallBack' }));
86
+ window.interceptBackCallBack = function (e) {
87
+ callback && callback(e);
88
+ };
89
+ }
100
90
  },
101
91
  // 关闭页面 closeSJKH
102
92
  closeSJKH: function () {
@@ -104,9 +94,12 @@ exports.default = {
104
94
  // iphone
105
95
  window.location.href = "objc://callIOSQuit/";
106
96
  }
107
- else {
97
+ else if (window.jtoJHandle) {
108
98
  window.jtoJHandle.closeSJKH();
109
99
  }
100
+ else {
101
+ window.HarmonyBridge.callJsHandler('closeSJKH');
102
+ }
110
103
  },
111
104
  /**
112
105
  * 通过pageId打开新的webview打开外部链接
@@ -147,35 +140,6 @@ exports.default = {
147
140
  (_b = window.jtoJHandle) === null || _b === void 0 ? void 0 : _b.openNewBusiness(paramsObj);
148
141
  }
149
142
  },
150
- /**
151
- * @param {object} params
152
- * @param {string} params.color 状态栏背景颜色,如#ff0000
153
- * @param {string} params.wordColorStyle 状态栏文字颜色,0 白色,1 黑色
154
- */
155
- setStatusBar: function (params) {
156
- return __awaiter(this, void 0, void 0, function () {
157
- var json;
158
- return __generator(this, function (_a) {
159
- // 规范化颜色:大写转小写并补齐(# 前缀、3 位补 6 位)
160
- if ((params === null || params === void 0 ? void 0 : params.color) && typeof params.color === "string") {
161
- params.color = normalizeColor(params.color);
162
- }
163
- json = JSON.stringify(params);
164
- console.log("window.jtoJHandle.setStatusBarColor(".concat(json, ")"));
165
- if (utils_1.ios) {
166
- actionMap.loadIOSNative("objc://setStatusBarColor/$?".concat(json));
167
- }
168
- else if ((0, utils_1.checkIsHarmonyOS)()) {
169
- window.HarmonyBridge.callJsHandler('setStatusBarColor', json);
170
- }
171
- else {
172
- console.log("window.jtoJHandle.setStatusBarColor(".concat(json, ")"));
173
- window.jtoJHandle.setStatusBarColor(json);
174
- }
175
- return [2 /*return*/];
176
- });
177
- });
178
- },
179
143
  /**
180
144
  * 在app内打开浏览器
181
145
  * @param url 浏览器地址
@@ -190,7 +154,7 @@ exports.default = {
190
154
  window.jtoJHandle.updateApp('1', url);
191
155
  }
192
156
  else {
193
- window.HarmonyBridge.callJsHandler('updateApp', url);
157
+ window.HarmonyBridge.callJsHandler('updateApp', JSON.stringify({ url: url }));
194
158
  }
195
159
  return [2 /*return*/];
196
160
  });
@@ -180,6 +180,7 @@ exports.default = {
180
180
  var _this = this;
181
181
  console.log("getDeviceInfo----");
182
182
  return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
183
+ var data;
183
184
  var _a;
184
185
  return __generator(this, function (_b) {
185
186
  window.getDeviceInfoCB = function (jsonStr) {
@@ -192,9 +193,15 @@ exports.default = {
192
193
  if (utils_1.ios) {
193
194
  actionMap.loadIOSNative("objc://getDeviceInfo/?getDeviceInfoCB");
194
195
  }
195
- else {
196
+ else if (window.jtoJHandle) {
196
197
  (_a = window.jtoJHandle) === null || _a === void 0 ? void 0 : _a.getDeviceInfo("getDeviceInfoCB");
197
198
  }
199
+ else {
200
+ data = {
201
+ callback: "getDeviceInfoCB",
202
+ };
203
+ window.HarmonyBridge.callJsHandler('getDeviceInfo', JSON.stringify(data));
204
+ }
198
205
  return [2 /*return*/];
199
206
  });
200
207
  }); });
@@ -227,24 +234,29 @@ exports.default = {
227
234
  */
228
235
  setStatusBar: function (params) {
229
236
  return __awaiter(this, void 0, void 0, function () {
230
- var json;
237
+ var json, jsonHarmony;
231
238
  return __generator(this, function (_a) {
232
239
  // 规范化颜色:大写转小写并补齐(# 前缀、3 位补 6 位)
233
240
  if ((params === null || params === void 0 ? void 0 : params.color) && typeof params.color === "string") {
234
241
  params.color = normalizeColor(params.color);
235
242
  }
236
243
  json = JSON.stringify(params);
237
- console.log("window.jtoJHandle.setStatusBarColor(".concat(json, ")"));
238
244
  if (utils_1.ios) {
245
+ console.log("window.location.href = \"objc://setStatusBarColor/".concat(json, "\""));
239
246
  actionMap.loadIOSNative("objc://setStatusBarColor/$?".concat(json));
240
247
  }
241
- else if ((0, utils_1.checkIsHarmonyOS)()) {
242
- window.HarmonyBridge.callJsHandler('setStatusBarColor', json);
243
- }
244
- else {
248
+ else if (window.jtoJHandle) {
245
249
  console.log("window.jtoJHandle.setStatusBarColor(".concat(json, ")"));
246
250
  window.jtoJHandle.setStatusBarColor(json);
247
251
  }
252
+ else {
253
+ jsonHarmony = JSON.stringify({
254
+ statusBarColor: params.color,
255
+ statusBarContentColor: params.wordColorStyle === 0 ? "ffffff" : "000000",
256
+ });
257
+ console.log("window.HarmonyBridge.callJsHandler('setStatusBarColor', ".concat(jsonHarmony, ")"));
258
+ window.HarmonyBridge.callJsHandler('setStatusBarColor', jsonHarmony);
259
+ }
248
260
  return [2 /*return*/];
249
261
  });
250
262
  });
@@ -50,8 +50,20 @@ exports.default = {
50
50
  getUser: function () {
51
51
  var _this = this;
52
52
  return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
53
+ var data;
53
54
  return __generator(this, function (_a) {
54
55
  window.getUserInfoCB = function (username, password, onUse, loginFlag) {
56
+ // 鸿蒙端将整个用户信息作为 JSON 字符串放在 username 参数中返回,需解析还原
57
+ if (typeof username === 'string' && username.startsWith('{')) {
58
+ try {
59
+ var userInfo = JSON.parse(username);
60
+ username = userInfo.username;
61
+ password = userInfo.password;
62
+ }
63
+ catch (e) {
64
+ console.error('解析鸿蒙用户信息失败:', e);
65
+ }
66
+ }
55
67
  if (username !== '' && username !== 'null' && username !== '(null)' && loginFlag !== '1') {
56
68
  resolve({
57
69
  username: username,
@@ -73,6 +85,12 @@ exports.default = {
73
85
  else if (window.jtoJHandle) {
74
86
  window.jtoJHandle.getUser("getUserInfoCB");
75
87
  }
88
+ else {
89
+ data = {
90
+ callback: "getUserInfoCB",
91
+ };
92
+ window.HarmonyBridge.callJsHandler('getUser', JSON.stringify(data));
93
+ }
76
94
  return [2 /*return*/];
77
95
  });
78
96
  }); });
@@ -126,6 +144,9 @@ exports.default = {
126
144
  else if (window.jtoJHandle) {
127
145
  window.jtoJHandle.callOtherLogin("userLogin");
128
146
  }
147
+ else {
148
+ window.HarmonyBridge.callJsHandler('callOtherLogin');
149
+ }
129
150
  return [2 /*return*/];
130
151
  });
131
152
  }); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crh-jssdk",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "crh-jssdk",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {