This commit is contained in:
lcw
2025-06-08 22:23:25 +08:00
commit d9f272ca7d
1154 changed files with 276763 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
}

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

@ -0,0 +1,124 @@
import {
ref,
toRefs
} from 'vue';
import {
getSysDictByCode
} from '@/api/sysDict' //引入封装数字字典接口
/**
* 获取字典数据
*/
let list = []
export function getDict(...args) {
const res = ref({});
return (() => {
args.forEach((d, index) => {
res.value[d] = [];
getSysDictByCode({
dictCode: d
}).then(result => {
result.itemList.forEach(p => {
p.label = p.zdmc
p.value = p.dm
p.id = p.dm
p.elTagType = p.dictType
if ( p.itemList && p.itemList.length > 0) {
getChildren(p)
}
p.children = p.itemList
})
res.value[d] = result.itemList
})
})
return toRefs(res.value);
})()
}
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
}

28
src/utils/dictionary.js Normal file
View File

@ -0,0 +1,28 @@
// 人员警种类型 D_BZ_RYJZLB
// 人员民辅警类别 D_BZ_RYMFJLB
// 人员警种类别D_BZ_RYJZLB
// 人员类别D_BZ_RYLB
// 保密级别D_BZ_BMJB
// 是否 D_BZ_SF
// 性别 D_BZ_XB
// 设备类型D_JCGL_TCSB_SBLX
// 设备网络类型D_JCGL_TCSB_WLLX
// 终端设备类型D_JCGL_ZDSB_SBLX
// 器械类型 D_JCGL_JYQX_QXLX
// 警用交通范围类别(大类别) D_JCGL_JYCL_JYJTFWLB
// 警用交通工具类别(小类别) D_JCGL_JYCL_JYJTGJLB
// 警用交通用途类别(类型) D_JCGL_JYCL_JYJTYTLB
// 警种类型 D_BZ_RYJZLB
// 号牌颜色类别 D_JCGL_JYCL_HPYSLB
// 频道电台类型 D_BZ_PDDTLX
// 勤务报备种类 D_QW_BBZL
// 频道电台类型 D_BZ_PDDTLX
// 跨天数D_QW_BC_KTS
// 警组勤务报备种类 D_QW_BBZL
// 巡防武装类型 D_BZ_WZLX
// 巡防巡逻方式 D_BZ_XLFS
// 巡防着装类型 D_BZ_ZZLX

392
src/utils/dicts.js Normal file
View File

@ -0,0 +1,392 @@
const JWZLXDM = {
'1': '街面警务站',
'2': '综合治安岗亭',
'3': '移动警务车组',
'4': '其他'
}
const GAJGJGDM = {
'1': '街面警务站',
'2': '综合治安岗亭',
'3': '移动警务车组',
'4': '其他'
}
const XLRYLBDM = {
'01': '巡警',
'02': '特警',
'03': '辅警',
'04': '派出所民警',
'05': '交警',
'06': '单位保安',
'07': '志愿者',
'99': '其他'
}
const XZQHDM = {
'510502': '四川省泸州市江阳区(510502)',
'510503': '四川省泸州市纳溪区(510503)',
'510504': '四川省泸州市龙马潭区(510504)',
'510521': '四川省泸县(510521)',
'510522': '四川省合江县(510522)',
'510524': '四川省叙永县(510524)',
'510525': '四川省古蔺县(510525)'
}
const XQFWLX = {
'1': '支队巡区',
'2': '大队巡区',
'3': '大队巡区网格',
'4': '派出所巡区网格',
'5': '派出所辖区'
}
const XQLXDM = {
'1': '一般区域',
'2': '人员密集场所',
'3': '重点核心区',
'9': '其他'
}
const BQMC = {
'01': '涉毒',
'02': '涉疆'
}
const PCCLJG = {
'1': '移交',
'2': '放行'
}
/** 装备 **/
const XLZBLXDM = {
'01': '移动警务终端',
'02': '执法记录仪',
'03': '智能化单兵设备',
'04': '警犬',
'05': '无人机',
'97': '武器',
'98': '对讲机',
'99': '其他'
}
const ZBZTDM = {
'1': '正常',
'2': '维修',
'3': '报废',
'4': '其他'
}
/** 指令 **/
const ZLLYDM = {
'01': '云墙',
'02': '犯罪预测',
'03': '警情',
'99': '人工下发'
}
const ZLLXDM = {
'01': '核查指定人员',
'02': '核查指定车辆',
'03': '警情',
'04': '巡防',
'05': '核查某类人员',
'06': '核查某类车辆',
'07': '消息',
'99': '其它指令'
}
const ZLGZYYJLX = {
'1': '人',
'2': '车',
'3': '电',
'4': '网',
'5': '像'
}
const ZLYJRCBQ = {
'01': '在逃',
'02': '涉毒',
'03': '前科',
'04': '肇事',
'05': '临控',
'80': '被盗抢车辆'
}
const ZLYJRCBQDM = {
'ZT': '在逃',
'SD': '涉毒',
'QK': '前科',
'ZS': '肇事',
'LKRY': '临控',
'LKCL': '临控',
'DQ': '被盗抢'
}
const PCRCBQ = {
'ZTRY': '在逃',
'XFDRY': '涉毒',
'QKRY': '前科',
'ZSRY': '肇事',
'LKRY': '临控',
'LKJDC': '临控',
'BDQJDC': '被盗抢'
}
const ZLFWDM = {
'1': '单人',
'2': '多人',
'3': '部门'
}
const ZLJBDM = {
'01': '红色',
'02': '橙色',
'03': '黄色',
'04': '蓝色'
}
const ZLANDYJBM = {
'10': '红色',
'15': '橙色',
'20': '黄色',
'30': '蓝色'
}
const ZLZTDM = {
'01': '待签收',
'02': '已签收',
'03': '到达现场',
'04': '已反馈',
'05': '处置完成',
'99': '归档'
}
const LOGINTYPE={
'0':'电脑',
'1':'手机'
}
const JQZTDM = {
'01': '未处理',
'02': '已处理'
}
const ZLYXQDM = {
'01': '一分钟',
'02': '五分钟',
'03': '十分钟',
'04': '三十分钟',
'05': '一小时',
'06': '当天',
'99': '指定结束时间'
}
const ZQLXDM = {
'03': '步巡',
'04': '车巡',
'05': '特殊报备'
}
const D_BZ_XB = {
"0":"未知的性别","1":"男","2":"女","9":"未说明的性别"
}
const XLDM = {"11":"博士","14":"硕士","17":"研究生","20":"本科","30":"专科","40":"中职","60":"普通高中","70":"初中","80":"小学","90":"其他"}
const HYZKDM = {"10":"未婚","20":"已婚","30":"丧偶","40":"离婚","90":"未说明的婚姻状况"}
const ZZMMDM = {"01":"中共党员","02":"中共预备党员","03":"共青团员","12":"无党派民主人士","13":"群众"}
const XLMJ_JWYWZJBDM = {"1000":"武装警察","1101":"上将","1102":"中将","1103":"少将","1201":"大校","1202":"上校","1203":"中校","1204":"少校","1301":"上尉","1302":"中尉","1303":"少尉","1411":"文职特级","1412":"文职1级","1413":"文职2级","1421":"文职3级","1422":"文职4级","1423":"文职5级","1424":"文职6级","1431":"文职7级","1432":"文职8级","1433":"文职9级","1501":"一级警士长","1502":"二级警士长","1503":"三级警士长","1514":"四级警士长","1515":"上士","1526":"中士","1527":"下士","1602":"专业技术中将","1603":"专业技术少将","1611":"专业技术大校","1612":"专业技术上校","1613":"专业技术中校","1614":"专业技术少校","1621":"专业技术上尉","1622":"专业技术中尉","1623":"专业技术少尉","1710":"上等兵","1720":"列兵","1880":"学员","1990":"未授武装警察警衔","1999":"其他","2000":"人民警察","2011":"总警监","2012":"副总警监","2101":"一级警监","2102":"二级警监","2103":"三级警监","2201":"一级警督","2202":"二级警督","2203":"三级警督","2301":"一级警司","2302":"二级警司","2303":"三级警司","2401":"一级警员","2402":"二级警员","2601":"专业技术一级警监","2602":"专业技术二级警监","2603":"专业技术三级警监","2701":"专业技术一级警督","2702":"专业技术二级警督","2703":"专业技术三级警督","2801":"专业技术一级警司","2802":"专业技术二级警司","2803":"专业技术三级警司","2901":"专业技术一级警员","2997":"见习人民警察","2998":"警察院校学员","2999":"其他"}
const D_BZ_MZ={"01":"汉族","02":"蒙古族","03":"回族","04":"藏族","05":"维吾尔族","06":"苗族","07":"彝族","08":"壮族","09":"布依族","10":"朝鲜族","11":"满族","12":"侗族","13":"瑶族","14":"白族","15":"土家族","16":"哈尼族","17":"哈萨克族","18":"傣族","19":"黎族","20":"傈僳族","21":"佤族","22":"畲族","23":"高山族","24":"拉祜族","25":"水族","26":"东乡族","27":"纳西族","28":"景颇族","29":"柯尔克孜族","30":"土族","31":"达斡尔族","32":"仫佬族","33":"羌族","34":"布朗族","35":"撒拉族","36":"毛南族","37":"仡佬族","38":"锡伯族","39":"阿昌族","40":"普米族","41":"塔吉克族","42":"怒族","43":"乌孜别克族","44":"俄罗斯族","45":"鄂温克族","46":"德昂族","47":"保安族","48":"裕固族","49":"京族","50":"塔塔尔族","51":"独龙族","52":"鄂伦春族","53":"赫哲族","54":"门巴族","55":"珞巴族","56":"基诺族","57":"其他","58":"外国血统"};
const CLLXDM = {
'01': '警车机动车',
'02': '警用摩托车',
'03': '电动巡逻车',
'04': '自行车',
'05': '助力车',
'06': '装甲车',
'99': '其他'
}
const CLZTDM = {
'1': '正常',
'2': '维修',
'3': '报废',
'4': '其他'
}
const CLPPDM={
"000":"其他",
"001":"大众",
"002":"别克",
"003":"宝马",
"004":"本田",
"005":"标致",
"006":"丰田",
"007":"福特",
"008":"日产",
"009":"奥迪",
"010":"马自达",
"011":"雪佛兰",
"012":"雪铁龙",
"013":"现代",
"014":"奇瑞",
"015":"起亚",
"016":"荣威",
"017":"三菱",
"018":"斯柯达",
"019":"吉利",
"020":"中华",
"021":"沃尔沃",
"022":"雷克萨斯",
"023":"菲亚特",
"024":"吉利帝豪",
"025":"东风",
"026":"比亚迪",
"027":"铃木",
"028":"金杯",
"029":"海马",
"030":"五菱",
"031":"江淮",
"032":"斯巴鲁",
"033":"英伦",
"034":"长城",
"035":"哈飞",
"036":"庆铃(五十铃)",
"037":"东南",
"038":"长安",
"039":"福田",
"040":"夏利",
"041":"奔驰",
"042":"一汽",
"043":"依维柯",
"044":"力帆",
"045":"一汽奔腾",
"046":"皇冠",
"047":"雷诺",
"048":"JMC",
"049":"MG名爵",
"050":"凯马",
"051":"众泰",
"052":"昌河",
"053":"厦门金龙",
"054":"上海汇众",
"055":"苏州金龙",
"056":"海格",
"057":"宇通",
"058":"中国重汽",
"059":"北奔重卡",
"060":"华菱星马汽车",
"061":"跃进汽车",
"062":"黄海汽车",
"065":"保时捷",
"066":"凯迪拉克",
"067":"英菲尼迪",
"068":"吉利全球鹰",
"069":"吉普",
"070":"路虎",
"071":"长丰猎豹",
"073":"时代汽车",
"075":"长安轿车",
"076":"陕汽重卡",
"081":"安凯",
"082":"申龙",
"083":"大宇",
"086":"中通",
"087":"宝骏",
"088":"北汽威旺",
"089":"广汽传祺",
"090":"陆风",
"092":"北京",
"094":"威麟",
"095":"欧宝",
"096":"开瑞",
"097":"华普",
"103":"讴歌",
"104":"启辰",
"107":"北汽制造",
"108":"纳智捷",
"109":"野马",
"110":"中兴",
"112":"克莱斯勒",
"113":"广汽吉奥",
"115":"瑞麟",
"117":"捷豹",
"119":"唐骏欧铃",
"121":"福迪",
"122":"莲花",
"124":"双环",
"128":"永源",
"136":"江南",
"144":"道奇",
"155":"大运汽车",
"167":"北方客车",
"176":"九龙",
"191":"宾利",
"201":"舒驰客车",
"230":"红旗"
}
/*收缴物品*/
const WPLXDM = {
"01":"工具类",
"02":"交通工具类",
"03":"毒物类",
"04":"爆炸物品",
"05":"工艺首饰及文物",
"06":"家用电器",
"07":"仪器仪表及计量器材",
"08":"农副渔牧产品及野生动物",
"09":"食品烟酒",
"10":"纺织物品",
"11":"服装鞋帽及穿戴品",
"12":"文教体育娱乐及办公用品",
"13":"家具及日用杂品",
"14":"通用设备电工及照明器材类",
"15":"橡胶塑料制品",
"16":"建筑装潢及金属材料",
"17":"石油化工产品",
"18":"医疗及医疗器械",
"19":"毒品类",
"20":"淫秽物品",
"21":"计算机设备及产品",
"22":"通信设备",
"99":"其他"
}
const YALXDM = {
"01":"维护稳定",
"02":"诈骗",
"03":"刑事治安",
"04":"爆炸",
"05":"纵火",
"06":"劫持",
}
const XLRYLBDM1 = {
'01': '巡警',
'02': '特警',
'04': '派出所民警',
'05': '交警',
}
const JSLX = {}
export default {
JWZLXDM,
XZQHDM,
GAJGJGDM,
XQFWLX,
XQLXDM,
BQMC,
PCCLJG,
XLZBLXDM,
ZBZTDM,
ZLLYDM,
ZLLXDM,
ZLGZYYJLX,
ZLYJRCBQ,
ZLYJRCBQDM,
PCRCBQ,
ZLFWDM,
ZLJBDM,
ZLZTDM,
JQZTDM,
ZLYXQDM,
D_BZ_XB,
D_BZ_MZ,
ZQLXDM,
XLRYLBDM,
CLLXDM,
CLZTDM,
CLPPDM,
WPLXDM,
XLDM,
HYZKDM,
ZZMMDM,
XLMJ_JWYWZJBDM,
LOGINTYPE,
YALXDM,
XLRYLBDM1,
JSLX,
ZLANDYJBM
}

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

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

603
src/utils/index.js Normal file
View File

@ -0,0 +1,603 @@
/* eslint-disable */
/**
* Created by PanJiaChen on 16/11/18.
*/
// import defaultSettings from '@/settings'
import dictData from './dicts'
/**
* Parse the time to string
* @param {(Object|string|number)} time
* @param {string} cFormat
* @returns {string | null}
*/
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
return null
}
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
const value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
return value.toString().padStart(2, '0')
})
return time_str
}
/**
* @param {number} time
* @param {string} option
* @returns {string}
*/
export function formatTime(time, option) {
if (('' + time).length === 10) {
time = parseInt(time) * 1000
} else {
time = +time
}
const d = new Date(time)
const now = Date.now()
const diff = (now - d) / 1000
if (diff < 30) {
return '刚刚'
} else if (diff < 3600) {
// less 1 hour
return Math.ceil(diff / 60) + '分钟前'
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + '小时前'
} else if (diff < 3600 * 24 * 2) {
return '1天前'
}
if (option) {
return parseTime(time, option)
} else {
return (
d.getMonth() +
1 +
'月' +
d.getDate() +
'日' +
d.getHours() +
'时' +
d.getMinutes() +
'分'
)
}
}
// 毫秒转时长
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 + "秒";
}
}
/**
* @param {string} url
* @returns {Object}
*/
export function getQueryObject(url) {
url = url == null ? window.location.href : url
const search = url.substring(url.lastIndexOf('?') + 1)
const obj = {}
const reg = /([^?&=]+)=([^?&=]*)/g
search.replace(reg, (rs, $1, $2) => {
const name = decodeURIComponent($1)
let val = decodeURIComponent($2)
val = String(val)
obj[name] = val
return rs
})
return obj
}
/**
* @param {string} input value
* @returns {number} output value
*/
export function byteLength(str) {
// returns the byte length of an utf8 string
let s = str.length
for (var i = str.length - 1; i >= 0; i--) {
const code = str.charCodeAt(i)
if (code > 0x7f && code <= 0x7ff) s++
else if (code > 0x7ff && code <= 0xffff) s += 2
if (code >= 0xDC00 && code <= 0xDFFF) i--
}
return s
}
/**
* @param {Array} actual
* @returns {Array}
*/
export function cleanArray(actual) {
const newArray = []
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i])
}
}
return newArray
}
/**
* @param {Object} json
* @returns {Array}
*/
export function param(json) {
if (!json) return ''
return cleanArray(
Object.keys(json).map(key => {
if (json[key] === undefined) return ''
return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
})
).join('&')
}
/**
* @param {string} url
* @returns {Object}
*/
export function param2Obj(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
)
}
/**
* @param {string} val
* @returns {string}
*/
export function html2Text(val) {
const div = document.createElement('div')
div.innerHTML = val
return div.textContent || div.innerText
}
/**
* Merges two objects, giving the last one precedence
* @param {Object} target
* @param {(Object|Array)} source
* @returns {Object}
*/
export function objectMerge(target, source) {
if (typeof target !== 'object') {
target = {}
}
if (Array.isArray(source)) {
return source.slice()
}
Object.keys(source).forEach(property => {
const sourceProperty = source[property]
if (typeof sourceProperty === 'object') {
target[property] = objectMerge(target[property], sourceProperty)
} else {
target[property] = sourceProperty
}
})
return target
}
/**
* @param {HTMLElement} element
* @param {string} className
*/
export function toggleClass(element, className) {
if (!element || !className) {
return
}
let classString = element.className
const nameIndex = classString.indexOf(className)
if (nameIndex === -1) {
classString += '' + className
} else {
classString =
classString.substr(0, nameIndex) +
classString.substr(nameIndex + className.length)
}
element.className = classString
}
/**
* @param {string} type
* @returns {Date}
*/
export function getTime(type) {
if (type === 'start') {
return new Date().getTime() - 3600 * 1000 * 24 * 90
} else {
return new Date(new Date().toDateString())
}
}
/**
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result
const later = function () {
// 据上一次触发时间间隔
const last = +new Date() - timestamp
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last)
} else {
timeout = null
// 如果设定为immediate===true因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args)
if (!timeout) context = args = null
}
}
}
return function (...args) {
context = this
timestamp = +new Date()
const callNow = immediate && !timeout
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait)
if (callNow) {
result = func.apply(context, args)
context = args = null
}
return result
}
}
/**
* This is just a simple version of deep copy
* Has a lot of edge cases bug
* If you want to use a perfect deep copy, use lodash's _.cloneDeep
* @param {Object} source
* @returns {Object}
*/
export function deepClone(source) {
if (!source && typeof source !== 'object') {
throw new Error('error arguments', 'deepClone')
}
const targetObj = source.constructor === Array ? [] : {}
Object.keys(source).forEach(keys => {
if (source[keys] && typeof source[keys] === 'object') {
targetObj[keys] = deepClone(source[keys])
} else {
targetObj[keys] = source[keys]
}
})
return targetObj
}
/**
* @param {Array} arr
* @returns {Array}
*/
export function uniqueArr(arr) {
return Array.from(new Set(arr))
}
/**
* @returns {string}
*/
export function createUniqueString() {
const timestamp = +new Date() + ''
const randomNum = parseInt((1 + Math.random()) * 65536) + ''
return (+(randomNum + timestamp)).toString(32)
}
/**
* Check if an element has a class
* @param {HTMLElement} elm
* @param {string} cls
* @returns {boolean}
*/
export function hasClass(ele, cls) {
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
}
/**
* Add class to element
* @param {HTMLElement} elm
* @param {string} cls
*/
export function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += ' ' + cls
}
/**
* Remove class from element
* @param {HTMLElement} elm
* @param {string} cls
*/
export function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
ele.className = ele.className.replace(reg, ' ')
}
}
// 拖动
/**
* 拖动div
* @param event // mouse event
* @param {HTMLElement} selectElement
*/
export function dargMove(event, selectElement) {
var div1 = selectElement
selectElement.style.cursor = 'move'
// this.isDowm = true
var distanceX = event.clientX - selectElement.offsetLeft
var distanceY = event.clientY - selectElement.offsetTop
document.onmousemove = function (ev) {
var oevent = ev || event
div1.style.left = oevent.clientX - distanceX + 'px'
div1.style.top = oevent.clientY - distanceY + 'px'
}
document.onmouseup = function () {
document.onmousemove = null
document.onmouseup = null
div1.style.cursor = 'default'
}
}
/* 时间戳 转换为 指定格式的日期字符串默认格式yyyy-mm-dd hh:mi:ss */
export function timestampToStr(timestamp, format) {
var dateStr = ''
// timestamp 为空
if (timestamp === null || timestamp === '') {
timestamp = new Date().getTime()
}
// timestamp string类型
if (typeof timestamp === 'string') {
timestamp = new Date(timestamp.replace(/-/g, '/')).getTime()
}
var d = new Date(Number(timestamp))
var year = d.getFullYear()
var month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1
var date = d.getDate() < 10 ? '0' + (d.getDate()) : d.getDate()
var hours = d.getHours() < 10 ? '0' + (d.getHours()) : d.getHours()
var minutes = d.getMinutes() < 10 ? '0' + (d.getMinutes()) : d.getMinutes()
var seconds = d.getSeconds() < 10 ? '0' + (d.getSeconds()) : d.getSeconds()
if (format === '' || format === null || format === undefined) {
dateStr = year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds
}
if (format === 'yyyy') {
dateStr = year
} else if (format === 'yyyy-mm') {
dateStr = year + '-' + month
} else if (format === 'yyyy-mm-dd') {
dateStr = year + '-' + month + '-' + date
} else if (format === 'mm-dd') {
dateStr = month + '-' + date
} else if (format === 'hh') {
dateStr = hours
} else if (format === 'hh:mi') {
dateStr = hours + ':' + minutes
} else if (format === 'hh:mi:ss') {
dateStr = hours + ':' + minutes + ':' + seconds
} else if (format === 'yyyy-mm-dd hh:mi') {
dateStr = year + '-' + month + '-' + date + ' ' + hours + ':' + minutes
} else if (format === 'yyyy-mm-dd hh:mi:ss') {
dateStr = year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds
} else if (format === 'mm-dd hh:mi') {
dateStr = month + '-' + date + ' ' + hours + ':' + minutes
}
return dateStr
}
export function objectToFormData(obj, form, namespace) {
let fd = form || new FormData()
let formKey
if (obj instanceof Array) {
for (let item of obj) {
if (typeof item === 'object' && !(item instanceof File)) {
this.objectToFormData(item, fd, namespace + '[]')
} else {
// 若是数组则在关键字后面加上[]
fd.append(namespace + '[]', item)
}
}
} else {
for (let property in obj) {
if (obj.hasOwnProperty(property) && obj[property]) {
if (namespace) {
// 若是对象,则这样
formKey = namespace + '[' + property + ']'
} else {
formKey = property
}
// if the property is an object, but not a File,
// use recursivity.
if (typeof obj[property] === 'object' && !(obj[property] instanceof File)) {
// 此处将formKey递归下去很重要因为数据结构会出现嵌套的情况
this.objectToFormData(obj[property], fd, formKey)
} else {
// if it's a string or a File object
fd.append(formKey, obj[property])
}
}
}
}
return fd
}
export function getNextDate(startDate, nextType, nextStep) {
var dateStr = "";
//startDate string类型
if (typeof startDate == 'string') {
startDate = new Date(startDate);
}
if (nextType == 'Y') {
startDate.setFullYear(startDate.getFullYear() + Number(nextStep));
} else if (nextType == 'M') {
startDate.setMonth(startDate.getMonth() + Number(nextStep));
} else if (nextType == 'D') {
startDate.setDate(startDate.getDate() + Number(nextStep));
} else if (nextType == 'H') {
startDate.setHours(startDate.getHours() + Number(nextStep));
} else if (nextType == 'm') {
startDate.setMinutes(startDate.getMinutes() + Number(nextStep));
} else if (nextType == 'S') {
startDate.setSeconds(startDate.getSeconds() + Number(nextStep));
}
var year = startDate.getFullYear();
var month = (startDate.getMonth() + 1) < 10 ? "0" + (startDate.getMonth() + 1) : startDate.getMonth() + 1;
var date = startDate.getDate() < 10 ? "0" + (startDate.getDate()) : startDate.getDate();
var hours = startDate.getHours() < 10 ? "0" + (startDate.getHours()) : startDate.getHours();
var minutes = startDate.getMinutes() < 10 ? "0" + (startDate.getMinutes()) : startDate.getMinutes();
var seconds = startDate.getSeconds() < 10 ? "0" + (startDate.getSeconds()) : startDate.getSeconds();
dateStr = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
return dateStr;
}
//大数据综合档案
export function getZhdaList(data, type) {
// if (type === 'RY') window.open(`${defaultSettings.zhdanRd_URL}/${data}`);
// if (type === 'CL') window.open(`${defaultSettings.zhdanCd_URL}/${data}`);
}
// 加载本地字典格式化
export function fromartBqDict(dict, key,yjlyjb) {
let html = ''
for (const x in dictData[dict]) {
if (x === key) {
if (dict === 'ZLYJRCBQ') {
if (x === '01' || x === '05' || x === '80') {
html = `<span class="list-tips tips-zl bg-red">${dictData[dict][x]}</span>`
} else {
let color = "";
if (yjlyjb== "10") {
color = "bg-red";
} else if (yjlyjb == "15") {
color = "bg-org";
} else if (yjlyjb == "20") {
color = "bg-yellow";
} else if (yjlyjb == "30") {
color = "bg-blue1";
} else {
color = "bg-yellow";
}
html = `<span class="list-tips tips-zl `+color+`">${dictData[dict][x]}</span>`
}
} else if (dict === 'ZLYJRCBQDM') {
if (x === 'ZT' || x === 'LKRY' || x === 'LKCL' || x === 'DQ') {
html = `<span class="list-tips tips-zl bg-red">${dictData[dict][x]}</span>`
} else {
html = `<span class="list-tips tips-zl bg-yellow">${dictData[dict][x]}</span>`
}
} else if (dict === 'ZLZTDM') {
switch (x) {
case '01':
html = `<span class="bold blue">${dictData[dict][x]}</span>`
break
case '02':
html = `<span class="bold blue">${dictData[dict][x]}</span>`
break
case '03':
html = `<span class="bold blue">${dictData[dict][x]}</span>`
break
case '04':
html = `<span class="bold blue">${dictData[dict][x]}</span>`
break
case '05':
html = `<span class="bold green">${dictData[dict][x]}</span>`
break
case '99':
html = `<span class="bold gray">${dictData[dict][x]}</span>`
break
default:
html = `<span class="bold white">${dictData[dict][x]}</span>`
break
}
} else if (dict === 'JQZTDM') {
switch (x) {
case '01':
html = `<span class="bold red">${dictData[dict][x]}</span>`
break
case '02':
html = `<span class="bold green">${dictData[dict][x]}</span>`
break
default:
html = `<span class="bold green">${dictData[dict][x]}</span>`
break
}
} else {
html = dictData[dict][x]
}
return html
}
}
}
// 格式化地址
export function fromartAdress(str) {
if (!str) return ''
if (str === '四川省泸州市公安局') return '市公安局'
let s = str.replace(/四川省/g, '')
s = s.replace(/泸州市公安局/g, '... ')
s = s.replace(/泸州市/g, '... ')
return s
}

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)
}
}
}

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;
};

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

@ -0,0 +1,65 @@
// 日历数据时间段处理
export function handleTime(start, end) {
//补0
function zeeo(num) {
let data = num;
if (num * 1 < 10) {
data = "0" + num;
}
return data;
}
let arr = [];
let kssj = new Date(start).getTime();
let jssj = new Date(end).getTime();
let dayTimes = 24 * 60 * 60 * 1000;
//天数
let n = Math.floor((jssj - kssj) / dayTimes);
for (var i = 0; i <= n; i++) {
let mytime = kssj + i * dayTimes;
arr.push({
start:
new Date(mytime).getFullYear() +
"-" +
zeeo(new Date(mytime).getMonth() + 1) +
"-" +
zeeo(new Date(mytime).getDate()),
end:
new Date(mytime).getFullYear() +
"-" +
zeeo(new Date(mytime).getMonth() + 1) +
"-" +
zeeo(new Date(mytime).getDate())
});
}
return arr;
}
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}`;
}
return `${yyyy}-${MM}-${dd} ${hh}:${mm}:${ss}`;
}
//获取n天前或n天后的日期
export function getTime(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;
}

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

@ -0,0 +1,294 @@
// 毫秒转时长
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(date) {
let val = (new Date(date)).getDay()
switch (val) {
case 0:
return '星期日'
case 1:
return '星期一'
case 2:
return '星期二'
case 3:
return '星期三'
case 4:
return '星期四'
case 5:
return '星期五'
case 6:
return '星期六'
}
}
// 两个日期的相差天数
export function getDifferTime(startDate, endDate, type='day') {
let startTime = new Date(Date.parse(startDate.replace(/-/g,"/"))).getTime();
let endTime = new Date(Date.parse(endDate.replace(/-/g,"/"))).getTime();
let dates = 0;
switch (type) {
case "day":
dates = Math.abs((startTime - endTime)) / (1000 * 60 * 60 * 24);
break;
case "hour":
dates = Math.abs((startTime - endTime)) / (1000 * 60 * 60);
break;
}
return Math.round(dates)
}
// 转换时间格式
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
}
// 获取时间的第一天 和最后一天
export function getThistWeekDare(type) {
var dateArr = []
var date = new Date()
let year = date.getFullYear() //当年
let m = date.getMonth() + 1 //当月
let mon = m < 10 ? ("0" + m) : m;
if (type == 'week') { //周
date.setDate(date.getDate() - date.getDay() + 1); // 本周一的日期
let first = year + '-' + mon + '-' + date.getDate()
date.setDate(date.getDate() - date.getDay() + 7); // 本周日的日期
let last = year + '-' + mon + '-' + date.getDate()
dateArr = [timeValidate(first,"ymd"),timeValidate(last,"ymd")]
} else if (type == 'month') { //月
let d = new Date(year, m, 0).getDate() //获取当月最后一天
let day = d < 10 ? "0" + d : d
dateArr = [[year, mon, '01'].join('-'), [year, mon, day].join('-')]
} else if (type == 'quarter') { //季度
let quarter = Math.floor(mon / 3)//从1开始到4
let quarterArr = []
if(quarter == 1) quarterArr = [new Date(year,0,1),new Date(year,2,31)];
if(quarter == 2) quarterArr = [new Date(year,3,1),new Date(year,5,30)];
if(quarter == 3) quarterArr = [new Date(year,6,1),new Date(year,8,30)];
if(quarter == 4) quarterArr = [new Date(year,9,1),new Date(year,11,31)];
dateArr = [timeValidate(quarterArr[0],'ymd'),timeValidate(quarterArr[1],'ymd')]
}
return dateArr
}
// 获取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}`;
}
// 随机颜色 - 把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})`
}
}

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
}
}

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

@ -0,0 +1,75 @@
const url = "ws://80.60.16.26:8006/mosty-api/mosty-websocket/socket/"; //线上
import {
getItem
} from "@/utils/storage";
import {
getUserInfoToId
} from "@/api/user-manage";
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()
let id = getItem("USERID");
getUserInfoToId(id).then((res) => {
let sfzh = res.idEntityCard
this.ws = new WebSocket(url + sfzh + '/' + 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;