소스 검색

feat:显示所有电站

simsir 2 년 전
부모
커밋
ae0ab3f2ac
1개의 변경된 파일62개의 추가작업 그리고 45개의 파일을 삭제
  1. 62 45
      src/api/charge.ts

+ 62 - 45
src/api/charge.ts

@@ -112,8 +112,8 @@ export function fetchChargeStatus(
     })
     .then((res) => {
       if (res) {
-        res.isAppointment = [0].includes(res.chargeStatus)
-        res.isStarted = [1, 2, 3].includes(res.chargeStatus)
+        res.isAppointment = [0].includes(res.chargeStatus);
+        res.isStarted = [1, 2, 3].includes(res.chargeStatus);
       }
       // 充电状态:0:预约中 1:启动中 2:充电中 3:停止中 4:已结束 5:未知
       if (checkAppointment && res && res.isAppointment) {
@@ -169,12 +169,40 @@ export function fetchStations(
   return fetchAllStations()
     .then((res) => {
       // console.log(latitude, longitude);
-      let list = JSON.parse(JSON.stringify(res));
-      const data: any[] = [];
+      // let list = JSON.parse(JSON.stringify(res));
+      const data: any[] = JSON.parse(JSON.stringify(res)); // []
       const start = (page - 1) * pageSize;
       const end = start + pageSize;
+      // 暂时废弃距离范围
+      // if (latitude && longitude) {
+      //   list.forEach((item: any) => {
+      //     item.stationLatDistance = _getDistance(
+      //       latitude,
+      //       longitude,
+      //       item.location.stationLat,
+      //       item.location.stationLng
+      //     );
+      //   });
+      //   list.sort((item1: any, item2: any) => {
+      //     return item1.stationLatDistance - item2.stationLatDistance;
+      //   });
+      // }
+      // 暂时废弃距离筛选
+      // if (options) {
+      //   if (options.distance && !isDebug) {
+      //     list = list.filter(
+      //       (item: any) => item.stationLatDistance <= (options.distance || 20)
+      //     );
+      //   }
+      // }
+      // list.forEach((item: any, index: number) => {
+      //   if (index >= start && index < end) {
+      //     data.push(item);
+      //   }
+      // });
+      // 暂时显示全部电站
       if (latitude && longitude) {
-        list.forEach((item: any) => {
+        data.forEach((item: any) => {
           item.stationLatDistance = _getDistance(
             latitude,
             longitude,
@@ -182,22 +210,10 @@ export function fetchStations(
             item.location.stationLng
           );
         });
-        list.sort((item1: any, item2: any) => {
+        data.sort((item1: any, item2: any) => {
           return item1.stationLatDistance - item2.stationLatDistance;
         });
       }
-      if (options) {
-        if (options.distance && !isDebug) {
-          list = list.filter(
-            (item: any) => item.stationLatDistance <= (options.distance || 20)
-          );
-        }
-      }
-      list.forEach((item: any, index: number) => {
-        if (index >= start && index < end) {
-          data.push(item);
-        }
-      });
       if (baseLatitude && baseLongitude) {
         data.forEach((item: any) => {
           item.stationLatDistance = _getDistance(
@@ -211,33 +227,34 @@ export function fetchStations(
       return _fetchStationStatus(data);
     })
     .then((list) => {
-      if (options && options.status) {
-        let res = false;
-        list = list.filter((item: any) => {
-          res = false;
-          item.equipmentInfos.forEach((eqInfo: any) => {
-            eqInfo.connectorInfos.forEach((coInfo: any) => {
-              if (
-                !res &&
-                options.status === 1 &&
-                coInfo.connectorStatusInfo &&
-                coInfo.connectorStatusInfo.status === 1
-              ) {
-                res = true;
-              }
-              if (
-                !res &&
-                options.status === 2 &&
-                coInfo.connectorStatusInfo &&
-                coInfo.connectorStatusInfo.status !== 1
-              ) {
-                res = true;
-              }
-            });
-          });
-          return res;
-        });
-      }
+      // 暂时废弃状态筛选
+      // if (options && options.status) {
+      //   let res = false;
+      //   list = list.filter((item: any) => {
+      //     res = false;
+      //     item.equipmentInfos.forEach((eqInfo: any) => {
+      //       eqInfo.connectorInfos.forEach((coInfo: any) => {
+      //         if (
+      //           !res &&
+      //           options.status === 1 &&
+      //           coInfo.connectorStatusInfo &&
+      //           coInfo.connectorStatusInfo.status === 1
+      //         ) {
+      //           res = true;
+      //         }
+      //         if (
+      //           !res &&
+      //           options.status === 2 &&
+      //           coInfo.connectorStatusInfo &&
+      //           coInfo.connectorStatusInfo.status !== 1
+      //         ) {
+      //           res = true;
+      //         }
+      //       });
+      //     });
+      //     return res;
+      //   });
+      // }
       return list;
     });
 }