ipanel-rnapp-ajb-base 1.0.38 → 1.0.39
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/app/base.js +68 -6
- package/app/eventBus/index.js +23 -22
- package/app/hooks/useMessageManager.js +119 -24
- package/app/screens/CommonScreens/BossScreen/index.js +30 -30
- package/app/utils/common.js +16 -14
- package/package.json +2 -2
package/app/base.js
CHANGED
|
@@ -51,10 +51,68 @@ global.base.homedHttp = homedHttp;
|
|
|
51
51
|
global.base.scaleSize = scaleSize;
|
|
52
52
|
global.base.px = scaleSize;
|
|
53
53
|
global.base.messageManager = {
|
|
54
|
-
messages: [],
|
|
54
|
+
messages: [], // deprecated,等addrMsgData使用起来之后废弃
|
|
55
|
+
addrMsgData: {
|
|
56
|
+
/**
|
|
57
|
+
* "addressId": {
|
|
58
|
+
* messages: [],
|
|
59
|
+
* latestReadedMsgId: "" // 最新一条已读的消息id。 latestReadedMsgId到最后一条消息之间的云端消息条数即为未读消息数
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
},
|
|
63
|
+
addrMsgDataTimer: null,
|
|
55
64
|
wsRef: null,
|
|
56
65
|
sessionId: "",
|
|
57
66
|
|
|
67
|
+
getAddrMsgList: function (addrId) {
|
|
68
|
+
return global.base.messageManager.addrMsgData[addrId]
|
|
69
|
+
? global.base.messageManager.addrMsgData[addrId].messages
|
|
70
|
+
: [];
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// 用户读取的最新一条消息
|
|
74
|
+
readLatestMsg: function (msg) {
|
|
75
|
+
if (global.base.messageManager.addrMsgData[msg.FromAddrId]) {
|
|
76
|
+
if (
|
|
77
|
+
global.base.messageManager.addrMsgData[msg.FromAddrId]
|
|
78
|
+
.latestReadedMsgId === msg.MsgId
|
|
79
|
+
) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
global.base.messageManager.addrMsgData[msg.FromAddrId].latestReadedMsgId =
|
|
83
|
+
msg.MsgId;
|
|
84
|
+
|
|
85
|
+
// 更新本地存储
|
|
86
|
+
clearTimeout(global.base.messageManager.addrMsgDataTimer);
|
|
87
|
+
global.base.messageManager.addrMsgDataTimer = setTimeout(() => {
|
|
88
|
+
storage.set("addrMsgData", global.base.messageManager.addrMsgData);
|
|
89
|
+
}, 500);
|
|
90
|
+
|
|
91
|
+
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// 获取未读消息数量
|
|
96
|
+
getUnreadMsgCount: function (addressId) {
|
|
97
|
+
const msgData = global.base.messageManager.addrMsgData[addressId];
|
|
98
|
+
|
|
99
|
+
if (!msgData || !msgData.latestReadedMsgId) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
const readedMsgIndex = msgData.messages.findIndex(
|
|
103
|
+
(msg) => msg.MsgId === msgData.latestReadedMsgId
|
|
104
|
+
);
|
|
105
|
+
let unreadMsgs =
|
|
106
|
+
readedMsgIndex === -1
|
|
107
|
+
? msgData.messages
|
|
108
|
+
: msgData.messages.slice(readedMsgIndex + 1);
|
|
109
|
+
|
|
110
|
+
// 来自云端的消息才计入未读消息
|
|
111
|
+
unreadMsgs = unreadMsgs.filter((msg) => msg.FromUserId === "cloud");
|
|
112
|
+
|
|
113
|
+
return unreadMsgs.length;
|
|
114
|
+
},
|
|
115
|
+
|
|
58
116
|
isConnected: function () {
|
|
59
117
|
return !!global.base.messageManager.wsRef.current;
|
|
60
118
|
},
|
|
@@ -71,18 +129,22 @@ global.base.messageManager = {
|
|
|
71
129
|
},
|
|
72
130
|
|
|
73
131
|
updateMessageToStorage: async function (message) {
|
|
74
|
-
const
|
|
132
|
+
const data = global.base.messageManager.addrMsgData[message.FromAddrId] || {
|
|
133
|
+
messages: [],
|
|
134
|
+
latestMsgId: "",
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const oldMsgIndex = data.messages.findIndex(
|
|
75
138
|
(msg) => msg.MsgId === message.MsgId
|
|
76
139
|
);
|
|
77
140
|
if (oldMsgIndex === -1) {
|
|
78
|
-
console.
|
|
141
|
+
console.log("不存在的消息,msgId=", message.MsgId);
|
|
79
142
|
return;
|
|
80
143
|
}
|
|
81
144
|
|
|
82
|
-
|
|
145
|
+
data.messages.splice(oldMsgIndex, 1, message);
|
|
83
146
|
|
|
84
|
-
|
|
85
|
-
await storage.set("messageList", global.base.messageManager.messages);
|
|
147
|
+
await storage.set("addrMsgData", global.base.messageManager.addrMsgData);
|
|
86
148
|
},
|
|
87
149
|
|
|
88
150
|
genMsg,
|
package/app/eventBus/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import EventEmitter from
|
|
1
|
+
import EventEmitter from "events";
|
|
2
2
|
|
|
3
3
|
// 全局事件总线
|
|
4
4
|
// 事件名规范:
|
|
@@ -11,45 +11,46 @@ export default eventBus;
|
|
|
11
11
|
export const EVENTS = {
|
|
12
12
|
// 智能客服聊天界面
|
|
13
13
|
MESSAGE: {
|
|
14
|
-
ADD:
|
|
15
|
-
RENDER:
|
|
16
|
-
CONNECT_STATUS_CHANGE:
|
|
17
|
-
RECONNECT:
|
|
18
|
-
CUSTOM_SERVICE_CONNECT_CHANGE:
|
|
14
|
+
ADD: "message.add", // 新增消息事件
|
|
15
|
+
RENDER: "message.render", // 渲染消息UI
|
|
16
|
+
CONNECT_STATUS_CHANGE: "message.connectStatusChange", // websocket连接状态变更事件
|
|
17
|
+
RECONNECT: "message.reconnect", // 触发websocket重连事件
|
|
18
|
+
CUSTOM_SERVICE_CONNECT_CHANGE: "message.customServiceConnectChange", // 智能客服转人工的进入和退出事件
|
|
19
|
+
UNREAD_COUNT_UPDATE: "message.unreadCountUpdate",
|
|
19
20
|
},
|
|
20
21
|
// 底部自定义导航栏
|
|
21
22
|
CUSTOM_TAB_BAR: {
|
|
22
|
-
HIDE_MORE_AREA:
|
|
23
|
+
HIDE_MORE_AREA: "CustomTabBar.hideMoreArea", // 隐藏更多按钮区域事件
|
|
23
24
|
},
|
|
24
25
|
// 我的家庭
|
|
25
26
|
FAMILY: {
|
|
26
|
-
CHANGE:
|
|
27
|
+
CHANGE: "family.change", // 当前家庭切换事件
|
|
27
28
|
},
|
|
28
29
|
HOMED: {
|
|
29
|
-
TOKEN_CHANGE:
|
|
30
|
+
TOKEN_CHANGE: "homed.tokenChange",
|
|
30
31
|
},
|
|
31
32
|
TV: {
|
|
32
|
-
SHARE_TIME_LIMIT:
|
|
33
|
-
HOME_DATA_CHANGE:
|
|
33
|
+
SHARE_TIME_LIMIT: "tv.shareTimeLimit",
|
|
34
|
+
HOME_DATA_CHANGE: "tv.homeDataChange",
|
|
34
35
|
},
|
|
35
36
|
SMART_HOME: {
|
|
36
|
-
BLE_MESH_ADD:
|
|
37
|
+
BLE_MESH_ADD: "smartHome.bleMeshAdd",
|
|
37
38
|
},
|
|
38
39
|
IOT: {
|
|
39
|
-
DEVICE_STATUS_UPDATE:
|
|
40
|
-
ITEE_NETWORK_CHANGE:
|
|
40
|
+
DEVICE_STATUS_UPDATE: "device.status.update",
|
|
41
|
+
ITEE_NETWORK_CHANGE: "itee.network.change",
|
|
41
42
|
},
|
|
42
43
|
ACCOUNT: {
|
|
43
|
-
AVATAR_CHANGE:
|
|
44
|
+
AVATAR_CHANGE: "avatar.change",
|
|
44
45
|
},
|
|
45
46
|
// 商城客服聊天界面
|
|
46
47
|
SHOPMESSAGE: {
|
|
47
|
-
ADD:
|
|
48
|
-
RENDER:
|
|
49
|
-
CONNECT_STATUS_CHANGE:
|
|
50
|
-
RECONNECT:
|
|
51
|
-
ONLINE_LIST:
|
|
52
|
-
CUSTOM_SERVICE_CONNECT_CHANGE:
|
|
53
|
-
HISTORY_MESSAGE_LIST:
|
|
48
|
+
ADD: "shop.message.add", // 新增消息事件
|
|
49
|
+
RENDER: "shop.message.render", // 渲染消息UI
|
|
50
|
+
CONNECT_STATUS_CHANGE: "shop.message.connectStatusChange", // websocket连接状态变更事件
|
|
51
|
+
RECONNECT: "shop.message.reconnect", // 触发websocket重连事件
|
|
52
|
+
ONLINE_LIST: "shop.message.online", // 商城在线用户
|
|
53
|
+
CUSTOM_SERVICE_CONNECT_CHANGE: "shop.message.customServiceConnectChange", // 智能客服转人工的进入和退出事件
|
|
54
|
+
HISTORY_MESSAGE_LIST: "shop.message.history", // 获取历史消息
|
|
54
55
|
},
|
|
55
56
|
};
|
|
@@ -17,18 +17,55 @@ let tryConnectTimes = 0;
|
|
|
17
17
|
* 智能客服中心JS
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
// storage.set('addrMsgData', {}); // 这是测试代码,如果要清空本地消息,则临时放开这段运行一下
|
|
20
21
|
// storage.set('messageList', []); // 这是测试代码,如果要清空本地消息,则临时放开这段运行一下
|
|
21
|
-
//
|
|
22
|
-
storage.get("
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
// 将持久化的消息列表数据恢复到内存中
|
|
23
|
+
storage.get("addrMsgData").then((data) => {
|
|
24
|
+
if (data) {
|
|
25
|
+
if (typeof data === "string") {
|
|
26
|
+
try {
|
|
27
|
+
data = JSON.parse(data);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.log("data error", e, data);
|
|
30
|
+
data = {};
|
|
31
|
+
}
|
|
29
32
|
}
|
|
33
|
+
global.base.messageManager.addrMsgData = data || {};
|
|
34
|
+
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
35
|
+
} else {
|
|
36
|
+
// deprecated,等addrMsgData使用起来之后废弃
|
|
37
|
+
// 将持久化的消息列表数据恢复到内存中
|
|
38
|
+
storage.get("messageList").then((msgList) => {
|
|
39
|
+
if (typeof msgList === "string") {
|
|
40
|
+
try {
|
|
41
|
+
msgList = JSON.parse(msgList);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.log("msgList error", e, msgList);
|
|
44
|
+
msgList = [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
global.base.messageManager.messages = msgList || [];
|
|
48
|
+
|
|
49
|
+
// 将废弃的旧格式字段转成新格式字段,再恢复到内存中
|
|
50
|
+
const addrMsgData = {};
|
|
51
|
+
global.base.messageManager.messages.forEach((msg) => {
|
|
52
|
+
if (addrMsgData[msg.FromAddrId]) {
|
|
53
|
+
addrMsgData[msg.FromAddrId].messages.push(msg);
|
|
54
|
+
addrMsgData[msg.FromAddrId].latestReadedMsgId = msg.MsgId;
|
|
55
|
+
} else {
|
|
56
|
+
addrMsgData[msg.FromAddrId] = {
|
|
57
|
+
messages: [msg],
|
|
58
|
+
latestReadedMsgId: msg.MsgId,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
global.base.messageManager.addrMsgData = addrMsgData;
|
|
63
|
+
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
64
|
+
storage.set("addrMsgData", addrMsgData);
|
|
65
|
+
// 移除旧格式字段
|
|
66
|
+
storage.remove("messageList");
|
|
67
|
+
});
|
|
30
68
|
}
|
|
31
|
-
global.base.messageManager.messages = msgList || [];
|
|
32
69
|
});
|
|
33
70
|
|
|
34
71
|
// 当前是否处于智能客服转人工
|
|
@@ -43,14 +80,24 @@ let manualCustomServiceTimer;
|
|
|
43
80
|
// 智能客服聊天AI模型: CUSTOMER_SERVICE=客服智能体
|
|
44
81
|
let aiModel = "CUSTOMER_SERVICE";
|
|
45
82
|
|
|
83
|
+
let storageTimer;
|
|
84
|
+
|
|
46
85
|
const UseMessageManager = () => {
|
|
47
86
|
const ws = useRef(null);
|
|
87
|
+
const connectedAddressId = useRef(null);
|
|
48
88
|
|
|
49
89
|
const sendMessage = useCallback((msg) => {
|
|
50
90
|
if (ws.current) {
|
|
51
91
|
console.log("ws.send");
|
|
52
92
|
ws.current.send(JSON.stringify(msg));
|
|
53
93
|
eventBus.emit(EVENTS.MESSAGE.ADD, msg);
|
|
94
|
+
} else {
|
|
95
|
+
// 未连接,触发重连
|
|
96
|
+
reConnect(() => {
|
|
97
|
+
console.log("ws.send");
|
|
98
|
+
ws.current.send(JSON.stringify(msg));
|
|
99
|
+
eventBus.emit(EVENTS.MESSAGE.ADD, msg);
|
|
100
|
+
});
|
|
54
101
|
}
|
|
55
102
|
}, []);
|
|
56
103
|
|
|
@@ -59,16 +106,27 @@ const UseMessageManager = () => {
|
|
|
59
106
|
const token = await storage.get("accessToken");
|
|
60
107
|
const accountData = await storage.get("accountData");
|
|
61
108
|
const activeAddr = await storage.get("activeAddr");
|
|
109
|
+
connectedAddressId.current = activeAddr?.address_id;
|
|
62
110
|
let wsUrl = `${
|
|
63
111
|
config.IPANEL_CLOUD_WSS_URI
|
|
64
112
|
}/s/ch/${await global.base.getHomeCloudServiceInstanceName()}/common/msgcenter/websocket`;
|
|
65
113
|
|
|
114
|
+
// 获取最新一条消息的id
|
|
115
|
+
const addrMsgData = await storage.get("addrMsgData");
|
|
116
|
+
const messages =
|
|
117
|
+
addrMsgData && addrMsgData[activeAddr?.address_id]
|
|
118
|
+
? addrMsgData[activeAddr?.address_id].messages
|
|
119
|
+
: [];
|
|
120
|
+
|
|
66
121
|
const connectParams = [
|
|
67
122
|
`user_id=${accountData.user.user_id}`, // 用户id
|
|
68
123
|
`address_id=${activeAddr.address_id}`, // 用户当前选中的家庭地址id
|
|
69
124
|
`token=${token}`,
|
|
70
125
|
"lon=",
|
|
71
126
|
"lat=",
|
|
127
|
+
`latest_msg_id=${
|
|
128
|
+
messages.length > 0 ? messages[messages.length - 1].MsgId : ""
|
|
129
|
+
}`,
|
|
72
130
|
];
|
|
73
131
|
|
|
74
132
|
// 设置智能客服AI大模型
|
|
@@ -89,6 +147,7 @@ const UseMessageManager = () => {
|
|
|
89
147
|
connectStatus = 0;
|
|
90
148
|
tryConnectTimes = 0;
|
|
91
149
|
eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
150
|
+
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
92
151
|
|
|
93
152
|
connectSuccessCallback && connectSuccessCallback();
|
|
94
153
|
};
|
|
@@ -97,8 +156,12 @@ const UseMessageManager = () => {
|
|
|
97
156
|
const msg = JSON.parse(data);
|
|
98
157
|
if (msg.MsgType === "chat" && msg.Chat.type === "tool_call_begin") {
|
|
99
158
|
const toolCallId = msg.Chat.payload.tool_calls[0].id;
|
|
159
|
+
const messages = global.base.messageManager.getAddrMsgList(
|
|
160
|
+
activeAddr.address_id
|
|
161
|
+
);
|
|
162
|
+
|
|
100
163
|
if (
|
|
101
|
-
|
|
164
|
+
messages.find(
|
|
102
165
|
(msg) =>
|
|
103
166
|
msg.MsgType === "chat" &&
|
|
104
167
|
msg.Chat.type === "end" &&
|
|
@@ -126,7 +189,11 @@ const UseMessageManager = () => {
|
|
|
126
189
|
global.base.messageManager.wsRef.current = null;
|
|
127
190
|
connectStatus = 1;
|
|
128
191
|
eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
129
|
-
|
|
192
|
+
|
|
193
|
+
// 触发重连
|
|
194
|
+
setTimeout(() => {
|
|
195
|
+
reConnect(connectSuccessCallback);
|
|
196
|
+
}, 1000);
|
|
130
197
|
};
|
|
131
198
|
};
|
|
132
199
|
|
|
@@ -147,7 +214,7 @@ const UseMessageManager = () => {
|
|
|
147
214
|
tryConnectTimes++;
|
|
148
215
|
connectMsgServer(connectSuccessCallback);
|
|
149
216
|
} else {
|
|
150
|
-
// 重连N次ws
|
|
217
|
+
// 重连N次ws失败,不再重试。等用户自己进入智能客服页面或者发送消息时触发重连
|
|
151
218
|
tryConnectTimes = 0;
|
|
152
219
|
connectStatus = 1;
|
|
153
220
|
eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
@@ -228,31 +295,59 @@ const UseMessageManager = () => {
|
|
|
228
295
|
useEffect(() => {
|
|
229
296
|
// 新增并显示一条消息
|
|
230
297
|
const onMessageAdd = (msg) => {
|
|
298
|
+
if (!global.base.messageManager.addrMsgData[msg.FromAddrId]) {
|
|
299
|
+
global.base.messageManager.addrMsgData[msg.FromAddrId] = {
|
|
300
|
+
messages: [],
|
|
301
|
+
latestReadedMsgId: "",
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const msgData = global.base.messageManager.addrMsgData[msg.FromAddrId];
|
|
305
|
+
|
|
306
|
+
const messages = msgData.messages;
|
|
231
307
|
// 如果msg.MsgId已存在,则直接更新,而不是push
|
|
232
|
-
const oldMsgIndex =
|
|
233
|
-
(m) => m.MsgId === msg.MsgId
|
|
234
|
-
);
|
|
308
|
+
const oldMsgIndex = messages.findIndex((m) => m.MsgId === msg.MsgId);
|
|
235
309
|
if (oldMsgIndex === -1) {
|
|
236
|
-
|
|
310
|
+
messages.push(msg);
|
|
311
|
+
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
237
312
|
} else {
|
|
238
|
-
|
|
313
|
+
messages.splice(oldMsgIndex, 1, msg);
|
|
314
|
+
}
|
|
315
|
+
// 每个家庭只保留近100条消息
|
|
316
|
+
if (messages.length > 100) {
|
|
317
|
+
msgData.messages = messages.slice(-100);
|
|
239
318
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
319
|
+
|
|
320
|
+
// 避免频繁写入本地存储,在ios可能会导致闪退
|
|
321
|
+
clearTimeout(storageTimer);
|
|
322
|
+
storageTimer = setTimeout(() => {
|
|
323
|
+
storage.set("addrMsgData", global.base.messageManager.addrMsgData);
|
|
324
|
+
}, 300);
|
|
245
325
|
|
|
246
326
|
eventBus.emit(EVENTS.MESSAGE.RENDER, msg);
|
|
247
327
|
};
|
|
248
328
|
|
|
329
|
+
const onFamilyChange = async () => {
|
|
330
|
+
const activeAddr = await storage.get("activeAddr");
|
|
331
|
+
|
|
332
|
+
if (activeAddr && activeAddr.address_id !== connectedAddressId.current) {
|
|
333
|
+
console.log(
|
|
334
|
+
`Family changed from ${connectedAddressId.current} to ${activeAddr.address_id}, reconnecting...`
|
|
335
|
+
);
|
|
336
|
+
closeMsgConnection();
|
|
337
|
+
} else {
|
|
338
|
+
console.log(
|
|
339
|
+
`Family not changed (${connectedAddressId.current}), skipping reconnect.`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
249
344
|
connectStatus = -1;
|
|
250
345
|
eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
251
346
|
// requestCameraPermission();
|
|
252
347
|
connectMsgServer();
|
|
253
348
|
|
|
254
349
|
// 监听家庭切换事件,切换websocket上下文
|
|
255
|
-
eventBus.on(EVENTS.FAMILY.CHANGE,
|
|
350
|
+
eventBus.on(EVENTS.FAMILY.CHANGE, onFamilyChange);
|
|
256
351
|
eventBus.on(EVENTS.MESSAGE.ADD, onMessageAdd);
|
|
257
352
|
eventBus.on(EVENTS.MESSAGE.RECONNECT, reConnect);
|
|
258
353
|
|
|
@@ -287,7 +382,7 @@ const UseMessageManager = () => {
|
|
|
287
382
|
eventBus.on(EVENTS.SHOPMESSAGE.ONLINE_LIST, handleGetOnlineUserList);
|
|
288
383
|
|
|
289
384
|
return () => {
|
|
290
|
-
eventBus.off(EVENTS.FAMILY.CHANGE,
|
|
385
|
+
eventBus.off(EVENTS.FAMILY.CHANGE, onFamilyChange);
|
|
291
386
|
eventBus.off(EVENTS.MESSAGE.ADD, onMessageAdd);
|
|
292
387
|
eventBus.off(EVENTS.MESSAGE.RECONNECT, reConnect);
|
|
293
388
|
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import React, { useEffect, useState } from
|
|
2
|
-
import { View } from
|
|
3
|
-
import { WebView } from
|
|
4
|
-
import { bindBossAccount, getUserInfo, getAssets } from
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { WebView } from "react-native-webview";
|
|
4
|
+
import { bindBossAccount, getUserInfo, getAssets } from "../../../api";
|
|
5
5
|
const { ScreenBackHeader } = global.base.commonComponents;
|
|
6
6
|
const { storage } = global.base;
|
|
7
7
|
|
|
8
8
|
export default ({ navigation, route }) => {
|
|
9
9
|
const module = route?.params?.module;
|
|
10
|
-
const [uri, setUri] = useState(
|
|
11
|
-
const [state, setState] = useState(
|
|
10
|
+
const [uri, setUri] = useState("");
|
|
11
|
+
const [state, setState] = useState("");
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
init();
|
|
14
|
-
global.loading.showLoading(
|
|
14
|
+
global.loading.showLoading("加载中...");
|
|
15
15
|
}, []);
|
|
16
16
|
const init = async () => {
|
|
17
|
-
const accountData = await storage.get(
|
|
17
|
+
const accountData = await storage.get("accountData");
|
|
18
18
|
const binding = 1; // 1:绑定,0:解绑.
|
|
19
19
|
const redirect_uri =
|
|
20
|
-
|
|
20
|
+
"https://ipanelcloud2.ipanel.cn:50443/iapp/ajbstatic/bind_boss_account/"; // 绑定后跳转地址
|
|
21
21
|
const state2 = generateRandomString(8);
|
|
22
22
|
setState(state2);
|
|
23
23
|
setUri(
|
|
24
|
-
`https://boss.ipanel.cn/ipanelTask/api/cas_open/isport/Isport_cloud_mall_c/binding?agentid=133&oauth2_id=72d2453f689fc99548187dca4b922a5b&redirect_uri=${redirect_uri}&open_id=${accountData.user?.user_id}&binding=${binding}&scope=
|
|
24
|
+
`https://boss.ipanel.cn/ipanelTask/api/cas_open/isport/Isport_cloud_mall_c/binding?agentid=133&oauth2_id=72d2453f689fc99548187dca4b922a5b&redirect_uri=${redirect_uri}&open_id=${accountData.user?.user_id}&binding=${binding}&scope=snsapi_privateinfo&response_type=code&state=${state2}`
|
|
25
25
|
);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const onMessage = async
|
|
28
|
+
const onMessage = async e => {
|
|
29
29
|
const data = JSON.parse(e.nativeEvent.data);
|
|
30
|
-
console.log(
|
|
30
|
+
console.log("onMessage", data);
|
|
31
31
|
if (data.ret === 0 && data.code && data.state === state) {
|
|
32
|
-
global.loading.showLoading(
|
|
32
|
+
global.loading.showLoading("正在绑定...");
|
|
33
33
|
const res = await bindBossAccount({
|
|
34
34
|
code: data.code,
|
|
35
|
-
oauth2:
|
|
35
|
+
oauth2: "72d2453f689fc99548187dca4b922a5b",
|
|
36
36
|
});
|
|
37
|
-
console.log(res,
|
|
38
|
-
global.loading.hideLoading(
|
|
37
|
+
console.log(res, "bindBossAccount");
|
|
38
|
+
global.loading.hideLoading("正在绑定...");
|
|
39
39
|
if (res.code === 0) {
|
|
40
|
-
global.toast.showToast(
|
|
40
|
+
global.toast.showToast("绑定成功");
|
|
41
41
|
get_user_info();
|
|
42
42
|
// navigation.goBack();
|
|
43
43
|
} else {
|
|
@@ -50,7 +50,7 @@ export default ({ navigation, route }) => {
|
|
|
50
50
|
|
|
51
51
|
const get_user_info = async () => {
|
|
52
52
|
const res = await getUserInfo();
|
|
53
|
-
console.log(res,
|
|
53
|
+
console.log(res, "getUserInfo");
|
|
54
54
|
if (
|
|
55
55
|
res?.code === 0 &&
|
|
56
56
|
res.result?.user_list &&
|
|
@@ -60,15 +60,15 @@ export default ({ navigation, route }) => {
|
|
|
60
60
|
// accountData.user.bind_list = res.result?.user_list[0].bind_list;
|
|
61
61
|
// await storage.set('accountData', accountData);
|
|
62
62
|
// const bossData = accountData.user.bind_list
|
|
63
|
-
const bossData = res.result?.user_list[0].bind_list.filter(
|
|
64
|
-
return item.third_type ===
|
|
63
|
+
const bossData = res.result?.user_list[0].bind_list.filter(item => {
|
|
64
|
+
return item.third_type === "boss";
|
|
65
65
|
});
|
|
66
66
|
console.log(bossData[0]);
|
|
67
67
|
if (bossData[0]) {
|
|
68
|
-
await storage.set(
|
|
68
|
+
await storage.set("bossData", bossData[0]);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
if (module ===
|
|
71
|
+
if (module === "shop") {
|
|
72
72
|
get_assets();
|
|
73
73
|
} else {
|
|
74
74
|
navigation.goBack();
|
|
@@ -80,24 +80,24 @@ export default ({ navigation, route }) => {
|
|
|
80
80
|
// 获取iSport积分。如果我的模块需要显示积分则应该在登录之后去获取这接口
|
|
81
81
|
const appID = await global.base.getAppId();
|
|
82
82
|
const params = {
|
|
83
|
-
action:
|
|
83
|
+
action: "get_assets",
|
|
84
84
|
currency: 0, // 0是获取全部,20000是获取iSport积分
|
|
85
85
|
};
|
|
86
86
|
if (appID) {
|
|
87
87
|
params.appid = appID;
|
|
88
88
|
}
|
|
89
|
-
getAssets(params).then(
|
|
89
|
+
getAssets(params).then(res => {
|
|
90
90
|
if (res?.code === 0) {
|
|
91
91
|
if (
|
|
92
92
|
res?.result &&
|
|
93
93
|
res?.result?.asset_list &&
|
|
94
94
|
res?.result?.asset_list?.length
|
|
95
95
|
) {
|
|
96
|
-
const current = res.result?.asset_list.filter(
|
|
96
|
+
const current = res.result?.asset_list.filter(item => {
|
|
97
97
|
return item.currency === 20000;
|
|
98
98
|
});
|
|
99
99
|
if (current.length) {
|
|
100
|
-
storage.set(
|
|
100
|
+
storage.set("isportData", current[0]);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -105,10 +105,10 @@ export default ({ navigation, route }) => {
|
|
|
105
105
|
});
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
const generateRandomString =
|
|
108
|
+
const generateRandomString = length => {
|
|
109
109
|
const characters =
|
|
110
|
-
|
|
111
|
-
let result =
|
|
110
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // Add any additional special characters you want to include
|
|
111
|
+
let result = "";
|
|
112
112
|
for (let i = 0; i < length; i++) {
|
|
113
113
|
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
114
114
|
result += characters.charAt(randomIndex);
|
|
@@ -127,7 +127,7 @@ export default ({ navigation, route }) => {
|
|
|
127
127
|
useWebKit
|
|
128
128
|
source={{
|
|
129
129
|
uri: uri,
|
|
130
|
-
headers: {
|
|
130
|
+
headers: { "Cache-Control": "no-store" },
|
|
131
131
|
}}
|
|
132
132
|
incognito={true}
|
|
133
133
|
onMessage={onMessage}
|
package/app/utils/common.js
CHANGED
|
@@ -29,11 +29,11 @@ async function updateHomedToken() {
|
|
|
29
29
|
console.log(accountData?.user, "accountData?.user");
|
|
30
30
|
const userList = res.result?.user_list || [];
|
|
31
31
|
const currentUser = userList.find(
|
|
32
|
-
item => item.user_id === accountData?.user.user_id
|
|
32
|
+
(item) => item.user_id === accountData?.user.user_id
|
|
33
33
|
);
|
|
34
34
|
const bindList = currentUser?.bind_list || [];
|
|
35
35
|
console.log(bindList, "bindList");
|
|
36
|
-
const homedConfig = bindList.find(item => item.third_type === "homed");
|
|
36
|
+
const homedConfig = bindList.find((item) => item.third_type === "homed");
|
|
37
37
|
let domain = activeAddr?.domain || (await global.base.getHomedDomain());
|
|
38
38
|
// if (!["禺乐慧家", "悦慧家"].includes(appName)) {
|
|
39
39
|
// domain = 'homed.tv'
|
|
@@ -44,9 +44,10 @@ async function updateHomedToken() {
|
|
|
44
44
|
let homedToken = "";
|
|
45
45
|
|
|
46
46
|
if (
|
|
47
|
-
homedConfig
|
|
48
|
-
homedConfig
|
|
49
|
-
homedConfig
|
|
47
|
+
homedConfig?.extend &&
|
|
48
|
+
homedConfig?.extend?.deviceno &&
|
|
49
|
+
homedConfig?.extend?.deviceid &&
|
|
50
|
+
homedConfig?.extend?.userid
|
|
50
51
|
) {
|
|
51
52
|
const mobileRelationLoginParams = {
|
|
52
53
|
deviceno: homedConfig.extend.deviceno,
|
|
@@ -63,7 +64,7 @@ async function updateHomedToken() {
|
|
|
63
64
|
const homedLoginResult = await mobileRelationLogin(
|
|
64
65
|
mobileRelationLoginParams,
|
|
65
66
|
domain
|
|
66
|
-
).catch(err => {});
|
|
67
|
+
).catch((err) => {});
|
|
67
68
|
if (homedLoginResult && homedLoginResult.ret === 0) {
|
|
68
69
|
homedToken = homedLoginResult.access_token;
|
|
69
70
|
await storage.set("homedLoginResult", homedLoginResult);
|
|
@@ -79,7 +80,7 @@ async function updateHomedToken() {
|
|
|
79
80
|
deviceType: 1,
|
|
80
81
|
},
|
|
81
82
|
domain
|
|
82
|
-
).catch(err => {});
|
|
83
|
+
).catch((err) => {});
|
|
83
84
|
console.log(tokenRes, "tokenRes");
|
|
84
85
|
if (tokenRes && tokenRes.ret === 0) {
|
|
85
86
|
homedToken = tokenRes.access_token;
|
|
@@ -94,7 +95,7 @@ async function updateHomedToken() {
|
|
|
94
95
|
const list = userListRes.user_list || [];
|
|
95
96
|
await storage.set(
|
|
96
97
|
"homedHomeMembers",
|
|
97
|
-
list.filter(item => item.user_id !== userListRes.bind_user_id)
|
|
98
|
+
list.filter((item) => item.user_id !== userListRes.bind_user_id)
|
|
98
99
|
);
|
|
99
100
|
}
|
|
100
101
|
} else {
|
|
@@ -153,7 +154,7 @@ async function initOperatorHomedTouristAccount(opHomedConfig) {
|
|
|
153
154
|
accounttype: 1,
|
|
154
155
|
iconid: 1,
|
|
155
156
|
pwd: "1bbd886460827015e5d605ed44252251", // md5("11111111")
|
|
156
|
-
}).catch(e => {
|
|
157
|
+
}).catch((e) => {
|
|
157
158
|
console.log("Error: homed游客注册请求失败", e);
|
|
158
159
|
});
|
|
159
160
|
|
|
@@ -177,7 +178,7 @@ async function updateHomedTouristToken() {
|
|
|
177
178
|
devicetype: 3,
|
|
178
179
|
accounttype: 2,
|
|
179
180
|
pwd: "1bbd886460827015e5d605ed44252251", // md5("11111111")
|
|
180
|
-
}).catch(e => {
|
|
181
|
+
}).catch((e) => {
|
|
181
182
|
console.log("Error: homed游客登录请求失败", e);
|
|
182
183
|
});
|
|
183
184
|
|
|
@@ -284,6 +285,7 @@ async function genMsg(type, msgType, payload) {
|
|
|
284
285
|
[payloadKey]: payload,
|
|
285
286
|
MsgId: id.replace(/-/g, ""),
|
|
286
287
|
SessionId: global.base.messageManager.sessionId,
|
|
288
|
+
CreateTime: new Date().getTime(),
|
|
287
289
|
};
|
|
288
290
|
const activeAddr = await storage.get("activeAddr");
|
|
289
291
|
const accountData = await storage.get("accountData");
|
|
@@ -292,11 +294,11 @@ async function genMsg(type, msgType, payload) {
|
|
|
292
294
|
// 当前用户发出
|
|
293
295
|
baseMsg.FromUserId = accountData.user.user_id;
|
|
294
296
|
baseMsg.FromAddrId = activeAddr.address_id;
|
|
295
|
-
baseMsg.ToUserId = "
|
|
297
|
+
baseMsg.ToUserId = "cloud";
|
|
296
298
|
baseMsg.ToAddrId = activeAddr.address_id;
|
|
297
299
|
} else if (type === "get") {
|
|
298
300
|
// 当前用户收到
|
|
299
|
-
baseMsg.FromUserId = "
|
|
301
|
+
baseMsg.FromUserId = "cloud";
|
|
300
302
|
baseMsg.FromAddrId = activeAddr.address_id;
|
|
301
303
|
baseMsg.ToUserId = accountData.user.user_id;
|
|
302
304
|
baseMsg.ToAddrId = activeAddr.address_id;
|
|
@@ -393,7 +395,7 @@ async function appReport(tag, extraData = {}) {
|
|
|
393
395
|
...extraData,
|
|
394
396
|
};
|
|
395
397
|
|
|
396
|
-
const res = await reportBigData(tag, appID, data).catch(err => {
|
|
398
|
+
const res = await reportBigData(tag, appID, data).catch((err) => {
|
|
397
399
|
console.log("reportBigData", err);
|
|
398
400
|
});
|
|
399
401
|
console.log("reportBigData", tag, res);
|
|
@@ -424,7 +426,7 @@ const checkToken = async () => {
|
|
|
424
426
|
]);
|
|
425
427
|
};
|
|
426
428
|
|
|
427
|
-
return new Promise(async resolve => {
|
|
429
|
+
return new Promise(async (resolve) => {
|
|
428
430
|
try {
|
|
429
431
|
const accountType = await storage.get("accountType");
|
|
430
432
|
const res = await refreshToken(
|