Router.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /**
  2. * 路由配置文件
  3. * @邠心vbe on 2021/03/22
  4. */
  5. import React, { useEffect, useRef } from 'react';
  6. import { Pressable } from 'react-native';
  7. import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
  8. import { createStackNavigator, TransitionPresets } from '@react-navigation/stack';
  9. import { enableScreens } from 'react-native-screens';
  10. import Toolbar, { BackButton, Styles } from '../components/Toolbar';
  11. import app from '../../app.json';
  12. import About from './about/AboutV2';
  13. import Launcher from './Launch';
  14. import Login from './sign/Login';
  15. import Regist from './sign/RegisterV2';
  16. import RegisterV3 from './sign/RegisterV3';
  17. import RegisterV4 from './sign/RegisterV4';
  18. import RegisterPublic from './sign/RegisterPublic';
  19. import RegisterDriver from './sign/RegisterDriver';
  20. import Home from './home/Index';
  21. import Search from './search/SearchV2';
  22. import SearchV3 from './search/SearchV3';
  23. import ChargeDetails from './charge/Details';
  24. import QRScan from './charge/QRScan';
  25. import Feedback from './my/Feedback';
  26. import Privacy from './my/Privacy';
  27. import Profile from './my/ProfileV2';
  28. import ProfileV3 from './my/ProfileV3';
  29. import Condition from './my/Condition';
  30. import Summary from './chargeV2/SummaryV2';
  31. import SummaryV3 from './chargeV2/SummaryV3';
  32. import Rating from './charge/Rating';
  33. import Wallet from './wallet/Wallet';
  34. import EditProfile from './my/EditProfile';
  35. import Referral from './my/Referral';
  36. import Topup from './wallet/Topup'; //not 2C2P
  37. import TopupV2 from './wallet/TopupV2'; //2C2P payment
  38. import TopupNew from './wallet/TopupNew';
  39. import AddCard from './wallet/AddCard';
  40. import FormCard from './payment/FormCard';
  41. import VehicleList from './vehicles/VehicleList';
  42. import AddVehicle from './vehicles/AddVehicle';
  43. import EditVehicle from './vehicles/EditVehicle';
  44. import VehicleDetail from './vehicles/VehicleDetail';
  45. import PayNow from './payment/PayNow';
  46. import CreditCard from './payment/CreditCard';
  47. import EditAddress from './my/EditAddress';
  48. import Notify from './home/Notify';
  49. import Test from './home/maps/Test';
  50. import ResetPassword from './sign/ResetPasswordV2';
  51. import PaymentMethod from './payment/PaymentMethod';
  52. import PayPerUse from './payment/PayPerUse';
  53. import PaymentWeb from './payment/PaymentWeb';
  54. import Settings from './Settings';
  55. import ChargeAdapter from './chargeV2/ChargeAdapter';
  56. import ChargingPage from './chargingV2/ChargingPage';
  57. import ChargingPageV4 from './chargingV3/ChargingPage';
  58. import { BridgePage } from '../utils/routeUtil';
  59. import HeaderTitle from '../components/HeaderTitle';
  60. import Bookmarks from './bookmark/Bookmarks';
  61. import MembersList from './member/MembersList';
  62. import ApplyMember from './member/ApplyMember';
  63. import Contact from './about/Contact';
  64. import Notification from './alert/Notification';
  65. import ViewAlerts from './alert/ViewAlerts';
  66. import ViewCampaign from './alert/ViewCampaign';
  67. import RefundPolicy from './payment/RefundPolicy';
  68. import ViewArticle from './alert/ViewArticle';
  69. import VehicleListV2 from './vehicles/VehicleListV2';
  70. import HistoryList from './wallet/HistoryList';
  71. import VoucherPage from './vouchers/VoucherPage';
  72. import VoucherSelect from './vouchers/VoucherSelect';
  73. import VoucherDetails from './vouchers/VoucherDetails';
  74. import PointsHistory from './vouchers/PointsHistory';
  75. import Transaction from './transaction/Transaction';
  76. import LoginVL from './signLumi/LoginVL';
  77. import RegisterVL from './signLumi/RegisterVL';
  78. import ForgotPwdVL from './signLumi/ForgotPwdVL';
  79. import Wallets from './wallets/Wallets';
  80. import utils from '../utils/utils';
  81. import DeleteAccount from './my/DeleteAccount';
  82. export var PageList = {
  83. 'splash': {
  84. component: Launcher
  85. },
  86. 'home': {
  87. component: Home,
  88. options: TransitionPresets.RevealFromBottomAndroid//.FadeFromBottomAndroid
  89. },
  90. 'bridge': {
  91. component: BridgePage
  92. },
  93. 'search': {
  94. title: 'Search',
  95. titleScope: 'route.search',
  96. component: app.isLumiWhitelabel ? SearchV3 : Search
  97. },
  98. 'login': {
  99. component: app.isLumiWhitelabel ? LoginVL : Login
  100. },
  101. 'register': {
  102. component: RegisterV4,
  103. title: 'Public Registration',
  104. titleScope: 'route.publicRegister'
  105. },
  106. 'registerLumi': {
  107. component: RegisterVL,
  108. title: 'Registration',
  109. titleScope: 'sign.btnRegister'
  110. },
  111. 'registerPublic': {
  112. component: RegisterPublic,
  113. title: 'Public Registration',
  114. titleScope: 'route.publicRegister'
  115. },
  116. 'registerFleet': {
  117. component: RegisterDriver,
  118. title: 'Fleet / PHV Registration',
  119. titleScope: 'route.driverRegister'
  120. },
  121. 'chargeDetail': {
  122. title: 'Charging Site',
  123. titleScope: 'route.chargingSite',
  124. component: ChargeDetails
  125. },
  126. 'chargeDetailPage': {
  127. //title: 'Charging Site',
  128. //titleScope: 'route.chargingSite',
  129. component: ChargeAdapter
  130. },
  131. 'chargingPage': {
  132. title: 'Charging',
  133. titleScope: 'route.charging',
  134. component: ChargingPage
  135. },
  136. 'chargingPageV4': {
  137. title: 'Charging',
  138. titleScope: 'route.charging',
  139. component: ChargingPageV4
  140. },
  141. 'scanqr': {
  142. title: 'QR Scan',
  143. titleScope: 'route.qrScan',
  144. component: QRScan
  145. },
  146. 'feedback': {
  147. title: 'Feedback',
  148. titleScope: 'route.feedback',
  149. component: Feedback
  150. },
  151. 'about': {
  152. title: 'About',
  153. titleScope: 'route.about',
  154. component: About
  155. },
  156. 'supportContact': {
  157. title: 'Support Hotline',
  158. titleScope: 'support.supportHotline',
  159. component: Contact
  160. },
  161. 'privacy': {
  162. title: 'Privacy Policy',
  163. titleScope: 'route.privacyPolicy',
  164. component: Privacy
  165. },
  166. 'condition': {
  167. title: 'Terms of Use',
  168. titleScope: 'route.termsOfUse',
  169. component: Condition
  170. },
  171. 'profile': {
  172. title: 'Profile Settings',
  173. titleScope: 'route.profileSettings',
  174. component: Profile
  175. },
  176. 'profileV3': {
  177. component: ProfileV3
  178. },
  179. 'summary': {
  180. title: 'Summary',
  181. titleScope: 'receipt.receipt',
  182. component: app.charge.newSummary ? SummaryV3 : Summary
  183. },
  184. 'rating': {
  185. title: 'Your Rating',
  186. titleScope: 'route.rating',
  187. component: Rating
  188. },
  189. 'wallet': {
  190. title: 'Transactions',
  191. titleScope: 'route.wallet',
  192. component: Wallet
  193. },
  194. 'wallets': {
  195. title: 'Wallets',
  196. titleScope: 'route.wallets',
  197. component: Wallets
  198. },
  199. 'history': {
  200. title: 'History',
  201. titleScope: 'route.history',
  202. component: HistoryList
  203. },
  204. 'transaction': {
  205. title: 'Transactions',
  206. titleScope: 'route.wallet',
  207. component: Transaction
  208. },
  209. 'editProfile': {
  210. title: 'My Profile',
  211. titleScope: 'route.editProfile',
  212. component: EditProfile
  213. },
  214. 'editAddress': {
  215. title: 'Edit Address',
  216. titleScope: 'route.editAddress',
  217. component: EditAddress
  218. },
  219. 'referral': {
  220. title: 'Referral',
  221. titleScope: 'route.referral',
  222. component: Referral
  223. },
  224. 'topup': {
  225. title: 'Top Up',
  226. titleScope: 'route.topUp',
  227. component: Topup
  228. },
  229. 'topupV2': {
  230. title: 'Top Up',
  231. titleScope: 'route.topUp',
  232. component: TopupV2
  233. },
  234. 'topupNew': {
  235. title: 'Top Up',
  236. titleScope: 'route.topUp',
  237. component: TopupNew
  238. },
  239. 'addCard': {
  240. title: 'Add Cards',
  241. titleScope: 'route.addCards',
  242. component: AddCard
  243. },
  244. 'myVehicles': {
  245. title: 'My Vehicles',
  246. titleScope: 'route.myVehicles',
  247. component: VehicleList,
  248. options: {
  249. headerRight: () => (
  250. <Pressable
  251. style={Styles.backIcon}
  252. android_ripple={rippleLessIcon}
  253. onPress={() => startPage(PageList.addVehicle)}>
  254. <MaterialCommunityIcons
  255. name='plus'
  256. color={pageTitleTint}
  257. size={24}
  258. style={Styles.iconOpacity}
  259. />
  260. </Pressable>
  261. )
  262. }
  263. },
  264. 'vehiclesListV2': {
  265. title: 'My Vehicles',
  266. titleScope: 'route.myVehicles',
  267. component: VehicleListV2
  268. },
  269. 'addVehicle': {
  270. title: 'Add Vehicle',
  271. titleScope: 'route.addVehicle',
  272. component: AddVehicle
  273. },
  274. 'editVehicle': {
  275. title: 'Update Vehicle',
  276. titleScope: 'route.editVehicle',
  277. component: EditVehicle
  278. },
  279. 'addVehicleV2': {
  280. title: 'Add Vehicle',
  281. titleScope: 'route.addVehicle',
  282. component: VehicleDetail
  283. },
  284. 'editVehicleV2': {
  285. title: 'Update Detail',
  286. titleScope: 'route.editVehicle',
  287. component: VehicleDetail
  288. },
  289. 'paynow': {
  290. title: 'PAYNOW',
  291. titleScope: 'route.paynow',
  292. component: PayNow
  293. },
  294. 'paycard': {
  295. title: 'Top Up with Card',
  296. titleScope: 'route.topUpWithCard',
  297. component: CreditCard
  298. },
  299. 'formCard': {
  300. title: 'Top Up with Card',
  301. titleScope: 'route.topUpWithCard',
  302. component: FormCard
  303. },
  304. 'paymentMethod': {
  305. title: 'Payment Method',
  306. titleScope: 'route.paymentMethod',
  307. component: PaymentMethod
  308. },
  309. 'paymentWeb': {
  310. title: 'Make Payment',
  311. titleScope: 'route.makePayment',
  312. component: PaymentWeb
  313. },
  314. 'payPeruse': {
  315. title: 'Pay Per Use',
  316. titleScope: 'route.payPerUse',
  317. component: PayPerUse
  318. },
  319. 'notification': {
  320. title: 'Notification',
  321. titleScope: 'route.notifications',
  322. component: Notification
  323. },
  324. 'viewMessage': {
  325. title: 'View Message',
  326. titleScope: 'notification.viewMessage',
  327. component: ViewAlerts
  328. },
  329. 'viewArticle': {
  330. //title: 'View Article',
  331. //titleScope: 'notification.viewMessage',
  332. component: ViewArticle
  333. },
  334. 'viewCampaign': {
  335. //title: 'View Campaign',
  336. //titleScope: 'notification.viewMessage',
  337. component: ViewCampaign
  338. },
  339. 'notify': {
  340. title: 'Notification Test',
  341. titleScope: 'route.notificationTest',
  342. component: Notify
  343. },
  344. 'mapTest': {
  345. component: Test
  346. },
  347. 'forgotPassword': {
  348. title: 'Forgot Password',
  349. titleScope: 'route.forgotPassword',
  350. component: ResetPassword
  351. },
  352. 'forgotPasswordLumi': {
  353. title: 'Forgot Password',
  354. titleScope: 'route.forgotPassword',
  355. component: ForgotPwdVL
  356. },
  357. 'changePassword': {
  358. title: 'Account Security',
  359. titleScope: 'route.changePassword',
  360. component: ResetPassword
  361. },
  362. 'bookmarks': {
  363. title: "Bookmarks",
  364. titleScope: 'route.bookmarks',
  365. component: Bookmarks
  366. },
  367. 'membersList': {
  368. title: "Your Membership",
  369. titleScope: 'route.yourMembers',
  370. component: MembersList,
  371. options: {
  372. headerRight: () => (
  373. <Pressable
  374. style={Styles.backIcon}
  375. android_ripple={rippleLessIcon}
  376. onPress={() => startPage(PageList.applyMember)}>
  377. <MaterialCommunityIcons
  378. name='plus'
  379. color={pageTitleTint}
  380. size={24}
  381. style={Styles.iconOpacity}
  382. />
  383. </Pressable>
  384. )
  385. }
  386. },
  387. 'applyMember': {
  388. title: "Apply Membership",
  389. titleScope: 'route.applyMember',
  390. component: ApplyMember
  391. },
  392. 'refundPolicy': {
  393. title: "Refund Policy",
  394. titleScope: 'route.refundPolicy',
  395. component: RefundPolicy
  396. },
  397. 'myVoucher': {
  398. title: "Vouchers",
  399. titleScope: 'route.vouchers',
  400. component: VoucherPage
  401. },
  402. 'voucherDetails': {
  403. title: "Voucher Details",
  404. titleScope: 'route.voucherDetails',
  405. component: VoucherDetails
  406. },
  407. 'selectVoucher': {
  408. title: "Select Voucher",
  409. titleScope: 'route.selectVoucher',
  410. component: VoucherSelect
  411. },
  412. 'pointsHistory': {
  413. title: "Points History",
  414. titleScope: 'route.pointsHistory',
  415. component: PointsHistory
  416. },
  417. 'deleteAccount': {
  418. title: "Delete Account",
  419. titleScope: 'profile.deleteAccount',
  420. component: DeleteAccount
  421. },
  422. 'settings': {
  423. title: 'Settings',
  424. titleScope: 'route.settings',
  425. component: Settings
  426. }
  427. }
  428. export const setPageList = (list) => {
  429. if (list) {
  430. PageList = list;
  431. //console.log("设置List", PageList);
  432. }
  433. }
  434. const Stack = createStackNavigator();
  435. enableScreens();
  436. /**
  437. * 配置APP主题色
  438. */
  439. const themeColor = {
  440. text: textPrimary,
  441. card: colorThemes,
  442. primary: colorPrimary,
  443. background: pageBackground,
  444. notification: colorDark
  445. }
  446. const noTitle = (opt = {}) => {
  447. return {
  448. title: isIOS ? 'Back' : app.displayName,
  449. headerShown: false,
  450. ...opt
  451. }
  452. }
  453. /**
  454. * 配置标题
  455. * @param {String} title 页面标题
  456. * @param {Object} opt 标题栏选项
  457. * @returns
  458. */
  459. const Title = (title, opt = {}, titleScope) => {
  460. const options = {
  461. headerShown: true,
  462. headerStyle: {
  463. ...titleHeight(),
  464. elevation: 0,
  465. shadowOpacity: 0,
  466. borderBottomWidth: 0,
  467. backgroundColor: app.isWhitelabel ? colorLight : colorPrimary //配置标题栏背景
  468. },
  469. headerTintColor: pageTitleTint, //配置标题栏文字和图标颜色
  470. headerBackTitle: ' ', //配置iOS返回按钮文字
  471. headerBackTitleVisible: false,
  472. ...opt
  473. }
  474. if (titleScope && $t) {
  475. //options.headerTitle = () => <HeaderTitle scope={titleScope}/>
  476. options.header = () => <Toolbar scope={titleScope} rightIcon={options?.headerRight}/>
  477. } else {
  478. options.title = title;
  479. options.header = () => <Toolbar scope={titleScope} rightIcon={options?.headerRight}/>
  480. //options.headerLeft = () => <BackButton/>
  481. }
  482. return options;
  483. }
  484. var bakPages = undefined;
  485. function getPages() {
  486. let pages = [], keys = {};
  487. if (bakPages == undefined) {
  488. bakPages = Object.assign({}, PageList);
  489. } else {
  490. setPageList(bakPages);
  491. }
  492. for (const page in bakPages) {
  493. var p = bakPages[page]
  494. keys[page] = page;
  495. pages.push(
  496. <Stack.Screen
  497. key={page}
  498. name={page}
  499. component={p.component}
  500. options={p.title ? Title(p.title, p.options, p.titleScope) : noTitle(p.options)}
  501. />
  502. );
  503. }
  504. setPageList(keys);
  505. return pages;
  506. }
  507. const Router = () => {
  508. const navigation = useRef();
  509. useEffect(() => {
  510. //注入全局方法
  511. global.startPage = (name, params = {}) => {
  512. if (utils.isNotEmpty(name)) {
  513. navigation.current?.navigate(name, params);
  514. }
  515. }
  516. global.dispatchPage = (params) => {
  517. navigation.current?.dispatch(params);
  518. }
  519. global.goBack = () => {
  520. if (global.pageBackFallback && global.pageBackFallback.names) {
  521. //console.log("覆盖返回", navigation.current.getCurrentRoute()?.name);
  522. if (global.pageBackFallback.names.indexOf(navigation.current.getCurrentRoute()?.name) >= 0) {
  523. global.pageBackFallback?.callback();
  524. global.pageBackFallback = undefined;
  525. return;
  526. }
  527. }
  528. if (navigation.current?.canGoBack()) {
  529. navigation.current?.goBack();
  530. } else {
  531. startPage(PageList.home);
  532. }
  533. }
  534. global.goBack2 = () => {
  535. if (navigation.current?.canGoBack()) {
  536. navigation.current?.goBack();
  537. } else {
  538. startPage(PageList.home);
  539. }
  540. }
  541. return (() => {
  542. global.startPage = null;
  543. global.goBack = null;
  544. });
  545. }, []);
  546. return (
  547. <NavigationContainer
  548. ref={navigation}
  549. theme={{
  550. ...DefaultTheme,
  551. dark: darkMode,
  552. colors: themeColor
  553. }}>
  554. <Stack.Navigator
  555. initialRouteName='splash'
  556. screenOptions={{animationEnabled: true, ...TransitionPresets.SlideFromRightIOS }}>
  557. {getPages()}
  558. </Stack.Navigator>
  559. </NavigationContainer>
  560. )
  561. }
  562. const titleHeight = () => {
  563. return isIOS ? {} : {height: toolbarSize};
  564. }
  565. export default Router;