PagerUtil.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { getFocusedRouteNameFromRoute } from "@react-navigation/core";
  2. import { PagerList } from "./ChargeAdapter";
  3. import app from '../../../app.json';
  4. var chargeInfoState = global.chargeInfoState
  5. var refreshListener = [];
  6. const DEBUG = app.debug && !app.product;
  7. export default PagerUtil = {
  8. ENABLE_NEW_UI: false, //是否启用新的充电页面
  9. getStationInfo: () => {
  10. return chargeInfoState.stationInfo ?? {}
  11. },
  12. setStationInfo: (info) => {
  13. chargeInfoState.stationInfo = info;
  14. },
  15. addOnRefresh: (page) => {
  16. refreshListener.push(page)
  17. },
  18. setRefreshing: (route) => {
  19. if (DEBUG) {
  20. console.log("[PagerUtil]刷新指定子页面:", route);
  21. }
  22. refreshListener.map((item, index) => {
  23. if (!route || route == item.props?.route?.name) {
  24. if (item.onRefresh)
  25. item.onRefresh();
  26. }
  27. })
  28. },
  29. setBackRefreshing: () => {
  30. refreshListener.map((item, index) => {
  31. if (item.onBackRefresh)
  32. item.onBackRefresh();
  33. })
  34. },
  35. onCharge: (props) => {
  36. const isFocused = props?.navigation?.isFocused();
  37. if (!isFocused) {
  38. if (DEBUG) {
  39. console.log("[PagerUtil]", "onCharge");
  40. }
  41. startPage(PagerList.tabCharge);
  42. } else if (DEBUG) {
  43. console.log("[PagerUtil]", "onCharge-skip");
  44. }
  45. },
  46. onReserve: (props) => {
  47. const isFocused = props?.navigation?.isFocused();
  48. if (!isFocused) {
  49. if (DEBUG) {
  50. console.log("[PagerUtil]", "onReserve");
  51. }
  52. startPage(PagerList.tabReserve);
  53. } else if (DEBUG) {
  54. console.log("[PagerUtil]", "onReserve-skip");
  55. }
  56. },
  57. onEnterStation: (props) => {
  58. const isFocused = props?.navigation?.isFocused();
  59. if (!isFocused) {
  60. if (DEBUG) {
  61. console.log("[PagerUtil]", "onEnterStation");
  62. }
  63. startPage(PagerList.tabCharge);
  64. } else if (DEBUG) {
  65. console.log("[PagerUtil]", "onEnterStation-skip");
  66. }
  67. },
  68. onDestory: () => {
  69. chargeInfoState = {};
  70. refreshListener = [];
  71. },
  72. getCurrentRoute: (props) => (
  73. getFocusedRouteNameFromRoute(props.route)
  74. )
  75. }