DrawerV2.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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={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='#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.notifications.enable && 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. { DEBUG && <>
  280. <Button
  281. style={styles.itemButton}
  282. viewStyle={styles.itemView}
  283. onClick={() => {
  284. startPage(PageList.notify);
  285. }}>
  286. <MaterialCommunityIcons
  287. style={styles.icon}
  288. name="dev-to"
  289. color="#333"
  290. size={26}
  291. />
  292. <TextView style={styles.label}>{$t('route.notificationTest')}</TextView>
  293. </Button>
  294. <Button
  295. style={styles.itemButton}
  296. viewStyle={styles.itemView}
  297. onClick={() => {
  298. startPage(PageList.paymentWeb);
  299. }}>
  300. <MaterialCommunityIcons
  301. style={styles.icon}
  302. name="dev-to"
  303. color="#333"
  304. size={26}
  305. />
  306. <TextView style={styles.label}>{"Test Page"}</TextView>
  307. </Button>
  308. </> }
  309. </View>
  310. );
  311. }
  312. const styles = StyleSheet.create({
  313. drawerView: {
  314. paddingTop: 8,
  315. paddingBottom: 8,
  316. },
  317. loginView: {
  318. paddingTop: 16,
  319. paddingBottom: 0
  320. },
  321. avatar: {
  322. width: 66,
  323. height: 66,
  324. marginLeft: 24,
  325. borderWidth: 2,
  326. borderRadius: 80,
  327. borderColor: colorLight,
  328. },
  329. closeMenu: {
  330. width: 46,
  331. height: 46,
  332. marginRight: 16,
  333. borderRadius: 46,
  334. alignItems: 'center',
  335. justifyContent: 'center',
  336. backgroundColor: colorPrimary
  337. },
  338. nickView: {
  339. borderRadius: 0,
  340. backgroundColor: colorLight
  341. },
  342. nickViewStyle: {
  343. flex: 1,
  344. alignItems: 'center',
  345. flexDirection: 'row',
  346. ...$padding(12, 16)
  347. },
  348. nickname: {
  349. flex: 1,
  350. color: textPrimary,
  351. fontSize: 20,
  352. fontWeight: 'bold',
  353. paddingLeft: 16,
  354. },
  355. emailText: {
  356. color: textPrimary,
  357. fontSize: 11,
  358. marginTop: -5,
  359. paddingLeft: 16,
  360. paddingBottom: 4
  361. },
  362. loginText: {
  363. flex: 1,
  364. color: textPrimary,
  365. fontSize: 20,
  366. fontWeight: 'bold',
  367. marginTop: 4,
  368. paddingTop: 4,
  369. paddingLeft: 16,
  370. paddingBottom: 4
  371. },
  372. divideLogin: {
  373. height: 4,
  374. marginTop: 2,
  375. marginRight: 0,
  376. marginBottom: 8,
  377. backgroundColor: colorPrimary
  378. },
  379. itemButton: {
  380. borderRadius: 0,
  381. backgroundColor: colorLight
  382. },
  383. itemView: {
  384. flex: 1,
  385. height: 48,
  386. paddingLeft: 16,
  387. marginBottom: 0,
  388. alignItems: 'center',
  389. flexDirection: 'row'
  390. },
  391. icon: {
  392. width: 24,
  393. height: 24,
  394. marginRight: 16
  395. },
  396. label: {
  397. flex: 1,
  398. color: textPrimary,
  399. fontSize: 14,
  400. },
  401. divided: {
  402. height: 1,
  403. marginTop: 24,
  404. marginLeft: 16,
  405. backgroundColor: colorAccent
  406. },
  407. balanceText: {
  408. color: textPrimary,
  409. fontSize: 14,
  410. marginRight: 20
  411. },
  412. balanceText2: {
  413. color: colorPrimary,
  414. fontSize: 14,
  415. marginRight: 20
  416. },
  417. bridgeText: {
  418. width: 20,
  419. height: 20,
  420. color: textLight,
  421. fontSize: 12,
  422. marginRight: 16,
  423. borderRadius: 30,
  424. fontWeight: 'bold',
  425. alignItems: 'center',
  426. flexDirection: 'row',
  427. justifyContent: 'center',
  428. backgroundColor: "#FF3B30"
  429. },
  430. bridgeText2: {
  431. width: 22,
  432. height: 22,
  433. color: textLight,
  434. fontSize: 10,
  435. marginRight: 16,
  436. borderRadius: 30,
  437. fontWeight: 'bold',
  438. alignItems: 'center',
  439. flexDirection: 'row',
  440. justifyContent: 'center',
  441. backgroundColor: "#FF3B30"
  442. }
  443. });