You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
crm-project/src/utils/util.js

79 lines
2.4 KiB

/*
* @Descripttion: 前端工具类,处理时间、数组处理等
* @version:
* @Author: Lone
* @Date: 2021-09-29 16:11:53
* @LastEditors: Lone
* @LastEditTime: 2022-01-04 19:51:03
*/
const Util = {
/**
* @name: 多色彩的打印函数
* @param {*} value 需要打印的值
* @param {*} key 值的备注
* @param {*} type 打印样式的类型
* @return {*} null
*/
console (value, key, type) {
let styleTheme = '';
if (!type) styleTheme = 'font-size:14px;line-height:28px;padding:0 8px;background:#222;color: #fadfa3';
if (type == 1) styleTheme = 'font-size:14px;line-height:28px;padding:0 8px;background:#fadfa3;color: #000';
if (type == 2) styleTheme = 'font-size:14px;line-height:28px;padding:0 8px;background:#ff8400;color: #fff';
console.log(
`%c ${ key != undefined ? key : '打印的是' } `,
styleTheme,
value
);
},
/**
* @name: 密码检查函数
* @param {*} pwd1
* @param {*} pwd2
* @return {*}
*/
checkPassword(pwd1, pwd2) {
if (pwd1 != pwd2) return { flag: false, message: '两次输入的密码不一致' };
if (pwd1.length < 6 || pwd2.length < 6) return { flag: false, message: '密码长度至少为6位' };
return { flag: true, message: '验证通过' };
},
/**
* @name: 数据整洁函数,用于清空表单输入等场景,默认返回所有值均为空值
* @param {*} data
* @return {*}
*/
tidy(data) {
for (let key in data) {
data[key] = '';
};
return data;
},
/**
* @name: 验证邮箱地址是否输入正确
* @param {*} mail
* @return {*}
*/
checkMail(mail) {
let Regex = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
console.log(Regex.test(mail), '验证电子邮件的结果是');
if (!Regex.test(mail)) return { flag: false, message: '请输入有效的电子邮件!' };
if (Regex.test(mail)) return { flag: true, message: '验证通过' };
}
}
const install=function(Vue){
if (install.installed) return // 如果已经注册过了,就跳过
install.installed = true
Object.defineProperties(Vue.prototype, {
$util: {
get(){
return Util;
}
}
})
}
export default {
install,
...Util
}