longyvfengyun
2023-11-16 b537c7bccbcc20644902ad6f0e309bbe9a6eda24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {nextTick, onUnmounted, ref} from "vue";
import {searchCarPos} from "@/views/moudle/carInfo/apis";
import const_num from "@/assets/js/const/const_num";
 
const carPosModule = ()=>{
  const carPosInfo = ref([]);
  let timer = 0;
  /**
   * 获取汽车的定位信息
   * @return {Promise<[]>}
   */
  const getCarPosList = async ()=>{
    try{
      const res = await searchCarPos();
      const rs = res.data;
      let data = [];
      if(rs.code === 1) {
        data = rs.data;
      }
      carPosInfo.value = data.map(item=>{
        item.show = false;
        return item;
      });
      return data;
    }catch (e) {
      console.log(e);
      return [];
    }
  }
 
  /**
   * 循环请求
   */
  const loopSearch = ()=>{
    clearTimeout(timer);
    // 页面开启定时请求
    nextTick().then(()=>{
      timer = setTimeout(()=>{
        getCarPosList();
      }, const_num.timer);
    });
  }
 
  onUnmounted(()=>{
    clearTimeout(timer);
  });
 
  return {
    carPosInfo,
    getCarPosList
  };
}
export default carPosModule;