/*
|
* @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 });
|
}
|