/* * @Company: hugeInfo * @Author: ldh * @Date: 2022-09-21 10:44:30 * @LastEditTime: 2023-05-23 16:39:41 * @LastEditors: lwh * @Version: 1.0.0 * @Description: 公共数据访问,可防止多次请求 */ import { ax } from '../utils/utility'; class publicDataStatus { constructor() { this.gridData = []; this.gridDataPolygon = {}; this.gridDataAllMarker = {}; this.HKData = []; } // 退出登录清空数据 clearLogin() { this.gridData = []; this.gridDataPolygon = {}; this.gridDataAllMarker = {}; this.HKData = []; } // 获取网络数据 async getUserGrid(callback, isSpin, notAll) { if (this.gridData.length === 0) { function getUserGridApi() { return ax.request({ url: 'opus/getUserGrid', type: 'get', service: 'opus' }); } isSpin && global.setSpinning(true); const res = await getUserGridApi(); isSpin && global.setSpinning(false); if (res.type) { this.gridData = res.data || []; } } let gridCode = this.gridData.map((x) => x.gridCode).join(); callback(notAll || this.gridData?.length <= 1 ? this.gridData : [{ gridNum: '全部', gridCode }, ...this.gridData]); } // 获取网格的点位 async getUserGridPolygon(gridCode, callback, isSpin) { if (!this.gridDataPolygon[gridCode] || this.gridDataPolygon[gridCode].length === 0) { function getUserGridPolygonApi() { return ax.request({ url: `gridMap/getAddressPlane?gridCode=${gridCode}`, type: 'get', service: 'geopro' }); } isSpin && global.setSpinning(true); const res = await getUserGridPolygonApi(); isSpin && global.setSpinning(false); if (res.type) { this.gridDataPolygon[gridCode] = res.data || []; } } callback(this.gridDataPolygon[gridCode]); } // 获取网格内所有的点位 async getUserGridAllMarker(gridCode, callback, isSpin) { if (!this.gridDataAllMarker[gridCode]) { function getUserGridAllMarkerApi() { return ax.request({ url: `buildingInfo/getAddressPoint?gridCode=${gridCode}`, type: 'get', service: 'reside' }); } isSpin && global.setSpinning(true); const res = await getUserGridAllMarkerApi(); isSpin && global.setSpinning(false); if (res.type) { // 处理数据便于地图加载 let markers = []; let markerTexts = res.data || []; res.data?.forEach((x) => { markers.push(x.point); }); this.gridDataAllMarker[gridCode] = { markers, markerTexts }; } } callback(this.gridDataAllMarker[gridCode]); } // 获取区,街道数据 async getMetaAddrHk(callback, isSpin, notAll) { if (this.HKData.length === 0) { function getMetaAddrHkApi() { return ax.request({ url: 'metaAddrHk/getChildren', type: 'get', service: 'opus' }); } isSpin && global.setSpinning(true); const res = await getMetaAddrHkApi(); isSpin && global.setSpinning(false); if (res.type) { this.HKData = res.data || []; } } callback(notAll ? this.HKData : [{ areaName: '全部', areaId: '' }, ...this.HKData]); } } export default new publicDataStatus();