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,364 @@
1
+ import React, {useState, useEffect, useRef} from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ TouchableHighlight,
7
+ ScrollView,
8
+ TouchableOpacity,
9
+ TextInput,
10
+ Alert,
11
+ } from 'react-native';
12
+
13
+ import ScreenBackHeader from '../../components/common/ScreenBackHeader';
14
+ import SmsCodeInput from '../../components/common/SmsCodeInput/indexNew';
15
+ import {Icon, Divider} from '@rneui/themed';
16
+ import CryptoJS from 'crypto-js';
17
+
18
+ import {obtainSmscode, changePwdByPhone, authSmscode} from '../../api';
19
+ import px from '../../utils/scaleSize';
20
+ import {replace} from '../../utils/RootNavigation';
21
+ // const passwordReg =
22
+ // /^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-zA-Z]|[0-9]){6,}$/;
23
+
24
+ const Index = ({route}) => {
25
+ const [step, setStep] = useState(0); // 0 输入账号绑定的手机号码,1 设置密码
26
+ const [phone, setPhone] = useState('');
27
+ const [smsId, setSmsId] = useState('');
28
+ const [userInputSmsCode, setUserInputSmsCode] = useState('');
29
+ const [smsCodeRightBtnDisabled, setSmsCodeRightBtnDisabled] = useState(false);
30
+ const [smsCodeRightBtnText, setSmsCodeRightBtnText] = useState('发送验证码');
31
+ const [smsCodeResendTimes, setSmsCodeResendTimes] = useState(0);
32
+ const [authCode, setAuthCode] = useState('');
33
+ const loginDisabled = !(step === 0 && phone && userInputSmsCode);
34
+
35
+ const timers = useRef(null);
36
+
37
+ let smsCodeTimer;
38
+
39
+ const [pwd1, setPwd1] = useState('');
40
+ const [pwd2, setPwd2] = useState('');
41
+ const [pwdMsg, setPwdMsg] = useState('');
42
+ const pwdDisabled = !(step === 1 && pwd1 && pwd2);
43
+ function validPhone(phoneNumber) {
44
+ if (!phoneNumber) {
45
+ Alert.alert('请输入手机号');
46
+ return false;
47
+ }
48
+ if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(phoneNumber)) {
49
+ // Alert.alert('请输入正确的手机号');
50
+ global.toast.showToast('手机号无效,请检查!');
51
+ return false;
52
+ }
53
+ return true;
54
+ }
55
+
56
+ const handleGetSmsId = async () => {
57
+ if (!validPhone(phone)) {
58
+ return;
59
+ }
60
+ // 60s后重发
61
+ setSmsCodeResendTimes(60);
62
+
63
+ setSmsCodeRightBtnDisabled(true);
64
+ const res = await obtainSmscode(
65
+ {
66
+ phone_number: phone,
67
+ length: 4,
68
+ type: 5, // type=5 表示重置密码用途
69
+ },
70
+ global.base.accountType,
71
+ ).catch(err => {
72
+ console.log(err);
73
+ setSmsCodeRightBtnText('获取验证码');
74
+ setSmsCodeRightBtnDisabled(false);
75
+ });
76
+
77
+ if (res && res.code === 0) {
78
+ setSmsId(res.result.sms_id);
79
+
80
+ smsCodeTimer = setTimeout(() => {
81
+ setSmsCodeRightBtnText('获取验证码');
82
+ setSmsCodeRightBtnDisabled(false);
83
+ }, 120000);
84
+ } else {
85
+ setSmsCodeRightBtnText('获取验证码');
86
+ setSmsCodeRightBtnDisabled(false);
87
+ }
88
+ };
89
+
90
+ const handleLoginPress = async () => {
91
+ if (step === 0) {
92
+ // 手机验证码校对
93
+ if (loginDisabled) {
94
+ return;
95
+ }
96
+ if (!userInputSmsCode) {
97
+ global.toast.showToast('请输入短信验证码');
98
+ return;
99
+ }
100
+ if (!validPhone(phone)) {
101
+ return;
102
+ }
103
+ const params = {
104
+ sms_id: smsId,
105
+ sms_code: userInputSmsCode,
106
+ };
107
+ const res = await authSmscode(params);
108
+ if (res.code === 0) {
109
+ console.log(res.result?.auth_code, 'res.result?.auth_code');
110
+ global.toast.showToast('校验验证码成功,请重置密码');
111
+ setAuthCode(res.result?.auth_code);
112
+ setStep(1);
113
+ clearTimeout(smsCodeTimer);
114
+ clearTimeout(timers.current);
115
+ } else {
116
+ global.toast.showToast('校验验证码失败');
117
+ }
118
+ } else {
119
+ if (pwdDisabled) {
120
+ return;
121
+ }
122
+ if (pwd1 !== pwd2) {
123
+ global.toast.showToast('两次密码输入不一致');
124
+ setPwdMsg('两次密码输入不一致');
125
+ return;
126
+ }
127
+ const passwordRegTest =
128
+ /^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-zA-Z]|[0-9]){8,}$/;
129
+ if (!passwordRegTest.test(pwd1)) {
130
+ global.toast.showToast('低密码安全,请按规范设置');
131
+ setPwdMsg('低密码安全,请按规范设置');
132
+ return;
133
+ }
134
+ setPwdMsg('');
135
+ const params = {
136
+ auth_code: authCode,
137
+ phone_number: phone,
138
+ new_password: CryptoJS.MD5(pwd1).toString(),
139
+ };
140
+ const res = await changePwdByPhone(params);
141
+ if (res && res.code === 0) {
142
+ console.log(res, 'res');
143
+ global.toast?.showToast('修改成功');
144
+ replace('Login', {
145
+ skip: true,
146
+ loginWay: 1,
147
+ });
148
+ } else {
149
+ global.toast?.showToast('修改失败');
150
+ setStep(0);
151
+ }
152
+ }
153
+ };
154
+
155
+ useEffect(() => {
156
+ if (phone.length === 11 && smsCodeResendTimes === 0) {
157
+ setSmsCodeRightBtnDisabled(false);
158
+ setSmsCodeRightBtnText('获取验证码');
159
+ } else {
160
+ setSmsCodeRightBtnDisabled(true);
161
+ }
162
+ }, [phone, smsCodeResendTimes]);
163
+ useEffect(() => {
164
+ if (smsCodeResendTimes > 0) {
165
+ console.log(smsCodeResendTimes, 'smsCodeResendTimes');
166
+ setSmsCodeRightBtnText(`${smsCodeResendTimes}s后重发`);
167
+ timers.current = setTimeout(() => {
168
+ setSmsCodeResendTimes(smsCodeResendTimes - 1);
169
+ }, 1000);
170
+ }
171
+ return () => {
172
+ clearTimeout(timers.current);
173
+ };
174
+ }, [smsCodeResendTimes]);
175
+
176
+ return (
177
+ <View style={styles.container}>
178
+ <ScreenBackHeader title="重置密码" />
179
+ <Divider width={px(12)} color="#F5F5F5" />
180
+ <View style={styles.stepContainer}>
181
+ {step === 0 ? (
182
+ <>
183
+ <Text style={styles.title}>请输入账号绑定的手机号码</Text>
184
+ <View style={[styles.inputBox, {marginBottom: px(75)}]}>
185
+ <Text style={styles.inputTitle}>+86</Text>
186
+ <View style={styles.inputDivider} />
187
+ <TextInput
188
+ keyboardType="number-pad"
189
+ style={styles.input}
190
+ value={phone}
191
+ placeholder="请输入您的手机号"
192
+ placeholderTextColor="#A6A6A6"
193
+ onChangeText={text => setPhone(text)}
194
+ returnKeyType="done"
195
+ maxLength={11}
196
+ />
197
+ </View>
198
+ <View style={[styles.inputBox]}>
199
+ <SmsCodeInput
200
+ value={userInputSmsCode}
201
+ placeholder="请输入验证码"
202
+ rightBtnDisabled={smsCodeRightBtnDisabled}
203
+ rightBtnText={smsCodeRightBtnText}
204
+ onChangeText={text => setUserInputSmsCode(text)}
205
+ onRightBtnPress={handleGetSmsId}
206
+ />
207
+ </View>
208
+ <TouchableOpacity
209
+ activeOpacity={0.7}
210
+ onPress={handleLoginPress}
211
+ disabled={loginDisabled}>
212
+ <View style={styles.loginBtnBox}>
213
+ <View
214
+ style={[
215
+ styles.loginBtn,
216
+ loginDisabled ? styles.disabledBtn : null,
217
+ ]}>
218
+ <Text style={[styles.loginBtnText]}>下一步</Text>
219
+ </View>
220
+ </View>
221
+ </TouchableOpacity>
222
+ </>
223
+ ) : (
224
+ <>
225
+ <Text style={{...styles.title, marginBottom: px(17)}}>
226
+ 设置密码
227
+ </Text>
228
+ <Text
229
+ style={{
230
+ ...styles.marginCommon,
231
+ color: '#999999',
232
+ fontSize: px(40),
233
+ marginBottom: px(81),
234
+ }}>
235
+ 密码至少包含数字/字母/符号2种组合
236
+ </Text>
237
+ <View style={[styles.inputBox, {marginBottom: px(75)}]}>
238
+ <TextInput
239
+ style={styles.input}
240
+ placeholder="请输入新密码(最少八位数)"
241
+ placeholderTextColor="#A6A6A6"
242
+ value={pwd1}
243
+ keyboardType="email-address"
244
+ onChangeText={text => setPwd1(text)}
245
+ />
246
+ </View>
247
+ <View style={[styles.inputBox]}>
248
+ <TextInput
249
+ style={styles.input}
250
+ placeholder="再次确认新密码"
251
+ placeholderTextColor="#A6A6A6"
252
+ value={pwd2}
253
+ keyboardType="email-address"
254
+ onChangeText={text => setPwd2(text)}
255
+ />
256
+ </View>
257
+ {pwdMsg ? (
258
+ <Text
259
+ style={{
260
+ ...styles.marginCommon,
261
+ color: '#E86003',
262
+ fontSize: px(35),
263
+ }}>
264
+ {pwdMsg}
265
+ </Text>
266
+ ) : null}
267
+ <TouchableOpacity
268
+ activeOpacity={0.7}
269
+ onPress={handleLoginPress}
270
+ disabled={pwdDisabled}>
271
+ <View
272
+ style={[
273
+ styles.loginBtnBox,
274
+ {marginTop: pwdMsg ? px(55) : px(114)},
275
+ ]}>
276
+ <View
277
+ style={[
278
+ styles.loginBtn,
279
+ pwdDisabled ? styles.disabledBtn : null,
280
+ ]}>
281
+ <Text style={[styles.loginBtnText]}>下一步</Text>
282
+ </View>
283
+ </View>
284
+ </TouchableOpacity>
285
+ </>
286
+ )}
287
+ </View>
288
+ </View>
289
+ );
290
+ };
291
+
292
+ const styles = StyleSheet.create({
293
+ container: {
294
+ flex: 1,
295
+ backgroundColor: '#fff',
296
+ flexDirection: 'column',
297
+ },
298
+ inputBox: {
299
+ marginHorizontal: px(115),
300
+ flexDirection: 'row',
301
+ alignItems: 'center',
302
+ borderBottomWidth: px(2),
303
+ // marginVertical: 10,
304
+ borderBottomColor: '#E8E8E8',
305
+ height: px(100),
306
+ },
307
+ inputView: {
308
+ backgroundColor: '#fff',
309
+ borderRadius: px(22),
310
+ flex: 1,
311
+ marginTop: px(-50),
312
+ },
313
+ inputDivider: {
314
+ width: px(3),
315
+ height: px(37),
316
+ backgroundColor: '#eee',
317
+ marginHorizontal: px(22),
318
+ },
319
+ inputTitle: {
320
+ color: '#333',
321
+ fontSize: px(40),
322
+ fontWeight: '400',
323
+ },
324
+ input: {
325
+ height: 50,
326
+ flex: 1,
327
+ color: '#000',
328
+ },
329
+ loginBtnBox: {
330
+ flexDirection: 'row',
331
+ alignItems: 'center',
332
+ marginTop: px(144),
333
+ },
334
+ loginBtn: {
335
+ marginHorizontal: px(115),
336
+ borderRadius: px(23),
337
+ backgroundColor: '#E86003',
338
+ flex: 1,
339
+ height: px(132),
340
+ alignItems: 'center',
341
+ justifyContent: 'center',
342
+ },
343
+ loginBtnText: {
344
+ color: '#fff',
345
+ fontSize: px(52),
346
+ fontWeight: '600',
347
+ },
348
+ title: {
349
+ fontWeight: 'bold',
350
+ fontSize: px(46),
351
+ color: '#333',
352
+ marginTop: px(46),
353
+ marginHorizontal: px(115),
354
+ marginBottom: px(153),
355
+ },
356
+ disabledBtn: {
357
+ backgroundColor: '#CFCFCF',
358
+ },
359
+ marginCommon: {
360
+ marginHorizontal: px(115),
361
+ },
362
+ });
363
+
364
+ export default Index;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import {View, Text, StyleSheet} from 'react-native';
3
+
4
+ const SbkScreen = () => {
5
+ return (
6
+ <View style={styles.container}>
7
+ <Text>声必可专用页面</Text>
8
+ </View>
9
+ );
10
+ };
11
+
12
+ const styles = StyleSheet.create({
13
+ container: {
14
+ backgroundColor: 'red',
15
+ height: '100%',
16
+ },
17
+ });
18
+
19
+ export default SbkScreen;
@@ -0,0 +1,41 @@
1
+ import React, {useState, useEffect} from 'react';
2
+ import {View, Text, StyleSheet, TouchableHighlight} from 'react-native';
3
+
4
+ import {WebView} from 'react-native-webview';
5
+ import ScreenBackHeader from '../components/common/ScreenBackHeader';
6
+
7
+ const Index = ({navigation, route}) => {
8
+ return (
9
+ <View style={styles.container}>
10
+ <ScreenBackHeader title={route.params.title} />
11
+
12
+ <View style={styles.webviewContainer}>
13
+ <WebView
14
+ bounces={false}
15
+ domStorageEnabled
16
+ javaScriptEnabled
17
+ useWebKit
18
+ // onNavigationStateChange={val => {
19
+ // if (!val.loading && route?.params?.onNavigationStateChange) {
20
+ // route?.params?.onNavigationStateChange(val);
21
+ // }
22
+ // }}
23
+ source={{
24
+ uri: route.params.url,
25
+ }}
26
+ />
27
+ </View>
28
+ </View>
29
+ );
30
+ };
31
+
32
+ const styles = StyleSheet.create({
33
+ container: {
34
+ flex: 1,
35
+ },
36
+ webviewContainer: {
37
+ flex: 1,
38
+ },
39
+ });
40
+
41
+ export default Index;
@@ -0,0 +1,166 @@
1
+ import Storage from 'react-native-storage';
2
+ import AsyncStorage from '@react-native-async-storage/async-storage';
3
+ var storage = new Storage({
4
+ // 最大容量,默认值1000条数据循环存储
5
+ size: 100000,
6
+
7
+ // 存储引擎:对于RN使用AsyncStorage,对于web使用window.localStorage
8
+ // 如果不指定则数据只会保存在内存中,重启后即丢失
9
+ storageBackend: AsyncStorage,
10
+
11
+ // 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期
12
+ defaultExpires: null,
13
+
14
+ // 读写时在内存中缓存数据。默认启用。
15
+ enableCache: true,
16
+
17
+ // 如果storage中没有相应数据,或数据已过期,
18
+ // 则会调用相应的sync方法,无缝返回最新数据。
19
+ // sync方法的具体说明会在后文提到
20
+ // 你可以在构造函数这里就写好sync的方法
21
+ // 或是在任何时候,直接对storage.sync进行赋值修改
22
+ // 或是写到另一个文件里,这里require引入
23
+ /* sync: require('你可以另外写一个文件专门处理sync')*/
24
+ });
25
+
26
+ var local = {
27
+ /**
28
+ * 设置缓存
29
+ * @params key 必传 唯一标识
30
+ * @params data 数据 type:string || object
31
+ * @params expires 过期时间 不传默认永久 单位:ms
32
+ * @params id 非必传 标识
33
+ *
34
+ * */
35
+ set(key, data, expires, id) {
36
+ let setValue = JSON.stringify(data);
37
+ if (id) {
38
+ return storage.save({
39
+ key: key,
40
+ id: id,
41
+ data: setValue,
42
+ expires: expires ? expires : null,
43
+ });
44
+ } else {
45
+ return storage.save({
46
+ key: key,
47
+ data: setValue,
48
+ expires: expires ? expires : null,
49
+ });
50
+ }
51
+ },
52
+ /**
53
+ * 根据key 或者 key-id的到数据
54
+ * @params key 必传
55
+ * @params id 可为空
56
+ *
57
+ * */
58
+ get(key, id) {
59
+ if (id) {
60
+ return storage
61
+ .load({
62
+ key: key,
63
+ id: id,
64
+ })
65
+ .then(ret => {
66
+ return JSON.parse(ret);
67
+ })
68
+ .catch(err => {
69
+ /**
70
+ * 抛出错误
71
+ * 注释部分为抛出详细错误
72
+ * */
73
+ // throw err;
74
+ switch (err.name) {
75
+ case 'NotFoundError':
76
+ // throw err.message;
77
+ break;
78
+ case 'ExpiredError':
79
+ throw err.message;
80
+ break;
81
+ default:
82
+ throw '未知错误';
83
+ break;
84
+ }
85
+ });
86
+ } else {
87
+ return storage
88
+ .load({
89
+ key: key,
90
+ })
91
+ .then(ret => {
92
+ return JSON.parse(ret);
93
+ })
94
+ .catch(err => {
95
+ /**
96
+ * 抛出错误
97
+ * 注释部分为抛出详细错误
98
+ * */
99
+ // throw err;
100
+ switch (err.name) {
101
+ case 'NotFoundError':
102
+ // throw err.message;
103
+ break;
104
+ case 'ExpiredError':
105
+ throw err.message;
106
+ break;
107
+ default:
108
+ throw '未知错误';
109
+ break;
110
+ }
111
+ });
112
+ }
113
+ },
114
+ /**
115
+ * 删除单个数据
116
+ * key 必传
117
+ * @params key 删除kay所对应的数据,必传
118
+ *
119
+ * @params id 删除id对应的数据 若删除的数据中有id,则必传
120
+ */
121
+
122
+ remove(key, id) {
123
+ if (id) {
124
+ return storage.remove({
125
+ key: key,
126
+ id: id,
127
+ });
128
+ } else {
129
+ return storage.remove({
130
+ key: key,
131
+ });
132
+ }
133
+ },
134
+ /**
135
+ * 清空所有map,移除所有key-id数据(但会保留只有key的数据)
136
+ * 测试 刷新之后有效,所以应该是在退出app时执行的
137
+ * */
138
+ clearMaps() {
139
+ return storage.clearMap();
140
+ },
141
+ /**
142
+ * 清空某个key下的所有数据(仅key-id数据)
143
+ * @paramas key
144
+ * */
145
+ clearMapForKey(key) {
146
+ return storage.clearMapForKey(key);
147
+ },
148
+ /**
149
+ * 获取key下的 所有数据(仅key-id数据)
150
+ * */
151
+ getAllDataForKey(key) {
152
+ return storage.getAllDataForKey(key).then(ret => {
153
+ return ret;
154
+ });
155
+ },
156
+ /**
157
+ * 获取某个key下的所有ID(仅key-id数据)
158
+ * */
159
+ getIdsForKey(key) {
160
+ return storage.getIdsForKey(key).then(ids => {
161
+ return ids;
162
+ });
163
+ },
164
+ };
165
+
166
+ export default local;
@@ -0,0 +1,43 @@
1
+ class EventEmitter {
2
+ constructor() {
3
+ // 事件缓存列表
4
+ this._events = {};
5
+ }
6
+
7
+ // 订阅
8
+ on(name, cb) {
9
+ // 如果存在事件
10
+ if (this._events[name]) {
11
+ this._events[name].push(cb);
12
+ } else {
13
+ this._events[name] = [cb];
14
+ }
15
+ }
16
+
17
+ // 取消订阅
18
+ off(name, fn) {
19
+ let cbs = this._events[name];
20
+ if (cbs) {
21
+ if (!fn) {
22
+ this._events[name] = null;
23
+ } else {
24
+ const index = cbs.findIndex(cb => cb === fn);
25
+ if (index >= 0) {
26
+ cbs.splice(index, 1);
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ // 发布
33
+ emit(name, ...args) {
34
+ if (this._events[name]) {
35
+ let cbs = this._events[name].slice();
36
+ for (let cb of cbs) {
37
+ cb(...args);
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ export default EventEmitter;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import {StackActions} from '@react-navigation/native';
3
+
4
+ export const navigationRef = React.createRef();
5
+
6
+ export function navigate(...args) {
7
+ navigationRef.current?.navigate(...args);
8
+ }
9
+
10
+ export function replace(...args) {
11
+ navigationRef.current?.dispatch(StackActions.replace(...args));
12
+ }
13
+
14
+ export function getRootState(...args) {
15
+ return navigationRef.current?.getRootState(...args);
16
+ }
17
+
18
+ export function goBack() {
19
+ navigationRef.current?.goBack();
20
+ }
21
+
22
+ export function push(...args) {
23
+ navigationRef.current?.dispatch(StackActions.push(...args));
24
+ }
25
+
26
+ export function pop(...args) {
27
+ navigationRef.current?.dispatch(StackActions.pop(...args));
28
+ }
29
+
30
+ export function popToTop() {
31
+ navigationRef.current?.dispatch(StackActions.popToTop());
32
+ }