Drawer.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /**
  2. * 新版首页
  3. * @邠心vbe on 2024/02/01
  4. */
  5. import React from 'react';
  6. import {View, Text, StyleSheet, Image} from 'react-native';
  7. import app from '../../../app.json';
  8. import { PageList } from '../Router';
  9. import Button from '../../components/Button';
  10. import { Styles } from '../../components/Toolbar';
  11. import TextView from '../../components/TextView';
  12. import apiCharge from '../../api/apiCharge';
  13. import { TouchableWithoutFeedback } from 'react-native-gesture-handler';
  14. import { toTopupPage } from '../payment/PaymentConfig';
  15. import utils from '../../utils/utils';
  16. const DEBUG = app.debug && !app.product;
  17. export default DrawerView = ({isLogin=false, userInfo, onLogout, notificationCount=0, navigation}) => {
  18. const getCharging = () => {
  19. Dialog.showProgressDialog();
  20. apiCharge.getUserCharging().then(res => {
  21. Dialog.dismissLoading();
  22. if (res.data.sitePk) {
  23. utils.toChargeDetailPage(res.data.sitePk, 'view', PageList.home);
  24. //startPage(PageList.chargeDetailPage, {stationInfo: {id: res.data.sitePk}, action: 'view', from: PageList.home});
  25. //startPage(PageList.chargeDetail, { stationInfo: {id: res.data.sitePk}, action: 'view'});
  26. } else if (res.msg) {
  27. toastShort(res.msg);
  28. } else {
  29. toastShort($t("drawer.noChargingSession"));
  30. }
  31. }).catch((err) => {
  32. if (app.debug)
  33. console.log(err);
  34. Dialog.dismissLoading();
  35. toastShort($t("drawer.noChargingSession"));
  36. })
  37. }
  38. const logout = () => {
  39. Dialog.showDialog({
  40. title: $t('profile.signOut'),
  41. message: $t('profile.tipSignOut'),
  42. callback: btn => {
  43. if (btn == Dialog.BUTTON_OK) {
  44. Dialog.showProgressDialog();
  45. setTimeout(() => {
  46. if (onLogout) onLogout();
  47. }, 500);
  48. }
  49. }
  50. })
  51. }
  52. return (
  53. <View style={styles.drawerView}>
  54. <View style={styles.loginView}>
  55. { userInfo.photoUrl
  56. ? <TouchableWithoutFeedback onPress={() => startPage(PageList.profile)}>
  57. <Image
  58. style={styles.avatar}
  59. source={{uri: utils.getImageUrl(userInfo.photoUrl)}}/>
  60. </TouchableWithoutFeedback>
  61. : <TouchableWithoutFeedback onPress={() => startPage(isLogin ? PageList.profile : PageList.login)}>
  62. <Image
  63. style={styles.avatar}
  64. source={require('../../images/user/ic-avatar-default.png')}/>
  65. </TouchableWithoutFeedback>
  66. }
  67. <Button
  68. style={styles.nickView}
  69. viewStyle={styles.nickViewStyle}
  70. onClick={() => startPage(isLogin ? PageList.profile : PageList.login)}>
  71. <TextView
  72. style={styles.nickname}
  73. ellipsizeMode='tail'
  74. numberOfLines={1}>
  75. { isLogin
  76. ? userInfo.nickName
  77. ? userInfo.nickName
  78. : $t('drawer.logging')
  79. : $t('drawer.sign')
  80. }
  81. </TextView>
  82. <FontAwesome
  83. size={24}
  84. color='#999'
  85. name='angle-right'/>
  86. </Button>
  87. </View>
  88. <View style={styles.divideLogin}></View>
  89. { isLogin
  90. ? <Button
  91. style={styles.itemButton}
  92. viewStyle={styles.itemView}
  93. onClick={() => getCharging()}>
  94. <MaterialCommunityIcons
  95. style={styles.icon}
  96. name="car-electric-outline"
  97. color="#333"
  98. size={26}
  99. />
  100. {/* <Image
  101. style={styles.icon}
  102. source={require('../../images/icon/draw-charge.png')}/> */}
  103. <TextView style={styles.label}>{$t('drawer.charging')}</TextView>
  104. </Button>
  105. : <View
  106. style={styles.disableItem}>
  107. <MaterialCommunityIcons
  108. style={styles.icon}
  109. name="car-electric-outline"
  110. color="#999"
  111. size={26}
  112. />
  113. {/* <Image
  114. style={styles.icon}
  115. source={require('../../images/icon/draw-charge-no.png')}/> */}
  116. <TextView style={styles.disable}>{$t('drawer.charging')}</TextView>
  117. </View>
  118. }
  119. {
  120. isLogin && <>
  121. <Button
  122. style={styles.itemButton}
  123. viewStyle={styles.itemView}
  124. onClick={() => {
  125. startPage(PageList.wallet);
  126. }}>
  127. <Image
  128. style={styles.icon}
  129. source={require('../../images/icon/draw-transaction.png')}/>
  130. <TextView style={styles.label}>{$t('drawer.wallet')}</TextView>
  131. </Button>
  132. <Button
  133. style={styles.itemButton}
  134. viewStyle={styles.itemView}
  135. onClick={() => toTopupPage()}>
  136. <MaterialCommunityIcons
  137. style={styles.icon}
  138. size={26}
  139. name={"wallet-outline"}
  140. color={colorDark}/>
  141. <TextView style={styles.label}>{$t('drawer.topup')}</TextView>
  142. <Text style={styles.balanceText2}>{userInfo.creditStr}</Text>
  143. </Button></>
  144. }
  145. {/*附加功能-开始*/}
  146. { (app.notifications.enable && isLogin) &&
  147. <Button
  148. style={styles.itemButton}
  149. viewStyle={styles.itemView}
  150. onClick={() => {
  151. startPage(PageList.notification);
  152. }}>
  153. <MaterialIcons
  154. style={styles.icon}
  155. name="notifications"
  156. color="#222"
  157. size={26}/>
  158. <TextView style={styles.label}>{$t('route.notifications')}</TextView>
  159. { notificationCount > 0 && (
  160. notificationCount < 100
  161. ? <TextView
  162. style={styles.bridgeText}
  163. fixedAlign={false}>{notificationCount}</TextView>
  164. : <TextView
  165. style={styles.bridgeText2}
  166. fixedAlign={false}>99+</TextView>
  167. )
  168. }
  169. </Button>
  170. }
  171. { (app.modules.bookmarks && isLogin) &&
  172. <Button
  173. style={styles.itemButton}
  174. viewStyle={styles.itemView}
  175. onClick={() => {
  176. startPage(PageList.bookmarks);
  177. }}>
  178. <MaterialIcons
  179. style={styles.icon}
  180. name="stars"
  181. color="#222"
  182. size={26}/>
  183. <TextView style={styles.label}>{$t('route.bookmarks')}</TextView>
  184. </Button>
  185. }
  186. {/*附加功能-结束*/}
  187. { (app.modules.membership && isLogin) &&
  188. <Button
  189. style={styles.itemButton}
  190. viewStyle={styles.itemView}
  191. onClick={() => {
  192. startPage(PageList.membersList);
  193. }}>
  194. <MaterialIcons
  195. style={styles.icon}
  196. name="card-membership"
  197. color="#222"
  198. size={26}/>
  199. <TextView style={styles.label}>{$t('drawer.members')}</TextView>
  200. </Button>
  201. }
  202. <Button
  203. style={styles.itemButton}
  204. viewStyle={styles.itemView}
  205. onClick={() => {
  206. startPage(PageList.feedback);
  207. }}>
  208. <MaterialCommunityIcons
  209. style={styles.icon2}
  210. name="message-alert-outline"
  211. color="#222"
  212. size={24}/>
  213. <TextView style={styles.label}>{$t('drawer.feedback')}</TextView>
  214. </Button>
  215. {/* <Button
  216. style={styles.itemButton}
  217. viewStyle={styles.itemView}
  218. onClick={() => {
  219. Linking.openURL(host+"juicePicture/pdf/FAQ.v1.0.pdf")
  220. }}>
  221. <Feather
  222. style={styles.icon2}
  223. name="download"
  224. color={colorDark}
  225. size={24}
  226. />
  227. <Text style={styles.label}>FAQs</Text>
  228. </Button> */}
  229. <Button
  230. style={styles.itemButton}
  231. viewStyle={styles.itemView}
  232. onClick={() => {
  233. startPage(PageList.settings);
  234. }}>
  235. <MaterialIcons
  236. style={styles.icon}
  237. name="settings"
  238. color="#222"
  239. size={25}
  240. />
  241. <TextView style={styles.label}>{$t('drawer.settings')}</TextView>
  242. </Button>
  243. { app.modules.support &&
  244. <Button
  245. style={styles.itemButton}
  246. viewStyle={styles.itemView}
  247. onClick={() => {
  248. startPage(PageList.supportContact);
  249. }}>
  250. <MaterialCommunityIcons
  251. style={styles.icon}
  252. name="face-agent"
  253. color="#333"
  254. size={26}
  255. />
  256. <TextView style={styles.label}>{$t('drawer.contactSupport')}</TextView>
  257. </Button>
  258. }
  259. <Button
  260. style={styles.itemButton}
  261. viewStyle={styles.itemView}
  262. onClick={() => {
  263. startPage(PageList.about);
  264. }}>
  265. <MaterialCommunityIcons
  266. style={styles.icon}
  267. name="information-outline"
  268. color="#333"
  269. size={26}
  270. />
  271. <TextView style={styles.label}>{$t('drawer.about')}</TextView>
  272. </Button>
  273. {/* <View style={styles.divided}></View> */}
  274. { DEBUG &&
  275. <>
  276. <View style={styles.divideLogin}></View>
  277. <TextView style={{color: "#ccc", paddingLeft: 16, paddingBottom: 8, fontSize: 12}}>{$t('drawer.debugOnly')}</TextView>
  278. <Button
  279. style={styles.itemButton}
  280. viewStyle={styles.itemView}
  281. onClick={() => {
  282. startPage(PageList.privacy);
  283. }}>
  284. <MaterialCommunityIcons
  285. style={styles.icon}
  286. name="file-eye-outline"
  287. color="#222"
  288. size={26}/>
  289. <TextView style={styles.label}>{$t('drawer.privacyPolicy')}</TextView>
  290. </Button>
  291. <Button
  292. style={styles.itemButton}
  293. viewStyle={styles.itemView}
  294. onClick={() => {
  295. startPage(PageList.condition);
  296. }}>
  297. <MaterialCommunityIcons
  298. style={styles.icon}
  299. name="file-eye-outline"
  300. color="#222"
  301. size={26}/>
  302. <TextView style={styles.label}>{$t('drawer.termsOfUse')}</TextView>
  303. </Button>
  304. <Button
  305. style={styles.itemButton}
  306. viewStyle={styles.itemView}
  307. onClick={() => {
  308. startPage(PageList.notify);
  309. }}>
  310. {/* <Image
  311. style={styles.icon2}
  312. source={require('../../images/icon/draw-terms.png')}/> */}
  313. <MaterialIcons
  314. style={styles.icon}
  315. name="notifications-none"
  316. color="#222"
  317. size={26}/>
  318. <TextView style={styles.label}>{$t('route.notificationTest')}</TextView>
  319. </Button>
  320. <Button
  321. style={styles.itemButton}
  322. viewStyle={styles.itemView}
  323. onClick={() => {
  324. startPage(isIOS ? PageList.notify : PageList.mapTest);
  325. }}>
  326. <MaterialCommunityIcons
  327. style={styles.icon}
  328. name="map-legend"
  329. color="#222"
  330. size={26}/>
  331. <TextView style={styles.label}>{$t('drawer.mapsTest')}</TextView>
  332. </Button>
  333. </>}
  334. {/* isLogin
  335. ? <View style={styles.walletView}>
  336. <Pressable
  337. style={styles.balanceView}
  338. android_ripple={ripple}
  339. onPress={() => toTopupPage()}>
  340. <Image
  341. style={styles.icon}
  342. source={require('../../images/icon/draw-wallet.png')}/>
  343. <Text style={styles.balanceText}>{currency}{userInfo.credit}</Text>
  344. </Pressable>
  345. {/* <Pressable
  346. style={styles.balanceView}
  347. android_ripple={ripple}
  348. onPress={() => {
  349. startPage(PageList.referral);
  350. }}>
  351. <Image
  352. style={styles.icon}
  353. source={require('../../images/icon/draw-gift.png')}/>
  354. <Text style={styles.referText}>Refer your friends to get $5 credit!</Text>
  355. </Pressable> *}
  356. </View>
  357. : <View style={ui.flex1}></View>s
  358. */}
  359. <View style={styles.bottomView}>
  360. <Image
  361. style={Styles.logo}
  362. resizeMode='contain'
  363. source={require('../../images/drawer-logo.png')}
  364. />
  365. <Text style={styles.versionText}>{app.displayName + ' ' + app.versionName}</Text>
  366. </View>
  367. {/* isLogin &&
  368. <Button
  369. style={styles.logoutView}
  370. text='Logout'
  371. textColor={textButton}
  372. borderRadius={0}
  373. onClick={() => logout()}/>
  374. */}
  375. </View>
  376. );
  377. }
  378. const styles = StyleSheet.create({
  379. drawerTop: {
  380. top: 0,
  381. left: 0,
  382. right: 0,
  383. height: statusHeight,
  384. position: 'absolute',
  385. fontSize: 10,
  386. backgroundColor: pageBackground
  387. },
  388. drawerView: {
  389. paddingTop: 16,
  390. paddingBottom: 8,
  391. minHeight: $vhs(101)
  392. },
  393. guessView: {
  394. padding: 16
  395. },
  396. loginView: {
  397. paddingTop: 16,
  398. paddingBottom: 4
  399. },
  400. avatar: {
  401. width: 66,
  402. height: 66,
  403. marginLeft: 24,
  404. borderWidth: 2,
  405. borderRadius: 80,
  406. borderColor: colorLight,
  407. },
  408. nickView: {
  409. marginTop: 6,
  410. borderRadius: 0,
  411. backgroundColor: colorLight
  412. },
  413. nickViewStyle: {
  414. flex: 1,
  415. alignItems: 'center',
  416. flexDirection: 'row',
  417. ...$padding(12, 24, 12, 16),
  418. },
  419. nickname: {
  420. flex: 1,
  421. color: textPrimary,
  422. fontSize: 20,
  423. fontWeight: 'bold',
  424. paddingLeft: 16,
  425. },
  426. divideLogin: {
  427. height: 1,
  428. marginTop: 4,
  429. marginRight: 22,
  430. marginBottom: 12,
  431. backgroundColor: '#E5E5E5'
  432. },
  433. itemButton: {
  434. borderRadius: 0,
  435. backgroundColor: colorLight
  436. },
  437. itemView: {
  438. flex: 1,
  439. height: 56,
  440. paddingLeft: 16,
  441. marginBottom: 6,
  442. alignItems: 'center',
  443. flexDirection: 'row'
  444. },
  445. disableItem: {
  446. height: 56,
  447. paddingLeft: 16,
  448. marginBottom: 6,
  449. alignItems: 'center',
  450. flexDirection: 'row'
  451. },
  452. icon: {
  453. width: 26,
  454. height: 26,
  455. marginRight: 16
  456. },
  457. icon2: {
  458. width: 24,
  459. height: 24,
  460. marginLeft: 1,
  461. marginRight: 17
  462. },
  463. label: {
  464. flex: 1,
  465. color: textPrimary,
  466. fontSize: 16,
  467. },
  468. disable: {
  469. color: '#999',
  470. fontSize: 18
  471. },
  472. divided: {
  473. height: 1,
  474. marginTop: 24,
  475. marginLeft: 16,
  476. backgroundColor: colorAccent
  477. },
  478. walletView: {
  479. paddingTop: 16,
  480. paddingLeft: 48,
  481. paddingRight: 48
  482. },
  483. balanceView: {
  484. marginTop: 16,
  485. borderRadius: 8,
  486. ...$padding(13, 22),
  487. alignItems: 'center',
  488. flexDirection: 'row',
  489. justifyContent: 'center',
  490. backgroundColor: 'rgba(0, 20, 137, 0.2)'
  491. },
  492. balanceText: {
  493. color: textPrimary,
  494. fontSize: 22,
  495. fontWeight: 'bold'
  496. },
  497. referText: {
  498. flex: 1,
  499. color: textPrimary,
  500. fontSize: 13
  501. },
  502. bottomView: {
  503. flex: 1,
  504. paddingTop: 48,
  505. paddingBottom: 0,
  506. alignItems: 'center',
  507. justifyContent: 'flex-end'
  508. },
  509. versionText: {
  510. color: textPrimary,
  511. fontSize: 10,
  512. paddingTop: 16
  513. },
  514. logoutView: {
  515. backgroundColor: colorPrimary
  516. },
  517. balanceText2: {
  518. color: textCancel,
  519. fontSize: 14,
  520. marginRight: 20
  521. },
  522. bridgeText: {
  523. width: 20,
  524. height: 20,
  525. color: textLight,
  526. fontSize: 12,
  527. marginRight: 16,
  528. borderRadius: 30,
  529. fontWeight: 'bold',
  530. alignItems: 'center',
  531. flexDirection: 'row',
  532. justifyContent: 'center',
  533. backgroundColor: "#FF3B30"
  534. },
  535. bridgeText2: {
  536. width: 22,
  537. height: 22,
  538. color: textLight,
  539. fontSize: 10,
  540. marginRight: 16,
  541. borderRadius: 30,
  542. fontWeight: 'bold',
  543. alignItems: 'center',
  544. flexDirection: 'row',
  545. justifyContent: 'center',
  546. backgroundColor: "#FF3B30"
  547. }
  548. });