| | |
| | | import myrequest from './request' |
| | | // 深拷贝 |
| | | function deepClone(obj){ |
| | | export function deepClone(obj) { |
| | | let objClone = Array.isArray(obj) ? [] : {}; |
| | | if(obj && typeof obj === 'object' && obj != null){ |
| | | for(let key in obj){ |
| | | if(obj.hasOwnProperty(key)){ |
| | | if(obj[key] && typeof obj[key] === 'object'){ |
| | | if (obj && typeof obj === 'object') { |
| | | for (let key in obj) { |
| | | if (obj.hasOwnProperty(key)) { |
| | | if (obj[key] && typeof obj[key] === 'object') { |
| | | objClone[key] = deepClone(obj[key]); |
| | | }else{ |
| | | } else { |
| | | objClone[key] = obj[key]; |
| | | } |
| | | } |
| | |
| | | } |
| | | return objClone; |
| | | } |
| | | export {deepClone}; |
| | | // 计算限制时间 |
| | | export function computeTime(time2) { |
| | | const t1 = new Date(); |
| | | const t2 = new Date(time2); |
| | | return filterTime(t2.getTime() - t1.getTime()); |
| | | } |
| | | // 获取字典表 |
| | | export async function getTypeList(level, code) { |
| | | let arr; |
| | | await myrequest({ |
| | | method: 'get', |
| | | url: `sccg/dict/query_type?level=${level}&typeCode=${code}` |
| | | }) |
| | | .then(res => { |
| | | arr = res.data; |
| | | }) |
| | | return arr; |
| | | } |
| | | // 获取字典表2 |
| | | export async function getCodeList(code){ |
| | | let arr; |
| | | await myrequest({ |
| | | method: 'get', |
| | | url: `/sccg/dict/queryByCode?code=${code}` |
| | | }) |
| | | .then(res => { |
| | | arr = res.data; |
| | | }) |
| | | return arr; |
| | | } |
| | | |
| | | // data: 文件, contentDisposition:请求头中文件的名字 |
| | | // 默认不用修改,直接将返回的res传入即可 |
| | | export function downloadFile(res) { |
| | | const blob = new Blob([res.data], { type: 'application/octet-stream' }); |
| | | const fileName = res.contentDisposition.split(`''`)[1]; |
| | | if (window.navigator && window.navigator.msSaveBlob) { |
| | | window.navigator.msSaveBlob(blob, fileName); |
| | | } else { |
| | | const link = document.createElement('a'); |
| | | link.style.display = 'none'; |
| | | link.href = window.URL.createObjectURL(blob); |
| | | link.download = decodeURI(fileName); |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | window.URL.revokeObjectURL(link.href); |
| | | document.body.removeChild(link); |
| | | } |
| | | } |
| | | |
| | | // 获取token |
| | | export function getToken() { |
| | | const token = sessionStorage.getItem('token'); |
| | | const tokenHead = sessionStorage.getItem('tokenHead'); |
| | | if (token && tokenHead) { |
| | | return tokenHead + token; |
| | | } |
| | | } |
| | | // 获取年月日时分秒 |
| | | export function getNowDate(time){ |
| | | const result = new Date(time); |
| | | let yy = result.getFullYear(), |
| | | mm = result.getMonth()+1, |
| | | dd = result.getDate(), |
| | | hh = result.getHours(), |
| | | mi = result.getMinutes(), |
| | | ss = result.getSeconds() |
| | | return yy+'-'+ fillTime(mm)+'-'+fillTime(dd)+" "+fillTime(hh)+':'+fillTime(mi) + ':' + fillTime(ss); |
| | | } |
| | | function filterTime(time) { |
| | | if (time < 0) { |
| | | return '已逾期'; |
| | | } |
| | | let dd = Math.floor(time / 24 / 60 / 60 / 1000), |
| | | hh = Math.floor(time / 60 / 60 / 1000 - dd * 24), |
| | | mi = Math.floor(time / 60 / 1000 - dd * 24 * 60 - hh * 60); |
| | | return addDay(fillTime(dd)) + addHour(fillTime(hh)) + addMin(fillTime(mi)); |
| | | } |
| | | function fillTime(num) { |
| | | if (num < 10) { |
| | | return '0' + num; |
| | | } |
| | | return num; |
| | | } |
| | | function addDay(str) { |
| | | str = parseFloat(str); |
| | | if (str < 0) { |
| | | return; |
| | | } |
| | | return str + '天' |
| | | } |
| | | function addHour(str) { |
| | | str = parseFloat(str); |
| | | if (str < 0) { |
| | | return; |
| | | } |
| | | return str + '小时' |
| | | } |
| | | function addMin(str) { |
| | | str = parseFloat(str); |
| | | if (str < 0) { |
| | | return; |
| | | } |
| | | return str + '分钟' |
| | | } |
| | | |
| | | export const EVENT_SOURCE = [ |
| | | { label: '视频抓拍', value: 1 }, |
| | | { label: '手动登记', value: 2 } |
| | | ] |
| | | |
| | | export const CATEGOTY = [ |
| | | { label: '违规', value: 1 }, |
| | | { label: '违建', value: 2 } |
| | | ] |
| | | |
| | | export const RESOURCE_TYPE = [ |
| | | { label: '上报', value: '01' }, |
| | | { label: '处置', value: '02' } |
| | | ] |