DrawerV2.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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 { BackButton, 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. import Dialog from '../../components/Dialog';
  17. import { Path, Svg } from 'react-native-svg';
  18. const DEBUG = app.debug && !app.product;
  19. export default DrawerV2 = ({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={28}
  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='#999'
  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"
  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. <MaterialIcons
  140. style={styles.icon}
  141. name="ev-station"
  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"
  166. color={textPrimary}
  167. size={24}/>
  168. <TextView style={styles.label}>{$t('drawer.topup')}</TextView>
  169. <Text style={styles.balanceText2}>{userInfo.creditStr}</Text>
  170. </Button></>
  171. }
  172. { (app.v3.vouchers && isLogin) &&
  173. <Button
  174. style={styles.itemButton}
  175. viewStyle={styles.itemView}
  176. onClick={() => startPage(PageList.myVoucher)}>
  177. <MaterialIcons
  178. style={styles.icon}
  179. name="discount"
  180. color={textPrimary}
  181. size={24}/>
  182. <TextView style={styles.label}>{$t('voucher.vouchers')}</TextView>
  183. <TextView
  184. style={styles.balanceText}
  185. fixedAlign={false}>
  186. <Text style={styles.balanceText2}>{sideCountInfo?.activeVoucherCount || 0}</Text> Active
  187. </TextView>
  188. </Button>
  189. }
  190. { (app.notifications.enable && isLogin) &&
  191. <Button
  192. style={styles.itemButton}
  193. viewStyle={styles.itemView}
  194. onClick={() => {
  195. startPage(PageList.notification);
  196. }}>
  197. <MaterialCommunityIcons
  198. style={styles.icon}
  199. name="bell-badge"
  200. color={textPrimary}
  201. size={24}/>
  202. <TextView style={styles.label}>{$t('route.notifications')}</TextView>
  203. <TextView
  204. style={styles.balanceText}
  205. fixedAlign={false}>
  206. <Text style={styles.balanceText2}>{sideCountInfo?.toBeReadCount || 0}</Text> Unread
  207. </TextView>
  208. </Button>
  209. }
  210. { (app.modules.bookmarks && isLogin) &&
  211. <Button
  212. style={styles.itemButton}
  213. viewStyle={styles.itemView}
  214. onClick={() => {
  215. startPage(PageList.bookmarks);
  216. }}>
  217. <MaterialCommunityIcons
  218. style={styles.icon}
  219. name="bookmark-check"
  220. color={textPrimary}
  221. size={24}/>
  222. <TextView style={styles.label}>{$t('route.bookmarks')}</TextView>
  223. <TextView
  224. style={styles.balanceText}
  225. fixedAlign={false}>
  226. <Text style={styles.balanceText2}>{sideCountInfo?.bookMarkCount || 0}</Text> Saved
  227. </TextView>
  228. </Button>
  229. }
  230. {/*附加功能-结束*/}
  231. { (app.modules.membership && isLogin) &&
  232. <Button
  233. style={styles.itemButton}
  234. viewStyle={styles.itemView}
  235. onClick={() => {
  236. startPage(PageList.membersList);
  237. }}>
  238. <Svg
  239. style={styles.icon}
  240. width={24}
  241. height={24}
  242. viewBox='0 0 24 24'>
  243. <Path
  244. fill={textPrimary}
  245. 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"/>
  246. </Svg>
  247. <TextView style={styles.label}>{$t('drawer.members')}</TextView>
  248. <TextView
  249. style={styles.balanceText}
  250. fixedAlign={false}>
  251. <Text style={styles.balanceText2}>{sideCountInfo?.membershipCount || 0}</Text> Active
  252. </TextView>
  253. </Button>
  254. }
  255. {/* <Button
  256. style={styles.itemButton}
  257. viewStyle={styles.itemView}
  258. onClick={() => {
  259. startPage(PageList.feedback);
  260. }}>
  261. <MaterialCommunityIcons
  262. style={styles.icon}
  263. name="message-alert-outline"
  264. color="#222"
  265. size={24}/>
  266. <TextView style={styles.label}>{$t('drawer.feedback')}</TextView>
  267. </Button> */}
  268. {/* <Button
  269. style={styles.itemButton}
  270. viewStyle={styles.itemView}
  271. onClick={() => {
  272. startPage(PageList.settings);
  273. }}>
  274. <MaterialIcons
  275. style={styles.icon}
  276. name="settings"
  277. color="#222"
  278. size={25}
  279. />
  280. <TextView style={styles.label}>{$t('drawer.settings')}</TextView>
  281. </Button> */}
  282. { app.modules.support &&
  283. <Button
  284. style={styles.itemButton}
  285. viewStyle={styles.itemView}
  286. onClick={() => {
  287. startPage(PageList.supportContact);
  288. }}>
  289. <MaterialCommunityIcons
  290. style={styles.icon}
  291. name="face-agent"
  292. color="#333"
  293. size={26}
  294. />
  295. <TextView style={styles.label}>{$t('drawer.contactSupport')}</TextView>
  296. </Button>
  297. }
  298. { DEBUG && <>
  299. <Button
  300. style={styles.itemButton}
  301. viewStyle={styles.itemView}
  302. onClick={() => {
  303. startPage(PageList.notify);
  304. }}>
  305. <MaterialCommunityIcons
  306. style={styles.icon}
  307. name="dev-to"
  308. color="#333"
  309. size={26}
  310. />
  311. <TextView style={styles.label}>{$t('route.notificationTest')}</TextView>
  312. </Button>
  313. <Button
  314. style={styles.itemButton}
  315. viewStyle={styles.itemView}
  316. onClick={() => {
  317. startPage(PageList.selectVoucher, {chargeBoxId: "LUMI-TEST", connectorId: 1});
  318. }}>
  319. <MaterialCommunityIcons
  320. style={styles.icon}
  321. name="dev-to"
  322. color="#333"
  323. size={26}
  324. />
  325. <TextView style={styles.label}>{"Test Page"}</TextView>
  326. </Button>
  327. </> }
  328. </View>
  329. );
  330. }
  331. const styles = StyleSheet.create({
  332. drawerView: {
  333. paddingTop: 8,
  334. paddingBottom: 8,
  335. },
  336. loginView: {
  337. paddingTop: 16,
  338. paddingBottom: 0
  339. },
  340. avatar: {
  341. width: 66,
  342. height: 66,
  343. marginLeft: 24,
  344. borderWidth: 2,
  345. borderRadius: 80,
  346. borderColor: colorLight,
  347. },
  348. closeMenu: {
  349. width: 46,
  350. height: 46,
  351. marginRight: 16,
  352. borderRadius: 46,
  353. alignItems: 'center',
  354. justifyContent: 'center',
  355. backgroundColor: colorPrimary
  356. },
  357. nickView: {
  358. borderRadius: 0,
  359. backgroundColor: colorLight
  360. },
  361. nickViewStyle: {
  362. flex: 1,
  363. alignItems: 'center',
  364. flexDirection: 'row',
  365. ...$padding(12, 16)
  366. },
  367. nickname: {
  368. flex: 1,
  369. color: textPrimary,
  370. fontSize: 20,
  371. fontWeight: 'bold',
  372. paddingLeft: 16,
  373. },
  374. emailText: {
  375. color: textPrimary,
  376. fontSize: 11,
  377. marginTop: -5,
  378. paddingLeft: 16,
  379. paddingBottom: 4
  380. },
  381. loginText: {
  382. flex: 1,
  383. color: textPrimary,
  384. fontSize: 20,
  385. fontWeight: 'bold',
  386. marginTop: 4,
  387. paddingTop: 4,
  388. paddingLeft: 16,
  389. paddingBottom: 4
  390. },
  391. divideLogin: {
  392. height: 4,
  393. marginTop: 2,
  394. marginRight: 0,
  395. marginBottom: 8,
  396. backgroundColor: colorPrimary
  397. },
  398. itemButton: {
  399. borderRadius: 0,
  400. backgroundColor: colorLight
  401. },
  402. itemView: {
  403. flex: 1,
  404. height: 48,
  405. paddingLeft: 16,
  406. marginBottom: 0,
  407. alignItems: 'center',
  408. flexDirection: 'row'
  409. },
  410. icon: {
  411. width: 24,
  412. height: 24,
  413. marginRight: 16
  414. },
  415. label: {
  416. flex: 1,
  417. color: textPrimary,
  418. fontSize: 14,
  419. },
  420. divided: {
  421. height: 1,
  422. marginTop: 24,
  423. marginLeft: 16,
  424. backgroundColor: colorAccent
  425. },
  426. balanceText: {
  427. color: textPrimary,
  428. fontSize: 14,
  429. marginRight: 20
  430. },
  431. balanceText2: {
  432. color: colorPrimary,
  433. fontSize: 14,
  434. marginRight: 20
  435. },
  436. bridgeText: {
  437. width: 20,
  438. height: 20,
  439. color: textLight,
  440. fontSize: 12,
  441. marginRight: 16,
  442. borderRadius: 30,
  443. fontWeight: 'bold',
  444. alignItems: 'center',
  445. flexDirection: 'row',
  446. justifyContent: 'center',
  447. backgroundColor: "#FF3B30"
  448. },
  449. bridgeText2: {
  450. width: 22,
  451. height: 22,
  452. color: textLight,
  453. fontSize: 10,
  454. marginRight: 16,
  455. borderRadius: 30,
  456. fontWeight: 'bold',
  457. alignItems: 'center',
  458. flexDirection: 'row',
  459. justifyContent: 'center',
  460. backgroundColor: "#FF3B30"
  461. }
  462. });