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;