DrawerV3.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /**
  2. * 新版首页抽屉菜单
  3. * @邠心vbe on 2024/02/01
  4. */
  5. import React from 'react';
  6. import { Path, Svg } from 'react-native-svg';
  7. import { Image, StyleSheet, Text, View } from 'react-native';
  8. import { TouchableWithoutFeedback } from 'react-native-gesture-handler';
  9. import app from '../../../app.json';
  10. import { PageList } from '../Router';
  11. import utils from '../../utils/utils';
  12. import apiCharge from '../../api/apiCharge';
  13. import Button from '../../components/Button';
  14. import Dialog from '../../components/Dialog';
  15. import TextView from '../../components/TextView';
  16. import { BackButton } from '../../components/Toolbar';
  17. import { toTopupPage } from '../payment/PaymentConfig';
  18. const DEBUG = app.debug && !app.product;
  19. export default DrawerV3 = ({isLogin=false, userInfo, onLogout, sideCountInfo={}, navigation}) => {
  20. const getCharging = () => {
  21. Dialog.showProgressDialog();
  22. apiCharge.getUserCharging().then(res => {
  23. Dialog.dismissLoading();
  24. if (res.data.sitePk) {
  25. utils.toChargeDetailPage(res.data.sitePk, 'view', PageList.home);
  26. //startPage(PageList.chargeDetailPage, {stationInfo: {id: res.data.sitePk}, action: 'view', from: PageList.home});
  27. //startPage(PageList.chargeDetail, { stationInfo: {id: res.data.sitePk}, action: 'view'});
  28. } else if (res.msg) {
  29. toastShort(res.msg);
  30. } else {
  31. toastShort($t("drawer.noChargingSession"));
  32. }
  33. }).catch((err) => {
  34. if (app.debug)
  35. console.log(err);
  36. Dialog.dismissLoading();
  37. toastShort($t("drawer.noChargingSession"));
  38. })
  39. }
  40. const logout = () => {
  41. Dialog.showDialog({
  42. title: $t('profile.signOut'),
  43. message: $t('profile.tipSignOut'),
  44. callback: btn => {
  45. if (btn == Dialog.BUTTON_OK) {
  46. Dialog.showProgressDialog();
  47. setTimeout(() => {
  48. if (onLogout) onLogout();
  49. }, 500);
  50. }
  51. }
  52. })
  53. }
  54. return (
  55. <View style={styles.drawerView}>
  56. <View style={styles.loginView}>
  57. {/* <View style={ui.flexcw}>
  58. { (isLogin && userInfo.photoUrl)
  59. ? <TouchableWithoutFeedback>
  60. <Image
  61. style={styles.avatar}
  62. source={{uri: utils.getImageUrl(userInfo.photoUrl)}}/>
  63. </TouchableWithoutFeedback>
  64. : <TouchableWithoutFeedback>
  65. <Image
  66. style={styles.avatar}
  67. source={require('../../images/user/ic-avatar-default.png')}/>
  68. </TouchableWithoutFeedback>
  69. }
  70. <BackButton
  71. style={styles.closeMenu}
  72. onPress={() => navigation?.toggleDrawer()}>
  73. <MaterialIcons
  74. name="menu-open"
  75. size={24}
  76. color={colorLight}/>
  77. </BackButton>
  78. </View> */}
  79. { isLogin
  80. ? <View
  81. style={styles.nickViewStyle}>
  82. <View style={ui.flex1}>
  83. <TextView
  84. style={styles.nickname}
  85. ellipsizeMode='tail'
  86. numberOfLines={1}>
  87. { userInfo.nickName
  88. ? userInfo.nickName
  89. : $t('drawer.logging')
  90. }
  91. </TextView>
  92. <TextView
  93. style={styles.emailText}
  94. ellipsizeMode='tail'
  95. numberOfLines={1}>{userInfo.email}</TextView>
  96. </View>
  97. <BackButton
  98. onPress={logout}>
  99. <MaterialIcons
  100. size={26}
  101. color={textPrimary}
  102. name='exit-to-app'/>
  103. </BackButton>
  104. </View>
  105. : <Button
  106. style={styles.nickView}
  107. viewStyle={styles.nickViewStyle}
  108. onClick={() => startPage(PageList.login)}>
  109. <TextView
  110. style={styles.loginText}
  111. ellipsizeMode='tail'
  112. numberOfLines={1}>
  113. {$t('drawer.sign')}
  114. </TextView>
  115. <FontAwesome
  116. size={24}
  117. color={textPrimary}
  118. name='angle-right'/>
  119. </Button>
  120. }
  121. </View>
  122. <View style={styles.divideLogin}></View>
  123. { isLogin && <>
  124. <Button
  125. style={styles.itemButton}
  126. viewStyle={styles.itemView}
  127. onClick={() => startPage(app.isLumiWhitelabel ? PageList.profileV3 : PageList.profile)}>
  128. <MaterialCommunityIcons
  129. style={styles.icon}
  130. name="account-circle-outline"
  131. color={textPrimary}
  132. size={24}/>
  133. <TextView style={styles.label}>{$t('route.profileSettings')}</TextView>
  134. </Button>
  135. <Button
  136. style={styles.itemButton}
  137. viewStyle={styles.itemView}
  138. onClick={() => getCharging()}>
  139. <MaterialCommunityIcons
  140. style={styles.icon}
  141. name="gas-station-outline"
  142. color={textPrimary}
  143. size={24}/>
  144. <TextView style={styles.label}>{$t('drawer.charging')}</TextView>
  145. </Button>
  146. <Button
  147. style={styles.itemButton}
  148. viewStyle={styles.itemView}
  149. onClick={() => {
  150. startPage(app.isLumiWhitelabel ? PageList.transaction : PageList.wallet);
  151. }}>
  152. <MaterialCommunityIcons
  153. style={styles.icon}
  154. name="finance"
  155. color={textPrimary}
  156. size={24}/>
  157. <TextView style={styles.label}>{$t('drawer.wallet')}</TextView>
  158. </Button>
  159. <Button
  160. style={styles.itemButton}
  161. viewStyle={styles.itemView}
  162. onClick={() => toTopupPage()}>
  163. <MaterialCommunityIcons
  164. style={styles.icon}
  165. name="wallet-plus-outline"
  166. color={textPrimary}
  167. size={24}/>
  168. <TextView style={styles.label}>{'Wallet'}</TextView>
  169. <Text style={styles.balanceText2}>{userInfo.creditStr}</Text>
  170. </Button>
  171. </>
  172. }
  173. { (app.v3.vouchers && isLogin) &&
  174. <Button
  175. style={styles.itemButton}
  176. viewStyle={styles.itemView}
  177. onClick={() => startPage(PageList.myVoucher)}>
  178. <MaterialCommunityIcons
  179. style={styles.icon}
  180. name="ticket-percent-outline"
  181. color={textPrimary}
  182. size={24}/>
  183. <TextView style={styles.label}>{$t('voucher.vouchers')}</TextView>
  184. <TextView
  185. style={styles.balanceText}
  186. fixedAlign={false}>
  187. <Text style={styles.balanceText2}>{sideCountInfo?.activeVoucherCount || 0}</Text> Active
  188. </TextView>
  189. </Button>
  190. }
  191. { (app.notifications.enable && isLogin) &&
  192. <Button
  193. style={styles.itemButton}
  194. viewStyle={styles.itemView}
  195. onClick={() => {
  196. startPage(PageList.notification);
  197. }}>
  198. <MaterialCommunityIcons
  199. style={styles.icon}
  200. name="bell-badge-outline"
  201. color={textPrimary}
  202. size={24}/>
  203. <TextView style={styles.label}>{$t('route.notifications')}</TextView>
  204. <TextView
  205. style={styles.balanceText}
  206. fixedAlign={false}>
  207. <Text style={styles.balanceText2}>{sideCountInfo?.toBeReadCount || 0}</Text> Unread
  208. </TextView>
  209. </Button>
  210. }
  211. { (app.modules.bookmarks && isLogin) &&
  212. <Button
  213. style={styles.itemButton}
  214. viewStyle={styles.itemView}
  215. onClick={() => {
  216. startPage(PageList.bookmarks);
  217. }}>
  218. <MaterialCommunityIcons
  219. style={styles.icon}
  220. name="bookmark-check-outline"
  221. color={textPrimary}
  222. size={24}/>
  223. <TextView style={styles.label}>{$t('route.bookmarks')}</TextView>
  224. <TextView
  225. style={styles.balanceText}
  226. fixedAlign={false}>
  227. <Text style={styles.balanceText2}>{sideCountInfo?.bookMarkCount || 0}</Text> Saved
  228. </TextView>
  229. </Button>
  230. }
  231. {/*附加功能-结束*/}
  232. { (app.modules.membership && isLogin) &&
  233. <Button
  234. style={styles.itemButton}
  235. viewStyle={styles.itemView}
  236. onClick={() => {
  237. startPage(PageList.membersList);
  238. }}>
  239. <Svg
  240. style={styles.icon}
  241. width={24}
  242. height={24}
  243. viewBox='0 0 24 24'>
  244. <Path
  245. fill={textPrimary}
  246. d="M7 4C4.8 4 3 5.8 3 8C3 10.2 4.8 12 7 12C9.2 12 11 10.2 11 8C11 5.8 9.2 4 7 4ZM7 10C5.9 10 5 9.1 5 8C5 6.9 5.9 6 7 6C8.1 6 9 6.9 9 8C9 9.1 8.1 10 7 10ZM0 18C0 15.8 3.1 14 7 14C8.5 14 9.9 14.3 11 14.7V17C10.2 16.5 8.8 16 7 16C3.8 16 2 17.4 2 18H11V20H0V18ZM22 4H15C13.9 4 13 4.9 13 6V18C13 19.1 13.9 20 15 20H22C23.1 20 24 19.1 24 18V6C24 4.9 23.1 4 22 4ZM22 18H15V6H22V18Z"/>
  247. </Svg>
  248. <TextView style={styles.label}>{$t('drawer.members')}</TextView>
  249. <TextView
  250. style={styles.balanceText}
  251. fixedAlign={false}>
  252. <Text style={styles.balanceText2}>{sideCountInfo?.membershipCount || 0}</Text> Active
  253. </TextView>
  254. </Button>
  255. }
  256. {/* <Button
  257. style={styles.itemButton}
  258. viewStyle={styles.itemView}
  259. onClick={() => {
  260. startPage(PageList.feedback);
  261. }}>
  262. <MaterialCommunityIcons
  263. style={styles.icon}
  264. name="message-alert-outline"
  265. color="#222"
  266. size={24}/>
  267. <TextView style={styles.label}>{$t('drawer.feedback')}</TextView>
  268. </Button> */}
  269. {/* <Button
  270. style={styles.itemButton}
  271. viewStyle={styles.itemView}
  272. onClick={() => {
  273. startPage(PageList.settings);
  274. }}>
  275. <MaterialIcons
  276. style={styles.icon}
  277. name="settings"
  278. color="#222"
  279. size={25}
  280. />
  281. <TextView style={styles.label}>{$t('drawer.settings')}</TextView>
  282. </Button> */}
  283. { app.modules.support &&
  284. <Button
  285. style={styles.itemButton}
  286. viewStyle={styles.itemView}
  287. onClick={() => {
  288. startPage(PageList.supportContact);
  289. }}>
  290. <MaterialCommunityIcons
  291. style={styles.icon}
  292. name="face-agent"
  293. color="#333"
  294. size={26}
  295. />
  296. <TextView style={styles.label}>{$t('drawer.contactSupport')}</TextView>
  297. </Button>
  298. }
  299. { DEBUG && <>
  300. <Button
  301. style={styles.itemButton}
  302. viewStyle={styles.itemView}
  303. onClick={() => {
  304. startPage(PageList.notify);
  305. }}>
  306. <MaterialCommunityIcons
  307. style={styles.icon}
  308. name="dev-to"
  309. color="#333"
  310. size={26}
  311. />
  312. <TextView style={styles.label}>{$t('route.notificationTest')}</TextView>
  313. </Button>
  314. <Button
  315. style={styles.itemButton}
  316. viewStyle={styles.itemView}
  317. onClick={() => {
  318. startPage(PageList.selectVoucher, {chargeBoxId: "LUMI-TEST", connectorId: 1});
  319. }}>
  320. <MaterialCommunityIcons
  321. style={styles.icon}
  322. name="dev-to"
  323. color="#333"
  324. size={26}
  325. />
  326. <TextView style={styles.label}>{"Test Page"}</TextView>
  327. </Button>
  328. </> }
  329. </View>
  330. );
  331. }
  332. const styles = StyleSheet.create({
  333. drawerView: {
  334. paddingTop: 8,
  335. paddingBottom: 8,
  336. },
  337. loginView: {
  338. paddingTop: 0,
  339. paddingBottom: 0,
  340. backgroundColor: colorLight
  341. },
  342. avatar: {
  343. width: 60,
  344. height: 60,
  345. marginLeft: 24,
  346. borderWidth: 2,
  347. borderRadius: 80,
  348. borderColor: colorPrimary,
  349. },
  350. closeMenu: {
  351. width: 40,
  352. height: 40,
  353. marginRight: 16,
  354. borderRadius: 40,
  355. alignItems: 'center',
  356. justifyContent: 'center',
  357. backgroundColor: colorPrimary
  358. },
  359. nickView: {
  360. marginTop: 2,
  361. borderRadius: 0,
  362. backgroundColor: colorLight
  363. },
  364. nickViewStyle: {
  365. flex: 1,
  366. alignItems: 'center',
  367. flexDirection: 'row',
  368. ...$padding(0, 4, 10)
  369. },
  370. nickname: {
  371. flex: 1,
  372. color: textPrimary,
  373. fontSize: 20,
  374. fontWeight: 'bold',
  375. paddingLeft: 16,
  376. },
  377. emailText: {
  378. color: textPrimary,
  379. fontSize: 10,
  380. marginTop: -5,
  381. paddingLeft: 16,
  382. paddingBottom: 4
  383. },
  384. loginText: {
  385. flex: 1,
  386. color: textPrimary,
  387. fontSize: 18,
  388. fontWeight: 'bold',
  389. marginTop: 4,
  390. paddingTop: 4,
  391. paddingLeft: 16,
  392. paddingBottom: 4,
  393. textTransform: 'uppercase'
  394. },
  395. divideLogin: {
  396. height: 8,
  397. marginTop: 2,
  398. marginRight: 0,
  399. marginBottom: 8,
  400. backgroundColor: colorPrimary
  401. },
  402. itemButton: {
  403. borderRadius: 0,
  404. backgroundColor: colorLight
  405. },
  406. itemView: {
  407. flex: 1,
  408. height: 48,
  409. paddingLeft: 16,
  410. marginBottom: 0,
  411. alignItems: 'center',
  412. flexDirection: 'row'
  413. },
  414. icon: {
  415. width: 24,
  416. height: 24,
  417. marginRight: 16
  418. },
  419. label: {
  420. flex: 1,
  421. color: textPrimary,
  422. fontSize: 14
  423. },
  424. divided: {
  425. height: 1,
  426. marginTop: 24,
  427. marginLeft: 16,
  428. backgroundColor: colorAccent
  429. },
  430. balanceText: {
  431. color: textPrimary,
  432. fontSize: 14,
  433. marginRight: 20
  434. },
  435. balanceText2: {
  436. color: colorPrimary,
  437. fontSize: 14,
  438. fontWeight: 'bold',
  439. marginRight: 20
  440. },
  441. bridgeText: {
  442. width: 20,
  443. height: 20,
  444. color: textLight,
  445. fontSize: 12,
  446. marginRight: 16,
  447. borderRadius: 30,
  448. fontWeight: 'bold',
  449. alignItems: 'center',
  450. flexDirection: 'row',
  451. justifyContent: 'center',
  452. backgroundColor: "#FF3B30"
  453. },
  454. bridgeText2: {
  455. width: 22,
  456. height: 22,
  457. color: textLight,
  458. fontSize: 10,
  459. marginRight: 16,
  460. borderRadius: 30,
  461. fontWeight: 'bold',
  462. alignItems: 'center',
  463. flexDirection: 'row',
  464. justifyContent: 'center',
  465. backgroundColor: "#FF3B30"
  466. }
  467. });