DrawerV2.js 13 KB

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