ipanel-rnapp-ajb-base 1.0.39 → 1.0.41
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/App.js +11 -6
- package/app/base.js +31 -8
- package/app/components/common/Cell/index.js +1 -1
- package/app/components/common/Dialog/prompt.js +2 -0
- package/app/hooks/useMessageManager.js +124 -40
- package/app/screens/CommonScreens/BossScreen/index.js +117 -43
- package/app/screens/CommonScreens/EditInvoiceTitleScreen/index.js +1 -0
- package/app/screens/LoginScreen/index.js +1554 -571
- package/app/screens/LoginScreen/indexSbk.js +950 -0
- package/app/screens/RegisteCountScreen/index.js +41 -39
- package/app/screens/WebviewScreen.js +216 -11
- package/app/utils/common.js +8 -0
- package/app/utils/http.js +33 -27
- package/package.json +2 -2
package/app/App.js
CHANGED
|
@@ -45,10 +45,10 @@ import { appReport } from "./utils/common";
|
|
|
45
45
|
|
|
46
46
|
// 基础导航页、登录页
|
|
47
47
|
import BaseScreen from "./screens/BaseScreen";
|
|
48
|
-
import SimpleBaseScreen from "./screens/SimpleBaseScreen.js"
|
|
49
|
-
import LoginScreen from "./screens/LoginScreen";
|
|
50
|
-
import
|
|
51
|
-
import LoginEduScreen from "./screens/LoginScreen/indexEdu"
|
|
48
|
+
import SimpleBaseScreen from "./screens/SimpleBaseScreen.js"; //简单导航:非爱家宝
|
|
49
|
+
import LoginScreen from "./screens/LoginScreen/index";
|
|
50
|
+
import SbkLoginScreen from "./screens/LoginScreen/indexSbk"; // 声必可屏登录页
|
|
51
|
+
import LoginEduScreen from "./screens/LoginScreen/indexEdu"; //教鞭登录页
|
|
52
52
|
import ResePasswordScreen from "./screens/ResePassword";
|
|
53
53
|
import SbkScreen from "./screens/SbkScreen";
|
|
54
54
|
|
|
@@ -121,7 +121,7 @@ if (Platform.OS === "android") {
|
|
|
121
121
|
// 公共 栈路由页面
|
|
122
122
|
const CommonScreens = {
|
|
123
123
|
Home: {
|
|
124
|
-
component: appName===
|
|
124
|
+
component: appName === "教鞭" ? SimpleBaseScreen : BaseScreen,
|
|
125
125
|
screenOptions: {
|
|
126
126
|
title: "首页",
|
|
127
127
|
headerShown: false,
|
|
@@ -129,7 +129,12 @@ const CommonScreens = {
|
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
131
|
Login: {
|
|
132
|
-
component:
|
|
132
|
+
component:
|
|
133
|
+
appName === "教鞭"
|
|
134
|
+
? LoginEduScreen
|
|
135
|
+
: DeviceInfo.getBrand() === "Allwinner"
|
|
136
|
+
? SbkLoginScreen /* 声必可屏 */
|
|
137
|
+
: LoginScreen,
|
|
133
138
|
screenOptions: {
|
|
134
139
|
title: "登录",
|
|
135
140
|
headerShown: false,
|
package/app/base.js
CHANGED
|
@@ -60,8 +60,9 @@ global.base.messageManager = {
|
|
|
60
60
|
* }
|
|
61
61
|
*/
|
|
62
62
|
},
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
addrMsgDataUpdateTimer: null,
|
|
64
|
+
ws: null,
|
|
65
|
+
connectStatus: undefined,
|
|
65
66
|
sessionId: "",
|
|
66
67
|
|
|
67
68
|
getAddrMsgList: function (addrId) {
|
|
@@ -72,6 +73,10 @@ global.base.messageManager = {
|
|
|
72
73
|
|
|
73
74
|
// 用户读取的最新一条消息
|
|
74
75
|
readLatestMsg: function (msg) {
|
|
76
|
+
if (msg.FromUserId !== "cloud") {
|
|
77
|
+
// 只针对云端消息设置已读
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
75
80
|
if (global.base.messageManager.addrMsgData[msg.FromAddrId]) {
|
|
76
81
|
if (
|
|
77
82
|
global.base.messageManager.addrMsgData[msg.FromAddrId]
|
|
@@ -83,10 +88,10 @@ global.base.messageManager = {
|
|
|
83
88
|
msg.MsgId;
|
|
84
89
|
|
|
85
90
|
// 更新本地存储
|
|
86
|
-
clearTimeout(global.base.messageManager.
|
|
87
|
-
global.base.messageManager.
|
|
91
|
+
clearTimeout(global.base.messageManager.addrMsgDataUpdateTimer);
|
|
92
|
+
global.base.messageManager.addrMsgDataUpdateTimer = setTimeout(() => {
|
|
88
93
|
storage.set("addrMsgData", global.base.messageManager.addrMsgData);
|
|
89
|
-
},
|
|
94
|
+
}, 300);
|
|
90
95
|
|
|
91
96
|
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
92
97
|
}
|
|
@@ -114,7 +119,7 @@ global.base.messageManager = {
|
|
|
114
119
|
},
|
|
115
120
|
|
|
116
121
|
isConnected: function () {
|
|
117
|
-
return !!global.base.messageManager.
|
|
122
|
+
return !!global.base.messageManager.ws;
|
|
118
123
|
},
|
|
119
124
|
|
|
120
125
|
setSessionId: function (sid) {
|
|
@@ -123,8 +128,8 @@ global.base.messageManager = {
|
|
|
123
128
|
|
|
124
129
|
sendMessage: async function (message) {
|
|
125
130
|
console.log("ws.send", message);
|
|
126
|
-
global.base.messageManager.
|
|
127
|
-
global.base.messageManager.
|
|
131
|
+
global.base.messageManager.ws &&
|
|
132
|
+
global.base.messageManager.ws.send(JSON.stringify(message));
|
|
128
133
|
eventBus.emit(EVENTS.MESSAGE.ADD, message);
|
|
129
134
|
},
|
|
130
135
|
|
|
@@ -147,6 +152,24 @@ global.base.messageManager = {
|
|
|
147
152
|
await storage.set("addrMsgData", global.base.messageManager.addrMsgData);
|
|
148
153
|
},
|
|
149
154
|
|
|
155
|
+
removeMsg(msgId) {
|
|
156
|
+
const addrMsgData = global.base.messageManager.addrMsgData;
|
|
157
|
+
|
|
158
|
+
for (let addrId in addrMsgData) {
|
|
159
|
+
const msgData = addrMsgData[addrId];
|
|
160
|
+
const msgIdx = msgData.messages.findIndex((msg) => msg.MsgId === msgId);
|
|
161
|
+
if (msgIdx !== -1) {
|
|
162
|
+
msgData.messages.splice(msgIdx, 1);
|
|
163
|
+
// 更新本地存储
|
|
164
|
+
clearTimeout(global.base.messageManager.addrMsgDataUpdateTimer);
|
|
165
|
+
global.base.messageManager.addrMsgDataUpdateTimer = setTimeout(() => {
|
|
166
|
+
storage.set("addrMsgData", addrMsgData);
|
|
167
|
+
}, 300);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
|
|
150
173
|
genMsg,
|
|
151
174
|
MSG_TYPES,
|
|
152
175
|
MSG_EVENT_TYPES,
|
|
@@ -96,6 +96,7 @@ const Prompt = ({ modelRef, setModalVisible }) => {
|
|
|
96
96
|
autoFocus={!!modelRef?.autoFocus}
|
|
97
97
|
onChangeText={setInput}
|
|
98
98
|
keyboardType={modelRef?.keyboardType}
|
|
99
|
+
returnKeyType={modelRef?.returnKeyType||'done'}
|
|
99
100
|
leftIcon={modelRef?.leftIcon}
|
|
100
101
|
containerStyle={{
|
|
101
102
|
height: 31,
|
|
@@ -148,6 +149,7 @@ const Prompt = ({ modelRef, setModalVisible }) => {
|
|
|
148
149
|
autoFocus={!!modelRef?.autoFocus2}
|
|
149
150
|
onChangeText={setInput2}
|
|
150
151
|
keyboardType={modelRef?.keyboardType2}
|
|
152
|
+
returnKeyType={modelRef?.returnKeyType2||'done'}
|
|
151
153
|
leftIcon={modelRef?.leftIcon2}
|
|
152
154
|
containerStyle={{
|
|
153
155
|
height: 31,
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import React, { useState, useEffect, useCallback, useRef } from "react";
|
|
2
|
-
import { PermissionsAndroid, Platform } from "react-native";
|
|
3
|
-
|
|
4
|
-
import { format } from "date-fns";
|
|
5
|
-
|
|
6
2
|
import storage from "../storage";
|
|
7
3
|
import eventBus, { EVENTS } from "../eventBus";
|
|
8
4
|
import config from "../utils/config";
|
|
9
|
-
import { MSG_TYPES, genMsg } from "../utils/common";
|
|
5
|
+
import { MSG_TYPES, genMsg, CONNECT_STATUS } from "../utils/common";
|
|
10
6
|
import applyPermissions from "../utils/applyPermissions";
|
|
11
7
|
|
|
12
|
-
let
|
|
8
|
+
let wsInstance = null;
|
|
13
9
|
|
|
14
10
|
let tryConnectTimes = 0;
|
|
11
|
+
let isReConnecting = false;
|
|
12
|
+
const MAX_CONNECT_TIMES = 7;
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* 智能客服中心JS
|
|
@@ -82,26 +80,48 @@ let aiModel = "CUSTOMER_SERVICE";
|
|
|
82
80
|
|
|
83
81
|
let storageTimer;
|
|
84
82
|
|
|
83
|
+
// 缓存正在发送中的消息,MsgId->Msg,当消息发送成功或发送失败时,需要将其从缓存中删除
|
|
84
|
+
const pendingMsgMap = {};
|
|
85
|
+
|
|
85
86
|
const UseMessageManager = () => {
|
|
86
|
-
const ws = useRef(null);
|
|
87
87
|
const connectedAddressId = useRef(null);
|
|
88
88
|
|
|
89
89
|
const sendMessage = useCallback((msg) => {
|
|
90
|
-
|
|
90
|
+
// 给用户发送的消息追加Status字段,此时消息是“未发送态”,如果未连接且重连失败,则将状态改为“发送失败态”
|
|
91
|
+
// 然后先直接把正在发送的消息显示出来,待消息发送成功或失败时再更新消息状态
|
|
92
|
+
msg.Status = "pending";
|
|
93
|
+
eventBus.emit(EVENTS.MESSAGE.ADD, msg);
|
|
94
|
+
|
|
95
|
+
if (wsInstance) {
|
|
91
96
|
console.log("ws.send");
|
|
92
|
-
|
|
93
|
-
eventBus.emit(EVENTS.MESSAGE.ADD, msg);
|
|
97
|
+
wsInstance.send(JSON.stringify(msg));
|
|
94
98
|
} else {
|
|
95
99
|
// 未连接,触发重连
|
|
96
100
|
reConnect(() => {
|
|
97
101
|
console.log("ws.send");
|
|
98
|
-
|
|
99
|
-
eventBus.emit(EVENTS.MESSAGE.ADD, msg);
|
|
102
|
+
wsInstance.send(JSON.stringify(msg));
|
|
100
103
|
});
|
|
101
104
|
}
|
|
102
105
|
}, []);
|
|
103
106
|
|
|
104
107
|
const connectMsgServer = async (connectSuccessCallback) => {
|
|
108
|
+
if (
|
|
109
|
+
global.base.messageManager.connectStatus === CONNECT_STATUS.CONNECTING ||
|
|
110
|
+
(global.base.messageManager.connectStatus === CONNECT_STATUS.CONNECTED &&
|
|
111
|
+
wsInstance &&
|
|
112
|
+
wsInstance.readyState < 2)
|
|
113
|
+
) {
|
|
114
|
+
console.log(
|
|
115
|
+
`useMessageManager connectMsgServer skipped, connectStatus=${global.base.messageManager.connectStatus}, ws.readyState=${wsInstance?.readyState}`
|
|
116
|
+
);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
global.base.messageManager.connectStatus = CONNECT_STATUS.CONNECTING;
|
|
120
|
+
eventBus.emit(
|
|
121
|
+
EVENTS.MESSAGE.CONNECT_STATUS_CHANGE,
|
|
122
|
+
global.base.messageManager.connectStatus
|
|
123
|
+
);
|
|
124
|
+
|
|
105
125
|
console.log("connectMsgServer start");
|
|
106
126
|
const token = await storage.get("accessToken");
|
|
107
127
|
const accountData = await storage.get("accountData");
|
|
@@ -135,35 +155,71 @@ const UseMessageManager = () => {
|
|
|
135
155
|
}
|
|
136
156
|
|
|
137
157
|
// 缓存全局智能客服websocket连接
|
|
138
|
-
global.base.messageManager.wsRef = ws;
|
|
139
158
|
global.base.messageManager.connectMsgServer = connectMsgServer;
|
|
140
159
|
|
|
141
160
|
const url = `${wsUrl}?${connectParams.join("&")}`;
|
|
142
161
|
console.log("useMessageManager ws url:", url);
|
|
143
162
|
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
wsInstance = new WebSocket(url);
|
|
164
|
+
global.base.messageManager.ws = wsInstance;
|
|
165
|
+
wsInstance.onopen = () => {
|
|
146
166
|
console.log("useMessageManager ws open");
|
|
147
|
-
connectStatus =
|
|
167
|
+
global.base.messageManager.connectStatus = CONNECT_STATUS.CONNECTED;
|
|
148
168
|
tryConnectTimes = 0;
|
|
149
|
-
|
|
169
|
+
isReConnecting = false;
|
|
170
|
+
eventBus.emit(
|
|
171
|
+
EVENTS.MESSAGE.CONNECT_STATUS_CHANGE,
|
|
172
|
+
global.base.messageManager.connectStatus
|
|
173
|
+
);
|
|
150
174
|
eventBus.emit(EVENTS.MESSAGE.UNREAD_COUNT_UPDATE);
|
|
151
175
|
|
|
152
176
|
connectSuccessCallback && connectSuccessCallback();
|
|
153
177
|
};
|
|
154
|
-
|
|
178
|
+
wsInstance.onmessage = ({ data }) => {
|
|
179
|
+
// 处理来自云端的消息
|
|
155
180
|
try {
|
|
156
181
|
const msg = JSON.parse(data);
|
|
157
|
-
if (msg.MsgType === "chat" && msg.Chat.type === "tool_call_begin") {
|
|
158
|
-
const toolCallId = msg.Chat.payload.tool_calls[0].id;
|
|
159
|
-
const messages = global.base.messageManager.getAddrMsgList(
|
|
160
|
-
activeAddr.address_id
|
|
161
|
-
);
|
|
162
182
|
|
|
183
|
+
const messages = global.base.messageManager.getAddrMsgList(
|
|
184
|
+
activeAddr.address_id
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// 用户每发送一条消息到云端,云端都会响应一条确认事件消息,用于更新该消息的本地MsgId为服务器生成的ID
|
|
188
|
+
if (
|
|
189
|
+
msg.MsgType === MSG_TYPES.EVENT &&
|
|
190
|
+
msg.Event.Type === "user_msg_received"
|
|
191
|
+
) {
|
|
192
|
+
const targetMsg = messages.find(
|
|
193
|
+
(item) => item.MsgId === msg.Event.Data.MsgId // 本地产生的ID
|
|
194
|
+
);
|
|
195
|
+
if (targetMsg) {
|
|
196
|
+
targetMsg.MsgId = msg.MsgId; // 服务器产生的ID
|
|
197
|
+
targetMsg.CreateTime = msg.CreateTime;
|
|
198
|
+
// 将消息从“未发送态”修改为“已发送态”(即删除Status字段)
|
|
199
|
+
delete targetMsg.Status;
|
|
200
|
+
delete pendingMsgMap[msg.Event.Data.MsgId];
|
|
201
|
+
|
|
202
|
+
// 避免频繁写入本地存储,在ios可能会导致闪退
|
|
203
|
+
clearTimeout(storageTimer);
|
|
204
|
+
storageTimer = setTimeout(() => {
|
|
205
|
+
storage.set(
|
|
206
|
+
"addrMsgData",
|
|
207
|
+
global.base.messageManager.addrMsgData
|
|
208
|
+
);
|
|
209
|
+
}, 300);
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// AI大模型工具消息合并处理
|
|
214
|
+
if (
|
|
215
|
+
msg.MsgType === MSG_TYPES.CHAT &&
|
|
216
|
+
msg.Chat.type === "tool_call_begin"
|
|
217
|
+
) {
|
|
218
|
+
const toolCallId = msg.Chat.payload.tool_calls[0].id;
|
|
163
219
|
if (
|
|
164
220
|
messages.find(
|
|
165
221
|
(msg) =>
|
|
166
|
-
msg.MsgType ===
|
|
222
|
+
msg.MsgType === MSG_TYPES.CHAT &&
|
|
167
223
|
msg.Chat.type === "end" &&
|
|
168
224
|
msg.Chat.payload.message.tool_calls &&
|
|
169
225
|
msg.Chat.payload.message.tool_calls[0].id === toolCallId
|
|
@@ -178,20 +234,28 @@ const UseMessageManager = () => {
|
|
|
178
234
|
console.log("msg不合法", e);
|
|
179
235
|
}
|
|
180
236
|
};
|
|
181
|
-
|
|
237
|
+
wsInstance.onerror = (err) => {
|
|
182
238
|
console.log("useMessageManager ws onerror", err);
|
|
183
|
-
connectStatus =
|
|
184
|
-
eventBus.emit(
|
|
239
|
+
global.base.messageManager.connectStatus = CONNECT_STATUS.DISCONNECTED;
|
|
240
|
+
eventBus.emit(
|
|
241
|
+
EVENTS.MESSAGE.CONNECT_STATUS_CHANGE,
|
|
242
|
+
global.base.messageManager.connectStatus
|
|
243
|
+
);
|
|
185
244
|
};
|
|
186
|
-
|
|
245
|
+
wsInstance.onclose = (event) => {
|
|
187
246
|
console.log("useMessageManager ws onclose", event);
|
|
188
247
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
248
|
+
wsInstance = null;
|
|
249
|
+
global.base.messageManager.ws = null;
|
|
250
|
+
global.base.messageManager.connectStatus = CONNECT_STATUS.DISCONNECTED;
|
|
251
|
+
eventBus.emit(
|
|
252
|
+
EVENTS.MESSAGE.CONNECT_STATUS_CHANGE,
|
|
253
|
+
global.base.messageManager.connectStatus
|
|
254
|
+
);
|
|
192
255
|
|
|
193
256
|
// 触发重连
|
|
194
257
|
setTimeout(() => {
|
|
258
|
+
isReConnecting = false;
|
|
195
259
|
reConnect(connectSuccessCallback);
|
|
196
260
|
}, 1000);
|
|
197
261
|
};
|
|
@@ -202,22 +266,38 @@ const UseMessageManager = () => {
|
|
|
202
266
|
|
|
203
267
|
// 正常主动关闭连接,重置重连次数
|
|
204
268
|
tryConnectTimes = 0;
|
|
269
|
+
isReConnecting = false;
|
|
205
270
|
|
|
206
|
-
|
|
207
|
-
|
|
271
|
+
if (wsInstance) {
|
|
272
|
+
wsInstance.close();
|
|
273
|
+
}
|
|
208
274
|
};
|
|
209
275
|
|
|
210
276
|
const reConnect = async (connectSuccessCallback) => {
|
|
277
|
+
if (isReConnecting) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
isReConnecting = true;
|
|
211
281
|
console.log("useMessageManager reConnect", tryConnectTimes);
|
|
212
|
-
if (tryConnectTimes <
|
|
282
|
+
if (tryConnectTimes < MAX_CONNECT_TIMES) {
|
|
213
283
|
// 重连ws
|
|
214
284
|
tryConnectTimes++;
|
|
215
285
|
connectMsgServer(connectSuccessCallback);
|
|
216
286
|
} else {
|
|
217
287
|
// 重连N次ws失败,不再重试。等用户自己进入智能客服页面或者发送消息时触发重连
|
|
218
288
|
tryConnectTimes = 0;
|
|
219
|
-
connectStatus =
|
|
220
|
-
|
|
289
|
+
global.base.messageManager.connectStatus = CONNECT_STATUS.DISCONNECTED;
|
|
290
|
+
isReConnecting = false;
|
|
291
|
+
eventBus.emit(
|
|
292
|
+
EVENTS.MESSAGE.CONNECT_STATUS_CHANGE,
|
|
293
|
+
global.base.messageManager.connectStatus
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
// 所有正在发送的消息全部失败,然后清空pendingMsgMap缓存
|
|
297
|
+
Object.keys(pendingMsgMap).forEach((MsgId) => {
|
|
298
|
+
pendingMsgMap[MsgId].Status = "fail";
|
|
299
|
+
delete pendingMsgMap[MsgId];
|
|
300
|
+
});
|
|
221
301
|
}
|
|
222
302
|
};
|
|
223
303
|
|
|
@@ -295,6 +375,11 @@ const UseMessageManager = () => {
|
|
|
295
375
|
useEffect(() => {
|
|
296
376
|
// 新增并显示一条消息
|
|
297
377
|
const onMessageAdd = (msg) => {
|
|
378
|
+
if (msg.MsgType === MSG_TYPES.EVENT) {
|
|
379
|
+
// 事件消息不持久化保存,也不渲染
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
298
383
|
if (!global.base.messageManager.addrMsgData[msg.FromAddrId]) {
|
|
299
384
|
global.base.messageManager.addrMsgData[msg.FromAddrId] = {
|
|
300
385
|
messages: [],
|
|
@@ -341,8 +426,6 @@ const UseMessageManager = () => {
|
|
|
341
426
|
}
|
|
342
427
|
};
|
|
343
428
|
|
|
344
|
-
connectStatus = -1;
|
|
345
|
-
eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
346
429
|
// requestCameraPermission();
|
|
347
430
|
connectMsgServer();
|
|
348
431
|
|
|
@@ -470,8 +553,9 @@ const UseMessageManager = () => {
|
|
|
470
553
|
aiModel = model;
|
|
471
554
|
|
|
472
555
|
// 触发重新连接
|
|
473
|
-
|
|
474
|
-
|
|
556
|
+
if (wsInstance) {
|
|
557
|
+
wsInstance.close();
|
|
558
|
+
}
|
|
475
559
|
};
|
|
476
560
|
|
|
477
561
|
return {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
import { WebView } from "react-native-webview";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
bindBossAccount,
|
|
6
|
+
getUserInfo,
|
|
7
|
+
getAssets,
|
|
8
|
+
delThirdId,
|
|
9
|
+
} from "../../../api";
|
|
5
10
|
const { ScreenBackHeader } = global.base.commonComponents;
|
|
6
11
|
const { storage } = global.base;
|
|
7
12
|
|
|
@@ -9,17 +14,23 @@ export default ({ navigation, route }) => {
|
|
|
9
14
|
const module = route?.params?.module;
|
|
10
15
|
const [uri, setUri] = useState("");
|
|
11
16
|
const [state, setState] = useState("");
|
|
17
|
+
const bind = route?.params?.binding === 0 ? 0 : 1; // 1:绑定,0:解绑
|
|
18
|
+
console.log("bind嘻嘻", bind);
|
|
12
19
|
useEffect(() => {
|
|
13
20
|
init();
|
|
14
21
|
global.loading.showLoading("加载中...");
|
|
15
22
|
}, []);
|
|
16
23
|
const init = async () => {
|
|
17
24
|
const accountData = await storage.get("accountData");
|
|
18
|
-
|
|
25
|
+
console.log("init", accountData, "accountData");
|
|
26
|
+
const binding = bind; // 1:绑定,0:解绑
|
|
19
27
|
const redirect_uri =
|
|
20
28
|
"https://ipanelcloud2.ipanel.cn:50443/iapp/ajbstatic/bind_boss_account/"; // 绑定后跳转地址
|
|
21
29
|
const state2 = generateRandomString(8);
|
|
22
30
|
setState(state2);
|
|
31
|
+
console.log(
|
|
32
|
+
`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}`
|
|
33
|
+
);
|
|
23
34
|
setUri(
|
|
24
35
|
`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
36
|
);
|
|
@@ -29,7 +40,7 @@ export default ({ navigation, route }) => {
|
|
|
29
40
|
const data = JSON.parse(e.nativeEvent.data);
|
|
30
41
|
console.log("onMessage", data);
|
|
31
42
|
if (data.ret === 0 && data.code && data.state === state) {
|
|
32
|
-
global.loading.showLoading("正在绑定...");
|
|
43
|
+
global.loading.showLoading(bind === 1 ? "正在绑定..." : "正在解绑...");
|
|
33
44
|
const res = await bindBossAccount({
|
|
34
45
|
code: data.code,
|
|
35
46
|
oauth2: "72d2453f689fc99548187dca4b922a5b",
|
|
@@ -37,8 +48,12 @@ export default ({ navigation, route }) => {
|
|
|
37
48
|
console.log(res, "bindBossAccount");
|
|
38
49
|
global.loading.hideLoading("正在绑定...");
|
|
39
50
|
if (res.code === 0) {
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
if (bind === 1) {
|
|
52
|
+
global.toast.showToast("绑定成功");
|
|
53
|
+
await get_user_info();
|
|
54
|
+
} else {
|
|
55
|
+
await delBind();
|
|
56
|
+
}
|
|
42
57
|
// navigation.goBack();
|
|
43
58
|
} else {
|
|
44
59
|
navigation.goBack();
|
|
@@ -48,29 +63,68 @@ export default ({ navigation, route }) => {
|
|
|
48
63
|
}
|
|
49
64
|
};
|
|
50
65
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// const bossData = accountData.user.bind_list
|
|
63
|
-
const bossData = res.result?.user_list[0].bind_list.filter(item => {
|
|
64
|
-
return item.third_type === "boss";
|
|
65
|
-
});
|
|
66
|
-
console.log(bossData[0]);
|
|
67
|
-
if (bossData[0]) {
|
|
68
|
-
await storage.set("bossData", bossData[0]);
|
|
66
|
+
const delBind = async () => {
|
|
67
|
+
try {
|
|
68
|
+
const bossData = await storage.get("bossData");
|
|
69
|
+
const appID = await global.base.getAppId();
|
|
70
|
+
const params = {
|
|
71
|
+
third_type: bossData?.third_type,
|
|
72
|
+
third_id: bossData?.third_id,
|
|
73
|
+
user_id: bossData?.user_id,
|
|
74
|
+
};
|
|
75
|
+
if (appID) {
|
|
76
|
+
params.appid = appID;
|
|
69
77
|
}
|
|
78
|
+
const res = await delThirdId(params);
|
|
79
|
+
global.loading.hideLoading("正在解绑...");
|
|
80
|
+
console.log(res, "delThirdId");
|
|
81
|
+
if (res.code === 0) {
|
|
82
|
+
await get_user_info();
|
|
83
|
+
global.toast.showToast("解绑成功");
|
|
84
|
+
} else {
|
|
85
|
+
global.toast.showToast("解绑失败");
|
|
86
|
+
navigation.goBack();
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("delBind error:", error);
|
|
90
|
+
global.loading.hideLoading("正在解绑...");
|
|
91
|
+
global.toast.showToast("解绑失败");
|
|
92
|
+
navigation.goBack();
|
|
70
93
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const get_user_info = async () => {
|
|
97
|
+
try {
|
|
98
|
+
const res = await getUserInfo();
|
|
99
|
+
console.log(res, "getUserInfo");
|
|
100
|
+
if (
|
|
101
|
+
res?.code === 0 &&
|
|
102
|
+
res.result?.user_list &&
|
|
103
|
+
res.result?.user_list.length
|
|
104
|
+
) {
|
|
105
|
+
// const accountData = await storage.get('accountData');
|
|
106
|
+
// accountData.user.bind_list = res.result?.user_list[0].bind_list;
|
|
107
|
+
// await storage.set('accountData', accountData);
|
|
108
|
+
// const bossData = accountData.user.bind_list
|
|
109
|
+
const bossData = res.result?.user_list[0].bind_list.filter(item => {
|
|
110
|
+
return item.third_type === "boss";
|
|
111
|
+
});
|
|
112
|
+
console.log(bossData[0]);
|
|
113
|
+
if (bossData[0]) {
|
|
114
|
+
await storage.set("bossData", bossData[0]);
|
|
115
|
+
} else {
|
|
116
|
+
await storage.set("bossData", {});
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
await storage.set("bossData", {});
|
|
120
|
+
}
|
|
121
|
+
if (module === "shop") {
|
|
122
|
+
await get_assets();
|
|
123
|
+
} else {
|
|
124
|
+
navigation.goBack();
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("get_user_info error:", error);
|
|
74
128
|
navigation.goBack();
|
|
75
129
|
}
|
|
76
130
|
};
|
|
@@ -86,7 +140,8 @@ export default ({ navigation, route }) => {
|
|
|
86
140
|
if (appID) {
|
|
87
141
|
params.appid = appID;
|
|
88
142
|
}
|
|
89
|
-
|
|
143
|
+
try {
|
|
144
|
+
const res = await getAssets(params);
|
|
90
145
|
if (res?.code === 0) {
|
|
91
146
|
if (
|
|
92
147
|
res?.result &&
|
|
@@ -97,12 +152,19 @@ export default ({ navigation, route }) => {
|
|
|
97
152
|
return item.currency === 20000;
|
|
98
153
|
});
|
|
99
154
|
if (current.length) {
|
|
100
|
-
storage.set("isportData", current[0]);
|
|
155
|
+
await storage.set("isportData", current[0]);
|
|
156
|
+
} else {
|
|
157
|
+
await storage.set("isportData", {});
|
|
101
158
|
}
|
|
159
|
+
} else {
|
|
160
|
+
await storage.set("isportData", {});
|
|
102
161
|
}
|
|
103
162
|
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error("get_assets error:", error);
|
|
165
|
+
} finally {
|
|
104
166
|
navigation.goBack();
|
|
105
|
-
}
|
|
167
|
+
}
|
|
106
168
|
};
|
|
107
169
|
|
|
108
170
|
const generateRandomString = length => {
|
|
@@ -120,20 +182,32 @@ export default ({ navigation, route }) => {
|
|
|
120
182
|
<View style={{ flex: 1 }}>
|
|
121
183
|
<ScreenBackHeader title="BOSS登录" />
|
|
122
184
|
<View style={{ flex: 1 }}>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
185
|
+
{!!uri && (
|
|
186
|
+
<WebView
|
|
187
|
+
bounces={false}
|
|
188
|
+
javaScriptEnabled={true}
|
|
189
|
+
useWebKit={true}
|
|
190
|
+
source={{
|
|
191
|
+
uri: uri,
|
|
192
|
+
headers: { "Cache-Control": "no-store" },
|
|
193
|
+
}}
|
|
194
|
+
incognito={true}
|
|
195
|
+
onMessage={onMessage}
|
|
196
|
+
onLoadStart={() => global.loading.showLoading()}
|
|
197
|
+
onLoadEnd={() => global.loading.hideLoading()}
|
|
198
|
+
onError={e => {
|
|
199
|
+
console.log("加载错误:", e.nativeEvent.description);
|
|
200
|
+
global.loading.hideLoading();
|
|
201
|
+
}}
|
|
202
|
+
// iOS 特定修复
|
|
203
|
+
// onShouldStartLoadWithRequest={request => {
|
|
204
|
+
// if (request.url.startsWith('file://')) {
|
|
205
|
+
// return true; // 允许加载本地文件
|
|
206
|
+
// }
|
|
207
|
+
// return true;
|
|
208
|
+
// }}
|
|
209
|
+
/>
|
|
210
|
+
)}
|
|
137
211
|
</View>
|
|
138
212
|
</View>
|
|
139
213
|
);
|
|
@@ -340,6 +340,7 @@ export default ({ navigation, route }) => {
|
|
|
340
340
|
value={item.value}
|
|
341
341
|
onChangeText={value => onChangeText(item.name, value)}
|
|
342
342
|
placeholder={item.placeholder}
|
|
343
|
+
returnKeyType="done"
|
|
343
344
|
/>
|
|
344
345
|
{item.name === 'telephone' && telMsg ? (
|
|
345
346
|
<Text style={styles.msg}>{telMsg}</Text>
|