|
|
@@ -0,0 +1,104 @@
|
|
|
+import { getFocusedRouteNameFromRoute } from "@react-navigation/core";
|
|
|
+import { PagerList } from "./ChargeAdapter";
|
|
|
+import app from '../../../app.json';
|
|
|
+import { PageList } from "../Router";
|
|
|
+
|
|
|
+var chargeInfoState = global.chargeInfoState
|
|
|
+var refreshListener = [];
|
|
|
+
|
|
|
+const DEBUG = app.debug && !app.product;
|
|
|
+
|
|
|
+export default PagerUtil = {
|
|
|
+ ENABLE_NEW_UI: app.charge.version > 2, //是否启用新的充电页面
|
|
|
+ getStationInfo: () => {
|
|
|
+ return chargeInfoState.stationInfo ?? {}
|
|
|
+ },
|
|
|
+ setStationInfo: (info) => {
|
|
|
+ chargeInfoState.stationInfo = info;
|
|
|
+ },
|
|
|
+ addOnRefresh: (page) => {
|
|
|
+ refreshListener.push(page)
|
|
|
+ },
|
|
|
+ setRefreshing: (route) => {
|
|
|
+ if (DEBUG) {
|
|
|
+ console.log("[PagerUtil]刷新指定子页面:", route);
|
|
|
+ }
|
|
|
+ refreshListener.map((item, index) => {
|
|
|
+ if (!route || route == item.props?.route?.name) {
|
|
|
+ if (item.onRefresh)
|
|
|
+ item.onRefresh();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ setBackRefreshing: () => {
|
|
|
+ refreshListener.map((item, index) => {
|
|
|
+ if (item.onBackRefresh)
|
|
|
+ item.onBackRefresh();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onCharge: (props) => {
|
|
|
+ const isFocused = props?.navigation?.isFocused();
|
|
|
+ if (!isFocused) {
|
|
|
+ if (DEBUG) {
|
|
|
+ console.log("[PagerUtil]", "onCharge");
|
|
|
+ }
|
|
|
+ startPage(PagerList.tabCharge);
|
|
|
+ } else if (DEBUG) {
|
|
|
+ console.log("[PagerUtil]", "onCharge-skip");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onReserve: (props) => {
|
|
|
+ const isFocused = props?.navigation?.isFocused();
|
|
|
+ if (!isFocused) {
|
|
|
+ if (DEBUG) {
|
|
|
+ console.log("[PagerUtil]", "onReserve");
|
|
|
+ }
|
|
|
+ startPage(PagerList.tabReserve);
|
|
|
+ } else if (DEBUG) {
|
|
|
+ console.log("[PagerUtil]", "onReserve-skip");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onInnerScanQR() {
|
|
|
+ global.chargeV3InnerScanQR = true;
|
|
|
+ if (this.ENABLE_NEW_UI) {
|
|
|
+ if (DEBUG) {
|
|
|
+ console.log("[PagerUtil]", "激活自动进入新充电页面的开关");
|
|
|
+ }
|
|
|
+ refreshListener.map((item, index) => {
|
|
|
+ if (item.activeNewUIPage)
|
|
|
+ item.activeNewUIPage();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ isInnerScanQR: () => {
|
|
|
+ return global.chargeV3InnerScanQR;
|
|
|
+ },
|
|
|
+ ofInnerScanQR: () => {
|
|
|
+ global.chargeV3InnerScanQR = false;
|
|
|
+ },
|
|
|
+ onEnterStation: (props) => {
|
|
|
+ //const isFocused = props?.navigation?.isFocused();
|
|
|
+ startPage(PagerList.tabCharge);
|
|
|
+ },
|
|
|
+ onDestory: () => {
|
|
|
+ chargeInfoState = {};
|
|
|
+ refreshListener = [];
|
|
|
+ },
|
|
|
+ getCurrentRoute: (props) => (
|
|
|
+ getFocusedRouteNameFromRoute(props.route)
|
|
|
+ ),
|
|
|
+ isSelectVoucher: () => {
|
|
|
+ return global.chargeSelectVoucher;
|
|
|
+ },
|
|
|
+ toSelectVoucher: (chargeBoxId, connectorId) => {
|
|
|
+ global.chargeSelectVoucher = true;
|
|
|
+ startPage(PageList.selectVoucher, {chargeBoxId: chargeBoxId, connectorId: connectorId});
|
|
|
+ },
|
|
|
+ setSelectedVoucher: (voucher) => {
|
|
|
+ global.chargeSelectedVoucher = voucher;
|
|
|
+ },
|
|
|
+ getSelectedVoucher: () => {
|
|
|
+ global.chargeSelectVoucher = false;
|
|
|
+ return global.chargeSelectedVoucher || {};
|
|
|
+ }
|
|
|
+}
|