forked from gzzfw/frontEnd/gzDyh

zhangyongtian
2024-09-13 82e0444fd7d91f3066d800adbea79c531adaea89
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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-02-16 11:57:54
 * @LastEditTime: 2022-11-01 09:20:25
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: 公共模块方法
 */
import { Modal, message } from 'antd';
import * as apiHandler from '../api/apiHandler';
export { default as iconContrast } from './icon';
export const ax = apiHandler; // axios
 
export const isDebug = true; // 是否测试环境
 
export const edition = '1.0.0'; // 版本号
 
const province = '19'; // 当前用户省id, 默认广东
 
// 省市区(县)街道社区的下拉框
// eslint-disable-next-line no-undef
export const locationOption = locationSelect[province].map((item1) => ({
    ...item1,
    children: item1.children.map((item2) => ({ ...item2, children: item2.children.map((item3) => ({ ...item3, children: [] })) })),
}));
 
// icon 对照表
 
// 缓存
export function setLocalStorage(value) {
    localStorage.setItem('operationData', JSON.stringify(value));
}
 
export function getLocalStorage() {
    let useData = localStorage.getItem('operationData');
    return !useData ? {} : JSON.parse(useData);
}
 
export function setLocal(name, value) {
    localStorage.setItem(name, JSON.stringify(value));
}
 
export function getLocal(name) {
    let data = localStorage.getItem(name);
    return !data ? null : JSON.parse(data);
}
 
export function clearLocal(name) {
    return name ? localStorage.removeItem(name) : localStorage.clear();
}
 
// 地址栏截取
export function getQueryString(name) {
    let result = window.location.href.match(new RegExp('[?&]' + name + '=([^&]+)', 'i'));
    if (!result || result.length < 1) {
        return null;
    }
    return decodeURI(result[1]);
}
 
// api错误提示
let errorNum = false; // 控制错误信息不重复弹出
export function catchApiError({ content, loginStatus }) {
    if (errorNum) {
        return false;
    }
    errorNum = true;
    const handleOkFunc =
        loginStatus == 'lose'
            ? () => {
                    errorNum = false;
                    window.location.href = '#/login';
              }
            : () => (errorNum = false);
    return Modal.error({ title: '错误提示', okText: '知道了', cancelText: null, onOk: handleOkFunc, content });
}
 
// 全局提示
export function info(value) {
    return message[value.type](value.content, value.duration || 3, value.onClose);
}
 
export function infoSuccess({ content, onClose }) {
    return info({ type: 'success', content, onClose });
}
 
export function modalInfo({ type = 'confirm', title = '提示', content, okText = '确定', cancelText = '取消', onCancel, onOk }) {
    return Modal[type]({
        title: title,
        content: content,
        onCancel: onCancel,
        onOk: onOk,
        okText,
        cancelText,
        closable: true,
        maskClosable: true,
    });
}