add 枚举

This commit is contained in:
赵霄
2023-11-30 15:22:11 +08:00
parent 00e6cee4a9
commit ce3f55e022
2 changed files with 241 additions and 0 deletions
+154
View File
@@ -0,0 +1,154 @@
export default class EsEnum {
constructor (val) {
if (!val) {
return
}
Object.keys(val).forEach(key => {
const item = val[key]
this.addAll(key, item)
})
return this
}
/**
* 添加枚举
* @param key
* @param item
*/
addAll (key, item) {
this[key] = item
}
/**
* 获取所有枚举值列表
* @params decend --是否是降序输出
* @returns {Array}
*/
getItemList (decend) {
const optionList = []
for (const i in this) {
const item = this[i]
const option = {}
Object.assign(option, item)
option.key = i
optionList.push(option)
}
optionList.sort((a, b) => {
const value1 = a['index']
const value2 = b['index']
return decend && (value2 - value1) || (value1 - value2)
})
return optionList
}
/**
* 获取需要排除的枚举值后的所有枚举值列表
* @param val 需要排除的枚举值或枚举值数组
*/
getItemListExcept (val) {
let valueArr = []
if (val) {
if (Array.isArray(val)) {
valueArr = val
} else {
valueArr.push(val)
}
}
const optionList = []
for (const i in this) {
const item = this[i]
if (!valueArr.includes(item.name)) {
const option = {}
Object.assign(option, item)
option.key = i
optionList.push(option)
}
}
return optionList
}
/**
* 根据name获取index
* @param name
*/
indexOfName (name) {
if (name) {
for (const i in this) {
const e = this[i]
if (e.name.toString() === name.toString()) {
return (e.index)
}
}
}
return null
}
/**
* 根据index获取name
* @param index
* @returns {*}
*/
nameOfIndex (index) {
if (index === null) {
return '--'
}
for (const i in this) {
const e = this[i]
if (e.value !== undefined && e.value !== null && e.value.toString() === index.toString()) {
return e.text
}
}
return '--'
}
/**
* 通过value获取其他属性
* @param key
* @param value
* @returns {*|null}
*/
propertyOfValue (key, value) {
if (!value && value !== 0) {
return null
}
for (const i in this) {
const e = this[i]
if (e[key] !== undefined && e[key] !== null && e.value.toString() === value.toString()) {
return e[key]
}
}
return null
}
/**
* 根据value模糊获取key
*/
keyOfValueByLike (value) {
if (!value && value !== 0) {
return null
}
for (const i in this) {
const e = this[i]
if (e.value !== undefined && e.value !== null && value.toString().indexOf(e.value.toString()) !== -1) {
return i
}
}
return null
}
/**
* 根据value获取key
*/
keyOfValue (value) {
if (!value && value !== 0) {
return null
}
for (const i in this) {
const e = this[i]
if (e.value !== undefined && e.value !== null && value.toString() === e.value.toString()) {
return i
}
}
return null
}
}
+87
View File
@@ -0,0 +1,87 @@
import EsEnums from './EsEnum'
export const YesOrNoEnum = new EsEnums({
NO: { name: '否', value: '0' },
YES: { name: '是', value: '1' }
})
// 既可以使用EsEnums 也可以单独写明
export const FieldType = {
DATE_SINGLE: { text: '单日期选择', value: '1' },
USER_SINGLE: { text: '单选用户弹框', value: '2' },
ORGAN_SINGLE: { text: '单选组织机构弹框', value: '3' },
DATE_MORE: { text: '多日期选择', value: '4' },
TEXTAREA: { text: '多行文本', value: '5' },
STANDARD_MORE: { text: '多选标准弹框', value: '6' },
ORGAN_MORE: { text: '多选组织机构弹框', value: '7' },
FILE_UP: { text: '上传文件', value: '8' },
TEXT_BOX: { text: '文本框', value: '9' },
OPTION_SINGLE: { text: '下拉单选', value: '10' },
OPTION_MORE: { text: '下拉多选', value: '11' },
TREE: { text: '树形结构(多选)', value: '12' },
// TEXT_LINK: { text: '输入框(链接)', value: '13' },
YEAR_PICKER: { text: '年份选择', value: '14' },
TREE_SINGLE: { text: '树形结构(单选)', value: '15' },
TREE_MODAL_SELECT: { text: '树形弹框', value: '16' }
}
// 标准来源
export const StandardSource = {
DOMESTIC: { text: '国内', value: '1' },
OVERSEAS: { text: '海外', value: '2' },
ENTERPRISE: { text: '企标', value: '3' }
}
// 流程key,获取人员信息前需要获取流程定义id,传这里的名字到WorkCenterMixin的getFlowDefinition方法中
export const ProcessKey = {
// 企标立项/变更计划
ES_INIT_CHANGE: { text: 'es-init-change', value: 'es-init-change' },
// 年度制修订-各部门主动上报
ES_ANNUAL_REPORT: { text: 'es-annual-report', value: 'es-annual-report' },
// 年度制修订-标准化部门主动发起
ES_ANNUAL_INIT: { text: 'es-annual-init', value: 'es-annual-init' },
// 企标制修订流程
ES_EDIT: { text: '', value: '' },
// 企标更改流程
ES_CHANGE: { text: 'es-change', value: 'es-change' },
// 企标复审流程
ES_RECHECK: { text: 'es-recheck', value: 'es-recheck' },
// 企标废止流程
ES_ABOLISH: { text: 'es-abolish', value: 'es-abolish' },
// 企标封存流程
ES_ARCHIVE: { text: 'es-archive', value: 'es-archive' },
// 已封存企标启用流程
ES_ENABLE: { text: 'es-enable', value: 'es-enable' },
// 标准法规入库/变更流程
FB_ENTRY_CHANGE: { text: 'fb-entry-change', value: 'fb-entry-change' },
// 征求意见流程
CONSULTATION: { text: 'fb-standard-consultation', value: 'fb-standard-consultation' },
// 项目合规评估流程
PROJECT_COMPLIANCE_EVALUATION: { text: '', value: '' },
// 未符合项跟踪流程
NO_MATCH_TRACKING: { text: '', value: '' },
// 法规合规评估流程
REGULATORY_COMPLIANCE_ASSESSMENT: { text: 'fb-standard-compliance-assessment', value: 'fb-standard-compliance-assessment' },
// 法规采购流程
LEGAL_PROCUREMENT: { text: 'fb-standard-purchase', value: 'fb-standard-purchase' },
// 企标稽查计划
ES_INSPECTION_PLAN: { text: 'inspect_plan', value: 'inspect_plan' },
// 企标稽查流程
ES_INSPECTION_PROCESS: { text: 'inspect_process', value: 'inspect_process' },
// 稽查延期申请流程
INSPECTION_EXTENSION_REQUEST_PROCESS: { text: 'inspect_delay_apply_process', value: 'inspect_delay_apply_process' },
// 企标稽查整改
ES_INSPECTION_RECTIFICATION: { text: 'inspect_plan', value: 'inspect_process' }
}
// 标准法规入库/变更流程
export const FGEntryChangeProcessNode = new EsEnums({
initiate: { text: '法规工程师发起', value: 'Activity_16zkjpn', btn: ['save', 'submit'], disabled: false },
approve: {
text: '法规工程师主管级领导审批',
value: 'Activity_084um6e',
btn: ['return', 'save', 'agree', 'reject'],
disabled: true
}
})