DrawerV2.js 12 KB

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