216 lines
6.3 KiB
JavaScript
216 lines
6.3 KiB
JavaScript
/**
|
||
* 枚举创建工厂(构造函数),扩展枚举对象:keys、values(含key值的[{key,text,type}])、formatter。
|
||
* @param {*} enumObj 枚举值,支持标准模式{key:{text,type},},简单模式{key:text,}(会自动转换为标准模式)
|
||
* @param {*} keyParseFunc key的转换函数,默认null,如果key为整数则传 parseInt
|
||
*/
|
||
export default function EnumFactory(enumObj, keyParseFunc = null) {
|
||
//复制(继承)enumObj
|
||
Object.assign(this, enumObj)
|
||
|
||
// keys:枚举的key集合[key]
|
||
Object.defineProperty(this, 'keys', {
|
||
value: keyParseFunc ? Object.keys(enumObj).map(s => keyParseFunc(s)) : Object.keys(enumObj)
|
||
})
|
||
|
||
// 处理 values
|
||
let values = []
|
||
const ovalues = Object.values(enumObj)
|
||
// 主要区分下value是简单类型(字符串)还是对象类型
|
||
if (typeof ovalues[0] === 'string') {
|
||
ovalues.forEach((text, index) => {
|
||
const obj = { key: this.keys[index], text }
|
||
values.push(obj)
|
||
this[this.keys[index]] = obj
|
||
})
|
||
}
|
||
else {
|
||
ovalues.forEach((item, index) => {
|
||
item.key = this.keys[index]
|
||
values.push(item)
|
||
})
|
||
}
|
||
// 设置values属性
|
||
Object.defineProperty(this, 'values', { value: values })
|
||
|
||
// formatter:element中表格绑定枚举数据文本的formatter函数
|
||
// r、c为行列,可传入null
|
||
Object.defineProperty(this, 'formatter', {
|
||
value: function(r, c, value) {
|
||
return values.filter(v => v.key == value || v.text == value)[0]?.text || 'notfound'
|
||
}
|
||
})
|
||
|
||
//枚举定义的数据都是常量,不可修改,冻结一下
|
||
Object.freeze(this)
|
||
}
|
||
|
||
export const runningStateEnum = new EnumFactory({
|
||
10: { text: '运行', type: 'success' },
|
||
20: { text: '待机', type: 'primary' },
|
||
30: { text: '停机', type: 'warning' },
|
||
40: { text: '故障', type: 'danger' },
|
||
50: { text: '离线', type: 'info' },
|
||
}, parseInt)
|
||
|
||
export const onlingEnum = new EnumFactory({
|
||
1: { text: '在线', type: 'success' },
|
||
0: { text: '离线', type: 'info' },
|
||
}, parseInt)
|
||
|
||
export const drainTypeEnum = new EnumFactory({
|
||
'product': '生产工艺',
|
||
'mtrans': '物料输送',
|
||
'mstore':'物料储存'
|
||
})
|
||
export const mioTypeEnum = new EnumFactory({
|
||
'do_out': '生产领料',
|
||
'sale_out': '销售发货',
|
||
'pur_in': '采购入库',
|
||
'do_in': '生产入库',
|
||
'other_in': '其他入库',
|
||
'other_out': '其他出库'
|
||
})
|
||
export const fiedTypeEnum = new EnumFactory({
|
||
'input-int': '整数',
|
||
'input-number': '小数',
|
||
'input-text': '文本',
|
||
'select-text': '单选',
|
||
'selects-text': '多选',
|
||
})
|
||
export const testTagsEnum = new EnumFactory({
|
||
'purin': '入厂检验',
|
||
'first': '首件检验',
|
||
'prod': '成品检验',
|
||
'process': '过程检验',
|
||
'performance': '性能检验',
|
||
})
|
||
export const productTypeEnum = new EnumFactory({
|
||
0: '电/水/气',
|
||
10: '成品',
|
||
20: '半成品',
|
||
30: '主要原料',
|
||
40: '辅助材料',
|
||
50: '加工工具',
|
||
60: '辅助工装',
|
||
70: '办公用品',
|
||
}, parseInt)
|
||
export const eqTypeEnum = new EnumFactory({
|
||
10: { text: '生产设备', type: 'success' },
|
||
20: { text: '计量设备', type: 'primary' },
|
||
30: { text: '治理设备', type: 'warning' },
|
||
40: { text: '监测设备', type: 'danger' },
|
||
50: { text: '监控设备', type: 'info' },
|
||
}, parseInt)
|
||
|
||
export const valTypeEnum = new EnumFactory({
|
||
'int': '整型',
|
||
'float': '浮点型',
|
||
'str': '字符串型',
|
||
'bool': '布尔型',
|
||
})
|
||
|
||
export const boolEnum = new EnumFactory({
|
||
true: '是',
|
||
false: '否',
|
||
})
|
||
|
||
export const iMEnum = new EnumFactory({
|
||
10: '单开为开/单停为停',
|
||
20: '单开为开/都停为停',
|
||
30: '都开为开/单停为停',
|
||
}, parseInt)
|
||
|
||
export const qTypeEnum = new EnumFactory({
|
||
10: '单选',
|
||
20: '多选',
|
||
30: '判断',
|
||
}, parseInt)
|
||
|
||
export const qLevelEnum = new EnumFactory({
|
||
10: '低',
|
||
20: '中',
|
||
30: '高',
|
||
}, parseInt)
|
||
|
||
export const mpointTypeEnum = new EnumFactory({
|
||
10: '自动采集',
|
||
20: '计算测点',
|
||
30: '手动录入',
|
||
}, parseInt)
|
||
|
||
export const mpointGatherStateEnum = new EnumFactory({
|
||
"0": { text: '正常', type: 'success' },
|
||
"-1": { text: '错误', type: 'danger' },
|
||
"-2": { text: '无', type: 'info' },
|
||
}, parseInt)
|
||
|
||
|
||
export const enpfieldEnum = new EnumFactory({
|
||
'running_state': '运行状态',
|
||
'dust_rtd': '颗粒物实测(mg/m3)',
|
||
'dust_zs': '颗粒物折算(mg/m3)',
|
||
'temperature': '温度(℃)',
|
||
'pressure': '压力(kPa)',
|
||
'speed': '流速(m/s)',
|
||
'humidity': '湿度(%)',
|
||
'flux': '流量(m3/h)',
|
||
'pm25': 'PM2.5(ug/m3)',
|
||
'pm10': 'PM10(ug/m3)',
|
||
'tsp': 'TSP(ug/m3)',
|
||
'wind_direction': '风向',
|
||
'wind_speed': '风速(m/s)',
|
||
'so2_rtd': '风向',
|
||
'so2_rtd': '二氧化硫实测(mg/m3)',
|
||
'so2_zs': '二氧化硫折算(mg/m3)',
|
||
'nox_rtd': '氮氧化物实测(mg/m3)',
|
||
'nox_zs': '氮氧化物折算(mg/m3)',
|
||
'o2': '含氧量(%)',
|
||
'ammonia_e': '氨逃逸(mg/m3)'
|
||
})
|
||
|
||
export const riskLevelEnum = new EnumFactory({
|
||
10: { text: '低风险', type: 'success' },
|
||
20: { text: '一般风险', type: 'primary' },
|
||
30: { text: '较大风险', type: 'warning' },
|
||
40: { text: '重大风险', type: 'danger' },
|
||
}, parseInt)
|
||
|
||
export const manageLevelEnum = new EnumFactory({
|
||
10: { text: '岗位级', type: 'primary' },
|
||
20: { text: '班组级', type: 'primary' },
|
||
30: { text: '部门级', type: 'primary' },
|
||
40: { text: '公司级', type: 'primary' },
|
||
}, parseInt)
|
||
|
||
export const riskTypeEnum = new EnumFactory({
|
||
10: { text: '作业活动类', type: 'primary' },
|
||
20: { text: '设备设施类', type: 'primary' },
|
||
}, parseInt)
|
||
|
||
|
||
export const scheduleTypeEnum = new EnumFactory({
|
||
10: '间隔',
|
||
20: '定时',
|
||
}, parseInt)
|
||
|
||
export const schedulePeriodEnum = new EnumFactory({
|
||
'seconds': '秒',
|
||
'minutes': '分钟',
|
||
'hours': '小时',
|
||
'days': '天',
|
||
})
|
||
|
||
export const wmState = new EnumFactory({
|
||
10: { text: '合格', type: 'success' },
|
||
20: { text: '不合格', type: 'warning' },
|
||
30: { text: '返修', type: 'warning' },
|
||
34: { text: '返修完成', type: 'warning' },
|
||
40: { text: '检验', type: 'primary' },
|
||
50: { text: '报废', type: 'danger' },
|
||
}, parseInt)
|
||
|
||
export const certStateEnum = new EnumFactory({
|
||
10: { text: '正常', type: 'success' },
|
||
20: { text: '临期', type: 'warning' },
|
||
30: { text: '过期', type: 'danger' }
|
||
}, parseInt) |