Initial commit

This commit is contained in:
2025-08-18 16:50:57 +08:00
commit 4fc95516d6
350 changed files with 175555 additions and 0 deletions

77
src/utils/auth.js Normal file
View File

@ -0,0 +1,77 @@
import {
getItem,
setItem
} from '@/utils/storage';
import {
TOKEN_TIMEOUT_VSLUE,
TIME_STAMP
} from '@/constant';
/*
* 1.设置时间戳
*/
export function setTimeStamp() {
setItem(TIME_STAMP, Date.now());
}
/*
* 2.获取时间戳
*/
export function getTimeStamp() {
return getItem(TIME_STAMP);
}
/*
* 1.是否超时 对比当前时间 和登录时间
*/
export function isCheckTimeout() {
const currentTime = Date.now();
const timeStamp = getTimeStamp();
return currentTime - timeStamp > TOKEN_TIMEOUT_VSLUE;
}
//格式化时间
export function dateFormat(date, fmt = "YY-MM-DD hh:mm:ss") {
let ret
const opt = {
"Y+": date.getFullYear().toString(), // 年
"M+": (date.getMonth() + 1).toString(), // 月
"D+": date.getDate().toString(), // 日
"h+": date.getHours().toString(), // 时
"m+": date.getMinutes().toString(), // 分
"s+": date.getSeconds().toString() // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
}
for (let k in opt) {
ret = new RegExp("(" + k + ")").exec(fmt)
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
}
}
return fmt
}
// 字符串拼数组
export function spliceArray(targetArr) {
let currentArr = []
if(targetArr.length > 0) {
targetArr.forEach((item, index) => {
if(index % 2 == 0 && index != targetArr.length){
currentArr.push([targetArr[index],targetArr[index+1]])
}
})
}
return currentArr
}
// 数组转字符串
export function spliceString(targetArr){
let tempArr = []
let currentStr = ''
if(targetArr.length > 0) {
targetArr.forEach(item => {
tempArr.push(...item)
})
currentStr = tempArr.toString()
}
return currentStr
}

95
src/utils/dict.js Normal file
View File

@ -0,0 +1,95 @@
import {
ref,
toRefs
} from 'vue';
export function getChildren(item) {
item.label = item.zdmc
item.value = item.dm
item.id = item.dm
if (item.itemList && item.itemList.length > 0) {
item.itemList.forEach(v => {
getChildren(v)
})
}
item.children = item.itemList
}
/**
* 设置级联选择器回显
* @param {*} id 选中ID
* @param {*} array 级联数据树
* @param {*} childDeptList 子集变量
*/
export function setCascader(id, array, childDeptList = 'childDeptList', fun) {
if (array) {
array.forEach(item => {
if (item.childDeptList && item.id != id) {
setCascader(id, item.childDeptList, childDeptList, fun)
} else if (item.childDeptList && item.id == id) {
fun(item)
} else if (!item.childDeptList && item.id == id) {
fun(item)
}
})
}
}
/**
* 当type=1时获取出生日期,type=2时获取性别,type=3时获取年龄 all
* @param {*} IdCard
* @param {*} type
* @returns
*/
export function IdCard(IdCard, type) {
let user = {
birthday: '',
sex: '',
age: ''
}
if (type === 1 || type == 'all') {
//获取出生日期
let birthday = IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14)
if (type == 'all') {
user.birthday = birthday
} else {
return birthday
}
}
if (type === 2 || type == 'all') {
//获取性别
if (parseInt(IdCard.substr(16, 1)) % 2 === 1) {
if (type == 'all') {
user.sex = '男'
} else {
return "男女"
}
} else {
if (type == 'all') {
user.sex = '女'
} else {
return "女"
}
}
}
if (type === 3 || type == 'all') {
//获取年龄
var ageDate = new Date()
var month = ageDate.getMonth() + 1
var day = ageDate.getDate()
var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day) {
age++
}
if (age <= 0) {
age = 1
}
if (type == 'all') {
user.age = age
} else {
return age
}
}
return user
}

23
src/utils/document.js Normal file
View File

@ -0,0 +1,23 @@
import axios from 'axios';
const baseUrl = "/daglApi";
export function getInfoPost(url, data = {}, token, fun) {
axios.post(`${baseUrl}${url}`, data, {
headers: {
"founder.authorization": `bearer ${token}`,
}
}).then(res => {
fun(res.data)
})
}
export function getInfo(url, params = {}, token, fun) {
axios.get(`${baseUrl}${url}`, {
params,
headers: {
"founder.authorization": `bearer ${token}`,
},
}).then(res => {
fun(res.data)
})
}

5
src/utils/eventBus.js Normal file
View File

@ -0,0 +1,5 @@
import mitt from 'mitt'
const emitter = mitt();
export default emitter

34
src/utils/lazyLoad.js Normal file
View File

@ -0,0 +1,34 @@
import {
getScrollContainer
} from "element-plus/lib/utils";
/**
* 自定义懒加载指令
*/
export default {
name:'InfiniteScroll',
inserted(el,binding,vnode){
//绑定回调函数
const cb = binding.value;
//当前组件实例引用
const vm = vnode.context;
const container = getScrollContainer(el,true);
const {delay,immediate} =getScrollOptions(el,vm);
const onScroll = throttle(delay,handleScroll.bind(el,cb));
el[scope] = {el,vm,container ,onScroll};
if(container){
container.addEventListener('scroll',onScroll);
if(immediate){
const observer = el[scope].observer = new MutationObserver(onScroll);
observer.observe(container,{childList:true,subtree:true});
onScroll()
}
}
},
unbind(el){
const {container,onScroll} = el[scope];
if(container){
container.removeEventListener('scrrll',onScroll)
}
}
}

View File

@ -0,0 +1,9 @@
import axios from 'axios';
import store from '@/store';
import {ElMessage} from 'element-plus';
const service = axios.create({
baseURL: '',
timeout: 100000
});
export default service;

94
src/utils/request.js Normal file
View File

@ -0,0 +1,94 @@
import axios from 'axios';
import store from '@/store';
import {
ElMessage
} from 'element-plus';
import {
isCheckTimeout
} from '@/utils/auth';
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 100000
});
// 1.请求拦截器
service.interceptors.request.use(
(config) => {
// 请求接口之前 做些什么
//1.统一注入token
if (store.getters.token) {
// if (isCheckTimeout()) {
// //超时 执行退出
// store.dispatch('user/logout');
// return Promise.reject(new Error('token 失效'));
// }
if (!config.url.startsWith("/jcApi")) {
config.headers.Authorization = `${store.getters.token}`;
}
}
//2.设置headers icode
// config.headers.code = '';
// 必须返回 config
return config;
},
(error) => {
return Promise.reject(error);
}
);
// 2.响应拦截器
service.interceptors.response.use(
// 请求成功的处理
(response) => {
const {
success,
code,
msg,
message,
data
} = response.data;
// 需要判断当前请求是否成功
if (success && code === 10000) {
return data; // 成功后返回解析后的数据
} else if (code === 200 || code == "00000" || code == "10000" || msg == 'success') {
return data; // 成功后返回解析后的数据
} else if (code === 401) {
store.dispatch('user/logout');
// ElMessage.error(message); // 提示错误信息
ElMessage({
message: message || msg,
grouping: true,
type: 'error'
})
} else {
// 失败(请求成功 ,业务失败) 弹出消息提示
ElMessage({
message: message || msg,
grouping: true,
type: 'error'
})
return Promise.reject(new Error(message));
}
},
// 请求失败处理
(error) => {
//token过期
if (
error.response &&
error.response.data &&
error.response.data.code === 401
) {
store.dispatch('user/logout');
}
ElMessage({
message: error.message,
grouping: true,
type: 'error'
})
return Promise.reject(error);
}
);
export default service;

75
src/utils/route.js Normal file
View File

@ -0,0 +1,75 @@
import path from "path";
/*
*获取所有的子集路由
*/
const getChildrenRoutes = (routes) => {
const result = [];
routes.forEach((route) => {
if (route.children && route.children.length > 0) {
result.push(...route.children);
}
});
return result;
};
/*
*处理脱离层级的路由
*/
export const filterRoutes = (routes) => {
//获取到所有的子集路由
const childrenRoutes = getChildrenRoutes(routes);
//根据子集路由进行查重操作
return routes.filter((route) => {
//根据route在childrenRoutes中进行查重把所有重复路由表 剔除
return !childrenRoutes.find((childrenRoute) => {
return childrenRoute.path === route.path;
});
});
};
function isNull(data) {
if (!data) return true;
if (JSON.stringify(data) === "{}") return true;
if (JSON.stringify(data) === "[]") return true;
return false;
}
/*
*根据routesfilterRoutes 数据, 返回对应的menu规则数据
*/
export function generateMenus(routes, basePath = "") {
const result = [];
// 遍历路由表
routes.forEach((item) => {
// 不存在 children && 不存在 meta 直接 return
if (isNull(item.meta) && isNull(item.children)) return;
// 存在 children 不存在 meta进入迭代
if (isNull(item.meta) && !isNull(item.children)) {
result.push(...generateMenus(item.children));
return;
}
// 合并 path 作为跳转路径
const routePath = path.resolve(basePath, item.path);
// 路由分离之后,存在同名父路由的情况,需要单独处理
let route = result.find((item) => item.path === routePath);
if (!route) {
route = {
...item,
path: routePath,
children: []
};
// icon 与 title 必须全部存在
if (route.meta.icon && route.meta.title) {
// meta 存在生成 route 对象,放入 arr
result.push(route);
}
}
// 存在 children 进入迭代到children
if (!isNull(item.children)) {
route.children.push(...generateMenus(item.children, route.path));
}
});
return result;
}

310
src/utils/rules.js Normal file
View File

@ -0,0 +1,310 @@
function isNull(data) {
if (!data) return true;
if (JSON.stringify(data) === "{}") return true;
if (JSON.stringify(data) === "[]") return true;
return false;
}
/* 1 . 手机校验 */
const validatePhone = () => {
return (rule, value, callback) => {
if (!value) {
} else {
const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
if (reg.test(value)) {
callback();
} else {
return callback(new Error("请输入正确的手机号"));
}
}
};
};
export const phoneRule = (rule,prop = 'phone') => {
if (isNull(rule)) return [];
const { require, validator } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请输入手机号",
trigger: "blur"
});
}
if (validator) {
result.push(
{
min: 11,
message: "手机号格式不正确",
trigger: "blur"
},
{
trigger: "blur",
validator: validatePhone()
}
);
}
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 手机校验end */
/* 2. 身份证校验 bengin */
const validateIdentity = () => {
return (rule, value, callback) => {
if (!value) {
// return callback(new Error('身份证号不能为空'));
} else if (!/(^\d{15}$)|(^\d{17}(\d|X|x)$)/.test(value)) {
callback(new Error("输入的身份证长度或格式错误"));
}
//身份证城市
var aCity = {
11: "北京",
12: "天津",
13: "河北",
14: "山西",
15: "内蒙古",
21: "辽宁",
22: "吉林",
23: "黑龙江",
31: "上海",
32: "江苏",
33: "浙江",
34: "安徽",
35: "福建",
36: "江西",
37: "山东",
41: "河南",
42: "湖北",
43: "湖南",
44: "广东",
45: "广西",
46: "海南",
50: "重庆",
51: "四川",
52: "贵州",
53: "云南",
54: "西藏",
61: "陕西",
62: "甘肃",
63: "青海",
64: "宁夏",
65: "新疆",
71: "台湾",
81: "香港",
82: "澳门",
91: "国外"
};
if (!aCity[parseInt(value?.substr(0, 2))]) { callback(new Error("身份证地区非法")); }
// 出生日期验证
var sBirthday = ( value.substr(6, 4) + "-" + Number(value.substr(10, 2)) + "-" + Number(value.substr(12, 2))).replace(/-/g, "/"),
d = new Date(sBirthday);
if ( sBirthday !== d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate()) {
callback(new Error("身份证上的出生日期非法"));
}
// 身份证号码校验
var sum = 0,
weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2],
codes = "10X98765432";
for (var i = 0; i < value.length - 1; i++) {
sum += value[i] * weights[i];
}
var last = codes[sum % 11]; //计算出来的最后一位身份证号码
if (value[value.length - 1] !== last) {
callback(new Error("输入的身份证号非法"));
}
callback();
};
};
export const identityCardRule = (rule,prop = 'idEntityCard') => {
if (isNull(rule)) return [];
const { require, validator } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请输入身份证号",
trigger: "blur"
});
}
if (validator) {
result.push({
trigger: "blur",
validator: validateIdentity()
});
}
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 身份证校验 end */
/* 3车牌号校验 */
const validateCarnumber = () => {
return (rule, value, callback) => {
const ptreg =
/^[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘桂琼川贵云渝藏陕甘青宁新粤]{1}[ABCDEFGHJKLMNOPQRSTUVWXY]{1}[0-9A-Z]{5}$/u;
const xnyreg =
/^[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘桂琼川贵云渝藏陕甘青宁新粤]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK]$)|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}$))/; // 2021年新能源车牌不止有DF
if (!value) {
callback(new Error("请选择车牌号"));
} else {
if (value.length === 7) {
if (!ptreg.test(value)) {
callback(new Error("请输入正确的普通车牌号"));
} else {
callback();
}
} else if (value.length === 8) {
if (!xnyreg.test(value)) {
callback(new Error("请输入正确的新能源车牌号"));
} else {
callback();
}
} else {
callback(new Error("车牌号错误"));
}
}
};
};
export const carNumberRule = (rule,prop = "carnumber") => {
if (isNull(rule)) return [];
const { require, validator } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请输入车牌号",
trigger: "blur"
});
}
if (validator) {
result.push({
trigger: "blur",
validator: validateCarnumber()
});
}
// return {
// carnumber: result
// };
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 3车牌号校验end */
/* 4民族校验 */
export const nationSelectRule = (rule,prop = 'nation') => {
if (isNull(rule)) return [];
const { require } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请选择民族",
trigger: "change"
});
}
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 5 组织机构 */
export const frameWorkRule = (rule,prop = 'frameWork') => {
if (isNull(rule)) return [];
const { require } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请选择组织机构",
trigger: "change"
});
}
// return {
// frameWork: result
// };
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 6 选择地址 */
export const addressSelectRule = (rule,prop = 'addredd') => {
if (isNull(rule)) return [];
const { require } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请选择地址",
trigger: "change"
});
}
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 7.Email */
const validateEmail = () => {
return (rule, value, callback) => {
const reg = /^([a-zA-Z0-9]+[-_\.]?)+@[a-zA-Z0-9]+\.[a-z]+$/;
if (!value) {
} else {
if (!reg.test(value)) {
return callback(new Error("请输入正确的邮箱地址"));
} else {
callback();
}
}
};
};
export const emailRule = (rule,prop = "email") => {
if (isNull(rule)) return [];
const { require, validator } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请输入邮箱",
trigger: "blur"
});
}
if (validator) {
result.push({
trigger: "change",
validator: validateEmail()
});
}
// return {
// email: result
// };
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};
/* 5 组织机构 */
export const departmentRule = (rule,prop = 'department') => {
if (isNull(rule)) return [];
const { require } = rule && { ...rule };
const result = [];
if (require) {
result.push({
required: true,
message: "请选择部门",
trigger: "change"
});
}
// return {
// frameWork: result
// };
const resultObj = {};
resultObj[prop] = result;
return { ...resultObj }
};

36
src/utils/storage.js Normal file
View File

@ -0,0 +1,36 @@
/*
*1.存储数据
*/
export const setItem = (key, value) => {
// value的两种情况 1. 基本数据类型 2.复杂数据类型
if (typeof value === "object") {
value = JSON.stringify(value);
}
window.localStorage.setItem(key, value);
};
/*
*2.获取数据
*/
export const getItem = (key) => {
const data = window.localStorage.getItem(key);
try {
return JSON.parse(data);
} catch (err) {
return data;
}
};
/*
*3.删除指定数据
*/
export const removeItem = (key) => {
window.localStorage.removeItem(key);
};
/*
*4.删除所有数据
*/
export const removeAllItem = () => {
window.localStorage.clear();
};

82
src/utils/theme.js Normal file
View File

@ -0,0 +1,82 @@
//导入色值表
import formula from '@/constant/formula.json';
import color from 'css-color-function';
import rgbHex from 'rgb-hex';
import axios from 'axios';
/*
*根据主题色 ,生成最新的样式表
*/
export const generateNewStyle = async (parimaryColor) => {
//1.根据主色 生成色值表
const colors = generateColors(parimaryColor);
//2.获取当前 element-plus 的默认样式表 并且把需要进行替换的色值打上标记
let cssText = await getOriginalStyle();
//3.遍历生成的色值表,在默认样式表 进行全局替换
Object.keys(colors).forEach((key) => {
// cssText = cssText.replace(
// new RegExp('(:|\\s+)' + key, 'g'),
// '$1' + colors[key]
// );
});
return cssText;
};
/*
*把生成的样式表写入到style中
*/
export const writeNewStyle = (newStyle) => {
const style = document.createElement('style');
style.innerText = newStyle;
document.head.appendChild(style);
};
export const generateColors = (primary) => {
if (!primary) return;
const colors = {
primary: primary
};
Object.keys(formula).forEach((key) => {
const value = formula[key].replace(/primary/g, primary);
colors[key] = '#' + rgbHex(color.convert(value));
});
return colors;
};
/*
* 获取当前 element-plus 的默认样式表
*/
const getOriginalStyle = async () => {
const version = require('element-plus/package.json').version;
// const url = `https://unpkg.com/element-plus@${version}/dist/index.css`;
// const { data } = await axios(url);
// // 把获取到的数据筛选为原样式模板
// return getStyleTemplate(data);
};
/**
* 返回 style 的 template
*/
const getStyleTemplate = (data) => {
// element-plus 默认色值
const colorMap = {
'#3a8ee6': 'shade-1',
'#409eff': 'primary',
'#53a8ff': 'light-1',
'#66b1ff': 'light-2',
'#79bbff': 'light-3',
'#8cc5ff': 'light-4',
'#a0cfff': 'light-5',
'#b3d8ff': 'light-6',
'#c6e2ff': 'light-7',
'#d9ecff': 'light-8',
'#ecf5ff': 'light-9'
};
// 根据默认色值为要替换的色值打上标记
Object.keys(colorMap).forEach((key) => {
const value = colorMap[key];
data = data.replace(new RegExp(key, 'ig'), value);
});
return data;
};

251
src/utils/tools.js Normal file
View File

@ -0,0 +1,251 @@
;
// 随机颜色 - 把16进制的颜色换成rgba格式
export function choseRbgb(color,opcity) {
if(color){
return 'rgba('+ parseInt('0x'+color.slice(1,3)) + ','+ parseInt('0x'+color.slice(3,5))+','+parseInt('0x'+color.slice(5,7)) + ','+opcity+')'
}else{
let r = Math.floor(Math.random()*256)
let g = Math.floor(Math.random()*256)
let b = Math.floor(Math.random()*256)
let a = opcity ? opcity :1
return `rgba(${r},${g},${b},${a})`
}
}
// 毫秒转时长
export function formatDuring(mss) {
var days = parseInt(mss / (1000 * 60 * 60 * 24));
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
var seconds = (mss % (1000 * 60)) / 1000;
if (days) {
return days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
} else if (hours) {
return hours + "小时" + minutes + "分钟" + seconds + "秒";
} else if (minutes) {
return minutes + "分钟" + seconds + "秒";
} else {
return seconds + "秒";
}
}
// 今天周几
export function weekValidate() {
let week = new Date().getDay()
let weekenday = ''
switch (week) {
case 0: return weekenday = '星期日'
case 1: return weekenday = '星期一'
case 2: return weekenday = '星期二'
case 3: return weekenday = '星期三'
case 4: return weekenday = '星期四'
case 5: return weekenday = '星期五'
case 6: return weekenday = '星期六'
}
}
// 转换时间格式
export function timeValidate(date, type) {
const time = date ? new Date(date) : new Date()
const yyyy = time.getFullYear()
const MM = (time.getMonth() + 1).toString().padStart(2, 0)
const dd = time.getDate().toString().padStart(2, '0')
const hh = time.getHours().toString().padStart(2, '0')
const mm = time.getMinutes().toString().padStart(2, '0')
const ss = time.getSeconds().toString().padStart(2, '0')
if (type == 'ymd') {
return `${yyyy}-${MM}-${dd}`;
}
if (type == 'md') {
return `${MM}.${dd}`
}
return `${yyyy}-${MM}-${dd} ${hh}:${mm}:${ss}`
}
// 获取当前近多少天 7后7天 -7 前五天
export function getRecentDay(n) {
var currentDate = new Date();
var preDate = new Date(currentDate.getTime() + n * 24 * 3600 * 1000)
let year = preDate.getFullYear()
let mon = preDate.getMonth() + 1
let day = preDate.getDate()
let s = year + '-' + (mon < 10 ? ('0' + mon) : mon) + '-' + (day < 10 ? ('0' + day) : day)
return s
}
// 获取n近7月 7后7 -7 前
export function getnRencebtMonth(n) {
let date = new Date();
date.setMonth(date.getMonth() - n)
date.toLocaleDateString()
let y = date.getFullYear()
let m = date.getMonth() + 1
m = m < 10 ? ('0' + m) : m + ''
return y + m
}
/**
* 数据去重 相同数据值累加
* @param {Object} array 数据
*/
export function setArray(array) {
let newArr = []
array.forEach(item => {
const res = newArr.findIndex(ol => {
//组织机构代码相同 并且报警类别相同
return item.ssbmdm == ol.ssbmdm && item.bjlb == ol.bjlb
})
if (res !== -1) {
newArr[res].sl = newArr[res].sl + item.sl
} else {
newArr.push(item)
}
})
return newArr
}
/**
* 合并数据
* @param {Object} array 数据
*/
export function hbArray(array, item1, item2, item3) {
let newArr = []
array.forEach(item => {
const res = newArr.findIndex(ol => {
//组织机构代码相同 并且报警类别相同
return item.product == ol.product
})
if (res !== -1) {
newArr[res][item1] = newArr[res][item1] + item[item1]
newArr[res][item2] = newArr[res][item2] + item[item2]
newArr[res][item3] = newArr[res][item3] + item[item3]
} else {
newArr.push(item)
}
})
return newArr
}
//时间格式
export function dateFormat(type, time) {
let date
if (time) {
date = new Date(time);
} else {
date = new Date();
}
let year = date.getFullYear();
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
let day
if (type == 'z') {
//前一天日期
day = date.getDate() - 1;
day = day < 10 ? "0" + day : day;
return `${year}-${month}-${day}`;
} else if (type == 'all') {
//格式化日期时间
day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
} else {
//当天日期
day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return `${year}-${month}-${day}`;
}
return day
}
//数字超长处理
export function handleNum(num) {
var data = 0
if (num) {
try {
if (num * 1 > 100000) {
data = (num / 10000).toFixed(0) + '万'
} else {
data = (num * 1).toFixed(0)
}
} catch (error) {
data = 0
}
}
return data
}
/**
* 文件是否是图片
* @param {*} val
*/
export function IS_PNG(val) {
return ['bmp', 'jpg', 'png', 'tif', 'gif', 'pcx', 'tga', 'exif', 'fpx', 'svg', 'psd', 'cdr', 'pcd', 'dxf', 'ufo',
'eps', 'ai', 'raw', 'wmf', 'webp', 'avif', 'apng'
].indexOf(val.toLowerCase()) !== -1
}
/**
* 文件是否是音频
* @param {*} val
*/
export function IS_MP3(val) {
return ['mp3', 'wav', 'wma', 'mp2', 'flac', 'midi', 'ra', 'ape', 'aac', 'cda', 'mov'].indexOf(val.toLowerCase()) !==
-1
}
/**
* 文件是否是视频
* @param {*} val
*/
export function IS_MP4(val) {
return ['avi', 'wmv', 'mpeg', 'mp4', 'm4v', 'mov', 'asf', 'fiv', 'f4v', 'mvb', 'rm', '3gp', 'vob'].indexOf(val
.toLowerCase()) !== -1
}
function handelArr(arr) {
let brr = []
if (arr && arr.length > 0) {
let obj = {}
let coords = "";
for (let i = 0; i < arr.length; i++) {
coords += arr[i] + ","
}
obj.coords = coords
brr.push(obj)
}
return brr
}
/**
* 时间 天数
* @param {*} val
*/
export function setEchartTime(val) {
let date = new Date();
let arrTime = [];
if (val == 0) {
for (let i = 0; i < 24; i++) {
arrTime.push(i)
}
} else {
for (let i = 0; i < val; i++) {
let date1 = new Date(date.getTime() - i * 24 * 60 * 60 * 1000)
arrTime.push(_setTime(date1))
}
arrTime.reverse()
}
return arrTime
}
//设置时间
function _setTime(date) {
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return `${month}-${day}`;
}

68
src/utils/validate.js Normal file
View File

@ -0,0 +1,68 @@
/**
* 判断是否为外部资源
*/
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
export function validateCarnumber(rule, value, callback) {
const ptreg = /^[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘桂琼川贵云渝藏陕甘青宁新粤]{1}[ABCDEFGHJKLMNOPQRSTUVWXY]{1}[0-9A-Z]{5}$/u;
const xnyreg = /^[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘桂琼川贵云渝藏陕甘青宁新粤]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK]$)|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}$))/; // 2021年新能源车牌不止有DF
if (!value) {
callback(new Error('请选择车牌号'))
} else {
if (value.length === 7) {
if (!ptreg.test(value)) {
callback(new Error('请输入正确的普通车牌号'))
} else {
callback()
}
} else if (value.length === 8) {
if (!xnyreg.test(value)) {
callback(new Error('请输入正确的新能源车牌号'))
} else {
callback()
}
} else {
callback(new Error('车牌号错误'))
}
}
}
// 表单重置
export function resetForm(refName) {
if (this.$refs[refName]) {
this.$refs[refName].resetFields();
}
}
//当type=1时获取出生日期,type=2时获取性别,type=3时获取年龄
export function IdCard(IdCard, type) {
if (type === 1) {
//获取出生日期
let birthday = IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14)
return birthday
}
if (type === 2) {
//获取性别
if (parseInt(IdCard.substr(16, 1)) % 2 === 1) {
return "男"
} else {
return "女"
}
}
if (type === 3) {
//获取年龄
var ageDate = new Date()
var month = ageDate.getMonth() + 1
var day = ageDate.getDate()
var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day) {
age++
}
if (age <= 0) {
age = 1
}
return age
}
}

65
src/utils/webSocket.js Normal file
View File

@ -0,0 +1,65 @@
const url = "ws://47.108.232.77:7555/socket/"; //线上
class WebSoketClass {
constructor(props) { }
ws = null;
static getInstance() {
if (!this.ws) this.ws = new WebSoketClass();
return this.ws;
}
//关闭连接
static close() {
this.ws.ws.close();
}
// 创建连接
connect(fun) {
let uuid = this.getUUid()
this.ws = new WebSocket(url + uuid);
this.ws.onopen = (e) => { fun(true); };
}
// 心跳机制
heartCheck() {
const _that = this;
this.state = setInterval(() => {
if (this.ws.readyState === 1) {
this.ws.send("/heart");
} else {
this.closeHandle(); //重新连接
}
}, 6e3);
}
// 获取uuid
getUUid() {
var s = [];
var hexDigits = "0123456789abcdefghijklmnopqrstuvwxyz";
for (var i = 0; i < 32; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23];
let uuid = s.join("");
return uuid
}
closeHandle() {
if (this.state) {
clearInterval(this.state);
this.connect();
} else {
}
}
// 接收发送消息
getMessage() {
this.ws.onmessage = (e) => {
if (e.data) {
let newsDate = JSON.parse(e.data);
this.newVal = newsDate;
//接收的数据
}
};
}
}
export default WebSoketClass;