广州矛调粤政易端
xusd
7 days ago d27794814b69d18aeb8ee96a46cae91d5613570c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * @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();