Router.js 14 KB

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