保存进度!
This commit is contained in:
49
企业级管理系统/web/项目源码/src/utils/common.js
Normal file
49
企业级管理系统/web/项目源码/src/utils/common.js
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @param { String } value 时间的值
|
||||
* @param { String } type
|
||||
* @param { Boolean } br true换行、false默认
|
||||
* @param { String } conn 任意字符
|
||||
* @returns 日期格式化
|
||||
*/
|
||||
export function getDate(params){
|
||||
const new_date = params.value ? new Date(params.value) : new Date();
|
||||
let year = new_date.getFullYear(); //年
|
||||
let month = new_date.getMonth() + 1; //月
|
||||
let day = new_date.getDate(); //日
|
||||
let hh = new_date.getHours(); //时
|
||||
let mm = new_date.getMinutes(); //分
|
||||
let ss = new_date.getSeconds(); //分
|
||||
if(month < 10) { month = `0${month}`; }
|
||||
if(day < 10) { day = `0${day}`; }
|
||||
if(hh < 10) { hh = `0${hh}`; }
|
||||
if(mm < 10) { mm = `0${mm}`; }
|
||||
if(ss < 10) { ss = `0${ss}`; }
|
||||
// 连接符
|
||||
const conn = params.connDate || "-";
|
||||
// 格式化
|
||||
const br = params.br ? "<br />" : " ";
|
||||
const date = `${year}${conn}${month}${conn}${day}`;
|
||||
const time = `${hh}:${mm}:${ss}`;
|
||||
// 仅日期
|
||||
if(params.type === "date") { return date; }
|
||||
// 仅时间
|
||||
if(params.type === "time") { return time; }
|
||||
// 整体
|
||||
return `${date}${br}${time}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { Function } fun 执行的函数
|
||||
* @param { Number } time 延时执行时间,默认500毫秒
|
||||
* @returns 防抖函数
|
||||
*/
|
||||
export function debounce(fun, time = 500) {
|
||||
let timer;
|
||||
return function() {
|
||||
let args = arguments;
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
fun.apply(this, args)
|
||||
}, time)
|
||||
}
|
||||
}
|
18
企业级管理系统/web/项目源码/src/utils/cookies.js
Normal file
18
企业级管理系统/web/项目源码/src/utils/cookies.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import Cookies from "js-cookie";
|
||||
// 变量
|
||||
const tokenKey = "tokenAdmin";
|
||||
const userNameKey = "username";
|
||||
|
||||
// 获取token
|
||||
export function getToken(){ return Cookies.get(tokenKey); }
|
||||
// 写入token
|
||||
export function setToken(value){ Cookies.set(tokenKey, value); }
|
||||
// 删除token
|
||||
export function removeToken(){ Cookies.remove(tokenKey); }
|
||||
|
||||
// 获取userName
|
||||
export function getUsername(){ return Cookies.get(userNameKey); }
|
||||
// 写入userName
|
||||
export function setUsername(value){ Cookies.set(userNameKey, value); }
|
||||
// 删除userName
|
||||
export function removeUsername(){ Cookies.remove(userNameKey); }
|
42
企业级管理系统/web/项目源码/src/utils/format.js
Normal file
42
企业级管理系统/web/项目源码/src/utils/format.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @param { responseData } Object 请求参数数据
|
||||
* @param { formData } Object Form表单字段
|
||||
* @returns 枚举匹配key
|
||||
*/
|
||||
export function formatRequestData(responseData, formData){
|
||||
// 判断是否有值存在
|
||||
if(JSON.stringify(responseData) === "{}") { return false; }
|
||||
// 获取form表单字段的所有key
|
||||
const keys = Object.keys(responseData);
|
||||
// 空JSON对象,存储过滤出来的数据
|
||||
const data_json = {};
|
||||
// 执行字段匹配
|
||||
for(let key in formData) {
|
||||
if(keys.includes(key) && formData.hasOwnProperty(key)) {
|
||||
data_json[key]= responseData[key];
|
||||
}
|
||||
}
|
||||
// 返回处理后的数据
|
||||
return data_json;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns 递归函数格式化树状菜单
|
||||
*/
|
||||
export function formatTree(data, id = "id", pid = "parent_id", child = "children", root){
|
||||
const tree = [];
|
||||
if(data && data.length > 0) {
|
||||
data.forEach(item => {
|
||||
// 获取顶层菜单,parent_id === 0
|
||||
if(item[pid] === root) {
|
||||
const children = formatTree(data, id, pid, child, item[id]);
|
||||
if(children) {
|
||||
item[child] = children;
|
||||
}
|
||||
tree.push(item);
|
||||
}
|
||||
})
|
||||
}
|
||||
return tree;
|
||||
}
|
59
企业级管理系统/web/项目源码/src/utils/global.js
Normal file
59
企业级管理系统/web/项目源码/src/utils/global.js
Normal file
@@ -0,0 +1,59 @@
|
||||
// Element Plus
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
// 命名空间
|
||||
const globalFunction = {}
|
||||
/**
|
||||
* @param { message } String 内容,可选
|
||||
* @param { title } String 标题,可选
|
||||
* @param { thenFun } Function 回调函数,可选
|
||||
* @description 确认弹窗
|
||||
*/
|
||||
globalFunction.deleteConfirm = (params) => {
|
||||
ElMessageBox.confirm(params.message || '确认删除当前数据吗?删除后将无法恢复', params.title || '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
showClose: false, // 取消右上角关闭按钮
|
||||
closeOnClickModal: false, // 取消点击遮罩关闭 MessageBox
|
||||
closeOnPressEscape: false, // 取消按下ESC键关闭MessageBox
|
||||
type: 'warning',
|
||||
beforeClose: (action, instance, done) => {
|
||||
globalFunction.deleteConfirmObj = { instance, done };
|
||||
if(action === "confirm") {
|
||||
// 按钮加载状态
|
||||
globalFunction.confirmButtonLoading(true);
|
||||
// 判断thenFun存在并且是Function类型,是则自动执行函数
|
||||
params.thenFun && Object.prototype.toString.call(params.thenFun) === "[object Function]" && params.thenFun();
|
||||
}else{
|
||||
globalFunction.deleteConfirmClose();
|
||||
}
|
||||
}
|
||||
}).then(()=>{}).catch(()=>{})
|
||||
|
||||
}
|
||||
/**
|
||||
* @param { bool } Boolean 加载状态,可选
|
||||
* @description 弹窗确认按钮加载状态
|
||||
*/
|
||||
globalFunction.confirmButtonLoading = (bool) => {
|
||||
globalFunction.deleteConfirmObj.instance.confirmButtonLoading = bool;
|
||||
}
|
||||
/**
|
||||
* @param {*} params
|
||||
*/
|
||||
globalFunction.deleteConfirmClose = () => {
|
||||
globalFunction.deleteConfirmObj.done();
|
||||
globalFunction.deleteConfirmObj = null;
|
||||
}
|
||||
/** 函数2 */
|
||||
globalFunction.message = (params) => {
|
||||
console.log(params)
|
||||
}
|
||||
|
||||
export default {
|
||||
install(app){
|
||||
app.config.globalProperties["deleteConfirm"] = globalFunction.deleteConfirm;
|
||||
app.config.globalProperties["deleteConfirmClose"] = globalFunction.deleteConfirmClose;
|
||||
app.config.globalProperties["confirmButtonLoading"] = globalFunction.confirmButtonLoading;
|
||||
app.config.globalProperties["message"] = globalFunction.message;
|
||||
}
|
||||
}
|
61
企业级管理系统/web/项目源码/src/utils/request.js
Normal file
61
企业级管理系统/web/项目源码/src/utils/request.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import axios from "axios";
|
||||
// cookies
|
||||
import { getToken, getUsername, removeToken, removeUsername } from "@/utils/cookies"; // 这是封装好的方法
|
||||
// ElementUI 单独引入
|
||||
import { ElMessage } from 'element-plus'
|
||||
// vue-router
|
||||
import router from "@/router";
|
||||
// 创建实例
|
||||
const instance = axios.create({
|
||||
baseURL: process.env.VUE_APP_API, // 请求地址
|
||||
timeout: 5000, // 超时
|
||||
});
|
||||
// 拦截器
|
||||
// 添加请求拦截器
|
||||
instance.interceptors.request.use(function (config) {
|
||||
// 在发送请求之前做些什么
|
||||
if(getToken()) {
|
||||
config.headers['Token'] = getToken(); // 携带token
|
||||
}
|
||||
if(getUsername()) {
|
||||
config.headers['Username'] = getUsername(); // 携带用户名
|
||||
}
|
||||
return config;
|
||||
}, function (error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
// 添加响应拦截器
|
||||
instance.interceptors.response.use(function (response) {
|
||||
// 对响应数据做点什么
|
||||
const data = response.data;
|
||||
if(data.resCode === 0) {
|
||||
return Promise.resolve(data);
|
||||
}else{
|
||||
ElMessage({
|
||||
message: data.message,
|
||||
type: "error"
|
||||
})
|
||||
return Promise.reject(data);
|
||||
}
|
||||
}, function (error) {
|
||||
const errorData = JSON.parse(error.request.response);
|
||||
if(errorData.message) {
|
||||
ElMessage({
|
||||
message: errorData.message,
|
||||
type: "error"
|
||||
})
|
||||
}
|
||||
// token失效自动退出
|
||||
if(errorData.resCode === 1010) {
|
||||
router.replace({
|
||||
name: "Login"
|
||||
})
|
||||
removeToken();
|
||||
removeUsername();
|
||||
}
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(errorData);
|
||||
});
|
||||
// 暴露instance
|
||||
export default instance;
|
40
企业级管理系统/web/项目源码/src/utils/validate.js
Normal file
40
企业级管理系统/web/项目源码/src/utils/validate.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// 校验邮箱
|
||||
export function validate_email(value){
|
||||
let regEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
|
||||
return regEmail.test(value);
|
||||
}
|
||||
|
||||
// 校验密码
|
||||
export function validate_password(value){
|
||||
let regPassword = /^(?!\D+$)(?![^a-zA-Z]+$)\S{6,20}$/;
|
||||
return regPassword.test(value);
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
export function validate_code(value){
|
||||
let regCode = /^[a-z0-9]{6}$/;
|
||||
return regCode.test(value);
|
||||
}
|
||||
|
||||
|
||||
// 密码校验
|
||||
export function checkPassword(rule, value, callback, source, options) {
|
||||
if(!value || value === ""){
|
||||
callback(new Error("请输入用密码"));
|
||||
}else if(!validate_password(value)) {
|
||||
callback(new Error("请输入>=6并且<=20位的密码,包含数字、字母"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
// 用户名校验
|
||||
export function checkUser(rule, value, callback, source, options) {
|
||||
if(!value || value === ""){
|
||||
callback(new Error("请输入用户名"));
|
||||
}else if(!validate_email(value)) {
|
||||
callback(new Error("邮箱格式不正确"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user