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.
Files changed (155) hide show
  1. package/app/.local_dev/DemoPage.js +46 -0
  2. package/app/.local_dev/env.js +1 -0
  3. package/app/.local_dev/polyfill.js +83 -0
  4. package/app/App.js +485 -0
  5. package/app/api/homedApi.js +42 -0
  6. package/app/api/index.js +2 -0
  7. package/app/api/ipanelCloudApi.js +796 -0
  8. package/app/assets/img/add.png +0 -0
  9. package/app/assets/img/add_img.png +0 -0
  10. package/app/assets/img/album.png +0 -0
  11. package/app/assets/img/album2.png +0 -0
  12. package/app/assets/img/album3.png +0 -0
  13. package/app/assets/img/album@2x.png +0 -0
  14. package/app/assets/img/album@3x.png +0 -0
  15. package/app/assets/img/audioRecordBar.png +0 -0
  16. package/app/assets/img/bootom_bar_bg.png +0 -0
  17. package/app/assets/img/close.png +0 -0
  18. package/app/assets/img/computer.png +0 -0
  19. package/app/assets/img/confirm.png +0 -0
  20. package/app/assets/img/delete_pic.png +0 -0
  21. package/app/assets/img/disabled.png +0 -0
  22. package/app/assets/img/goBack.png +0 -0
  23. package/app/assets/img/goBack2.png +0 -0
  24. package/app/assets/img/ischeck.png +0 -0
  25. package/app/assets/img/launch_bg.png +0 -0
  26. package/app/assets/img/launch_bg_panyu.png +0 -0
  27. package/app/assets/img/launch_logo.png +0 -0
  28. package/app/assets/img/launch_logo_panyu.png +0 -0
  29. package/app/assets/img/launch_text.png +0 -0
  30. package/app/assets/img/launch_text_panyu.png +0 -0
  31. package/app/assets/img/link.png +0 -0
  32. package/app/assets/img/login_bg.png +0 -0
  33. package/app/assets/img/login_bg_new.png +0 -0
  34. package/app/assets/img/login_left.png +0 -0
  35. package/app/assets/img/login_right.png +0 -0
  36. package/app/assets/img/nocheck.png +0 -0
  37. package/app/assets/img/personal.png +0 -0
  38. package/app/assets/img/photo.png +0 -0
  39. package/app/assets/img/photo@2x.png +0 -0
  40. package/app/assets/img/photo@3x.png +0 -0
  41. package/app/assets/img/protocol_checked.png +0 -0
  42. package/app/assets/img/qiehuan.png +0 -0
  43. package/app/assets/img/scan_border_bottom_left.png +0 -0
  44. package/app/assets/img/scan_border_bottom_right.png +0 -0
  45. package/app/assets/img/scan_border_top_left.png +0 -0
  46. package/app/assets/img/scan_border_top_right.png +0 -0
  47. package/app/assets/img/scan_move.png +0 -0
  48. package/app/assets/img/szjt.png +0 -0
  49. package/app/assets/img/tab.png +0 -0
  50. package/app/assets/img/tykz.png +0 -0
  51. package/app/assets/img/update_bg.png +0 -0
  52. package/app/assets/img/video.png +0 -0
  53. package/app/assets/img/video@2x.png +0 -0
  54. package/app/assets/img/video@3x.png +0 -0
  55. package/app/assets/img/worker.png +0 -0
  56. package/app/assets/img/wx.png +0 -0
  57. package/app/assets/img/ykq.png +0 -0
  58. package/app/assets/img/zfb.png +0 -0
  59. package/app/base.js +342 -0
  60. package/app/components/VersionUpdateConfirm.js +117 -0
  61. package/app/components/common/AccordionCell/index.js +67 -0
  62. package/app/components/common/ActionPicker/BasicPicker.js +136 -0
  63. package/app/components/common/ActionPicker/index.js +106 -0
  64. package/app/components/common/AddressPicker/index.js +211 -0
  65. package/app/components/common/Card/index.js +19 -0
  66. package/app/components/common/Cell/index.js +381 -0
  67. package/app/components/common/CustomDialog/index.js +120 -0
  68. package/app/components/common/CustomTabBar/index.js +157 -0
  69. package/app/components/common/CustomTabBar_bak/TabBarInput.js +210 -0
  70. package/app/components/common/CustomTabBar_bak/index.js +832 -0
  71. package/app/components/common/DateTimingPicker/index.js +254 -0
  72. package/app/components/common/Dialog/Notify.js +36 -0
  73. package/app/components/common/Dialog/baseDialog.js +146 -0
  74. package/app/components/common/Dialog/index.js +113 -0
  75. package/app/components/common/Dialog/prompt.js +145 -0
  76. package/app/components/common/Dialog/quickSelect.js +54 -0
  77. package/app/components/common/Dialog/select.js +125 -0
  78. package/app/components/common/Dialog/styles.js +167 -0
  79. package/app/components/common/Loading/index.js +71 -0
  80. package/app/components/common/LoginType/index.js +171 -0
  81. package/app/components/common/LoginType/protocol.js +160 -0
  82. package/app/components/common/Notify/index.js +68 -0
  83. package/app/components/common/OnceTouchable/index.js +33 -0
  84. package/app/components/common/PaymentPicker/index.js +264 -0
  85. package/app/components/common/ProductOrderPicker/index.js +524 -0
  86. package/app/components/common/ScreenBackHeader/index.js +144 -0
  87. package/app/components/common/ScrollPicker/index.js +232 -0
  88. package/app/components/common/SelectPicker/index.js +171 -0
  89. package/app/components/common/SmsCodeInput/index.js +93 -0
  90. package/app/components/common/SmsCodeInput/indexNew.js +101 -0
  91. package/app/components/common/Steps/index.js +126 -0
  92. package/app/components/common/Tag/index.js +17 -0
  93. package/app/components/common/Toast/index.js +103 -0
  94. package/app/components/common/WeekDaysPicker/index.js +196 -0
  95. package/app/components/index.js +8 -0
  96. package/app/components/iot/AddDeviceActionSheet/index.js +934 -0
  97. package/app/components/iot/AddressActionSheet/index.js +91 -0
  98. package/app/components/iot/RoomActionSheet/index.js +205 -0
  99. package/app/components/iot/ViewDeviceActionSheet/index.js +834 -0
  100. package/app/components/sheets.js +30 -0
  101. package/app/eventBus/index.js +54 -0
  102. package/app/hooks/checkLogin.js +30 -0
  103. package/app/hooks/shopMessageManager.js +308 -0
  104. package/app/hooks/useAddress.js +179 -0
  105. package/app/hooks/useAddress2.js +587 -0
  106. package/app/hooks/useDebounceFn.js +6 -0
  107. package/app/hooks/useDynamicPackages.js +22 -0
  108. package/app/hooks/useKeyboard.js +25 -0
  109. package/app/hooks/useLatest.js +10 -0
  110. package/app/hooks/useMessageManager.js +368 -0
  111. package/app/hooks/useNavigationFocus.js +19 -0
  112. package/app/hooks/useUser.js +56 -0
  113. package/app/screens/BaseScreen.js +389 -0
  114. package/app/screens/CommonScreens/BindPhoneScreen/index.js +179 -0
  115. package/app/screens/CommonScreens/BossScreen/index.js +138 -0
  116. package/app/screens/CommonScreens/DeviceAnswerDetailScreen/index.js +50 -0
  117. package/app/screens/CommonScreens/DeviceFeedbackScreen/index.js +365 -0
  118. package/app/screens/CommonScreens/EditInvoiceTitleScreen/index.js +279 -0
  119. package/app/screens/CommonScreens/FamilyDetailScreen/index.js +421 -0
  120. package/app/screens/CommonScreens/InvoiceTitleListScreen/index.js +118 -0
  121. package/app/screens/CommonScreens/OperatorSelectScreen/index.js +315 -0
  122. package/app/screens/CommonScreens/PersonalScreen/index.js +348 -0
  123. package/app/screens/CommonScreens/ScanQRCodeScreen/index.js +407 -0
  124. package/app/screens/CommonScreens/TvAlbumScreen/index.js +407 -0
  125. package/app/screens/LoginScreen/OpenLogSheet.js +241 -0
  126. package/app/screens/LoginScreen/index.js +920 -0
  127. package/app/screens/LoginScreen/indexNew.js +1354 -0
  128. package/app/screens/ResePassword/index.js +364 -0
  129. package/app/screens/SbkScreen.js +19 -0
  130. package/app/screens/WebviewScreen.js +41 -0
  131. package/app/storage/index.js +166 -0
  132. package/app/utils/EventEmitter.js +43 -0
  133. package/app/utils/RootNavigation.js +32 -0
  134. package/app/utils/SBK_plugin/convert.js +90 -0
  135. package/app/utils/SBK_plugin/convertStatus.js +250 -0
  136. package/app/utils/SBK_plugin/eventProcess.js +339 -0
  137. package/app/utils/SBK_plugin/index.js +32 -0
  138. package/app/utils/SBK_plugin/ipanelDeviceToSbkDevice.js +68 -0
  139. package/app/utils/SBK_plugin/sbk_defs.js +191 -0
  140. package/app/utils/StyleComposite.js +37 -0
  141. package/app/utils/applyPermissions.js +251 -0
  142. package/app/utils/bundleUpdater.js +46 -0
  143. package/app/utils/common.js +380 -0
  144. package/app/utils/config.js +47 -0
  145. package/app/utils/errCodes.js +3 -0
  146. package/app/utils/homedData.js +57 -0
  147. package/app/utils/http.js +178 -0
  148. package/app/utils/notice.js +15 -0
  149. package/app/utils/priceConversion.js +30 -0
  150. package/app/utils/registerDialog.js +90 -0
  151. package/app/utils/scaleSize.js +12 -0
  152. package/app/utils/soundPlayer.js +85 -0
  153. package/bin/local-dev.js +7 -0
  154. package/index.js +8 -0
  155. package/package.json +18 -0
@@ -0,0 +1,368 @@
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
+ import storage from '../storage';
7
+ import eventBus, {EVENTS} from '../eventBus';
8
+ import config from '../utils/config';
9
+ import {MSG_TYPES, genMsg} from '../utils/common';
10
+ import applyPermissions from '../utils/applyPermissions';
11
+
12
+ let connectStatus = -1; // -1 连接中 0 连接成功 1连接失败
13
+
14
+ let tryConnectTimes = 0;
15
+
16
+ /**
17
+ * 智能客服中心JS
18
+ */
19
+
20
+ // storage.set('messageList', []); // 这是测试代码,如果要清空本地消息,则临时放开这段运行一下
21
+ // get local messageList
22
+ storage.get('messageList').then(msgList => {
23
+ if (typeof msgList === 'string') {
24
+ try {
25
+ msgList = JSON.parse(msgList);
26
+ } catch (e) {
27
+ console.log('msgList error', e, msgList);
28
+ msgList = [];
29
+ }
30
+ }
31
+ global.base.messageManager.messages = msgList || [];
32
+ });
33
+
34
+ // 当前是否处于智能客服转人工
35
+ let isManualCustomServiceActive = false;
36
+ // 当前人工客服
37
+ let currentCustomStaff = {};
38
+ // 用户长时间没有发送消息后自动退出转人工的定时器
39
+ let manualCustomServiceTimer;
40
+
41
+ // TODO 定期轮询检查消息过期
42
+
43
+ const UseMessageManager = () => {
44
+ const ws = useRef(null);
45
+
46
+ const sendMessage = useCallback(msg => {
47
+ if (ws.current) {
48
+ console.log('ws.send');
49
+ ws.current.send(JSON.stringify(msg));
50
+ eventBus.emit(EVENTS.MESSAGE.ADD, msg);
51
+ }
52
+ }, []);
53
+
54
+ const connectMsgServer = async connectSuccessCallback => {
55
+ console.log('connectMsgServer start');
56
+ const token = await storage.get('accessToken');
57
+ const accountData = await storage.get('accountData');
58
+ const activeAddr = await storage.get('activeAddr');
59
+ let wsUrl = `${
60
+ config.IPANEL_CLOUD_WSS_URI
61
+ }/s/ch/${await global.base.getHomeCloudServiceInstanceName()}/common/msgcenter/websocket`;
62
+
63
+ const connectParams = [
64
+ `user_id=${accountData.user.user_id}`, // 用户id
65
+ `address_id=${activeAddr.address_id}`, // 用户当前选中的家庭地址id
66
+ `token=${token}`,
67
+ 'lon=',
68
+ 'lat=',
69
+ ];
70
+
71
+ // 缓存全局智能客服websocket连接
72
+ global.base.messageManager.wsRef = ws;
73
+ global.base.messageManager.connectMsgServer = connectMsgServer;
74
+
75
+ const url = `${wsUrl}?${connectParams.join('&')}`;
76
+ console.log('useMessageManager ws url:', url);
77
+
78
+ ws.current = new WebSocket(url);
79
+ ws.current.onopen = () => {
80
+ console.log('useMessageManager ws open');
81
+ connectStatus = 0;
82
+ eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
83
+
84
+ connectSuccessCallback && connectSuccessCallback();
85
+ };
86
+ ws.current.onmessage = ({data}) => {
87
+ const msg = JSON.parse(data);
88
+ eventBus.emit(EVENTS.MESSAGE.ADD, msg);
89
+ };
90
+ ws.current.onerror = err => {
91
+ console.log('useMessageManager ws onerror', err);
92
+ connectStatus = 1;
93
+ eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
94
+ };
95
+ ws.current.onclose = event => {
96
+ console.log('useMessageManager ws onclose', event);
97
+
98
+ global.base.messageManager.wsRef.current = null;
99
+ connectStatus = 1;
100
+ eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
101
+ reConnect(connectSuccessCallback);
102
+ };
103
+ };
104
+
105
+ const closeMsgConnection = () => {
106
+ console.log('useMessageManager closeMsgConnection');
107
+
108
+ // 正常主动关闭连接,重置重连次数
109
+ tryConnectTimes = 0;
110
+
111
+ global.base.messageManager.wsRef.current &&
112
+ global.base.messageManager.wsRef.current.close();
113
+ };
114
+
115
+ const reConnect = async connectSuccessCallback => {
116
+ console.log('useMessageManager reConnect', tryConnectTimes);
117
+ if (tryConnectTimes < 7) {
118
+ // 重连ws
119
+ tryConnectTimes++;
120
+ connectMsgServer(connectSuccessCallback);
121
+ } else {
122
+ // 重连N次ws失败,不再重试。等用户自己进入智能客服页面时触发重连
123
+ tryConnectTimes = 0;
124
+ connectStatus = 1;
125
+ eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
126
+ }
127
+ };
128
+
129
+ const [onlineUser, setOnlineUser] = useState([]); // 在线用户列表
130
+ const nameRef = useRef('');
131
+ // 请求到客服列表的回调
132
+ const handleGetOnlineUserList = async data => {
133
+ if (isManualCustomServiceActive) {
134
+ return;
135
+ }
136
+ console.log('handleGetOnlineUserList', data);
137
+ let dataList = data?.list.filter(val => {
138
+ return val.nick_name !== nameRef.current;
139
+ });
140
+ // // console.log(dataList, nameRef.current);
141
+ setOnlineUser(dataList);
142
+
143
+ if (dataList.length === 0) {
144
+ global.toast.showToast('当前没有人工客服在线,请稍候再试!');
145
+ return;
146
+ }
147
+
148
+ console.log('当前客服列表:', dataList);
149
+ // 分配一个人工客服
150
+ currentCustomStaff =
151
+ dataList.find(user => user.nick_name === '壮壮') || dataList[0];
152
+ console.log('已分配智能客服人工客服:', currentCustomStaff.nick_name);
153
+
154
+ // 设置当前处于人工客服的标志
155
+ isManualCustomServiceActive = true;
156
+ eventBus.emit(EVENTS.MESSAGE.CUSTOM_SERVICE_CONNECT_CHANGE, true);
157
+
158
+ // 显示消息
159
+ const customerStaffMsg = await genMsg(
160
+ 'get',
161
+ MSG_TYPES.TEXT,
162
+ `您好,客服“${currentCustomStaff.nick_name}”为您服务!`,
163
+ );
164
+ customerStaffMsg.CreateTime = Date.now();
165
+ eventBus.emit(EVENTS.MESSAGE.ADD, customerStaffMsg);
166
+
167
+ resetManualCustomServiceExitTimer();
168
+ };
169
+ const resetManualCustomServiceExitTimer = () => {
170
+ // 10分钟没发消息后自动退出人工
171
+ clearTimeout(manualCustomServiceTimer);
172
+ manualCustomServiceTimer = setTimeout(() => {
173
+ exitManualCustomService(true);
174
+ }, 600000);
175
+ };
176
+ // 请求转人工
177
+ const requestManualCustomService = async () => {
178
+ const user = await storage.get('accountData');
179
+ nameRef.current = user.user?.nickname;
180
+ // 发送获取客服列表消息,在EVENTS.SHOPMESSAGE.ONLINE_LIST事件回调中处理获取到的客服列表数据
181
+ global.base.shopMessageManager.getOnlineUser();
182
+ };
183
+ const exitManualCustomService = async timeout => {
184
+ isManualCustomServiceActive = false;
185
+ eventBus.emit(EVENTS.MESSAGE.CUSTOM_SERVICE_CONNECT_CHANGE, false);
186
+ console.log('退出智能客服人工客服');
187
+
188
+ // 显示消息
189
+ const customerStaffMsg = await genMsg(
190
+ 'get',
191
+ MSG_TYPES.TEXT,
192
+ timeout
193
+ ? '您已经很长时间没说话了,已自动退出人工客服,如有需要请再次联系'
194
+ : '您已退出人工客服。',
195
+ );
196
+ customerStaffMsg.CreateTime = Date.now();
197
+ eventBus.emit(EVENTS.MESSAGE.ADD, customerStaffMsg);
198
+ };
199
+
200
+ useEffect(() => {
201
+ // 新增并显示一条消息
202
+ const onMessageAdd = msg => {
203
+ global.base.messageManager.messages.push(msg);
204
+ // save to local
205
+ storage.set(
206
+ 'messageList',
207
+ global.base.messageManager.messages.slice(-500),
208
+ );
209
+
210
+ eventBus.emit(EVENTS.MESSAGE.RENDER, msg);
211
+ };
212
+
213
+ connectStatus = -1;
214
+ eventBus.emit(EVENTS.MESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
215
+ // requestCameraPermission();
216
+ connectMsgServer();
217
+
218
+ // 监听家庭切换事件,切换websocket上下文
219
+ eventBus.on(EVENTS.FAMILY.CHANGE, closeMsgConnection);
220
+ eventBus.on(EVENTS.MESSAGE.ADD, onMessageAdd);
221
+ eventBus.on(EVENTS.MESSAGE.RECONNECT, reConnect);
222
+
223
+ // 转人工客服
224
+ const onShopMessageRender = async msg => {
225
+ if (isManualCustomServiceActive) {
226
+ // if(!msg.conversation_id.endsWith("-znkf")){
227
+ // // 忽略非智能客服转人工的会话消息
228
+ // return;
229
+ // }
230
+
231
+ // 收到人工客服消息 消息转成智能客服能识别的格式再发EVENTS.MESSAGE.ADD显示
232
+ console.log('onShopMessageRender', msg);
233
+ if (msg.type === 1000) {
234
+ // 暂时只支持接收客服的文本消息
235
+ const customerStaffMsg = await genMsg(
236
+ 'get',
237
+ MSG_TYPES.TEXT,
238
+ msg.message_data,
239
+ );
240
+ // 显示消息
241
+ customerStaffMsg.CreateTime = Date.now();
242
+ eventBus.emit(EVENTS.MESSAGE.ADD, customerStaffMsg);
243
+ }
244
+
245
+ resetManualCustomServiceExitTimer();
246
+ }
247
+ };
248
+ // 监听收到人工客服的消息
249
+ eventBus.on(EVENTS.SHOPMESSAGE.RENDER, onShopMessageRender);
250
+ // 监听请求客服人员列表的回调
251
+ eventBus.on(EVENTS.SHOPMESSAGE.ONLINE_LIST, handleGetOnlineUserList);
252
+
253
+ return () => {
254
+ eventBus.off(EVENTS.FAMILY.CHANGE, closeMsgConnection);
255
+ eventBus.off(EVENTS.MESSAGE.ADD, onMessageAdd);
256
+ eventBus.off(EVENTS.MESSAGE.RECONNECT, reConnect);
257
+
258
+ eventBus.off(EVENTS.SHOPMESSAGE.RENDER, onShopMessageRender);
259
+ eventBus.off(EVENTS.SHOPMESSAGE.ONLINE_LIST, handleGetOnlineUserList);
260
+ };
261
+ }, []);
262
+
263
+ // 文本输入发消息
264
+ const handleTextSubmit = useCallback(async inputText => {
265
+ const userMsg = await genMsg('send', MSG_TYPES.TEXT, inputText);
266
+
267
+ if (isManualCustomServiceActive) {
268
+ const accountData = await storage.get('accountData');
269
+
270
+ // (转人工)处于人工客服状态,走商城客服im系统发送消息
271
+ global.base.shopMessageManager.handleShopTextSubmit(
272
+ inputText,
273
+ currentCustomStaff.user_id,
274
+ `${accountData.user.user_id}-${currentCustomStaff.user_id}-znkf`, // 智能客服会话id:终端用户id-后台客服id-znkf
275
+ );
276
+ // 显示消息
277
+ eventBus.emit(EVENTS.MESSAGE.ADD, userMsg);
278
+
279
+ resetManualCustomServiceExitTimer();
280
+ } else {
281
+ // 普通智能客服状态
282
+ // http/ws /send_message
283
+ sendMessage(userMsg);
284
+ }
285
+ }, []);
286
+
287
+ // 发送图片或视频消息
288
+ const handleMediaSelect = useCallback(async file => {
289
+ const msgType = file.type.split('/')[0];
290
+ let userMsg;
291
+ if (msgType === 'image') {
292
+ userMsg = await genMsg('send', msgType, {
293
+ MediaId: '123',
294
+ ...file,
295
+ });
296
+ } else {
297
+ userMsg = await genMsg('send', msgType, {
298
+ MediaId: '456',
299
+ ...file,
300
+ });
301
+ }
302
+
303
+ if (isManualCustomServiceActive) {
304
+ // (转人工)处于人工客服状态,走商城客服im系统发送消息
305
+ const message_data = file.uri; // todo 传上传后拿到的url
306
+ const message_prop = JSON.stringify({
307
+ msgType,
308
+ localUrl: file.uri,
309
+ width: file.width,
310
+ height: file.height,
311
+ });
312
+ const accountData = await storage.get('accountData');
313
+ global.base.shopMessageManager.handleShopMediaSelect(
314
+ message_data,
315
+ message_prop,
316
+ currentCustomStaff.user_id,
317
+ `${accountData.user.user_id}-${currentCustomStaff.user_id}-znkf`, // 智能客服会话id:终端用户id-后台客服id-znkf
318
+ );
319
+ // 显示消息
320
+ eventBus.emit(EVENTS.MESSAGE.ADD, userMsg);
321
+
322
+ resetManualCustomServiceExitTimer();
323
+ } else {
324
+ // 普通智能客服状态
325
+ // http/ws /send_message
326
+ sendMessage(userMsg);
327
+ }
328
+ }, []);
329
+
330
+ const getManualCustomServiceActiveFlag = () => isManualCustomServiceActive;
331
+
332
+ return {
333
+ sendMessage,
334
+ handleTextSubmit,
335
+ handleMediaSelect,
336
+ requestManualCustomService,
337
+ exitManualCustomService,
338
+ getManualCustomServiceActiveFlag,
339
+ };
340
+ };
341
+
342
+ //请求权限的方法
343
+ function requestCameraPermission() {
344
+ // if (Platform.OS === 'android') {
345
+ // try {
346
+ // const granted = await PermissionsAndroid.request(
347
+ // PermissionsAndroid.PERMISSIONS.CAMERA,
348
+ // {
349
+ // title: '申请摄像头权限',
350
+ // message: '扫码需要摄像头权限',
351
+ // buttonNeutral: '稍后再说',
352
+ // buttonNegative: '拒绝',
353
+ // buttonPositive: '允许',
354
+ // },
355
+ // );
356
+ // if (granted === PermissionsAndroid.RESULTS.GRANTED) {
357
+ // console.log('现在你获得摄像头权限了');
358
+ // } else {
359
+ // console.log('用户拒绝了摄像头权限');
360
+ // }
361
+ // } catch (err) {
362
+ // console.log(err);
363
+ // }
364
+ // }
365
+ applyPermissions.camera();
366
+ }
367
+
368
+ export default UseMessageManager;
@@ -0,0 +1,19 @@
1
+ import {useFocusEffect} from '@react-navigation/native';
2
+ import React, {useState} from 'react';
3
+
4
+ export default (handler, deps = []) => {
5
+ const [isFocus, setIsFocus] = useState(false);
6
+ useFocusEffect(
7
+ React.useCallback(() => {
8
+ setIsFocus(true);
9
+ const onBlurHandler = handler && handler();
10
+
11
+ return () => {
12
+ setIsFocus(false);
13
+ onBlurHandler && onBlurHandler();
14
+ };
15
+ }, deps),
16
+ );
17
+
18
+ return isFocus;
19
+ };
@@ -0,0 +1,56 @@
1
+ import {useEffect, useMemo, useState} from 'react';
2
+ import storage from '../storage';
3
+ import {getAddressUser} from '../api';
4
+
5
+ export default address_id => {
6
+ // 该家庭的成员
7
+ const [memberList, setMemberList] = useState([]);
8
+ // 当前登录用户
9
+ const [currentUser, setCurrentUser] = useState({});
10
+ useEffect(() => {
11
+ if (address_id) {
12
+ refresh();
13
+ }
14
+ }, []);
15
+
16
+ // 该家庭创建者
17
+ const creator = useMemo(() => {
18
+ return memberList.find(item => item.role === 15) || {};
19
+ }, [memberList]);
20
+
21
+ // 当前登录用户是否是创建者
22
+ const isCreator = useMemo(() => {
23
+ return currentUser.user_id && currentUser.user_id === creator.user_id;
24
+ }, [creator, currentUser]);
25
+
26
+ // 当前登录用户是否是管理员
27
+ const isAdministrator = useMemo(() => {
28
+ return (
29
+ memberList.findIndex(
30
+ item => item.role === 7 && item.user_id === currentUser.user_id,
31
+ ) > -1
32
+ );
33
+ }, [memberList, currentUser]);
34
+
35
+ const refresh = async currentAddressId => {
36
+ if (!currentAddressId && !address_id) {
37
+ return;
38
+ }
39
+ storage.get('accountData').then(res => {
40
+ setCurrentUser(res?.user || {});
41
+ });
42
+ const res = await getAddressUser({
43
+ address_id: currentAddressId || address_id,
44
+ });
45
+ setMemberList(res?.result?.address_list || []);
46
+ };
47
+
48
+ return {
49
+ memberList,
50
+ creator,
51
+ currentUser,
52
+ isCreator,
53
+ isAdministrator,
54
+ refresh,
55
+ };
56
+ };