95 lines
2.3 KiB
JavaScript
95 lines
2.3 KiB
JavaScript
|
|
/*
|
|
* @Date: 2020-12-29 16:49:28
|
|
* @LastEditors: zwq
|
|
* @LastEditTime: 2024-09-11 13:40:48
|
|
* @FilePath: \basic-admin\src\filters\basicData\index.js
|
|
* @Description:
|
|
*/
|
|
|
|
const table = {
|
|
lineStatus: {
|
|
1: '生产中',
|
|
2: '停止',
|
|
3: '未知',
|
|
},
|
|
deactivate: {
|
|
1: '启用',
|
|
0: '停用',
|
|
},
|
|
wareType: {
|
|
1: '缓存',
|
|
2: '活动',
|
|
3: '其它',
|
|
},
|
|
reportType: {
|
|
2: '日',
|
|
3: '周',
|
|
4: '月',
|
|
5: '年',
|
|
},
|
|
manual: {
|
|
1: '手动',
|
|
0: '自动',
|
|
},
|
|
}
|
|
|
|
// 日期格式化
|
|
export function parseTime(time, pattern) {
|
|
if (arguments.length === 0 || !time) {
|
|
return null
|
|
}
|
|
const format = pattern || '{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)
|
|
} else if (typeof time === 'string') {
|
|
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.\d{3}/gm), '');
|
|
}
|
|
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(),
|
|
w: '',
|
|
}
|
|
const time_str = format.replace(/{([ymdhisaw])+}/g, (result, key) => {
|
|
let value = formatObj[key]
|
|
// Note: getDay() returns 0 on Sunday
|
|
if (key === 'a') {
|
|
return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
}
|
|
if (key === 'w') {
|
|
const current = new Date(time);
|
|
current.setHours(0, 0, 0);
|
|
current.setDate(current.getDate() + 4 - (current.getDay() || 7));
|
|
const firstThursday = new Date(current.getFullYear(), 0, 4);
|
|
firstThursday.setDate(firstThursday.getDate() + 4 - (firstThursday.getDay() || 7));
|
|
const time1 = current.getTime() - firstThursday.getTime();
|
|
const weeks = Math.ceil(time1 / (7 * 24 * 3600 * 1000));
|
|
return (weeks + 1)
|
|
}
|
|
if (result.length > 0 && value < 10) {
|
|
value = '0' + value
|
|
}
|
|
return value || 0
|
|
})
|
|
return time_str
|
|
}
|
|
export default function (dictTable) {
|
|
return function (val) {
|
|
return table?.[dictTable]?.[val]
|
|
}
|
|
}
|