detection-business/utils/utils.js

35 lines
984 B
JavaScript
Raw Normal View History

2024-12-12 18:51:08 +08:00
import request from "./request";
import {
setStorageWithExpiry,
getStorageWithExpiry
} from './auth'
export function getDictDataByType(type) {
let data = getStorageWithExpiry(type)
if (data === null || data === undefined) {
request({
url: '/system/dict-data/type',
method: 'get',
params: {type: type}
}).then(res => {
setStorageWithExpiry(type, res.data, 3600)
return res.data
}).catch(() => {
console.log("出现了异常")
})
} else {
return data
}
}
2024-12-16 16:11:30 +08:00
export function formatDate(timestamp) {
// 将时间戳转换为Date对象
const date = new Date(timestamp);
// 获取年月日时分秒
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
// 组合成日期时间字符串
return `${year}-${month}-${day}`;
}