ipanel-rnapp-ajb-base 1.0.0
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/.local_dev/DemoPage.js +46 -0
- package/app/.local_dev/env.js +1 -0
- package/app/.local_dev/polyfill.js +83 -0
- package/app/App.js +485 -0
- package/app/api/homedApi.js +42 -0
- package/app/api/index.js +2 -0
- package/app/api/ipanelCloudApi.js +796 -0
- package/app/assets/img/add.png +0 -0
- package/app/assets/img/add_img.png +0 -0
- package/app/assets/img/album.png +0 -0
- package/app/assets/img/album2.png +0 -0
- package/app/assets/img/album3.png +0 -0
- package/app/assets/img/album@2x.png +0 -0
- package/app/assets/img/album@3x.png +0 -0
- package/app/assets/img/audioRecordBar.png +0 -0
- package/app/assets/img/bootom_bar_bg.png +0 -0
- package/app/assets/img/close.png +0 -0
- package/app/assets/img/computer.png +0 -0
- package/app/assets/img/confirm.png +0 -0
- package/app/assets/img/delete_pic.png +0 -0
- package/app/assets/img/disabled.png +0 -0
- package/app/assets/img/goBack.png +0 -0
- package/app/assets/img/goBack2.png +0 -0
- package/app/assets/img/ischeck.png +0 -0
- package/app/assets/img/launch_bg.png +0 -0
- package/app/assets/img/launch_bg_panyu.png +0 -0
- package/app/assets/img/launch_logo.png +0 -0
- package/app/assets/img/launch_logo_panyu.png +0 -0
- package/app/assets/img/launch_text.png +0 -0
- package/app/assets/img/launch_text_panyu.png +0 -0
- package/app/assets/img/link.png +0 -0
- package/app/assets/img/login_bg.png +0 -0
- package/app/assets/img/login_bg_new.png +0 -0
- package/app/assets/img/login_left.png +0 -0
- package/app/assets/img/login_right.png +0 -0
- package/app/assets/img/nocheck.png +0 -0
- package/app/assets/img/personal.png +0 -0
- package/app/assets/img/photo.png +0 -0
- package/app/assets/img/photo@2x.png +0 -0
- package/app/assets/img/photo@3x.png +0 -0
- package/app/assets/img/protocol_checked.png +0 -0
- package/app/assets/img/qiehuan.png +0 -0
- package/app/assets/img/scan_border_bottom_left.png +0 -0
- package/app/assets/img/scan_border_bottom_right.png +0 -0
- package/app/assets/img/scan_border_top_left.png +0 -0
- package/app/assets/img/scan_border_top_right.png +0 -0
- package/app/assets/img/scan_move.png +0 -0
- package/app/assets/img/szjt.png +0 -0
- package/app/assets/img/tab.png +0 -0
- package/app/assets/img/tykz.png +0 -0
- package/app/assets/img/update_bg.png +0 -0
- package/app/assets/img/video.png +0 -0
- package/app/assets/img/video@2x.png +0 -0
- package/app/assets/img/video@3x.png +0 -0
- package/app/assets/img/worker.png +0 -0
- package/app/assets/img/wx.png +0 -0
- package/app/assets/img/ykq.png +0 -0
- package/app/assets/img/zfb.png +0 -0
- package/app/base.js +342 -0
- package/app/components/VersionUpdateConfirm.js +117 -0
- package/app/components/common/AccordionCell/index.js +67 -0
- package/app/components/common/ActionPicker/BasicPicker.js +136 -0
- package/app/components/common/ActionPicker/index.js +106 -0
- package/app/components/common/AddressPicker/index.js +211 -0
- package/app/components/common/Card/index.js +19 -0
- package/app/components/common/Cell/index.js +381 -0
- package/app/components/common/CustomDialog/index.js +120 -0
- package/app/components/common/CustomTabBar/index.js +157 -0
- package/app/components/common/CustomTabBar_bak/TabBarInput.js +210 -0
- package/app/components/common/CustomTabBar_bak/index.js +832 -0
- package/app/components/common/DateTimingPicker/index.js +254 -0
- package/app/components/common/Dialog/Notify.js +36 -0
- package/app/components/common/Dialog/baseDialog.js +146 -0
- package/app/components/common/Dialog/index.js +113 -0
- package/app/components/common/Dialog/prompt.js +145 -0
- package/app/components/common/Dialog/quickSelect.js +54 -0
- package/app/components/common/Dialog/select.js +125 -0
- package/app/components/common/Dialog/styles.js +167 -0
- package/app/components/common/Loading/index.js +71 -0
- package/app/components/common/LoginType/index.js +171 -0
- package/app/components/common/LoginType/protocol.js +160 -0
- package/app/components/common/Notify/index.js +68 -0
- package/app/components/common/OnceTouchable/index.js +33 -0
- package/app/components/common/PaymentPicker/index.js +264 -0
- package/app/components/common/ProductOrderPicker/index.js +524 -0
- package/app/components/common/ScreenBackHeader/index.js +144 -0
- package/app/components/common/ScrollPicker/index.js +232 -0
- package/app/components/common/SelectPicker/index.js +171 -0
- package/app/components/common/SmsCodeInput/index.js +93 -0
- package/app/components/common/SmsCodeInput/indexNew.js +101 -0
- package/app/components/common/Steps/index.js +126 -0
- package/app/components/common/Tag/index.js +17 -0
- package/app/components/common/Toast/index.js +103 -0
- package/app/components/common/WeekDaysPicker/index.js +196 -0
- package/app/components/index.js +8 -0
- package/app/components/iot/AddDeviceActionSheet/index.js +934 -0
- package/app/components/iot/AddressActionSheet/index.js +91 -0
- package/app/components/iot/RoomActionSheet/index.js +205 -0
- package/app/components/iot/ViewDeviceActionSheet/index.js +834 -0
- package/app/components/sheets.js +30 -0
- package/app/eventBus/index.js +54 -0
- package/app/hooks/checkLogin.js +30 -0
- package/app/hooks/shopMessageManager.js +308 -0
- package/app/hooks/useAddress.js +179 -0
- package/app/hooks/useAddress2.js +587 -0
- package/app/hooks/useDebounceFn.js +6 -0
- package/app/hooks/useDynamicPackages.js +22 -0
- package/app/hooks/useKeyboard.js +25 -0
- package/app/hooks/useLatest.js +10 -0
- package/app/hooks/useMessageManager.js +368 -0
- package/app/hooks/useNavigationFocus.js +19 -0
- package/app/hooks/useUser.js +56 -0
- package/app/screens/BaseScreen.js +389 -0
- package/app/screens/CommonScreens/BindPhoneScreen/index.js +179 -0
- package/app/screens/CommonScreens/BossScreen/index.js +138 -0
- package/app/screens/CommonScreens/DeviceAnswerDetailScreen/index.js +50 -0
- package/app/screens/CommonScreens/DeviceFeedbackScreen/index.js +365 -0
- package/app/screens/CommonScreens/EditInvoiceTitleScreen/index.js +279 -0
- package/app/screens/CommonScreens/FamilyDetailScreen/index.js +421 -0
- package/app/screens/CommonScreens/InvoiceTitleListScreen/index.js +118 -0
- package/app/screens/CommonScreens/OperatorSelectScreen/index.js +315 -0
- package/app/screens/CommonScreens/PersonalScreen/index.js +348 -0
- package/app/screens/CommonScreens/ScanQRCodeScreen/index.js +407 -0
- package/app/screens/CommonScreens/TvAlbumScreen/index.js +407 -0
- package/app/screens/LoginScreen/OpenLogSheet.js +241 -0
- package/app/screens/LoginScreen/index.js +920 -0
- package/app/screens/LoginScreen/indexNew.js +1354 -0
- package/app/screens/ResePassword/index.js +364 -0
- package/app/screens/SbkScreen.js +19 -0
- package/app/screens/WebviewScreen.js +41 -0
- package/app/storage/index.js +166 -0
- package/app/utils/EventEmitter.js +43 -0
- package/app/utils/RootNavigation.js +32 -0
- package/app/utils/SBK_plugin/convert.js +90 -0
- package/app/utils/SBK_plugin/convertStatus.js +250 -0
- package/app/utils/SBK_plugin/eventProcess.js +339 -0
- package/app/utils/SBK_plugin/index.js +32 -0
- package/app/utils/SBK_plugin/ipanelDeviceToSbkDevice.js +68 -0
- package/app/utils/SBK_plugin/sbk_defs.js +191 -0
- package/app/utils/StyleComposite.js +37 -0
- package/app/utils/applyPermissions.js +251 -0
- package/app/utils/bundleUpdater.js +46 -0
- package/app/utils/common.js +380 -0
- package/app/utils/config.js +47 -0
- package/app/utils/errCodes.js +3 -0
- package/app/utils/homedData.js +57 -0
- package/app/utils/http.js +178 -0
- package/app/utils/notice.js +15 -0
- package/app/utils/priceConversion.js +30 -0
- package/app/utils/registerDialog.js +90 -0
- package/app/utils/scaleSize.js +12 -0
- package/app/utils/soundPlayer.js +85 -0
- package/bin/local-dev.js +7 -0
- package/index.js +8 -0
- package/package.json +18 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {registerSheet} from 'react-native-actions-sheet';
|
|
2
|
+
import AddressActionSheet from './iot/AddressActionSheet';
|
|
3
|
+
import RoomActionSheet from './iot/RoomActionSheet';
|
|
4
|
+
import AddDeviceActionSheet from './iot/AddDeviceActionSheet';
|
|
5
|
+
import ViewDeviceActionSheet from './iot/ViewDeviceActionSheet';
|
|
6
|
+
import ActionPicker from './common/ActionPicker';
|
|
7
|
+
import DateTimingPicker from './common/DateTimingPicker';
|
|
8
|
+
import WeekDaysPicker from './common/WeekDaysPicker';
|
|
9
|
+
import SelectPicker from './common/SelectPicker';
|
|
10
|
+
import ProductOrderPicker from './common/ProductOrderPicker';
|
|
11
|
+
import PaymentPicker from './common/PaymentPicker';
|
|
12
|
+
import AddressPicker from './common/AddressPicker';
|
|
13
|
+
import ScrollPicker from './common/ScrollPicker';
|
|
14
|
+
|
|
15
|
+
// 要用SheetManager调用的action-sheet都需要在这里注册
|
|
16
|
+
// 注意:测试发现这里的注册顺序会影响其层级,前面的会被后面遮盖
|
|
17
|
+
registerSheet('address-action-sheet', AddressActionSheet);
|
|
18
|
+
registerSheet('room-action-sheet', RoomActionSheet);
|
|
19
|
+
registerSheet('add-device-action-sheet', AddDeviceActionSheet);
|
|
20
|
+
registerSheet('view-device-action-sheet', ViewDeviceActionSheet);
|
|
21
|
+
registerSheet('date-timing-picker', DateTimingPicker);
|
|
22
|
+
registerSheet('week-days-picker', WeekDaysPicker);
|
|
23
|
+
registerSheet('action-picker', ActionPicker);
|
|
24
|
+
registerSheet('select-picker', SelectPicker);
|
|
25
|
+
registerSheet('product-order-picker', ProductOrderPicker);
|
|
26
|
+
registerSheet('payment-picker', PaymentPicker);
|
|
27
|
+
registerSheet('address-picker', AddressPicker);
|
|
28
|
+
registerSheet('scroll-picker', ScrollPicker);
|
|
29
|
+
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
// 全局事件总线
|
|
4
|
+
// 事件名规范:
|
|
5
|
+
// "事件命名空间.事件动作", 如"message.add"
|
|
6
|
+
const eventBus = new EventEmitter();
|
|
7
|
+
|
|
8
|
+
export default eventBus;
|
|
9
|
+
|
|
10
|
+
// 全部事件汇总声明,便于查验引用
|
|
11
|
+
export const EVENTS = {
|
|
12
|
+
// 智能客服聊天界面
|
|
13
|
+
MESSAGE: {
|
|
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
|
+
},
|
|
20
|
+
// 底部自定义导航栏
|
|
21
|
+
CUSTOM_TAB_BAR: {
|
|
22
|
+
HIDE_MORE_AREA: 'CustomTabBar.hideMoreArea', // 隐藏更多按钮区域事件
|
|
23
|
+
},
|
|
24
|
+
// 我的家庭
|
|
25
|
+
FAMILY: {
|
|
26
|
+
CHANGE: 'family.change', // 当前家庭切换事件
|
|
27
|
+
},
|
|
28
|
+
HOMED: {
|
|
29
|
+
TOKEN_CHANGE: 'homed.tokenChange',
|
|
30
|
+
},
|
|
31
|
+
TV: {
|
|
32
|
+
SHARE_TIME_LIMIT: 'tv.shareTimeLimit',
|
|
33
|
+
HOME_DATA_CHANGE: 'tv.homeDataChange',
|
|
34
|
+
},
|
|
35
|
+
SMART_HOME: {
|
|
36
|
+
BLE_MESH_ADD: 'smartHome.bleMeshAdd',
|
|
37
|
+
},
|
|
38
|
+
IOT: {
|
|
39
|
+
DEVICE_STATUS_UPDATE: 'device.status.update',
|
|
40
|
+
ITEE_NETWORK_CHANGE: 'itee.network.change',
|
|
41
|
+
},
|
|
42
|
+
ACCOUNT: {
|
|
43
|
+
AVATAR_CHANGE: 'avatar.change',
|
|
44
|
+
},
|
|
45
|
+
// 商城客服聊天界面
|
|
46
|
+
SHOPMESSAGE: {
|
|
47
|
+
ADD: 'shop.message.add', // 新增消息事件
|
|
48
|
+
RENDER: 'shop.message.render', // 渲染消息UI
|
|
49
|
+
CONNECT_STATUS_CHANGE: 'shop.message.connectStatusChange', // websocket连接状态变更事件
|
|
50
|
+
RECONNECT: 'shop.message.reconnect', // 触发websocket重连事件
|
|
51
|
+
ONLINE_LIST: 'shop.message.online', // 商城在线用户
|
|
52
|
+
CUSTOM_SERVICE_CONNECT_CHANGE: 'shop.message.customServiceConnectChange', // 智能客服转人工的进入和退出事件
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {getRootState, replace, popToTop} from '../utils/RootNavigation';
|
|
2
|
+
import storage from '../storage';
|
|
3
|
+
|
|
4
|
+
// 测试用:启动APP后设置登录态为false
|
|
5
|
+
// storage.set("accessToken", false);
|
|
6
|
+
|
|
7
|
+
async function checkLogin() {
|
|
8
|
+
const rootNavigationState = getRootState();
|
|
9
|
+
|
|
10
|
+
if (rootNavigationState) {
|
|
11
|
+
const currentStackRoute =
|
|
12
|
+
rootNavigationState.routes[rootNavigationState.routes.length - 1];
|
|
13
|
+
// console.log("正在进行登录鉴权", currentStackRoute.name);
|
|
14
|
+
if (!['Login', 'WebviewScreen'].includes(currentStackRoute.name)) {
|
|
15
|
+
// const start = new Date().getTime();
|
|
16
|
+
const token = await storage.get('accessToken');
|
|
17
|
+
// console.log(isLogined, new Date() - start); // 获取登录状态是异步的
|
|
18
|
+
if (!token) {
|
|
19
|
+
if (rootNavigationState.routes.length > 1) {
|
|
20
|
+
popToTop();
|
|
21
|
+
}
|
|
22
|
+
replace('Login', {
|
|
23
|
+
skip: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default checkLogin;
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import {useEffect, useCallback, useRef, useState} from 'react';
|
|
2
|
+
// import {PermissionsAndroid, Platform} from 'react-native';
|
|
3
|
+
|
|
4
|
+
// import {format} from 'date-fns';
|
|
5
|
+
|
|
6
|
+
import storage from '../storage';
|
|
7
|
+
import eventBus, {EVENTS} from '../eventBus';
|
|
8
|
+
import config from '../utils/config';
|
|
9
|
+
import {shopGenMsg} from '../utils/common';
|
|
10
|
+
|
|
11
|
+
let connectStatus = -1; // -1 连接中 0 连接成功 1连接失败
|
|
12
|
+
let tryConnectTimes = 0;
|
|
13
|
+
let seq_id = 0;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 商城客服中心JS
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// 消息记录
|
|
20
|
+
storage.get('shopMessageList').then(msgList => {
|
|
21
|
+
if (typeof msgList === 'string') {
|
|
22
|
+
try {
|
|
23
|
+
msgList = JSON.parse(msgList);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.log('msgList error', e, msgList);
|
|
26
|
+
msgList = [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// console.log(msgList, '商城客服消息列表msgList');
|
|
30
|
+
global.base.shopMessageManager.messages = msgList || [];
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 当前是否处于智能客服转人工
|
|
34
|
+
// let isManualCustomServiceActive = false;
|
|
35
|
+
// // 当前人工客服
|
|
36
|
+
// let currentCustomStaff = {};
|
|
37
|
+
// // 用户长时间没有发送消息后自动退出转人工的定时器
|
|
38
|
+
// let manualCustomServiceTimer;
|
|
39
|
+
|
|
40
|
+
// TODO 定期轮询检查消息过期
|
|
41
|
+
|
|
42
|
+
const ShopMessageManager = () => {
|
|
43
|
+
const ws = useRef(null);
|
|
44
|
+
// 获取在线用户
|
|
45
|
+
const getOnlineUser = useCallback(() => {
|
|
46
|
+
if (ws.current) {
|
|
47
|
+
const data = {
|
|
48
|
+
page_pos: 1,
|
|
49
|
+
page_num: 20,
|
|
50
|
+
};
|
|
51
|
+
let proto = {
|
|
52
|
+
id: seq_id,
|
|
53
|
+
type: 1000, // 1000 request 2000 response
|
|
54
|
+
ecode: 0,
|
|
55
|
+
emessage: '',
|
|
56
|
+
route: 'online_user_list',
|
|
57
|
+
data: JSON.stringify(data),
|
|
58
|
+
};
|
|
59
|
+
ws.current.send(JSON.stringify(proto));
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
// 发送消息
|
|
64
|
+
const sendMessage = useCallback(msg => {
|
|
65
|
+
if (ws.current) {
|
|
66
|
+
console.log('ws.shop.send');
|
|
67
|
+
ws.current.send(JSON.stringify(msg));
|
|
68
|
+
let msgData = JSON.parse(msg.data);
|
|
69
|
+
msgData.type = 2000;
|
|
70
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.ADD, msgData);
|
|
71
|
+
}
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
74
|
+
const connectMsgServer = async connectCallback => {
|
|
75
|
+
const token = await storage.get('accessToken');
|
|
76
|
+
const accountData = await storage.get('accountData');
|
|
77
|
+
const wsUrl = 'ws://192.168.36.241:9100/imchat';
|
|
78
|
+
const connectParams = [
|
|
79
|
+
`accesstoken=${token}`,
|
|
80
|
+
`nick_name=${accountData?.user?.nickname}`,
|
|
81
|
+
'face_url=',
|
|
82
|
+
`user_id=${accountData?.user?.user_id}`,
|
|
83
|
+
'platform=web',
|
|
84
|
+
'api=ipanel_test',
|
|
85
|
+
`source=${'dev.ipanelcloud2.ipanel.cn' || config.IPANEL_CLOUD_DOMAIN}`,
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
// 缓存全局商城客服websocket连接
|
|
89
|
+
global.shopMessageWebsocketRef = ws;
|
|
90
|
+
global.base.shopMessageManager.wsRef = ws;
|
|
91
|
+
ws.current = new WebSocket(
|
|
92
|
+
encodeURI(`${wsUrl}?${connectParams.join('&')}`),
|
|
93
|
+
);
|
|
94
|
+
ws.current.onopen = () => {
|
|
95
|
+
console.log('商城客服已连接ws shop open');
|
|
96
|
+
connectCallback && connectCallback(null); // success
|
|
97
|
+
connectStatus = 0;
|
|
98
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
99
|
+
};
|
|
100
|
+
ws.current.onmessage = ({data}) => {
|
|
101
|
+
const msgData = JSON.parse(data);
|
|
102
|
+
// 2000是接收自己发的消息
|
|
103
|
+
if (msgData.type === 1000) {
|
|
104
|
+
const msg = JSON.parse(msgData?.data);
|
|
105
|
+
msg.type = msgData.type;
|
|
106
|
+
console.log('接收消息', msg?.message_data, msg);
|
|
107
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.ADD, msg);
|
|
108
|
+
} else if (
|
|
109
|
+
msgData.type === 2000 &&
|
|
110
|
+
msgData.route === 'online_user_list'
|
|
111
|
+
) {
|
|
112
|
+
// 获取在线用户
|
|
113
|
+
const msg = JSON.parse(msgData?.data);
|
|
114
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.ONLINE_LIST, msg);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
ws.current.onerror = err => {
|
|
118
|
+
console.log('onerror', err);
|
|
119
|
+
};
|
|
120
|
+
ws.current.onclose = event => {
|
|
121
|
+
console.log('onclose', event);
|
|
122
|
+
reConnect(connectCallback);
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const reConnect = async callback => {
|
|
127
|
+
if (tryConnectTimes < 5) {
|
|
128
|
+
// 重连ws
|
|
129
|
+
tryConnectTimes++;
|
|
130
|
+
connectMsgServer(callback);
|
|
131
|
+
} else {
|
|
132
|
+
// 重连5次ws失败,不再重试。等用户自己发消息时触发重连
|
|
133
|
+
tryConnectTimes = 0;
|
|
134
|
+
connectStatus = 1;
|
|
135
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
136
|
+
callback && callback('error');
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// const [onlineUser, setOnlineUser] = useState([]); // 在线用户列表
|
|
141
|
+
// const nameRef = useRef('');
|
|
142
|
+
// // 请求到客服列表的回调
|
|
143
|
+
// const handleGetOnlineUserList = async data => {
|
|
144
|
+
// if (isManualCustomServiceActive) {
|
|
145
|
+
// return;
|
|
146
|
+
// }
|
|
147
|
+
// const accountData = await storage.get('accountData');
|
|
148
|
+
// console.log('handleGetOnlineUserList', data);
|
|
149
|
+
// let dataList = data?.list.filter(val => {
|
|
150
|
+
// return val.nick_name !== nameRef.current;
|
|
151
|
+
// });
|
|
152
|
+
// // // console.log(dataList, nameRef.current);
|
|
153
|
+
// setOnlineUser(dataList);
|
|
154
|
+
|
|
155
|
+
// if (dataList.length === 0) {
|
|
156
|
+
// global.toast.showToast('当前没有人工客服在线,请稍候再试!');
|
|
157
|
+
// return;
|
|
158
|
+
// }
|
|
159
|
+
|
|
160
|
+
// console.log('当前商城客服列表:', dataList);
|
|
161
|
+
// // 分配一个人工客服
|
|
162
|
+
// currentCustomStaff =
|
|
163
|
+
// dataList.find(user => user.nick_name === '壮壮') || dataList[0];
|
|
164
|
+
// console.log('已分配商城智能客服人工客服:', currentCustomStaff.nick_name);
|
|
165
|
+
|
|
166
|
+
// // 设置当前处于人工客服的标志
|
|
167
|
+
// isManualCustomServiceActive = true;
|
|
168
|
+
// eventBus.emit(EVENTS.SHOPMESSAGE.CUSTOM_SERVICE_CONNECT_CHANGE, true);
|
|
169
|
+
|
|
170
|
+
// // 显示消息
|
|
171
|
+
// handleShopTextSubmit(
|
|
172
|
+
// `您好,客服“${currentCustomStaff.nick_name}”为您服务!`,
|
|
173
|
+
// currentCustomStaff?.user_id,
|
|
174
|
+
// `${accountData.user?.user_id}-${currentCustomStaff.user_id}-shop`,
|
|
175
|
+
// );
|
|
176
|
+
|
|
177
|
+
// resetManualCustomServiceExitTimer();
|
|
178
|
+
// };
|
|
179
|
+
// const resetManualCustomServiceExitTimer = () => {
|
|
180
|
+
// // 10分钟没发消息后自动退出人工
|
|
181
|
+
// clearTimeout(manualCustomServiceTimer);
|
|
182
|
+
// manualCustomServiceTimer = setTimeout(() => {
|
|
183
|
+
// exitShopManualCustomService(true);
|
|
184
|
+
// }, 600000);
|
|
185
|
+
// };
|
|
186
|
+
// // 请求转人工
|
|
187
|
+
// const requestShopManualCustomService = async () => {
|
|
188
|
+
// const user = await storage.get('accountData');
|
|
189
|
+
// nameRef.current = user.user?.nickname;
|
|
190
|
+
// // 发送获取客服列表消息,在EVENTS.SHOPMESSAGE.ONLINE_LIST事件回调中处理获取到的客服列表数据
|
|
191
|
+
// getOnlineUser();
|
|
192
|
+
// };
|
|
193
|
+
// const exitShopManualCustomService = async timeout => {
|
|
194
|
+
// isManualCustomServiceActive = false;
|
|
195
|
+
// eventBus.emit(EVENTS.SHOPMESSAGE.CUSTOM_SERVICE_CONNECT_CHANGE, false);
|
|
196
|
+
// console.log('退出商城智能客服人工客服');
|
|
197
|
+
|
|
198
|
+
// // 显示消息
|
|
199
|
+
// const accountData = await storage.get('accountData');
|
|
200
|
+
// handleShopTextSubmit(
|
|
201
|
+
// timeout
|
|
202
|
+
// ? '您已经很长时间没说话了,已自动退出人工客服,如有需要请再次联系'
|
|
203
|
+
// : '您已退出人工客服。',
|
|
204
|
+
// currentCustomStaff?.user_id,
|
|
205
|
+
// `${accountData.user?.user_id}-${currentCustomStaff.user_id}-shop`,
|
|
206
|
+
// );
|
|
207
|
+
// };
|
|
208
|
+
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
const onMessageAdd = msg => {
|
|
211
|
+
msg.MsgId =
|
|
212
|
+
msg.MsgId ||
|
|
213
|
+
parseInt(Math.random().toString().slice(2), 10)
|
|
214
|
+
.toString(16)
|
|
215
|
+
.slice(0, 7);
|
|
216
|
+
msg.CreateTime = new Date().getTime();
|
|
217
|
+
console.log(msg, '商城客服msg');
|
|
218
|
+
// console.log(global.base.shopMessageManager.messages, '22');
|
|
219
|
+
global.base.shopMessageManager.messages.push(msg);
|
|
220
|
+
|
|
221
|
+
// // save to local 存到本地
|
|
222
|
+
storage.set(
|
|
223
|
+
'shopMessageList',
|
|
224
|
+
global.base.shopMessageManager.messages.slice(-100),
|
|
225
|
+
);
|
|
226
|
+
// storage.remove('shopMessageList');
|
|
227
|
+
|
|
228
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.RENDER, msg);
|
|
229
|
+
};
|
|
230
|
+
seq_id = 0;
|
|
231
|
+
connectStatus = -1;
|
|
232
|
+
eventBus.emit(EVENTS.SHOPMESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
|
|
233
|
+
(async () => {
|
|
234
|
+
const accountType = await storage.get('accountType');
|
|
235
|
+
if (accountType !== 'adg') {
|
|
236
|
+
connectMsgServer();
|
|
237
|
+
}
|
|
238
|
+
})();
|
|
239
|
+
|
|
240
|
+
eventBus.on(EVENTS.SHOPMESSAGE.ADD, onMessageAdd);
|
|
241
|
+
eventBus.on(EVENTS.SHOPMESSAGE.RECONNECT, reConnect);
|
|
242
|
+
|
|
243
|
+
// 监听请求客服人员列表的回调
|
|
244
|
+
// eventBus.on(EVENTS.SHOPMESSAGE.ONLINE_LIST, handleGetOnlineUserList);
|
|
245
|
+
|
|
246
|
+
return () => {
|
|
247
|
+
eventBus.off(EVENTS.SHOPMESSAGE.ADD, onMessageAdd);
|
|
248
|
+
eventBus.off(EVENTS.SHOPMESSAGE.RECONNECT, reConnect);
|
|
249
|
+
// eventBus.off(EVENTS.SHOPMESSAGE.ONLINE_LIST, handleGetOnlineUserList);
|
|
250
|
+
};
|
|
251
|
+
}, []);
|
|
252
|
+
|
|
253
|
+
// 文本输入发消息
|
|
254
|
+
const handleShopTextSubmit = useCallback(
|
|
255
|
+
async (inputText, recver_id, conversation_id) => {
|
|
256
|
+
// 1000 request 2000 response
|
|
257
|
+
let message_prop = JSON.stringify({
|
|
258
|
+
msgType: 'text',
|
|
259
|
+
});
|
|
260
|
+
const userMsg = await shopGenMsg(
|
|
261
|
+
1000,
|
|
262
|
+
message_prop,
|
|
263
|
+
inputText,
|
|
264
|
+
seq_id++,
|
|
265
|
+
recver_id,
|
|
266
|
+
conversation_id,
|
|
267
|
+
);
|
|
268
|
+
sendMessage(userMsg);
|
|
269
|
+
},
|
|
270
|
+
[],
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
// 发送图片或视频消息
|
|
274
|
+
const handleShopMediaSelect = useCallback(
|
|
275
|
+
async (file, message_prop, recver_id, conversation_id) => {
|
|
276
|
+
// 本地手机存储url
|
|
277
|
+
const userMsg = await shopGenMsg(
|
|
278
|
+
1000,
|
|
279
|
+
message_prop,
|
|
280
|
+
file,
|
|
281
|
+
seq_id++,
|
|
282
|
+
recver_id,
|
|
283
|
+
conversation_id,
|
|
284
|
+
);
|
|
285
|
+
// console.log(userMsg);
|
|
286
|
+
sendMessage(userMsg);
|
|
287
|
+
},
|
|
288
|
+
[],
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
// const getShopManualCustomServiceActiveFlag = () =>
|
|
292
|
+
// isManualCustomServiceActive;
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
sendMessage,
|
|
296
|
+
getOnlineUser,
|
|
297
|
+
// requestShopManualCustomService,
|
|
298
|
+
// exitShopManualCustomService,
|
|
299
|
+
// getShopManualCustomServiceActiveFlag,
|
|
300
|
+
handleShopTextSubmit,
|
|
301
|
+
handleShopMediaSelect,
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export default ShopMessageManager;
|
|
306
|
+
|
|
307
|
+
//global.base.messageManager
|
|
308
|
+
//EVENTS.MESSAGE
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {useState, useEffect, useCallback, useMemo} from 'react';
|
|
2
|
+
|
|
3
|
+
import {getAddrInfo} from '../api';
|
|
4
|
+
|
|
5
|
+
import storage from '../storage';
|
|
6
|
+
import eventBus, {EVENTS} from '../eventBus';
|
|
7
|
+
|
|
8
|
+
function isStorageRoom(room) {
|
|
9
|
+
return room.room_type === 'STORAGEROOM';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Hook = (addressId, roomId) => {
|
|
13
|
+
const [addressList, setAddressList] = useState([]);
|
|
14
|
+
const [activeAddr, setActiveAddr] = useState({});
|
|
15
|
+
|
|
16
|
+
// 从本地存储中更新到当前组件内存
|
|
17
|
+
async function updateAddrFromStorage() {
|
|
18
|
+
// todo 数据超时更新
|
|
19
|
+
const addrList = await storage.get('addressList');
|
|
20
|
+
setAddressList(addrList || []);
|
|
21
|
+
|
|
22
|
+
const addr = await storage.get('activeAddr');
|
|
23
|
+
setActiveAddr(addr || {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const updateAddrList = async addrList => {
|
|
27
|
+
await storage.set('addressList', addrList);
|
|
28
|
+
setAddressList(addrList);
|
|
29
|
+
|
|
30
|
+
const oldActiveAddr = await storage.get('activeAddr');
|
|
31
|
+
const newActiveAddr = addrList.find(
|
|
32
|
+
addr => oldActiveAddr && addr.address_id === oldActiveAddr.address_id,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (newActiveAddr) {
|
|
36
|
+
updateActiveAddr(newActiveAddr);
|
|
37
|
+
} else {
|
|
38
|
+
const defaultAddr = addrList[0] ? addrList[0] : {};
|
|
39
|
+
eventBus.emit(EVENTS.FAMILY.CHANGE, defaultAddr);
|
|
40
|
+
updateActiveAddr(defaultAddr);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const updateActiveAddr = addr => {
|
|
45
|
+
setActiveAddr(addr);
|
|
46
|
+
storage.set('activeAddr', addr);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const mapModel = (brand, model) => {
|
|
50
|
+
/* 兼容存量 start */
|
|
51
|
+
if (brand === 'SQ' && model === 'Flight') {
|
|
52
|
+
return 'FLI17131';
|
|
53
|
+
}
|
|
54
|
+
if (brand === 'YGZM' && model === 'Tlight') {
|
|
55
|
+
return 'DLI19121';
|
|
56
|
+
}
|
|
57
|
+
if (brand === 'YHWL' && model === 'Tlight') {
|
|
58
|
+
return 'DLIIP121';
|
|
59
|
+
}
|
|
60
|
+
if (brand === 'YHWL' && model === 'SIL500B1') {
|
|
61
|
+
return 'SLIIP121';
|
|
62
|
+
}
|
|
63
|
+
if (brand === 'dooya' && model === 'ELCEC001') {
|
|
64
|
+
return 'ELC22011';
|
|
65
|
+
}
|
|
66
|
+
if (brand === 'YHWL' && model === 'Dlight') {
|
|
67
|
+
return 'DLIIP121';
|
|
68
|
+
}
|
|
69
|
+
if (brand === 'merach' && model === 'IRMIR101') {
|
|
70
|
+
return 'IRM24101';
|
|
71
|
+
}
|
|
72
|
+
if (brand === 'merach' && model === 'ISR12071') {
|
|
73
|
+
return 'ISR24101';
|
|
74
|
+
}
|
|
75
|
+
/* 兼容存量 end */
|
|
76
|
+
|
|
77
|
+
return model;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const mapAddrList = addrList => {
|
|
81
|
+
addrList.forEach(address => {
|
|
82
|
+
const roomList = address.room_list || [];
|
|
83
|
+
roomList.forEach(room => {
|
|
84
|
+
const deviceList = room.device_list || [];
|
|
85
|
+
deviceList.forEach(device => {
|
|
86
|
+
device.extend.model = mapModel(
|
|
87
|
+
device.extend?.brand,
|
|
88
|
+
device.extend?.model,
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// 从网络更新到本地存储和内存
|
|
96
|
+
const updateAddrFromNetwork = useCallback(async timeout => {
|
|
97
|
+
try {
|
|
98
|
+
const res = await getAddrInfo({detail: false});
|
|
99
|
+
const addrList = res?.result?.address_list || [];
|
|
100
|
+
mapAddrList(addrList);
|
|
101
|
+
await updateAddrList(addrList);
|
|
102
|
+
return addrList;
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.log('房间数据拉取失败');
|
|
105
|
+
throw e;
|
|
106
|
+
}
|
|
107
|
+
}, []);
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
updateAddrFromStorage();
|
|
111
|
+
|
|
112
|
+
// 监听用户家庭切换事件
|
|
113
|
+
eventBus.on(EVENTS.FAMILY.CHANGE, updateActiveAddr);
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
eventBus.off(EVENTS.FAMILY.CHANGE, updateActiveAddr);
|
|
117
|
+
};
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 当前家庭
|
|
122
|
+
* @type {unknown}
|
|
123
|
+
*/
|
|
124
|
+
const currentAddr = useMemo(() => {
|
|
125
|
+
if (!addressId) {
|
|
126
|
+
return activeAddr;
|
|
127
|
+
}
|
|
128
|
+
return addressList.find(addr => addr.address_id === addressId) || {};
|
|
129
|
+
}, [addressList, activeAddr]);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 当前家庭下的家庭列表
|
|
133
|
+
* @type {unknown}
|
|
134
|
+
*/
|
|
135
|
+
const roomList = useMemo(() => {
|
|
136
|
+
return currentAddr.room_list || [];
|
|
137
|
+
}, [currentAddr]);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 当前家庭下的储物间
|
|
141
|
+
*/
|
|
142
|
+
const storageRoom = useMemo(() => {
|
|
143
|
+
return roomList.find(room => isStorageRoom(room));
|
|
144
|
+
}, [roomList]);
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 当前房间
|
|
148
|
+
* @type {unknown}
|
|
149
|
+
*/
|
|
150
|
+
const currentRoom = useMemo(() => {
|
|
151
|
+
if (!roomId) {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
return roomList.find(room => room.room_id === roomId) || {};
|
|
155
|
+
}, [roomList]);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 当前房间下的所有设备
|
|
159
|
+
* @type {unknown}
|
|
160
|
+
*/
|
|
161
|
+
const deviceListOfCurrentRoom = useMemo(() => {
|
|
162
|
+
return currentRoom.device_list || [];
|
|
163
|
+
}, [currentRoom]);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
addressList,
|
|
167
|
+
activeAddr,
|
|
168
|
+
setActiveAddr,
|
|
169
|
+
updateAddrFromNetwork,
|
|
170
|
+
updateAddrFromStorage,
|
|
171
|
+
currentAddr,
|
|
172
|
+
roomList,
|
|
173
|
+
currentRoom,
|
|
174
|
+
deviceListOfCurrentRoom,
|
|
175
|
+
storageRoom,
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export default Hook;
|