Router.js 14 KB

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