DrawerV4.js 13 KB

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