提交代码
This commit is contained in:
20
src/filters/gage/index.js
Normal file
20
src/filters/gage/index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: zhp
|
||||
* @LastEditTime: 2023-05-08 10:26:39
|
||||
* @FilePath: \basic-admin\src\filters\DataDict\index.js
|
||||
* @Description: 部分常量的数据字典定义
|
||||
*/
|
||||
|
||||
const table = {
|
||||
measurementType: {
|
||||
0: '计量',
|
||||
1:'计数',
|
||||
}
|
||||
}
|
||||
|
||||
export default function (dictTable) {
|
||||
return function (val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
153
src/filters/index.js
Normal file
153
src/filters/index.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* @Date: 2020-12-14 09:07:03
|
||||
* @LastEditors: zhp
|
||||
* @LastEditTime: 2023-04-18 15:14:26
|
||||
* @FilePath: \basic-admin\src\filters\index.js
|
||||
* @Description: 过滤器定义、多语言过滤器修改
|
||||
*/
|
||||
// import parseTime, formatTime and set to filter
|
||||
// export { parseTime, formatTime } from '@/utils'
|
||||
import i18n from '@/i18n'
|
||||
import Cookies from 'js-cookie'
|
||||
import moment from 'moment'
|
||||
|
||||
/**
|
||||
* Show plural label if time is plural number
|
||||
* @param {number} time
|
||||
* @param {string} label
|
||||
* @return {string}
|
||||
*/
|
||||
function pluralize(time, label) {
|
||||
if (time === 1) {
|
||||
return time + label
|
||||
}
|
||||
return time + label + 's'
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} type
|
||||
*/
|
||||
export function i18nFilter(type) {
|
||||
const n = i18n
|
||||
const keyArr = [n].concat(type.split('.'))
|
||||
// for (let i = 0; i < keyArr.length; i++) {
|
||||
// n = n[keyArr[i]]
|
||||
// }
|
||||
// return n[Cookies.get('language')]
|
||||
const result = keyArr.reduce((a, b) => {
|
||||
return a[b] ? a[b] : a
|
||||
})
|
||||
return result?.[Cookies.get('language')] || type
|
||||
// return result[Cookies.get('language')] ? result[Cookies.get('language')] : result
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array} type
|
||||
*/
|
||||
export function i18nFilterForm(type) {
|
||||
// console.log(type)
|
||||
const n = i18n
|
||||
const keyArr = [n].concat(type[0].split('.'))
|
||||
// console.log(keyArr)
|
||||
// for (let i = 0; i < keyArr.length; i++) {
|
||||
// n = n[keyArr[i]]
|
||||
// }
|
||||
// return n[Cookies.get('language')]
|
||||
const result = keyArr.reduce((a, b) => {
|
||||
return a[b] ? a[b] : a
|
||||
})
|
||||
// console.log(result)
|
||||
// console.log((result?.[Cookies.get('language')]))
|
||||
return type[0]+ ''+ type[1]
|
||||
// return result[Cookies.get('language')] ? result[Cookies.get('language')] : result
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} time
|
||||
*/
|
||||
export function timeAgo(time) {
|
||||
const between = Date.now() / 1000 - Number(time)
|
||||
if (between < 3600) {
|
||||
return pluralize(~~(between / 60), ' minute')
|
||||
} else if (between < 86400) {
|
||||
return pluralize(~~(between / 3600), ' hour')
|
||||
} else {
|
||||
return pluralize(~~(between / 86400), ' day')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Number formatting
|
||||
* like 10000 => 10k
|
||||
* @param {number} num
|
||||
* @param {number} digits
|
||||
*/
|
||||
export function numberFormatter(num, digits) {
|
||||
const si = [
|
||||
{ value: 1E18, symbol: 'E' },
|
||||
{ value: 1E15, symbol: 'P' },
|
||||
{ value: 1E12, symbol: 'T' },
|
||||
{ value: 1E9, symbol: 'G' },
|
||||
{ value: 1E6, symbol: 'M' },
|
||||
{ value: 1E3, symbol: 'k' }
|
||||
]
|
||||
for (let i = 0; i < si.length; i++) {
|
||||
if (num >= si[i].value) {
|
||||
return (num / si[i].value).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
|
||||
}
|
||||
}
|
||||
return num.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 10000 => "10,000"
|
||||
* @param {number} num
|
||||
*/
|
||||
export function toThousandFilter(num) {
|
||||
return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
|
||||
}
|
||||
|
||||
/**
|
||||
* Upper case first char
|
||||
* @param {String} string
|
||||
*/
|
||||
export function uppercaseFirst(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
}
|
||||
export function timeFormatter(timeObj) {
|
||||
if (timeObj) {
|
||||
return moment(timeObj).format('YYYY-MM-DD HH:mm:ss')
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
export function DateFormatter(timeObj) {
|
||||
if (timeObj) {
|
||||
return moment(timeObj).format('YYYY-MM-DD')
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
export function onlyTimeFormatter(timeObj) {
|
||||
if (timeObj) {
|
||||
return moment(timeObj).format('HH:mm:ss')
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
export function handleLimit(string) {
|
||||
if (string.length > 10) {
|
||||
return string.slice(0, 10) + '......'
|
||||
} else {
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
export function getSimpleText(html) {
|
||||
var re1 = new RegExp('<.+?>', 'g')
|
||||
var msg = html.replace(re1, '')
|
||||
return msg.slice(0, 10) + '......'
|
||||
}
|
||||
34
src/filters/nonconform/index.js
Normal file
34
src/filters/nonconform/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: zhp
|
||||
* @LastEditTime: 2023-04-18 16:12:08
|
||||
* @FilePath: \basic-admin\src\filters\DataDict\index.js
|
||||
* @Description: 部分常量的数据字典定义
|
||||
*/
|
||||
|
||||
const table = {
|
||||
inspectionType: {
|
||||
0: '监控',
|
||||
1:'电芯来料检验',
|
||||
2: 'IQC抽检',
|
||||
3: 'IQC抽检2',
|
||||
4: '原料抽检',
|
||||
5: '进货外观检验',
|
||||
6: '库内原料检验',
|
||||
7: '来料检验',
|
||||
8: '胶片',
|
||||
9: '抽检',
|
||||
10: '巡检',
|
||||
11: '首检',
|
||||
12: '末检',
|
||||
13: '实时监测',
|
||||
14: 'FQC抽检',
|
||||
15: 'OQC抽检'
|
||||
}
|
||||
}
|
||||
|
||||
export default function (dictTable) {
|
||||
return function (val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
24
src/filters/supplier/index.js
Normal file
24
src/filters/supplier/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: zhp
|
||||
* @LastEditTime: 2023-04-18 16:12:04
|
||||
* @FilePath: \basic-admin\src\filters\DataDict\index.js
|
||||
* @Description: 部分常量的数据字典定义
|
||||
*/
|
||||
|
||||
const table = {
|
||||
whether: {
|
||||
0: '否',
|
||||
1:'是',
|
||||
},
|
||||
available: {
|
||||
0: '不可用',
|
||||
1:'不可用',
|
||||
}
|
||||
}
|
||||
|
||||
export default function (dictTable) {
|
||||
return function (val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user