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