mirror of
https://gitee.com/log4j/pig-ui.git
synced 2024-12-22 21:22:33 +08:00
'admin-21.02.27:规划代码格式,去掉ts中多余的结束分号'
This commit is contained in:
parent
27fdc7b18a
commit
c0c57c4aad
@ -1,7 +1,7 @@
|
||||
import axios from "axios";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { clearSession, getSession } from "/@/utils/storage.ts";
|
||||
import router, { resetRoute } from "/@/router/index.ts";
|
||||
import axios from "axios"
|
||||
import { ElMessage, ElMessageBox } from "element-plus"
|
||||
import { clearSession, getSession } from "/@/utils/storage.ts"
|
||||
import router, { resetRoute } from "/@/router/index.ts"
|
||||
|
||||
// 配置新建一个 axios 实例
|
||||
const service = axios.create({
|
||||
@ -15,13 +15,13 @@ service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 在发送请求之前做些什么 token
|
||||
if (getSession("token")) {
|
||||
config.headers.common["Authorization"] = `${getSession("token")}`;
|
||||
config.headers.common["Authorization"] = `${getSession("token")}`
|
||||
}
|
||||
return config;
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
|
||||
@ -29,32 +29,32 @@ service.interceptors.request.use(
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
// 对响应数据做点什么
|
||||
const res = response.data;
|
||||
const res = response.data
|
||||
if (res.code && res.code !== 0) {
|
||||
// `token` 过期或者账号已在别处登录
|
||||
if (res.code === 401 || res.code === 4001) {
|
||||
clearSession(); // 清除浏览器全部临时缓存
|
||||
router.push("/login"); // 去登录页面
|
||||
router.push("/login") // 去登录页面
|
||||
resetRoute() // 删除/重置路由
|
||||
ElMessageBox.alert('你已被登出,请重新登录', '提示', {}).then(() => { }).catch(() => { });
|
||||
ElMessageBox.alert('你已被登出,请重新登录', '提示', {}).then(() => { }).catch(() => { })
|
||||
}
|
||||
return Promise.reject(service.interceptors.response);
|
||||
return Promise.reject(service.interceptors.response)
|
||||
} else {
|
||||
return response.data;
|
||||
return response.data
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
// 对响应错误做点什么
|
||||
if (error.message.indexOf("timeout") != -1) {
|
||||
ElMessage.error("网络超时");
|
||||
ElMessage.error("网络超时")
|
||||
} else if (error.message == "Network Error") {
|
||||
ElMessage.error("网络连接错误");
|
||||
ElMessage.error("网络连接错误")
|
||||
} else {
|
||||
if (error.response.data) ElMessage.error(error.response.statusText)
|
||||
else ElMessage.error('接口路径找不到')
|
||||
}
|
||||
return Promise.reject(error);
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
|
||||
export default service;
|
||||
export default service
|
||||
|
@ -7,17 +7,17 @@
|
||||
// 小数或整数(不可以负数)
|
||||
export function verifyNumberIntegerAndFloat(val) {
|
||||
// 匹配空格
|
||||
let v = val.replace(/(^\s*)|(\s*$)/g, "");
|
||||
let v = val.replace(/(^\s*)|(\s*$)/g, "")
|
||||
// 只能是数字和小数点,不能是其他输入
|
||||
v = v.replace(/[^\d.]/g, "");
|
||||
v = v.replace(/[^\d.]/g, "")
|
||||
// 以0开始只能输入一个
|
||||
v = v.replace(/^0{2}$/g, "0");
|
||||
v = v.replace(/^0{2}$/g, "0")
|
||||
// 保证第一位只能是数字,不能是点
|
||||
v = v.replace(/^\./g, "");
|
||||
v = v.replace(/^\./g, "")
|
||||
// 小数只能出现1位
|
||||
v = v.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
|
||||
v = v.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".")
|
||||
// 小数点后面保留2位
|
||||
v = v.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
|
||||
v = v.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
|
||||
// 返回结果
|
||||
return v
|
||||
}
|
||||
@ -25,85 +25,85 @@ export function verifyNumberIntegerAndFloat(val) {
|
||||
// 正整数验证
|
||||
export function verifiyNumberInteger(val) {
|
||||
// 匹配空格
|
||||
let v = val.replace(/(^\s*)|(\s*$)/g, "");
|
||||
let v = val.replace(/(^\s*)|(\s*$)/g, "")
|
||||
// 去掉 '.' , 防止贴贴的时候出现问题 如 0.1.12.12
|
||||
v = v.replace(/[\.]*/g, "");
|
||||
v = v.replace(/[\.]*/g, "")
|
||||
// 去掉以 0 开始后面的数, 防止贴贴的时候出现问题 如 00121323
|
||||
v = v.replace(/(^0[\d]*)$/g, "0");
|
||||
v = v.replace(/(^0[\d]*)$/g, "0")
|
||||
// 首位是0,只能出现一次
|
||||
v = v.replace(/^0\d$/g, "0");
|
||||
v = v.replace(/^0\d$/g, "0")
|
||||
// 只匹配数字
|
||||
v = v.replace(/[^\d]/g, "");
|
||||
v = v.replace(/[^\d]/g, "")
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// 去掉中文及空格
|
||||
export function verifyCnAndSpace(val) {
|
||||
// 匹配中文与空格
|
||||
let v = val.replace(/[\u4e00-\u9fa5\s]+/g, "");
|
||||
let v = val.replace(/[\u4e00-\u9fa5\s]+/g, "")
|
||||
// 匹配空格
|
||||
v = v.replace(/(^\s*)|(\s*$)/g, "");
|
||||
v = v.replace(/(^\s*)|(\s*$)/g, "")
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// 去掉英文及空格
|
||||
export function verifyEnAndSpace(val) {
|
||||
// 匹配英文与空格
|
||||
let v = val.replace(/[a-zA-Z]+/g, "");
|
||||
let v = val.replace(/[a-zA-Z]+/g, "")
|
||||
// 匹配空格
|
||||
v = v.replace(/(^\s*)|(\s*$)/g, "");
|
||||
v = v.replace(/(^\s*)|(\s*$)/g, "")
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// 禁止输入空格
|
||||
export function verifyAndSpace(val) {
|
||||
// 匹配空格
|
||||
let v = val.replace(/(^\s*)|(\s*$)/g, "");
|
||||
let v = val.replace(/(^\s*)|(\s*$)/g, "")
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// 金额用 `,` 区分开
|
||||
export function verifyNumberComma(val) {
|
||||
// 调用小数或整数(不可以负数)方法
|
||||
let v = verifyNumberIntegerAndFloat(val);
|
||||
let v = verifyNumberIntegerAndFloat(val)
|
||||
// 字符串转成数组
|
||||
v = v.toString().split(".");
|
||||
v = v.toString().split(".")
|
||||
// \B 匹配非单词边界,两边都是单词字符或者两边都是非单词字符
|
||||
v[0] = v[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
v[0] = v[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",")
|
||||
// 数组转字符串
|
||||
v = v.join(".");
|
||||
v = v.join(".")
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// 匹配文字变色(搜索时)
|
||||
export function verifyTextColor(val, text = '', color = 'red') {
|
||||
// 返回内容,添加颜色
|
||||
let v = text.replace(new RegExp(val, 'gi'), `<span style='color: ${color}'>${val}</span>`);
|
||||
let v = text.replace(new RegExp(val, 'gi'), `<span style='color: ${color}'>${val}</span>`)
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// 数字转中文大写
|
||||
export function verifyNumberCnUppercase(val, unit = '仟佰拾亿仟佰拾万仟佰拾元角分', v = '') {
|
||||
// 当前内容字符串添加 2个0,为什么??
|
||||
val += "00";
|
||||
val += "00"
|
||||
// 返回某个指定的字符串值在字符串中首次出现的位置,没有出现,则该方法返回 -1
|
||||
let lookup = val.indexOf('.');
|
||||
let lookup = val.indexOf('.')
|
||||
// substring:不包含结束下标内容,substr:包含结束下标内容
|
||||
if (lookup >= 0) val = val.substring(0, lookup) + val.substr(lookup + 1, 2);
|
||||
if (lookup >= 0) val = val.substring(0, lookup) + val.substr(lookup + 1, 2)
|
||||
// 根据内容 val 的长度,截取返回对应大写
|
||||
unit = unit.substr(unit.length - val.length);
|
||||
unit = unit.substr(unit.length - val.length)
|
||||
// 循环截取拼接大写
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
v += '零壹贰叁肆伍陆柒捌玖'.substr(val.substr(i, 1), 1) + unit.substr(i, 1);
|
||||
v += '零壹贰叁肆伍陆柒捌玖'.substr(val.substr(i, 1), 1) + unit.substr(i, 1)
|
||||
}
|
||||
// 正则处理
|
||||
v = v.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元");
|
||||
v = v.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元")
|
||||
// 返回结果
|
||||
return v
|
||||
}
|
||||
@ -111,108 +111,108 @@ export function verifyNumberCnUppercase(val, unit = '仟佰拾亿仟佰拾万仟
|
||||
// 手机号码
|
||||
export function verifyPhone(val) {
|
||||
// false: 手机号码不正确
|
||||
if (!/^((12[0-9])|(13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$/.test(val)) return false;
|
||||
if (!/^((12[0-9])|(13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$/.test(val)) return false
|
||||
// true: 手机号码正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 国内电话号码
|
||||
export function verifyTelPhone(val) {
|
||||
// false: 国内电话号码不正确
|
||||
if (!/\d{3}-\d{8}|\d{4}-\d{7}/.test(val)) return false;
|
||||
if (!/\d{3}-\d{8}|\d{4}-\d{7}/.test(val)) return false
|
||||
// true: 国内电话号码正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 登录账号 (字母开头,允许5-16字节,允许字母数字下划线)
|
||||
export function verifyAccount(val) {
|
||||
// false: 登录账号不正确
|
||||
if (!/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/.test(val)) return false;
|
||||
if (!/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/.test(val)) return false
|
||||
// true: 登录账号正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 密码 (以字母开头,长度在6~16之间,只能包含字母、数字和下划线)
|
||||
export function verifyPassword(val) {
|
||||
// false: 密码不正确
|
||||
if (!/^[a-zA-Z]\w{5,15}$/.test(val)) return false;
|
||||
if (!/^[a-zA-Z]\w{5,15}$/.test(val)) return false
|
||||
// true: 密码正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 强密码 (字母+数字+特殊字符,长度在6-16之间)
|
||||
export function verifyPasswordPowerful(val) {
|
||||
// false: 强密码不正确
|
||||
if (!/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) return false;
|
||||
if (!/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) return false
|
||||
// true: 强密码正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 密码强度
|
||||
export function verifyPasswordStrength(val) {
|
||||
let v = ''
|
||||
// 弱:纯数字,纯字母,纯特殊字符
|
||||
if (/^(?:\d+|[a-zA-Z]+|[!@#$%^&\.*]+){6,16}$/.test(val)) v = '弱';
|
||||
if (/^(?:\d+|[a-zA-Z]+|[!@#$%^&\.*]+){6,16}$/.test(val)) v = '弱'
|
||||
// 中:字母+数字,字母+特殊字符,数字+特殊字符
|
||||
if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = '中';
|
||||
if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = '中'
|
||||
// 强:字母+数字+特殊字符
|
||||
if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = '强';
|
||||
if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = '强'
|
||||
// 返回结果
|
||||
return v;
|
||||
return v
|
||||
}
|
||||
|
||||
// IP地址
|
||||
export function verifyIPAddress(val) {
|
||||
// false: IP地址不正确
|
||||
if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(val)) return false;
|
||||
if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(val)) return false
|
||||
// true: IP地址正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 邮箱
|
||||
export function verifyEmail(val) {
|
||||
// false: 邮箱不正确
|
||||
if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(val)) return false;
|
||||
if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(val)) return false
|
||||
// true: 邮箱正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 身份证
|
||||
export function verifyIdCard(val) {
|
||||
// false: 身份证不正确
|
||||
if (!/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(val)) return false;
|
||||
if (!/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(val)) return false
|
||||
// true: 身份证正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 姓名
|
||||
export function verifyFullName(val) {
|
||||
// false: 姓名不正确
|
||||
if (!/^[\u4e00-\u9fa5]{1,6}(·[\u4e00-\u9fa5]{1,6}){0,2}$/.test(val)) return false;
|
||||
if (!/^[\u4e00-\u9fa5]{1,6}(·[\u4e00-\u9fa5]{1,6}){0,2}$/.test(val)) return false
|
||||
// true: 姓名正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 邮政编码
|
||||
export function verifyPostalCode(val) {
|
||||
// false: 邮政编码不正确
|
||||
if (!/^[1-9][0-9]{5}$/.test(val)) return false;
|
||||
if (!/^[1-9][0-9]{5}$/.test(val)) return false
|
||||
// true: 邮政编码正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// url
|
||||
export function verifyUrl(val) {
|
||||
// false: url不正确
|
||||
if (!/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(val)) return false;
|
||||
if (!/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(val)) return false
|
||||
// true: url正确
|
||||
else return true;
|
||||
else return true
|
||||
}
|
||||
|
||||
// 车牌号
|
||||
export function verifyCarNum(val) {
|
||||
// false: 车牌号不正确
|
||||
if (!/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(val)) return false;
|
||||
if (!/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(val)) return false
|
||||
// true:车牌号正确
|
||||
else return true
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user