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)
-
gsettings set org.gnome.desktop.interface clock-show-seconds true
-
Move https://www.cnblogs.com/zzqcn/p/4656518.html - 字符 - h 左移一个字符 - l 右移一个字符 - 单词 - w,W 移动到下一个单词开头,大写是以空格分隔的单词 - b,B 移动到上一...
-
later 后来 later defend辩护 defend,defend,defend,defend,defend defend,defend,defend,defend,defend defend,defend,defend,defend,defend defend,de...
没有评论:
发表评论