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,920 @@
1
+ import React, {useState, useEffect, useCallback, useRef} from 'react';
2
+ import {
3
+ View,
4
+ ScrollView,
5
+ Text,
6
+ TextInput,
7
+ StyleSheet,
8
+ Alert,
9
+ Platform,
10
+ StatusBar,
11
+ TouchableOpacity,
12
+ NativeModules,
13
+ ImageBackground,
14
+ TouchableWithoutFeedback,
15
+ Dimensions,
16
+ } from 'react-native';
17
+ import {useSafeArea} from 'react-native-safe-area-context';
18
+ import CryptoJS from 'crypto-js';
19
+ import UUIDGenerator from 'react-native-uuid-generator';
20
+ import {Icon, Image, CheckBox, Button} from '@rneui/themed';
21
+
22
+ import SmsCodeInput from '../../components/common/SmsCodeInput';
23
+
24
+ import storage from '../../storage';
25
+ import {replace} from '../../utils/RootNavigation';
26
+ import {
27
+ getUserLocation,
28
+ updateHomedToken,
29
+ initOperatorHomedTouristAccount,
30
+ appReport,
31
+ } from '../../utils/common';
32
+ import {obtainSmscode, smscodeLogin, accountLogin} from '../../api';
33
+ import {hideLoading, showLoading, showToast} from '../../utils/notice';
34
+
35
+ import {confirmWithContent} from '../../utils/registerDialog';
36
+ import config from '../../utils/config';
37
+ import ProtocolType from '../../components/common/LoginType/protocol';
38
+ let protocolAgreeResolve = null;
39
+
40
+ function LoginScreen({navigation, route}) {
41
+ const insets = useSafeArea();
42
+
43
+ const [isLoading, setIsLoading] = useState(true);
44
+ const [isLogined, setIsLogined] = useState(false);
45
+ const timer = useRef(null);
46
+ const [isLogining, setIsLogining] = useState(false);
47
+
48
+ useEffect(() => {
49
+ // 获取登录状态
50
+ storage.get('accessToken').then(token => {
51
+ // const appUserAgreement = await storage.get('appUserAgreement');
52
+ // if (!appUserAgreement) {
53
+ // setProtocolAgree(false);
54
+ // }
55
+
56
+ if (token) {
57
+ replace('Home', {
58
+ redirect: true,
59
+ });
60
+
61
+ // 上报APP启动事件
62
+ appReport('APP_STARTUP');
63
+ }
64
+ setTimeout(() => {
65
+ setIsLoading(false);
66
+ setIsLogined(!!token);
67
+ }, 0);
68
+ });
69
+ }, []);
70
+
71
+ // useEffect(() => {
72
+ // if (isLogined) {
73
+ // // console.log("检测到已登录,自动跳转首页");
74
+ // // TODO update account_data
75
+ // replace('Home', {
76
+ // redirect: true,
77
+ // });
78
+ // }
79
+ // }, [isLogined]);
80
+
81
+ const [phone, setPhone] = useState('');
82
+ const [smsId, setSmsId] = useState('');
83
+ const [userInputSmsCode, setUserInputSmsCode] = useState('');
84
+ const [smsCodeRightBtnDisabled, setSmsCodeRightBtnDisabled] = useState(false);
85
+ const [smsCodeRightBtnText, setSmsCodeRightBtnText] = useState('获取验证码');
86
+ const [smsCodeResendTime, setSmsCodeResendTime] = useState(0);
87
+
88
+ useEffect(() => {
89
+ if (phone && smsCodeResendTime === 0) {
90
+ setSmsCodeRightBtnDisabled(false);
91
+ setSmsCodeRightBtnText('获取验证码');
92
+ } else {
93
+ setSmsCodeRightBtnDisabled(true);
94
+ }
95
+ }, [phone, smsCodeResendTime]);
96
+ useEffect(() => {
97
+ if (smsCodeResendTime > 0) {
98
+ setSmsCodeRightBtnText(`${smsCodeResendTime}s后重发`);
99
+ timer.current = setTimeout(() => {
100
+ setSmsCodeResendTime(smsCodeResendTime - 1);
101
+ }, 1000);
102
+ }
103
+
104
+ return () => {
105
+ clearTimeout(timer.current);
106
+ };
107
+ }, [smsCodeResendTime]);
108
+
109
+ // 0 手机号+短信验证码登录
110
+ // 1 账号密码登录
111
+ const [loginWay, setLoginWay] = useState(0);
112
+
113
+ const [username, setUsername] = useState('');
114
+ const [password, setPassword] = useState('');
115
+
116
+ const [protocolAgree, setProtocolAgree] = useState(false);
117
+ const [protocolDialogVisible, setProtocolDialogVisible] = useState(false);
118
+
119
+ const [serviceAgree, setServiceAgree] = useState(false);
120
+ const [serviceDialogVisible, setServiceDialogVisible] = useState(false);
121
+ const [privacyAgree, setPrivacyAgree] = useState(false);
122
+ const [privacyDialogVisible, setPrivacyDialogVisible] = useState(false);
123
+
124
+ useEffect(() => {
125
+ if (!route.params?.skip) {
126
+ openProtocolDialog();
127
+ }
128
+ }, []);
129
+
130
+ useEffect(() => {
131
+ if (serviceAgree && privacyAgree) {
132
+ setProtocolAgree(true);
133
+ } else {
134
+ setProtocolAgree(false);
135
+ }
136
+ }, [serviceAgree, privacyAgree]);
137
+
138
+ const loginDisabled = !(
139
+ (loginWay === 0 && phone && userInputSmsCode) ||
140
+ (loginWay === 1 && username && password)
141
+ );
142
+
143
+ let smsCodeTimer;
144
+
145
+ function validPhone(phone) {
146
+ if (!phone) {
147
+ Alert.alert('请输入手机号');
148
+ return false;
149
+ }
150
+ if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(phone)) {
151
+ Alert.alert('请输入正确的手机号');
152
+ return false;
153
+ }
154
+ return true;
155
+ }
156
+
157
+ const handleGetSmsId = async () => {
158
+ if (!validPhone(phone)) {
159
+ return;
160
+ }
161
+ // 60s后重发
162
+ setSmsCodeResendTime(60);
163
+
164
+ setSmsCodeRightBtnDisabled(true);
165
+
166
+ const res = await obtainSmscode({
167
+ phone_number: phone,
168
+ length: 4,
169
+ type: 1, // type=1 表示登录用途
170
+ }).catch(err => {
171
+ console.log(err);
172
+ setSmsCodeRightBtnText('获取验证码');
173
+ setSmsCodeRightBtnDisabled(false);
174
+ });
175
+
176
+ if (res && res.code === 0) {
177
+ setSmsId(res.result.sms_id);
178
+
179
+ smsCodeTimer = setTimeout(() => {
180
+ setSmsCodeRightBtnText('获取验证码');
181
+ setSmsCodeRightBtnDisabled(false);
182
+ }, 120000);
183
+ } else {
184
+ setSmsCodeRightBtnText('获取验证码');
185
+ setSmsCodeRightBtnDisabled(false);
186
+ }
187
+ };
188
+
189
+ const handleUserAgree = () => {
190
+ // setProtocolDialogVisible(false);
191
+ // handleLogin();
192
+ // storage.set('appUserAgreement', true);
193
+
194
+ // getUserLocation().then(geoRes => {
195
+ // global.base.storage.set('location', geoRes);
196
+ // });
197
+ setProtocolAgree(true);
198
+ typeof protocolAgreeResolve === 'function' && protocolAgreeResolve();
199
+ protocolAgreeResolve = null;
200
+ };
201
+
202
+ const handleUserDisagree = async () => {
203
+ // await storage.set('appUserAgreement', false);
204
+ // NativeModules?.RNToNativeEmitter?.exitApp();
205
+ setProtocolDialogVisible(false);
206
+ setProtocolAgree(false);
207
+ setServiceAgree(false);
208
+ setPrivacyAgree(false);
209
+ };
210
+
211
+ const handleLoginPress = () => {
212
+ if (loginDisabled) {
213
+ return;
214
+ }
215
+ if (protocolAgree) {
216
+ handleLogin();
217
+ } else {
218
+ // setProtocolDialogVisible(true);
219
+ openProtocolDialog().then(() => {
220
+ handleLogin();
221
+ });
222
+ }
223
+ };
224
+
225
+ const openProtocolDialog = () => {
226
+ return new Promise(resolve => {
227
+ // setProtocolDialogVisible(true);
228
+ protocolAgreeResolve = resolve;
229
+ }).then(() => {
230
+ setProtocolDialogVisible(false);
231
+ });
232
+ };
233
+
234
+ const handleLogin = async () => {
235
+ let res;
236
+
237
+ const {deviceModal, appName} = NativeModules?.RNToNativeEmitter || {};
238
+
239
+ const appID = await global.base.getAppId();
240
+
241
+ console.log('appID', appID);
242
+
243
+ let finallyAppID = appID;
244
+ if (!appID) {
245
+ // 兼容本地开发测试
246
+ finallyAppID = await UUIDGenerator.getRandomUUID();
247
+ }
248
+
249
+ if (loginWay === 0) {
250
+ if (!validPhone(phone)) {
251
+ return;
252
+ }
253
+
254
+ if (!smsId) {
255
+ Alert.alert('请先获取验证码');
256
+ return;
257
+ }
258
+
259
+ if (!userInputSmsCode) {
260
+ Alert.alert('请输入短信验证码');
261
+ return;
262
+ }
263
+ showLoading('登录中...');
264
+ setIsLogining(true);
265
+ res = await smscodeLogin({
266
+ phone_number: phone,
267
+ sms_id: smsId,
268
+ sms_code: userInputSmsCode,
269
+ create_address: 1, // 注册时自动建默认家庭
270
+ extend: {
271
+ appid: finallyAppID,
272
+ model: deviceModal || '开发测试',
273
+ application: appName || '爱家宝',
274
+ },
275
+ });
276
+ } else {
277
+ if (!username) {
278
+ Alert.alert('请输入账号');
279
+ return;
280
+ }
281
+
282
+ if (!password) {
283
+ Alert.alert('请输入密码');
284
+ return;
285
+ }
286
+ console.log(global.loading, 'global.loading');
287
+ showLoading('登录中...');
288
+ setIsLogining(true);
289
+ res = await accountLogin({
290
+ account_name: username,
291
+ password: CryptoJS.MD5(password).toString(),
292
+ create_address: 1, // 注册时自动建默认家庭
293
+ extend: {
294
+ appid: finallyAppID,
295
+ model: deviceModal || '开发测试',
296
+ application: appName || '爱家宝',
297
+ },
298
+ });
299
+ }
300
+ if (res.code === 0) {
301
+ console.log(res.result, 'ipanelClound用户信息');
302
+ await storage.set('accessToken', res.result.access_token);
303
+ await storage.set('refreshToken', res.result.refresh_token);
304
+
305
+ if (res.result.address && res.result.address[0]) {
306
+ const defaultAddr = res.result.address[0];
307
+ await storage.set('activeAddr', defaultAddr);
308
+ await storage.set('addressList', res.result.address || []);
309
+ await updateHomedToken();
310
+ } else {
311
+ await storage.set('activeAddr', {});
312
+ await storage.set('addressList', []);
313
+ }
314
+
315
+ delete res.result.address;
316
+ await storage.set('accountData', res.result);
317
+
318
+ // 放开这段重新登录就会置空运营商(进入标准版)
319
+ // await storage.set(
320
+ // `${res.result?.account?.account_id || ''}currentOperator`,
321
+ // {},
322
+ // );
323
+
324
+ // 初始化默认运营商对应的homed游客账号
325
+ const envVersion =
326
+ NativeModules?.RNToNativeEmitter?.serverCluster || 'dev';
327
+ await initOperatorHomedTouristAccount({
328
+ touristUsername: finallyAppID,
329
+ domain: envVersion === 'dev' ? 'homed.me' : 'homed.tv',
330
+ touristGroupId: envVersion === 'dev' ? 115017 : 4664, // 4664: tv集群的手机APP游客用户组. 115017: 运营集群手机APP游客用户组
331
+ });
332
+ clearTimeout(smsCodeTimer);
333
+ // setIsLogined(true);
334
+ // 判断是否已经选了运营商
335
+ const currentOperator = await storage.get(
336
+ `${res.result?.account?.account_id || ''}currentOperator`,
337
+ );
338
+
339
+ // 上报APP启动事件
340
+ appReport('APP_STARTUP');
341
+
342
+ hideLoading();
343
+ setIsLogining(false);
344
+ const appName =
345
+ NativeModules?.RNToNativeEmitter?.appName || config.LOCALTEST_APP_NAME;
346
+ if (currentOperator || appName.includes('安电工')) {
347
+ replace('Home', {
348
+ redirect: false,
349
+ });
350
+ } else {
351
+ confirmWithContent({
352
+ title: '选择运营商',
353
+ component: '你是否要选择运营商',
354
+ confirmButtonText: '确定',
355
+ confirmCallback: () => {
356
+ replace('OperatorSelectScreen', {
357
+ purpose: 'init',
358
+ });
359
+ },
360
+ cancelButtonText: '先不选',
361
+ cancelCallback: () => {
362
+ replace('Home', {
363
+ redirect: false,
364
+ });
365
+ },
366
+ });
367
+ }
368
+ } else {
369
+ hideLoading();
370
+ setIsLogining(false);
371
+ global.toast.showToast(res.message + '(code: ' + res.code + ')');
372
+ }
373
+ };
374
+
375
+ const statusBarPlaceholderStyle = {
376
+ height: (Platform.OS === 'ios' ? insets.top : 0) + StatusBar.currentHeight,
377
+ };
378
+
379
+ const handleSwitchLoginWay = () => {
380
+ if (loginWay === 0) {
381
+ setLoginWay(1);
382
+ } else {
383
+ setLoginWay(0);
384
+ }
385
+ };
386
+
387
+ const handleViewUserAgreement = () => {
388
+ navigation.navigate('WebviewScreen', {
389
+ title: '用户协议',
390
+ url: 'https://ipanelcloud2.ipanel.cn:50443/iapp/ajbstatic/service_agreement/user_agreement.html',
391
+ });
392
+ };
393
+ const handleViewPrivacyClause = () => {
394
+ navigation.navigate('WebviewScreen', {
395
+ title: '隐私条款',
396
+ url: 'https://ipanelcloud2.ipanel.cn:50443/iapp/ajbstatic/service_agreement/privacy_policy.html',
397
+ });
398
+ };
399
+ const handleViewUserAgreementByType = type => {
400
+ if (type === 'service') {
401
+ setServiceDialogVisible(true);
402
+ } else if (type === 'privacy') {
403
+ setPrivacyDialogVisible(true);
404
+ }
405
+ };
406
+
407
+ const handleSetProtocolAgree = isAgree => {
408
+ setProtocolAgree(isAgree);
409
+ setServiceAgree(isAgree);
410
+ setPrivacyAgree(isAgree);
411
+ };
412
+
413
+ const handleOneDisagree = async type => {
414
+ setProtocolAgree(false);
415
+ if (type === 'service') {
416
+ setServiceAgree(false);
417
+ setServiceDialogVisible(false);
418
+ } else if (type === 'privacy') {
419
+ setPrivacyAgree(false);
420
+ setPrivacyDialogVisible(false);
421
+ }
422
+ };
423
+ const handleOneAgree = type => {
424
+ if (type === 'service') {
425
+ setServiceAgree(true);
426
+ setServiceDialogVisible(false);
427
+ } else if (type === 'privacy') {
428
+ setPrivacyAgree(true);
429
+ setPrivacyDialogVisible(false);
430
+ }
431
+
432
+ typeof protocolAgreeResolve === 'function' && protocolAgreeResolve();
433
+ protocolAgreeResolve = null;
434
+ };
435
+
436
+ loginDisabled;
437
+ const loginBtnBg = {
438
+ backgroundColor: loginDisabled
439
+ ? 'rgba(234, 96, 0, 0.3)'
440
+ : 'rgba(234, 96, 0, 1)',
441
+ };
442
+
443
+ return (
444
+ <ImageBackground
445
+ source={require('../../assets/img/login_bg.png')}
446
+ style={[
447
+ styles.container,
448
+ {paddingTop: Platform.OS === 'ios' ? insets.top : 0},
449
+ ]}>
450
+ {isLoading || isLogined ? (
451
+ <View style={styles.welcomeView}>{/* 白屏界面 */}</View>
452
+ ) : (
453
+ <View style={styles.loginView}>
454
+ <View style={statusBarPlaceholderStyle} />
455
+
456
+ <View style={styles.changeLoginWay}>
457
+ <TouchableOpacity
458
+ activeOpacity={0.7}
459
+ onPress={handleSwitchLoginWay}>
460
+ <View style={styles.changeLoginWayInner}>
461
+ <Image
462
+ source={require('../../assets/img/qiehuan.png')}
463
+ style={styles.exchangeIcon}
464
+ />
465
+
466
+ <Text style={styles.changeLoginWayText}>
467
+ {loginWay === 0 ? '密码登录' : '验证码登录'}
468
+ </Text>
469
+ </View>
470
+ </TouchableOpacity>
471
+ </View>
472
+
473
+ <View style={styles.content}>
474
+ <View style={styles.titleBox}>
475
+ <Text style={styles.title}>
476
+ {loginWay === 0 ? '验证码登录' : '密码登录'}
477
+ </Text>
478
+
479
+ <Text style={styles.subTitle}>
480
+ {loginWay === 0
481
+ ? '未注册过的手机号验证通过后将自动注册'
482
+ : '请使用账号和密码登录'}
483
+ </Text>
484
+ </View>
485
+
486
+ {loginWay === 0 && (
487
+ <>
488
+ <View style={styles.inputBox}>
489
+ <TextInput
490
+ style={styles.input}
491
+ value={phone}
492
+ placeholder="手机号"
493
+ onChangeText={text => setPhone(text)}
494
+ />
495
+ </View>
496
+ <View style={styles.inputBox}>
497
+ <SmsCodeInput
498
+ value={userInputSmsCode}
499
+ placeholder="验证码"
500
+ rightBtnDisabled={smsCodeRightBtnDisabled}
501
+ rightBtnText={smsCodeRightBtnText}
502
+ onChangeText={text => setUserInputSmsCode(text)}
503
+ onRightBtnPress={handleGetSmsId}
504
+ />
505
+ </View>
506
+ </>
507
+ )}
508
+
509
+ {loginWay === 1 && (
510
+ <>
511
+ <View style={styles.inputBox}>
512
+ <TextInput
513
+ style={styles.input}
514
+ value={username}
515
+ placeholder="账号"
516
+ onChangeText={text => setUsername(text)}
517
+ />
518
+ </View>
519
+ <View style={styles.inputBox}>
520
+ <TextInput
521
+ style={styles.input}
522
+ value={password}
523
+ secureTextEntry
524
+ placeholder="密码"
525
+ onChangeText={text => setPassword(text)}
526
+ />
527
+ </View>
528
+ </>
529
+ )}
530
+
531
+ <View style={styles.protocol}>
532
+ <CheckBox
533
+ center
534
+ checked={protocolAgree}
535
+ containerStyle={{
536
+ margin: 0,
537
+ padding: 0,
538
+ backgroundColor: 'transparent',
539
+ }}
540
+ onPress={() => handleSetProtocolAgree(!protocolAgree)}
541
+ checkedIcon={
542
+ <Icon
543
+ name="checkmark-circle-outline"
544
+ type="ionicon"
545
+ color={styles.protocolLinkAgree.color}
546
+ size={20}
547
+ />
548
+ }
549
+ uncheckedIcon={
550
+ <Icon
551
+ name="radio-button-off"
552
+ type="ionicon"
553
+ color={styles.protocolText.color}
554
+ size={20}
555
+ />
556
+ }
557
+ />
558
+ <TouchableWithoutFeedback
559
+ onPress={() => setProtocolAgree(!protocolAgree)}>
560
+ <Text style={styles.protocolText}>
561
+ 已阅读并同意
562
+ <TouchableWithoutFeedback
563
+ style={{paddingVertical: 100}}
564
+ onPress={() => handleViewUserAgreementByType('service')}>
565
+ <Text
566
+ style={
567
+ protocolAgree || serviceAgree
568
+ ? styles.protocolLinkAgree
569
+ : styles.protocolLink
570
+ }>
571
+ 用户协议
572
+ </Text>
573
+ </TouchableWithoutFeedback>
574
+ 和
575
+ <TouchableWithoutFeedback
576
+ style={{paddingVertical: 100}}
577
+ onPress={() => handleViewUserAgreementByType('privacy')}>
578
+ <Text
579
+ style={
580
+ protocolAgree || privacyAgree
581
+ ? styles.protocolLinkAgree
582
+ : styles.protocolLink
583
+ }>
584
+ 隐私条款
585
+ </Text>
586
+ </TouchableWithoutFeedback>
587
+ </Text>
588
+ </TouchableWithoutFeedback>
589
+ </View>
590
+
591
+ <TouchableOpacity
592
+ activeOpacity={0.7}
593
+ onPress={handleLoginPress}
594
+ disabled={loginDisabled}>
595
+ <View style={styles.loginBtnBox}>
596
+ <View style={[styles.loginBtn, loginBtnBg]}>
597
+ <Text style={styles.loginBtnText}>
598
+ {isLogining ? '正在登录中...' : '登录'}
599
+ </Text>
600
+ </View>
601
+ </View>
602
+ </TouchableOpacity>
603
+ </View>
604
+ </View>
605
+ )}
606
+
607
+ {serviceDialogVisible && !isLoading && (
608
+ <ProtocolType
609
+ handleOneDisagree={handleOneDisagree}
610
+ handleOneAgree={handleOneAgree}
611
+ url="https://ipanelcloud2.ipanel.cn:50443/iapp/ajbstatic/service_agreement/user_agreement.html"
612
+ type="service"
613
+ />
614
+ )}
615
+ {privacyDialogVisible && !isLoading && (
616
+ <ProtocolType
617
+ handleOneDisagree={handleOneDisagree}
618
+ handleOneAgree={handleOneAgree}
619
+ url="https://ipanelcloud2.ipanel.cn:50443/iapp/ajbstatic/service_agreement/privacy_policy.html"
620
+ type="privacy"
621
+ />
622
+ )}
623
+
624
+ {protocolDialogVisible && !isLoading && (
625
+ <View style={styles.agreementMask}>
626
+ <View style={styles.agreementConfirmContent}>
627
+ <View style={styles.agreementConfirmHead}>
628
+ <TouchableOpacity
629
+ style={styles.headerLeft}
630
+ onPress={() => {
631
+ console.log(111);
632
+ setProtocolDialogVisible(false);
633
+ }}>
634
+ <Image
635
+ source={require('../../assets/img/goBack.png')}
636
+ style={styles.goBackImg}
637
+ resizeMode="contain"
638
+ />
639
+ </TouchableOpacity>
640
+ <View style={styles.agreementConfirmTitleBox}>
641
+ <Text style={styles.agreementConfirmTitle}>欢迎使用爱家宝</Text>
642
+ </View>
643
+ </View>
644
+ <ScrollView>
645
+ <View>
646
+ <Text style={styles.agreementConfirmText}>
647
+ 为了更好的保障您的合法权益,请您阅读并同意
648
+ <TouchableWithoutFeedback onPress={handleViewUserAgreement}>
649
+ <Text style={styles.agreementConfirmImportantText}>
650
+ 用户协议
651
+ </Text>
652
+ </TouchableWithoutFeedback>
653
+ 和
654
+ <TouchableWithoutFeedback onPress={handleViewPrivacyClause}>
655
+ <Text style={styles.agreementConfirmImportantText}>
656
+ 隐私条款
657
+ </Text>
658
+ </TouchableWithoutFeedback>
659
+ 。为向您提供更优质的服务,我们可能会向您申请下列相关权限:
660
+ </Text>
661
+ </View>
662
+ <View>
663
+ <Text style={styles.agreementConfirmText}>
664
+ 1. 读写设备存储权限(Android
665
+ 版本):用于用于用户反馈、客服等功能中读写设备上的照片及文件;
666
+ </Text>
667
+ </View>
668
+ <View>
669
+ <Text style={styles.agreementConfirmText}>
670
+ 2. 地理位置权限(Android、iOS
671
+ 版本):用于家庭位置管理、判断地区提供天气服务、发现附近智能设备;
672
+ </Text>
673
+ </View>
674
+ <View>
675
+ <Text style={styles.agreementConfirmText}>
676
+ 3. 相机权限(Android、iOS
677
+ 版本):用于扫码绑定电视账户、扫码进行设备添加等功能;
678
+ </Text>
679
+ </View>
680
+ <View>
681
+ <Text style={styles.agreementConfirmText}>
682
+ 4. 相册权限(Android、ios
683
+ 版本):用于用户反馈等功能中读写设备上的照片及视频;
684
+ </Text>
685
+ </View>
686
+ <View>
687
+ <Text style={styles.agreementConfirmText}>
688
+ 5. 麦克风权限(Android、ioS 版本):智能客服等功能;
689
+ </Text>
690
+ </View>
691
+ <View>
692
+ <Text style={styles.agreementConfirmText}>
693
+ 6. 读取电话联系人权限(Android):用于电视通讯功能;
694
+ </Text>
695
+ </View>
696
+ <View>
697
+ <Text style={styles.agreementConfirmText}>
698
+ 7. 开启蓝牙权限(Android、ios
699
+ 版本):用于连接设备时连接设备发出的蓝牙信号,以进行设备通信,对于通过蓝牙连接的智能设备,也需要蓝牙权限用于通信;
700
+ </Text>
701
+ </View>
702
+ <View>
703
+ <Text style={styles.agreementConfirmText}>
704
+ 8. 开启蓝牙权限(Android、ios
705
+ 版本):用于连接设备时连接设备发出的蓝牙信号,以进行设备通信,对于通过蓝牙连接的智能设备,也需要蓝牙权限用于通信;
706
+ </Text>
707
+ </View>
708
+ <View>
709
+ <Text style={styles.agreementConfirmText}>
710
+ 7. 开启蓝牙权限(Android、ios
711
+ 版本):用于连接设备时连接设备发出的蓝牙信号,以进行设备通信,对于通过蓝牙连接的智能设备,也需要蓝牙权限用于通信;
712
+ </Text>
713
+ </View>
714
+ </ScrollView>
715
+
716
+ <View style={styles.agreementButtons}>
717
+ <TouchableOpacity
718
+ style={styles.disagreeBtn}
719
+ activeOpacity={0.7}
720
+ onPress={handleUserDisagree}>
721
+ <Text style={styles.disagreeBtnText}>不同意</Text>
722
+ </TouchableOpacity>
723
+ <TouchableOpacity
724
+ style={styles.agreeBtn}
725
+ activeOpacity={0.7}
726
+ onPress={handleUserAgree}>
727
+ <Text style={styles.agreeBtnText}>同意</Text>
728
+ </TouchableOpacity>
729
+ </View>
730
+ </View>
731
+ </View>
732
+ )}
733
+ </ImageBackground>
734
+ );
735
+ }
736
+
737
+ const styles = StyleSheet.create({
738
+ container: {
739
+ flex: 1,
740
+ backgroundColor: '#fff',
741
+ },
742
+ welcomeView: {
743
+ flex: 1,
744
+ alignItems: 'center',
745
+ justifyContent: 'center',
746
+ },
747
+ content: {
748
+ padding: 30,
749
+ },
750
+ titleBox: {
751
+ justifyContent: 'center',
752
+ },
753
+ title: {
754
+ fontSize: 36,
755
+ color: 'rgba(48, 48, 48, 1)',
756
+ },
757
+ subTitle: {
758
+ fontSize: 14,
759
+ marginTop: 10,
760
+ marginBottom: 40,
761
+ },
762
+ inputBox: {
763
+ borderBottomWidth: 1,
764
+ marginVertical: 10,
765
+ borderBottomColor: 'rgba(217, 217, 217, 1)',
766
+ },
767
+ input: {
768
+ height: 50,
769
+ color: '#333',
770
+ },
771
+ welcomText: {
772
+ fontSize: 30,
773
+ },
774
+ loginView: {
775
+ flex: 1,
776
+ },
777
+ changeLoginWay: {
778
+ height: 70,
779
+ justifyContent: 'center',
780
+ alignItems: 'flex-end',
781
+ marginRight: 20,
782
+ },
783
+ changeLoginWayInner: {
784
+ flexDirection: 'row',
785
+ alignItems: 'center',
786
+ },
787
+ changeLoginWayText: {
788
+ color: 'rgba(51, 51, 51, 1)',
789
+ fontSize: 16,
790
+ },
791
+ exchangeIcon: {
792
+ width: 16,
793
+ height: 16,
794
+ marginRight: 3,
795
+ },
796
+ protocol: {
797
+ marginVertical: 15,
798
+ flexDirection: 'row',
799
+ alignItems: 'center',
800
+ },
801
+ protocolText: {
802
+ color: 'rgba(102, 102, 102, 1)',
803
+ },
804
+ protocolLink: {
805
+ color: 'rgba(234, 96, 0, 1)',
806
+ },
807
+ protocolLinkAgree: {
808
+ color: '#0EC12C',
809
+ },
810
+ agreementMask: {
811
+ position: 'absolute',
812
+ left: 0,
813
+ top: 0,
814
+ bottom: 0,
815
+ right: 0,
816
+ zIndex: 2,
817
+ },
818
+ agreementConfirmContent: {
819
+ position: 'absolute',
820
+ width: Dimensions.get('window').width - 60,
821
+ height: 400,
822
+ left: 30,
823
+ top: Dimensions.get('window').height / 2 - 200,
824
+ backgroundColor: '#fff',
825
+ paddingBottom: 0,
826
+ borderWidth: 1,
827
+ borderColor: '#a1a1a1',
828
+ borderRadius: 20,
829
+ },
830
+ agreementConfirmHead: {
831
+ position: 'relative',
832
+ flexDirection: 'row',
833
+ alignItems: 'center',
834
+ paddingTop: 10,
835
+ paddingLeft: 10,
836
+ marginBottom: 5,
837
+ height: 40,
838
+ },
839
+ headerLeft: {
840
+ position: 'absolute',
841
+ top: 15,
842
+ left: 10,
843
+ zIndex: 2,
844
+ },
845
+ goBackImg: {
846
+ width: 20,
847
+ height: 20,
848
+ },
849
+ agreementConfirmTitleBox: {
850
+ // flex: 1,
851
+ position: 'absolute',
852
+ top: 10,
853
+ bottom: 0,
854
+ left: 0,
855
+ right: 0,
856
+ zIndex: 1,
857
+ },
858
+ agreementConfirmTitle: {
859
+ fontSize: 20,
860
+ // lineHeight: 50,
861
+ color: '#000',
862
+ textAlign: 'center',
863
+ // paddingTop: 20,
864
+ },
865
+ agreementConfirmText: {
866
+ fontSize: 16,
867
+ lineHeight: 30,
868
+ paddingHorizontal: 20,
869
+ color: '#000',
870
+ },
871
+ agreementConfirmImportantText: {
872
+ color: 'rgba(234, 96, 0, 1)',
873
+ },
874
+ agreementButtons: {
875
+ height: 50,
876
+ flexDirection: 'row',
877
+ justifyContent: 'space-around',
878
+ borderTopColor: '#c1c1c1',
879
+ borderTopWidth: 0.5,
880
+ },
881
+ disagreeBtn: {
882
+ flex: 1,
883
+ alignItems: 'center',
884
+ justifyContent: 'center',
885
+ borderBottomLeftRadius: 20,
886
+ },
887
+ disagreeBtnText: {
888
+ color: '#ccc',
889
+ },
890
+ agreeBtn: {
891
+ flex: 1,
892
+ alignItems: 'center',
893
+ justifyContent: 'center',
894
+ borderLeftColor: '#c1c1c1',
895
+ borderLeftWidth: 0.5,
896
+ borderBottomRightRadius: 20,
897
+ },
898
+ agreeBtnText: {
899
+ color: '#333',
900
+ fontSize: 16,
901
+ },
902
+ loginBtnBox: {
903
+ flexDirection: 'row',
904
+ alignItems: 'center',
905
+ },
906
+ loginBtn: {
907
+ flex: 1,
908
+ height: 48,
909
+ marginHorizontal: 10,
910
+ borderRadius: 24,
911
+ alignItems: 'center',
912
+ justifyContent: 'center',
913
+ },
914
+ loginBtnText: {
915
+ color: '#fff',
916
+ fontSize: 18,
917
+ },
918
+ });
919
+
920
+ export default LoginScreen;