forked from huge/frontEnd/hugeDyh2.0

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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-02-16 11:57:54
 * @LastEditTime: 2022-02-17 11:19:54
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: 公共模块方法
 */
import { Modal, message } from 'antd';
 
export const edition = '1.0.0'; // 版本号
 
// 缓存
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 }) {
    if (errorNum) {
        return false;
    }
    errorNum = true;
    const handleOkFunc = () => (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 }) {
    return info({ type: 'success', content });
}