Drawer.js 15 KB

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