Router.js 14 KB

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