'init'
This commit is contained in:
45
src/filters/DataDict/index.js
Normal file
45
src/filters/DataDict/index.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* @Author:
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: fzq
|
||||
* @LastEditTime: 2022-07-25 18:20:52
|
||||
* @FilePath: \basic-admin\src\filters\DataDict\index.js
|
||||
* @Description: 部分常量的数据字典定义
|
||||
*/
|
||||
const table = {
|
||||
enableState: {
|
||||
'0': '停用',
|
||||
'1': '启用'
|
||||
},
|
||||
enabled: {
|
||||
'0': '异常',
|
||||
'1': '正常'
|
||||
},
|
||||
yesOrNo: {
|
||||
'0': '否',
|
||||
'1': '是'
|
||||
},
|
||||
bool2String: {
|
||||
true: '是',
|
||||
false: '否'
|
||||
},
|
||||
doneStatus: {
|
||||
'0': i18n.t('module.equipmentManager.repair.undone'),
|
||||
'1': i18n.t('module.equipmentManager.repair.done')
|
||||
},
|
||||
sex: {
|
||||
1: '男',
|
||||
2: '女'
|
||||
},
|
||||
source: {
|
||||
'0': i18n.t('module.equipmentManager.repair.manual'),
|
||||
'1': 'PDA'
|
||||
}
|
||||
}
|
||||
|
||||
import i18n from '@/lang'
|
||||
export default function(dictTable) {
|
||||
return function(val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
78
src/filters/basicData/index.js
Normal file
78
src/filters/basicData/index.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: gtz
|
||||
* @LastEditTime: 2022-05-12 11:21:06
|
||||
* @FilePath: \mt-bus-fe\src\filters\basicData\index.js
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
const table = {
|
||||
sex: {
|
||||
'0': '女',
|
||||
'1': '男'
|
||||
},
|
||||
onDuty: {
|
||||
'0': '否',
|
||||
'1': '是'
|
||||
},
|
||||
orderStatus: {
|
||||
'1': '新增',
|
||||
'2': '启动',
|
||||
'3': '暂停',
|
||||
'4': '已下发',
|
||||
'9': '完成'
|
||||
},
|
||||
workOrderStatus: {
|
||||
'1': '未激活',
|
||||
'2': '等待',
|
||||
'3': '激活',
|
||||
'4': '暂停',
|
||||
'9': '完成'
|
||||
},
|
||||
source: {
|
||||
'1': '手动',
|
||||
'2': 'ERP',
|
||||
'3': 'PID1',
|
||||
'4': '00A',
|
||||
'5': '00C'
|
||||
},
|
||||
priority: {
|
||||
'1': '低',
|
||||
'2': '正常',
|
||||
'3': '高'
|
||||
},
|
||||
feeSource: {// 费用来源
|
||||
'1': '手动',
|
||||
'2': '自动'
|
||||
},
|
||||
workStatus: {
|
||||
'0': '失败',
|
||||
'1': '成功'
|
||||
},
|
||||
roleType: {
|
||||
'1': 'pc',
|
||||
'2': 'app',
|
||||
'3': 'wechat',
|
||||
'4': 'miniapp',
|
||||
'5': 'pda'
|
||||
},
|
||||
menuType: {
|
||||
'0': '目录',
|
||||
'1': '菜单',
|
||||
'2': '按钮'
|
||||
},
|
||||
enableState: {
|
||||
'0': '停用',
|
||||
'1': '启用'
|
||||
},
|
||||
registerState: {
|
||||
'0': '离职',
|
||||
'1': '在职'
|
||||
}
|
||||
}
|
||||
|
||||
export default function(dictTable) {
|
||||
return function(val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
33
src/filters/equipment/index.js
Normal file
33
src/filters/equipment/index.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: gtz
|
||||
* @LastEditTime: 2021-04-20 14:24:04
|
||||
* @FilePath: \basic-admin\src\filters\DataDict\index.js
|
||||
* @Description: 部分常量的数据字典定义
|
||||
*/
|
||||
import i18n from '@/lang/index'
|
||||
|
||||
const table = {
|
||||
controlStatus: {
|
||||
0: i18n.t('module.equipmentManager.statusSetting.controlStatusLocal'),
|
||||
1: i18n.t('module.equipmentManager.statusSetting.controlStatusOnline')
|
||||
},
|
||||
communication: {
|
||||
0: i18n.t('module.equipmentManager.statusSetting.communicationOff'),
|
||||
1: i18n.t('module.equipmentManager.statusSetting.communicationOn')
|
||||
},
|
||||
category: {
|
||||
'M': i18n.t('module.equipmentManager.baseinfoparam.M'),
|
||||
'V': i18n.t('module.equipmentManager.baseinfoparam.V'),
|
||||
'P': i18n.t('module.equipmentManager.baseinfoparam.P'),
|
||||
'R': i18n.t('module.equipmentManager.baseinfoparam.R'),
|
||||
'C': i18n.t('module.equipmentManager.baseinfoparam.C'),
|
||||
'I': i18n.t('module.equipmentManager.baseinfoparam.I')
|
||||
}
|
||||
}
|
||||
|
||||
export default function(dictTable) {
|
||||
return function(val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
26
src/filters/factory/index.js
Normal file
26
src/filters/factory/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* @Date: 2020-12-29 16:49:28
|
||||
* @LastEditors: gtz
|
||||
* @LastEditTime: 2021-03-24 20:32:40
|
||||
* @FilePath: \basic-admin\src\filters\DataDict\index.js
|
||||
* @Description: 部分常量的数据字典定义
|
||||
*/
|
||||
import i18n from '@/lang/index'
|
||||
|
||||
const table = {
|
||||
alarmStatus: {
|
||||
3: i18n.t('module.factory.abnormalAlarm.processingComplete'),
|
||||
2: i18n.t('module.factory.abnormalAlarm.inHand'),
|
||||
1: i18n.t('module.factory.abnormalAlarm.waitingProcess')
|
||||
},
|
||||
alarmNotify: {
|
||||
0: i18n.t('module.factory.abnormalAlarm.email'),
|
||||
1: i18n.t('module.factory.abnormalAlarm.wechat')
|
||||
}
|
||||
}
|
||||
|
||||
export default function(dictTable) {
|
||||
return function(val) {
|
||||
return table?.[dictTable]?.[val]
|
||||
}
|
||||
}
|
||||
173
src/filters/index.js
Normal file
173
src/filters/index.js
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* @Date: 2020-12-14 09:07:03
|
||||
* @LastEditors: lb
|
||||
* @LastEditTime: 2022-03-24 9:30:00
|
||||
* @FilePath: \basic-admin\src\filters\index.js
|
||||
* @Description: 过滤器定义、多语言过滤器修改
|
||||
*/
|
||||
// import parseTime, formatTime and set to filter
|
||||
export { parseTime, formatTime } from '@/utils'
|
||||
import i18n from '@/lang/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) {
|
||||
const n = i18n
|
||||
const keyArr = [n].concat(type[0].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) + ' ' + type[1]
|
||||
return (result?.[Cookies.get('language')] || type) + type[1] // 修改placeholder文字中空格
|
||||
// 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 rateFormatter(rateObj) {
|
||||
if (rateObj) {
|
||||
return rateObj.toFixed(2) + '%'
|
||||
} else {
|
||||
return '0.00%'
|
||||
}
|
||||
}
|
||||
|
||||
export function amountFormatter(param) {
|
||||
if (param) {
|
||||
return parseFloat(param).toFixed(2)
|
||||
} else {
|
||||
return '0.00'
|
||||
}
|
||||
}
|
||||
|
||||
export function handleLimit(string, maxLength = 10) {
|
||||
if (string && string.length > maxLength) {
|
||||
return string.slice(0, maxLength) + '......'
|
||||
} else {
|
||||
// return ''
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
export function getSimpleText(html) {
|
||||
var re1 = new RegExp('<.+?>', 'g')
|
||||
var msg = html.replace(re1, '')
|
||||
return msg.slice(0, 10) + '......'
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据服务器返回的 operateType 值决定表格显示'出库'还是'入库'
|
||||
* @param {number} operateType
|
||||
* @returns
|
||||
*/
|
||||
export function operateTypeFilter(operateType) {
|
||||
return operateType === 1 ? '出库' : operateType === 2 ? '入库' : 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据服务器返回的 source 值决定表格显示'手动','AGV','PDA'还是'其他'
|
||||
* @param {number} source
|
||||
* @returns
|
||||
*/
|
||||
export function sourceFilter(source) {
|
||||
return source === 0 ? '手动' : source === 1 ? 'AGV' : source === 2 ? 'PDA' : '其他'
|
||||
}
|
||||
|
||||
export function nonEmptyFilter(value) {
|
||||
return value || '-'
|
||||
}
|
||||
18
src/filters/newBasicData/index.js
Normal file
18
src/filters/newBasicData/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* @Description:1
|
||||
* @Author: juzi
|
||||
* @Date: 2022-05-16
|
||||
* @LastEditTime: 2022-05-16
|
||||
* @LastEditors: Please set LastEditors
|
||||
*/
|
||||
const dictObj = JSON.parse(localStorage.getItem('dictObj'))
|
||||
export default function(dictTable) {
|
||||
return function(val) {
|
||||
const arr = {}
|
||||
const dicList = dictObj?.[dictTable]
|
||||
dicList.map(item => {
|
||||
arr[item.dataCode] = item.dataName
|
||||
})
|
||||
return arr?.[val]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user