import myrequest from './request' // 深拷贝 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') { objClone[key] = deepClone(obj[key]); } else { objClone[key] = obj[key]; } } } } return objClone; } // 计算限制时间 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; } export async function myDownLoad(arr){ let fileName = arr.headers['content-disposition']; console.log(fileName); if (fileName) { fileName = fileName.slice(fileName.indexOf('filename=') + 9); } const blob = new Blob([arr.data], { type: 'application/octet-stream' }) // content-disposition const downloadElement = document.createElement('a') // 创建下载的链接 const href = window.URL.createObjectURL(blob) downloadElement.href = href // // 下载后文件名 downloadElement.download = fileName document.body.appendChild(downloadElement) // 点击下载 downloadElement.click() // 下载完成移除元素 document.body.removeChild(downloadElement) // 释放掉blob对象 window.URL.revokeObjectURL(href) } // 获取token export function getToken() { const token = sessionStorage.getItem('token'); const tokenHead = sessionStorage.getItem('tokenHead'); if (token && tokenHead) { return tokenHead + token; } return; } // 获取年月日时分秒 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 + '分钟' }