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,934 @@
1
+ import React, {useState, useEffect} from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ Alert,
7
+ TouchableHighlight,
8
+ Platform,
9
+ } from 'react-native';
10
+ import ActionSheet, {SheetManager} from 'react-native-actions-sheet';
11
+ import {Icon, Button} from '@rneui/themed';
12
+ import {Cell} from '../../index';
13
+ import {
14
+ getBarcodeInfo,
15
+ getTvIrCode,
16
+ getTemplateCode,
17
+ getDeviceCode,
18
+ addDevice,
19
+ moveDevice,
20
+ } from '../../../api';
21
+
22
+ const {navigate} = global.base;
23
+
24
+ const switchUsages = [
25
+ {
26
+ name: '控制灯',
27
+ value: 'IGOT_LIGHT',
28
+ },
29
+ {
30
+ name: '控制排气风扇',
31
+ value: 'IGOT_FAN',
32
+ },
33
+ {
34
+ name: '默认',
35
+ value: '',
36
+ },
37
+ ];
38
+
39
+ const lightUsages = [
40
+ {
41
+ name: '吊灯',
42
+ value: 'PENDENT_LAMP',
43
+ },
44
+ {
45
+ name: '吸顶灯',
46
+ value: 'CEILING_LIGHT',
47
+ },
48
+ {
49
+ name: '筒灯',
50
+ value: 'DOWN_LIGHT',
51
+ },
52
+ {
53
+ name: '灯带',
54
+ value: 'LIGHT_BELT',
55
+ },
56
+ {
57
+ name: '床头灯',
58
+ value: 'BEDSIDE_LAMP',
59
+ },
60
+ {
61
+ name: '镜前灯',
62
+ value: 'MIRROR_LIGHT',
63
+ },
64
+ {
65
+ name: '过道灯',
66
+ value: 'CORRIDOR_LAMP',
67
+ },
68
+ {
69
+ name: '玄关灯',
70
+ value: 'PORCH_LIGHT',
71
+ },
72
+ {
73
+ name: '台灯',
74
+ value: 'DESK_LAMP',
75
+ },
76
+ {
77
+ name: '壁灯',
78
+ value: 'WALL_LAMP',
79
+ },
80
+ {
81
+ name: '餐厅灯',
82
+ value: 'RESTAURANT_LIGHT',
83
+ },
84
+ {
85
+ name: '浴室灯',
86
+ value: 'BATHROOM_LIGHT',
87
+ },
88
+ {
89
+ name: '厨房灯',
90
+ value: 'KITCHEN_LIGHT',
91
+ },
92
+ {
93
+ name: '默认',
94
+ value: '',
95
+ },
96
+ ];
97
+
98
+ // 公共设备类型,只能添加到“储物间”(room_type === "STORAGEROOM")
99
+ const publicDeviceTypes = ['scale', 'hematometer'];
100
+
101
+ // 跳转到添加设备导航页前需要初始化该参数对象,并传递过去
102
+ let currentPageOptions = {};
103
+
104
+ async function getSub1gJsonByBarcode(params) {
105
+ const result = await getBarcodeInfo(params).catch(() => {});
106
+
107
+ if (result && result.code === 0) {
108
+ return result.result.coding;
109
+ }
110
+
111
+ return false;
112
+ }
113
+
114
+ function isStorageRoom(room) {
115
+ return room.room_type === 'STORAGEROOM';
116
+ }
117
+
118
+ function iteeConfigureNetwork(barcode) {
119
+ const screen = 'Itee';
120
+
121
+ if (barcode) {
122
+ // 添加itee流程-传递机身条码,用于配网页面向云端请求sn(当需要写入sn时)
123
+ currentPageOptions.action = 'addDevice';
124
+ currentPageOptions.barcode = barcode;
125
+ navigate(screen, currentPageOptions);
126
+ } else {
127
+ navigate(screen, currentPageOptions);
128
+ }
129
+ }
130
+
131
+ function sub1gLearning() {
132
+ const screen = 'Sub1gStudy'; // todo 填写实际的screen name
133
+
134
+ navigate(screen, currentPageOptions);
135
+ }
136
+
137
+ function LingPuPair() {
138
+ const screen = 'Lingpu'; // todo 填写实际的screen name
139
+
140
+ navigate(screen, currentPageOptions);
141
+ }
142
+
143
+ function WuxiandaoLightPair(room_id) {
144
+ const screen = 'WuXianDao';
145
+
146
+ currentPageOptions.room_id = room_id;
147
+ navigate(screen, currentPageOptions);
148
+ }
149
+
150
+ function yhwlLightPair(room_id) {
151
+ const screen = 'YHWL'; // todo 填写实际的screen name
152
+
153
+ currentPageOptions.room_id = room_id;
154
+ navigate(screen, currentPageOptions);
155
+ }
156
+
157
+ function kangwlHematometerPair(room_id) {
158
+ const screen = 'Kangwl';
159
+
160
+ currentPageOptions.room_id = room_id;
161
+ navigate(screen, currentPageOptions);
162
+ }
163
+
164
+ function lefuScalePair(room_id) {
165
+ const screen = 'LeFuScale';
166
+
167
+ currentPageOptions.room_id = room_id;
168
+ navigate(screen, currentPageOptions);
169
+ }
170
+
171
+ // 扫码获取到结果后的回调函数
172
+ let scanCodeCallback;
173
+
174
+ const DeviceActionSheet = ({sheetId, payload}) => {
175
+ let title = '添加设备';
176
+
177
+ useEffect(() => {
178
+ const unsubscribe = payload.navigation.addListener('focus', () => {
179
+ // Home
180
+ try {
181
+ const homeNavigation = payload.navigation.getParent();
182
+ const homeRoutes = homeNavigation.getState().routes;
183
+ const homeRouteParams = homeRoutes[homeRoutes.length - 1].params;
184
+ if (homeRouteParams.scanResult && scanCodeCallback) {
185
+ scanCodeCallback(homeRouteParams.scanResult);
186
+ scanCodeCallback = null;
187
+ homeRouteParams.scanResult = undefined;
188
+ }
189
+ } catch (e) {
190
+ console.log(e);
191
+ }
192
+ });
193
+
194
+ return unsubscribe;
195
+ }, [payload.navigation]);
196
+
197
+ // 设备类型
198
+ const deviceTypes = payload.deviceTypeList.map(item => ({
199
+ name: item.title,
200
+ value: item.class,
201
+ }));
202
+ let defaultDeviceTypeIndex = payload.defaultData
203
+ ? payload.defaultData.defaultDeviceTypeIndex
204
+ : 0;
205
+ let defaultDeviceTypeName = deviceTypes[defaultDeviceTypeIndex]
206
+ ? deviceTypes[defaultDeviceTypeIndex].name
207
+ : '';
208
+ const [deviceTypeIndex, setDeviceTypeIndex] = useState(
209
+ defaultDeviceTypeIndex,
210
+ );
211
+ const [deviceTypeName, setDeviceTypeName] = useState(defaultDeviceTypeName);
212
+ const handleShowDeviceTypePicker = async () => {
213
+ const result = await SheetManager.show('action-picker', {
214
+ context: 'global',
215
+ payload: {
216
+ title: '选择设备类型',
217
+ defaultIndex: deviceTypeIndex,
218
+ columns: deviceTypes,
219
+ nameProp: 'name',
220
+ },
221
+ });
222
+ if (result) {
223
+ setDeviceTypeIndex(result.index);
224
+ setDeviceTypeName(result.data.name);
225
+ }
226
+ };
227
+
228
+ const targetDeviceType = payload.deviceTypeList[deviceTypeIndex];
229
+
230
+ // 品牌型号
231
+ const [brandModelColumns, setBrandModelColumns] = useState([]);
232
+
233
+ const hasDefaultBrandModelData =
234
+ payload.defaultData &&
235
+ payload.defaultData.selectedBrand &&
236
+ payload.defaultData.selectedModel;
237
+
238
+ const [defaultBrandModelIndex, setDefaultBrandModelIndex] = useState(
239
+ hasDefaultBrandModelData ? payload.defaultData.defaultBrandModelIndex : [],
240
+ );
241
+ const [selectedBrand, setSelectedBrand] = useState(
242
+ hasDefaultBrandModelData ? payload.defaultData.selectedBrand : {},
243
+ );
244
+ const [selectedModel, setSelectedModel] = useState(
245
+ hasDefaultBrandModelData ? payload.defaultData.selectedModel : {},
246
+ );
247
+ const [brandModelText, setBrandModelText] = useState(
248
+ hasDefaultBrandModelData
249
+ ? payload.defaultData.brandModelText
250
+ : '请选择品牌型号',
251
+ );
252
+ useEffect(() => {
253
+ setDeviceName('');
254
+
255
+ if (
256
+ targetDeviceType &&
257
+ targetDeviceType.brands &&
258
+ targetDeviceType.brands[0] &&
259
+ targetDeviceType.brands[0].models
260
+ ) {
261
+ const columns = targetDeviceType.brands.map(brand => ({
262
+ name: brand.name,
263
+ value: brand.code,
264
+ children: (brand.models || []).map(model => ({
265
+ name: model.name,
266
+ value: model.code,
267
+ emit: model.emit,
268
+ })),
269
+ }));
270
+ setBrandModelColumns(columns);
271
+ } else {
272
+ setBrandModelColumns([]);
273
+ }
274
+ setDefaultBrandModelIndex([0, 0]);
275
+ setSelectedBrand({});
276
+ setSelectedModel({});
277
+ setBrandModelText('请选择品牌型号');
278
+
279
+ const storageRoomIndex = payload.roomList.findIndex(room =>
280
+ isStorageRoom(room),
281
+ );
282
+ if (storageRoomIndex > -1) {
283
+ const storageRoom = payload.roomList[storageRoomIndex];
284
+ if (publicDeviceTypes.includes(curDeviceType)) {
285
+ // 公共设备,默认选中“默认储物间”
286
+ setRoomIndex(storageRoomIndex);
287
+ setRoomName(storageRoom.room_name);
288
+ } else {
289
+ // 非公共设备,不能选择“默认储物间”
290
+ if (payload.roomList[roomIndex].room_id === storageRoom.room_id) {
291
+ const defaultRoomIndex = payload.roomList.findIndex(
292
+ room => !isStorageRoom(room),
293
+ );
294
+ if (defaultRoomIndex > -1) {
295
+ const defaultRoom = payload.roomList[defaultRoomIndex];
296
+ setRoomIndex(defaultRoomIndex);
297
+ setRoomName(defaultRoom.room_name);
298
+ }
299
+ }
300
+ }
301
+ }
302
+ }, [deviceTypeIndex]);
303
+ const handleShowBrandModelPicker = async () => {
304
+ if (brandModelColumns.length > 0) {
305
+ const result = await SheetManager.show('action-picker', {
306
+ context: 'global',
307
+ payload: {
308
+ title: '选择设备品牌型号',
309
+ defaultIndex: defaultBrandModelIndex,
310
+ columns: brandModelColumns,
311
+ depth: 2,
312
+ nameProp: 'name',
313
+ },
314
+ });
315
+ if (result) {
316
+ setDefaultBrandModelIndex(result.index);
317
+ const brand = result.data[0];
318
+ const model = result.data[1];
319
+ setSelectedBrand(brand);
320
+ setSelectedModel(model);
321
+ const text = `${brand.name} ${model.name}`;
322
+ setBrandModelText(text);
323
+ if (!['igot', 'ifree'].includes(curDeviceType)) {
324
+ setDeviceName(text);
325
+ }
326
+ }
327
+ }
328
+ };
329
+
330
+ const [tvid, setTvid] = useState('');
331
+ const [barcode, setBarcode] = useState(
332
+ payload.defaultData ? payload.defaultData.barcode : '',
333
+ );
334
+ const [deviceName, setDeviceName] = useState('');
335
+
336
+ const handleScanTvId = () => {
337
+ navigate('ScanQRCodeScreen');
338
+ scanCodeCallback = scanResult => {
339
+ const qrdata = {};
340
+ scanResult.split('\n').forEach(kvStr => {
341
+ const [k, v] = kvStr.split('=');
342
+ qrdata[k] = v;
343
+ });
344
+
345
+ if (qrdata.tv_id) {
346
+ setTvid(qrdata.tv_id);
347
+ } else {
348
+ Alert.alert('未识别到电视ID');
349
+ }
350
+ };
351
+ };
352
+ const handleScanBarcode = () => {
353
+ navigate('ScanQRCodeScreen');
354
+ scanCodeCallback = setBarcode;
355
+ };
356
+
357
+ // 开关用途
358
+ let defaultSwitchUsageIndex = switchUsages.findIndex(
359
+ item => item.value === '',
360
+ );
361
+ let defaultSwitchUsageName = switchUsages[defaultSwitchUsageIndex]
362
+ ? switchUsages[defaultSwitchUsageIndex].name
363
+ : '';
364
+ const [switchUsageIndex, setSwitchUsageIndex] = useState(
365
+ defaultSwitchUsageIndex,
366
+ );
367
+ const [switchUsage, setSwitchUsage] = useState(defaultSwitchUsageName);
368
+ const handleShowSwitchUsagePicker = async () => {
369
+ const result = await SheetManager.show('action-picker', {
370
+ context: 'global',
371
+ payload: {
372
+ title: '选择开关用途',
373
+ defaultIndex: switchUsageIndex,
374
+ columns: switchUsages,
375
+ nameProp: 'name',
376
+ },
377
+ });
378
+ if (result) {
379
+ setSwitchUsageIndex(result.index);
380
+ setSwitchUsage(result.data.name);
381
+ }
382
+ };
383
+
384
+ // 灯光用途
385
+ let defaultLightUsageIndex = lightUsages.findIndex(item => item.value === '');
386
+ let defaultLightUsageName = lightUsages[defaultLightUsageIndex]
387
+ ? lightUsages[defaultLightUsageIndex].name
388
+ : '';
389
+ const [lightUsageIndex, setLightUsageIndex] = useState(
390
+ defaultLightUsageIndex,
391
+ );
392
+ const [lightUsage, setLightUsage] = useState(defaultLightUsageName);
393
+ const handleShowLightUsagePicker = async () => {
394
+ const result = await SheetManager.show('action-picker', {
395
+ context: 'global',
396
+ payload: {
397
+ title: '选择灯光用途',
398
+ defaultIndex: lightUsageIndex,
399
+ columns: lightUsages,
400
+ nameProp: 'name',
401
+ },
402
+ });
403
+ if (result) {
404
+ setLightUsageIndex(result.index);
405
+ setLightUsage(result.data.name);
406
+
407
+ if (!deviceName) {
408
+ setDeviceName(result.data.name);
409
+ }
410
+ }
411
+ };
412
+
413
+ // 选择房间
414
+ let defaultRoomIndex = 0;
415
+ let defaultRoomName = payload.roomList[defaultRoomIndex]
416
+ ? payload.roomList[defaultRoomIndex].room_name
417
+ : '';
418
+ const [roomIndex, setRoomIndex] = useState(defaultRoomIndex);
419
+ const [roomName, setRoomName] = useState(defaultRoomName);
420
+ const handleShowRoomPicker = async () => {
421
+ const result = await SheetManager.show('action-picker', {
422
+ context: 'global',
423
+ payload: {
424
+ title: '选择房间',
425
+ defaultIndex: roomIndex,
426
+ columns: payload.roomList,
427
+ nameProp: 'room_name',
428
+ },
429
+ });
430
+
431
+ if (result) {
432
+ if (curDeviceType) {
433
+ const isPickingStorageRoom = isStorageRoom(result.data);
434
+ if (
435
+ publicDeviceTypes.includes(curDeviceType) &&
436
+ !isPickingStorageRoom
437
+ ) {
438
+ Alert.alert('公共设备不能加入储物间以外的房间');
439
+ return;
440
+ }
441
+ if (
442
+ !publicDeviceTypes.includes(curDeviceType) &&
443
+ isPickingStorageRoom
444
+ ) {
445
+ Alert.alert('非公共设备不能加入储物间');
446
+ return;
447
+ }
448
+ }
449
+
450
+ setRoomIndex(result.index);
451
+ setRoomName(result.data.room_name);
452
+ }
453
+ };
454
+
455
+ const curDeviceType = targetDeviceType ? targetDeviceType.class : '';
456
+ const curBrand = selectedBrand.value;
457
+ const curModel = selectedModel.value;
458
+
459
+ // 支持根据条码生成码值的通断器
460
+ const hasBarcodeSwitch = (() => {
461
+ if (curDeviceType === 'igot') {
462
+ if (
463
+ (curBrand === 'kingserry' && curModel === 'IGRL0012') ||
464
+ (curBrand === 'yibailong' && curModel === 'IGRL0021') ||
465
+ (curBrand === 'shengbiao' && curModel === 'IGRLN041')
466
+ ) {
467
+ return true;
468
+ }
469
+ }
470
+ return false;
471
+ })();
472
+ // 易百珑随意贴
473
+ const isYblSyt = (() => {
474
+ if (curDeviceType === 'ifree') {
475
+ if (curBrand === 'yibailong' && curModel === 'ITFKE101W') {
476
+ return true;
477
+ }
478
+ }
479
+ return false;
480
+ })();
481
+ // 当前要添加的设备是否为需要学习码值的433随意贴
482
+ const isSub1gLearningSuiyitieSelected = (() => {
483
+ if (curDeviceType === 'ifree') {
484
+ if (
485
+ (curBrand === 'kingserry' && curModel === 'ITFBT101W') ||
486
+ (curBrand === 'lingpu' && curModel === 'ITFKR101W')
487
+ ) {
488
+ return true;
489
+ }
490
+ }
491
+ return false;
492
+ })();
493
+ // 本页面添加设备时是否需要填写设备名称、开关用途、灯光用途、设备位置等信息
494
+ // 根据设备类型+品牌+型号来判断,有些设备要走进一步流程的,因此不在这里做上述信息的填写
495
+ const addDeviceNeedMoreInfo = (() => {
496
+ if (
497
+ isSub1gLearningSuiyitieSelected ||
498
+ (curDeviceType === 'ifree' && curBrand === 'lingpu')
499
+ ) {
500
+ return false;
501
+ }
502
+ return true;
503
+ })();
504
+
505
+ const submitBtnText = (() => {
506
+ let text = '添加设备';
507
+
508
+ switch (curDeviceType) {
509
+ case 'itee':
510
+ return '开始配网';
511
+ case 'light':
512
+ return '开始配对';
513
+ case 'igot':
514
+ return '添加通断器';
515
+ }
516
+
517
+ if (isSub1gLearningSuiyitieSelected) {
518
+ text = '学习码值';
519
+ }
520
+ if (isYblSyt) {
521
+ text = '添加易百珑随意贴';
522
+ }
523
+
524
+ return text;
525
+ })();
526
+
527
+ const [isSaveBtnDisabled, setIsSaveBtnDisabled] = useState(false);
528
+ const handleSaveDevice = async () => {
529
+ if (curDeviceType === '') {
530
+ Alert.alert('请选择设备');
531
+ return;
532
+ }
533
+ if (curDeviceType === 'tv' && tvid === '') {
534
+ Alert.alert('请输入电视ID');
535
+ return;
536
+ }
537
+
538
+ currentPageOptions = {
539
+ device_type: curDeviceType,
540
+ };
541
+ if (curBrand && curModel) {
542
+ currentPageOptions.brand = curBrand;
543
+ currentPageOptions.model = curModel;
544
+ }
545
+ if (curDeviceType === 'itee' || hasBarcodeSwitch || isYblSyt) {
546
+ if (barcode === '') {
547
+ Alert.alert('请扫一扫机身条码');
548
+ return;
549
+ }
550
+ if (curDeviceType === 'itee') {
551
+ // 跳转到配网页面,之后添加itee再由单独的页面进行
552
+ iteeConfigureNetwork(barcode);
553
+ SheetManager.hide(sheetId);
554
+ return;
555
+ }
556
+ }
557
+ if (
558
+ targetDeviceType &&
559
+ targetDeviceType.brands &&
560
+ targetDeviceType.brands.length > 0 &&
561
+ (!curBrand || !curModel)
562
+ ) {
563
+ Alert.alert('请选择品牌型号');
564
+ return;
565
+ }
566
+ if (isSub1gLearningSuiyitieSelected) {
567
+ // 需要学习码值的随意贴_RF版(433版)
568
+
569
+ // 进入433学习添加流程
570
+ sub1gLearning();
571
+ SheetManager.hide(sheetId);
572
+ return;
573
+ }
574
+ if (curDeviceType === 'ifree' && curBrand === 'lingpu') {
575
+ if (Platform.OS === 'ios') {
576
+ Alert.alert('暂不支持ios');
577
+ } else {
578
+ LingPuPair();
579
+ SheetManager.hide(sheetId);
580
+ }
581
+ return;
582
+ }
583
+ if (deviceName === '') {
584
+ Alert.alert('请输入设备名称');
585
+ return;
586
+ }
587
+ if (roomName === '') {
588
+ Alert.alert('请选择设备位置');
589
+ return;
590
+ }
591
+ const roomId = payload.roomList[roomIndex].room_id;
592
+ if (curDeviceType === 'light') {
593
+ if (curBrand === 'WXD') {
594
+ // 无线道蓝牙灯
595
+ WuxiandaoLightPair(roomId);
596
+ SheetManager.hide(sheetId);
597
+ return;
598
+ } else if (curBrand === 'YHWL') {
599
+ // 云海物联蓝牙灯
600
+ yhwlLightPair(roomId);
601
+ SheetManager.hide(sheetId);
602
+ return;
603
+ } else if (selectedModel.emit === 'blebc') {
604
+ Alert.alert('此类型蓝牙灯暂未支持添加');
605
+ return;
606
+ }
607
+ }
608
+ if (curDeviceType === 'hematometer' && curBrand === 'kangwl') {
609
+ // 康维乐蓝牙血压计(维乐高)
610
+ kangwlHematometerPair(roomId);
611
+ SheetManager.hide(sheetId);
612
+ return;
613
+ }
614
+ if (curDeviceType === 'scale' && curBrand === 'lefuscale') {
615
+ // 乐福蓝牙体脂称
616
+ lefuScalePair(roomId);
617
+ SheetManager.hide(sheetId);
618
+ return;
619
+ }
620
+
621
+ setIsSaveBtnDisabled(true);
622
+
623
+ const params = {
624
+ room_id: roomId,
625
+ device_type: curDeviceType,
626
+ device_name: deviceName,
627
+ extend: {
628
+ code_groups: [],
629
+ },
630
+ };
631
+ let fcodes;
632
+ if (hasBarcodeSwitch) {
633
+ // 获取通断器码值
634
+ // fcodes: type === "device" ? "1543,1544,2000,2002"/* 通断器device */ : "1543,1544,2001,2003"/* 通断器group */,
635
+ fcodes = '1543,1544,2000,2002';
636
+ } else if (isYblSyt) {
637
+ // 获取易百珑随意贴码值
638
+ fcodes = '1669';
639
+ }
640
+ if (fcodes) {
641
+ const sub1g_code = await getSub1gJsonByBarcode({
642
+ type: 'device',
643
+ fcodes: fcodes,
644
+ barcode: barcode,
645
+ });
646
+ if (sub1g_code) {
647
+ params.extend.sub1g_code = sub1g_code;
648
+ } else {
649
+ Alert.alert('获取码值失败!');
650
+ setIsSaveBtnDisabled(false);
651
+ return;
652
+ }
653
+ }
654
+ if (curBrand && curModel) {
655
+ const extend = {
656
+ brand: curBrand,
657
+ model: curModel,
658
+ emit: selectedModel.emit,
659
+ };
660
+
661
+ Object.assign(params.extend, extend);
662
+ } else {
663
+ if (['tv', 'ac'].includes(curDeviceType)) {
664
+ params.extend.emit = 'ir';
665
+ }
666
+ }
667
+ if (curDeviceType === 'tv') {
668
+ params.device_mac = tvid;
669
+
670
+ if (params.extend.emit === 'ir') {
671
+ // 获取tv红外码库id
672
+ const result = await getTvIrCode({
673
+ tv_id: params.device_mac,
674
+ }).catch(() => {});
675
+
676
+ if (result && result.code === 0 && result.result && result.result.ir) {
677
+ params.extend.ir_code = result.result.ir;
678
+ }
679
+ }
680
+ }
681
+ if (
682
+ params.extend.emit === 'sub1g' &&
683
+ !params.extend.sub1g_code &&
684
+ params.extend.brand &&
685
+ params.extend.model
686
+ ) {
687
+ // 小程序添加设备时,如果判断emit是sub1g,
688
+ if (
689
+ (curDeviceType === 'curtain' && params.extend.brand === 'dooya') ||
690
+ (curDeviceType === 'curtain' && params.extend.brand === 'raex')
691
+ ) {
692
+ // 如果该类433设备属于特定设备的(尚未约定条码和码值映射规则),则走谢振南的接口获取随机生成的码值(临时方案)
693
+ const result = await getTemplateCode({
694
+ type_code: curDeviceType,
695
+ brand_code: params.extend.brand,
696
+ model_code: params.extend.model,
697
+ });
698
+ if (result.code === 0) {
699
+ params.extend.sub1g_code = result.result;
700
+ }
701
+ } else {
702
+ // 如果该类433设备不属于学习获取码值、扫码获取码值或上述特定设备的,则走谢振南的新接口获取相应模版的码值。谢振南从段中虎那边取数据
703
+ const result = await getDeviceCode({
704
+ type_code: curDeviceType,
705
+ brand_code: params.extend.brand,
706
+ model_code: params.extend.model,
707
+ });
708
+ if (result.code === 0) {
709
+ params.extend.sub1g_code = result.result;
710
+ }
711
+ }
712
+ }
713
+ if (barcode) {
714
+ params.extend.barcode = barcode;
715
+
716
+ // 当没有device_mac时,以机身条码作为唯一标识
717
+ if (!params.device_mac) {
718
+ params.device_mac = params.extend.barcode;
719
+ }
720
+ }
721
+ if (curDeviceType === 'igot') {
722
+ params.extend.switch_usage = switchUsages[switchUsageIndex].value;
723
+ }
724
+
725
+ if (
726
+ curDeviceType === 'light' ||
727
+ (curDeviceType === 'igot' &&
728
+ switchUsages[switchUsageIndex].value === 'IGOT_LIGHT')
729
+ ) {
730
+ params.extend.light_usage = lightUsages[lightUsageIndex].value;
731
+ }
732
+
733
+ console.log(params);
734
+ const result = await addDevice(params);
735
+
736
+ setIsSaveBtnDisabled(false);
737
+
738
+ if (result.code === 0) {
739
+ SheetManager.hide(sheetId, {
740
+ payload: {
741
+ room_id: params.room_id,
742
+ },
743
+ });
744
+ } else {
745
+ if (result.code === 20512) {
746
+ // 该设备已被自己的某个房间关联
747
+ Alert.alert('移动设备', '设备已绑定房间,是否移动至目标房间?', [
748
+ {
749
+ text: '确定',
750
+ onPress: async () => {
751
+ const res = await moveDevice({
752
+ room_id: result.result.room_id,
753
+ device_id: result.result.device_id,
754
+ new_room_id: params.room_id,
755
+ });
756
+ if (res.code === 0) {
757
+ Alert.alert('设备移动成功');
758
+ SheetManager.hide(sheetId, {
759
+ payload: {
760
+ room_id: params.room_id,
761
+ },
762
+ });
763
+ }
764
+ },
765
+ },
766
+ {
767
+ text: '取消',
768
+ },
769
+ ]);
770
+ } else if (result.code === 20511) {
771
+ // 该设备已被其它家庭关联
772
+ Alert.alert('设备已被其它家庭绑定了');
773
+ }
774
+ }
775
+ };
776
+
777
+ return (
778
+ <>
779
+ <ActionSheet id={sheetId} isModal={false} useBottomSafeAreaPadding>
780
+ <View style={styles.title}>
781
+ <Text style={styles.titleText}>{title}</Text>
782
+ <View style={styles.closeBtn}>
783
+ <Icon
784
+ name="close"
785
+ type="ionicon"
786
+ size={28}
787
+ color="#999"
788
+ onPress={() => {
789
+ SheetManager.hide(sheetId);
790
+ }}
791
+ />
792
+ </View>
793
+ </View>
794
+
795
+ <Cell
796
+ type="link"
797
+ label="智能设备"
798
+ value={deviceTypeName}
799
+ onRightPress={handleShowDeviceTypePicker}
800
+ />
801
+ {targetDeviceType &&
802
+ targetDeviceType.brands &&
803
+ targetDeviceType.brands.length > 0 &&
804
+ curDeviceType !== 'itee' && (
805
+ <Cell
806
+ type="link"
807
+ label="品牌型号"
808
+ value={brandModelText}
809
+ onRightPress={handleShowBrandModelPicker}
810
+ />
811
+ )}
812
+
813
+ {curDeviceType === 'tv' && (
814
+ <Cell
815
+ type="input"
816
+ label="电视ID"
817
+ value={tvid}
818
+ placeholder="请输入电视ID"
819
+ inputIcon={
820
+ <TouchableHighlight
821
+ onPress={handleScanTvId}
822
+ activeOpacity={0.9}
823
+ underlayColor="#f0f0f0">
824
+ <Icon
825
+ name="scan-outline"
826
+ type="ionicon"
827
+ size={40}
828
+ color="#aaa"
829
+ />
830
+ </TouchableHighlight>
831
+ }
832
+ onChangeText={text => setTvid(text)}
833
+ />
834
+ )}
835
+ {(curDeviceType === 'itee' || hasBarcodeSwitch || isYblSyt) && (
836
+ <Cell
837
+ type="input"
838
+ label="机身条码"
839
+ value={barcode}
840
+ placeholder="请输入机身条码"
841
+ inputIcon={
842
+ <TouchableHighlight
843
+ onPress={handleScanBarcode}
844
+ activeOpacity={0.9}
845
+ underlayColor="#f0f0f0">
846
+ <Icon
847
+ name="scan-outline"
848
+ type="ionicon"
849
+ size={40}
850
+ color="#aaa"
851
+ />
852
+ </TouchableHighlight>
853
+ }
854
+ onChangeText={text => setBarcode(text)}
855
+ />
856
+ )}
857
+
858
+ {addDeviceNeedMoreInfo && (
859
+ <>
860
+ {!['itee', 'light'].includes(curDeviceType) && (
861
+ <Cell
862
+ type="input"
863
+ label="设备名称"
864
+ value={deviceName}
865
+ placeholder="请输入设备名称"
866
+ onChangeText={text => setDeviceName(text)}
867
+ />
868
+ )}
869
+ {curDeviceType === 'igot' && (
870
+ <Cell
871
+ type="link"
872
+ label="开关用途"
873
+ value={switchUsage}
874
+ onRightPress={handleShowSwitchUsagePicker}
875
+ />
876
+ )}
877
+ {((curDeviceType === 'igot' &&
878
+ switchUsages[switchUsageIndex].value === 'IGOT_LIGHT') ||
879
+ curDeviceType === 'light') && (
880
+ <Cell
881
+ type="link"
882
+ label="灯光用途"
883
+ value={lightUsage}
884
+ onRightPress={handleShowLightUsagePicker}
885
+ />
886
+ )}
887
+ {!['itee'].includes(curDeviceType) && (
888
+ <Cell
889
+ type="link"
890
+ label="设备位置"
891
+ value={roomName}
892
+ onRightPress={handleShowRoomPicker}
893
+ />
894
+ )}
895
+ </>
896
+ )}
897
+
898
+ <View>
899
+ <Button
900
+ title={submitBtnText}
901
+ disabled={isSaveBtnDisabled}
902
+ size="lg"
903
+ onPress={handleSaveDevice}
904
+ />
905
+ </View>
906
+ </ActionSheet>
907
+ </>
908
+ );
909
+ };
910
+
911
+ const styles = StyleSheet.create({
912
+ title: {
913
+ position: 'relative',
914
+ height: 50,
915
+ paddingHorizontal: 60,
916
+ alignItems: 'center',
917
+ justifyContent: 'center',
918
+ },
919
+ titleText: {
920
+ fontSize: 18,
921
+ color: '#333',
922
+ },
923
+ closeBtn: {
924
+ position: 'absolute',
925
+ height: '100%',
926
+ top: 0,
927
+ right: 0,
928
+ width: 60,
929
+ alignItems: 'center',
930
+ justifyContent: 'center',
931
+ },
932
+ });
933
+
934
+ export default DeviceActionSheet;