DrawerV2.js 12 KB

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