import {toast} from "react-toastify"; import Router from "next/router"; import {getPathSearchParamObj} from "./window"; import $ from 'jquery' export const getQuery = (name) => { let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); let r = window.location.search.substr(1).match(reg); if (r != null) return decodeURI(r[2]); return null; } export const isEmpty = (value) => { return value === '' || value === undefined } export const successTime = 2000 export const warningTime = 5000 export const errorTime = 5000 export const infoTime = 2000 export const resCode = (code, msg, tid) => { if (isEmpty(tid)) { switch (code) { case 3: // error toast.error(msg, {autoClose: errorTime}) return true case 2: // warning toast.warning(msg, {autoClose: warningTime}) return true case 1: // info toast.info(msg, {autoClose: infoTime}) return false case 0: toast.success(msg, {autoClose: successTime}) return false case -1: toast.error(msg, {autoClose: errorTime}) return true case -2: toast.warning(msg, {autoClose: warningTime}) Router.push('/login') return true } } else { switch (code) { case 3: // error toast.update(tid, {autoClose: errorTime, render: msg, type: "error", isLoading: false}) return true case 2: // warning toast.update(tid, {autoClose: warningTime, render: msg, type: 'warning', isLoading: false}) return true case 1: // info toast.update(tid, {autoClose: infoTime, render: msg, type: 'info', isLoading: false}) return false case 0: toast.update(tid, {autoClose: successTime, render: msg, type: 'success', isLoading: false}) return false case -1: toast.update(tid, {autoClose: errorTime, render: msg, type: 'error', isLoading: false}) return true case -2: toast.update(tid, {autoClose: warningTime, render: msg, type: 'warning', isLoading: false}) Router.push('/login') return true } } } export const refresh = () => { Router.push(location.pathname + '?' + $.param(getPathSearchParamObj())) }
2021年12月4日星期六
util.js
订阅:
博文评论 (Atom)
-
import '../styles/globals.css' import 'bootstrap/dist/css/bootstrap.min.css'; import 'react-toastify/dist/ReactToastif...
-
sudo apt update sudo apt install openjdk-11-jdk java -version
-
心情 伤心 万念俱灰 伤心欲绝 五内如焚 肝肠寸断 触景伤心 闷闷不乐 哭泣 泣不成声 泪如雨下 抱头大哭 撕心裂肺 哀天叫地 着急 心急如焚 坐立不安
没有评论:
发表评论