This commit is contained in:
fan 2022-09-08 15:37:41 +08:00
commit 4904e30450
3 changed files with 234 additions and 113 deletions

View File

@ -8,7 +8,7 @@
<el-dialog :title="title" :visible.sync="dialogVisible" :width="dialogWidth" :modal="false" :close-on-click-modal="false" :before-close="doClose" center :style="{'margin-left': dialogMarginLeft + 'px'}">
<div @click="editValue(null, '')">
<div>
<Expression ref="expression" :materials-list="materialsList" @editExpression="editExpression" />
<Expression ref="expression" :materials-list="materialsList" :get-device-list="getDeviceList" @editExpression="editExpression" @addExp="addExp" />
</div>
<el-table
:data="tableData"
@ -19,13 +19,13 @@
<template slot-scope="scope">
<div v-if="!scope.row.valuables[0]" class="nullDiv" @click.stop="editValue(scope.row, '0')"></div>
<div v-else>
<ExpressionValue ref="ExpressionValue" :value-obj="scope.row" :index-path="scope.$index + ''" :active-index-path="activeIndexPath" @editValue="editValue" />
<ExpressionValue ref="ExpressionValue" :materials-list="materialsList" :get-device-list="getDeviceList" :value-obj="scope.row" :index-path="scope.$index + ''" :active-index-path="activeIndexPath" @editValue="editValue" />
</div>
</template>
</el-table-column>
</el-table>
<div class="conditionBtn">
<el-button size="small" @click="addExp">新增条件关系</el-button>
<!-- <el-button size="small" @click="addExp">新增条件关系</el-button> -->
<el-button size="small" :disabled="deleteDisabled" @click="deleteExp">删除条件关系</el-button>
<el-button size="small" :disabled="clearDisabled" @click="clearExp">清空条件关系</el-button>
</div>
@ -42,6 +42,7 @@
<script>
import Expression from './expression.vue';
import ExpressionValue from './expressionValue.vue';
import ConstConfig from '@/scripts/ConstConfig';
export default {
name: 'EditCondition',
@ -49,6 +50,11 @@ export default {
ExpressionValue,
Expression
},
provide() {
return {
optionObj: this.optionObj
};
},
props: {
materialsList: {
type: Array,
@ -65,7 +71,32 @@ export default {
tableData: [],
activeIndexPath: '',
rowIndex: 0,
conditionKey: ''
conditionKey: '',
optionObj: {
boolean: [
{ label: '是', value: true },
{ label: '否', value: false }
],
RunLevel: [
{ label: 'cbtc级别', value: 'CBTC' },
{ label: '点式通信', value: 'ITC' },
{ label: '联锁级', value: 'IL' }
],
SignalAspect: [
{label:'红', value:1},
{label:'绿', value:2},
{label:'黄', value:3},
{label:'黄红', value:4},
{label:'绿绿', value:5},
{label:'绿黄', value:6},
{label:'黄黄', value:7},
{label:'黄闪黄', value:8},
{label:'白红', value:9},
{label:'蓝', value:10},
{label:'白', value:11},
{label:'红闪', value:12}
]
}
};
},
computed: {
@ -83,6 +114,42 @@ export default {
const ml = (w - parseInt(this.dialogWidth)) / 2;
return ml;
},
ConstSelect() {
return ConstConfig.ConstSelect;
},
mapDevice() {
return this.$store.state.map.mapDevice;
},
getDeviceList() {
const typeObj = {};
this.ConstSelect.operationDeviceList.forEach(ii => {
typeObj[ii.value] = ii.label;
});
const list = [];
Object.values(this.mapDevice).forEach(item => {
if (typeObj[item._type]) {
list.push({
code: item.code,
name: `${item.groupNumber || item.name}(${typeObj[item._type]})`,
_type: item._type
});
}
});
this.getRouteList.forEach(item => {
list.push({
code: item.code,
name: `${item.name}(进路)`,
_type: 'Route'
});
});
return list;
},
routeData() {
return this.$store.state.map.routeData;
},
getRouteList() {
return Object.values(this.routeData);
},
deleteDisabled() {
let s = false;
if (!this.tableData[0] || !this.tableData[0].valuables || !this.tableData[0].valuables[0] || !this.activeIndexPath) {
@ -100,11 +167,15 @@ export default {
},
watch: {},
methods: {
addExp() {
addExp(obj) {
let addData = { t: 'E', operator: 'EQ', valuables: [] };
if (obj) {
addData = obj;
}
const data = {
t: 'E',
operator: 'AND',
valuables: [this.tableData[0], {t: 'E', operator: 'EQ', valuables: [] }]
valuables: [this.tableData[0], addData]
};
this.tableData.splice(0, 1, data);
},
@ -153,15 +224,12 @@ export default {
}
});
tData.splice(lastIndex, 1, data);
console.log(this.tableData, indexPath, '----');
},
doSave() {
console.log('保存', this.tableData);
let data = this.tableData[0];
if (this.clearDisabled) {
data = null;
}
console.log(this.checkData(data), '校验结果');
if (this.checkData(data)) {
this.$emit('editConditionFn', data, this.rowIndex, this.conditionKey);
this.doClose();

View File

@ -69,7 +69,8 @@
</el-form-item>
</div>
<el-form-item class="dialog-footer">
<el-button size="small" type="primary" :disabled="!indexPath" @click="doSave">修改</el-button>
<el-button v-if="indexPath" size="mini" type="primary" @click="doSave">修改</el-button>
<el-button v-else size="mini" type="primary" @click="doAdd">新增</el-button>
</el-form-item>
</el-form>
</div>
@ -80,7 +81,14 @@ import ConstConfig from '@/scripts/ConstConfig';
export default {
name: 'Expression',
components:{},
inject: ['optionObj'],
props: {
getDeviceList: {
type: Array,
default() {
return [];
}
},
materialsList: {
type: Array,
default() {
@ -92,31 +100,6 @@ export default {
return {
indexPath: '',
field: '',
optionObj: {
boolean: [
{ label: '是', value: true },
{ label: '否', value: false }
],
RunLevel: [
{ label: 'cbtc级别', value: 'CBTC' },
{ label: '点式通信', value: 'ITC' },
{ label: '联锁级', value: 'IL' }
],
SignalAspect: [
{label:'红', value:1},
{label:'绿', value:2},
{label:'黄', value:3},
{label:'黄红', value:4},
{label:'绿绿', value:5},
{label:'绿黄', value:6},
{label:'黄黄', value:7},
{label:'黄闪黄', value:8},
{label:'白红', value:9},
{label:'蓝', value:10},
{label:'白', value:11},
{label:'红闪', value:12}
]
},
formModel: {
t: 'E',
t1: 'S',
@ -167,39 +150,6 @@ export default {
optionValueType() {
return this.optionObj[this.valueType] || [];
},
mapDevice() {
return this.$store.state.map.mapDevice;
},
getDeviceList() {
const typeObj = {};
this.ConstSelect.operationDeviceList.forEach(ii => {
typeObj[ii.value] = ii.label;
});
const list = [];
Object.values(this.mapDevice).forEach(item => {
if (typeObj[item._type]) {
list.push({
code: item.code,
name: `${item.groupNumber || item.name}(${typeObj[item._type]})`,
_type: item._type
});
}
});
this.getRouteList.forEach(item => {
list.push({
code: item.code,
name: `${item.name}(进路)`,
_type: 'Route'
});
});
return list;
},
routeData() {
return this.$store.state.map.routeData;
},
getRouteList() {
return Object.values(this.routeData);
},
getAttributeList() {
let attr = [];
if (this.deviceType) {
@ -209,7 +159,6 @@ export default {
if (obj) {
attr = obj.materials;
}
console.log(attr, '========ppp');
}
return attr;
},
@ -286,42 +235,55 @@ export default {
this.field = field == this.field ? '' : field;
this.$emit('hover', field);
},
validate() {
return new Promise((resolve, reject) => {
this.$refs.formModel.validate(valid => {
if (valid) {
const cpData = {};
cpData.t = this.formModel.t;
cpData.operator = this.formModel.operator;
let objV1 = {
valuables: this.formModel.valuables1.valuables || [],
operator: this.formModel.valuables1.operator || 'EQ',
t: this.formModel.valuables1.t || 'E'
};
let objV2 = {
valuables: this.formModel.valuables2.valuables || [],
operator: this.formModel.valuables2.operator || 'EQ',
t: this.formModel.valuables2.t || 'E'
};
if (this.formModel.t1 == 'S') {
objV1 = {
elementCode: this.formModel.elementCode,
filedName: this.formModel.filedName,
t: 'S'
};
}
if (this.formModel.t2 == 'V') {
objV2 = {
v: this.formModel.v,
t: 'V'
};
}
cpData.valuables = [objV1];
if (this.showConditionList2) {
cpData.valuables[1] = objV2;
}
resolve(cpData);
} else {
reject();
}
});
});
},
doAdd() {
this.validate().then(res => {
this.$emit('addExp', res);
});
},
doSave() {
this.$refs.formModel.validate(valid => {
if (valid) {
const cpData = {};
cpData.t = this.formModel.t;
cpData.operator = this.formModel.operator;
let objV1 = {
valuables: this.formModel.valuables1.valuables || [],
operator: this.formModel.valuables1.operator || 'EQ',
t: this.formModel.valuables1.t || 'E'
};
let objV2 = {
valuables: this.formModel.valuables2.valuables || [],
operator: this.formModel.valuables2.operator || 'EQ',
t: this.formModel.valuables2.t || 'E'
};
if (this.formModel.t1 == 'S') {
objV1 = {
elementCode: this.formModel.elementCode,
filedName: this.formModel.filedName,
t: 'S'
};
}
if (this.formModel.t2 == 'V') {
objV2 = {
v: this.formModel.v,
t: 'V'
};
}
cpData.valuables = [objV1];
if (this.showConditionList2) {
cpData.valuables[1] = objV2;
}
console.log('编辑表达式', cpData, this.indexPath);
this.$emit('editExpression', cpData, this.indexPath);
}
this.validate().then(res => {
this.$emit('editExpression', res, this.indexPath);
});
},
setFormData(data, indexPath) {
@ -351,7 +313,6 @@ export default {
this.formModel.t2 = 'V';
}
}
console.log(data, indexPath, '---data, indexPath---');
},
clearFromData() {
this.$refs.formModel.resetFields();

View File

@ -4,17 +4,20 @@
<span>{{ valueObj.v }}</span>
</span>
<span v-if="valueObj.t == 'S'">
<span>设备{{ valueObj.elementCode }}</span>
<span>{{ getElementCodeName(valueObj.elementCode) }}</span>
<span></span>
<span>属性{{ valueObj.filedName }}</span>
<span>{{ getFiledName(valueObj) }}</span>
</span>
<div v-if="valueObj.t == 'E'" :style="{background: activeIndexPath==indexPath ? '#32f807' : ''}">
<span>&nbsp;</span>
<span v-if="hasSunExp(valueObj) && indexPath != '0'">&nbsp;(&nbsp;</span>
<span v-if="!valueObj.valuables[0]">
<span>??</span>
<span v-if="!valueObj.valuables[0]">??</span>
<span v-if="valueObj.valuables[0] && valueObj.valuables[0].t == 'S'">
<span>{{ getElementCodeName(valueObj.valuables[0].elementCode) }}</span>
<span></span>
<span>{{ getFiledName(valueObj.valuables[0]) }}</span>
</span>
<ExpressionValue :value-obj="valueObj.valuables[0]" :index-path="indexPath+'-0'" :active-index-path="activeIndexPath" @editValue="clickExpression" />
<ExpressionValue v-if="valueObj.valuables[0] && valueObj.valuables[0].t == 'E'" :materials-list="materialsList" :get-device-list="getDeviceList" :value-obj="valueObj.valuables[0]" :index-path="indexPath+'-0'" :active-index-path="activeIndexPath" @editValue="clickExpression" />
<span v-if="isBigExp(valueObj)" class="bigExpressionDiv">
<el-select v-model="valueObj.operator" placeholder="请选择" size="mini" style="width: 60px">
<el-option
@ -26,10 +29,11 @@
</el-select>
</span>
<span v-else class="expressionDiv" @click.stop="clickExpression(valueObj, indexPath)">&nbsp;{{ getOperatorName(valueObj.operator) }}&nbsp;</span>
<ExpressionValue v-if="!hasNotIs(valueObj.operator)" :value-obj="valueObj.valuables[1]" :index-path="indexPath+'-1'" :active-index-path="activeIndexPath" @editValue="clickExpression" />
<span v-if="!hasNotIs(valueObj.operator) && !valueObj.valuables[1]">
<span>??</span>
<ExpressionValue v-if="!hasNotIs(valueObj.operator) && valueObj.valuables[1] && valueObj.valuables[1].t == 'E'" :materials-list="materialsList" :get-device-list="getDeviceList" :value-obj="valueObj.valuables[1]" :index-path="indexPath+'-1'" :active-index-path="activeIndexPath" @editValue="clickExpression" />
<span v-if="valueObj.valuables[1] && valueObj.valuables[1].t == 'V'">
<span>{{ getValueName(valueObj) }}</span>
</span>
<span v-if="!hasNotIs(valueObj.operator) && !valueObj.valuables[1]">??</span>
<span v-if="hasSunExp(valueObj) && indexPath != '0'">&nbsp;)&nbsp;</span>
<span>&nbsp;</span>
</div>
@ -41,6 +45,7 @@ import ConstConfig from '@/scripts/ConstConfig';
export default {
name: 'ExpressionValue',
components:{},
inject: ['optionObj'],
props: {
valueObj: {
type: Object,
@ -59,6 +64,18 @@ export default {
default() {
return '';
}
},
getDeviceList: {
type: Array,
default() {
return [];
}
},
materialsList: {
type: Array,
default() {
return [];
}
}
},
data() {
@ -73,11 +90,86 @@ export default {
return this.ConstSelect.operationList.filter(item => {
return arr.includes(item.value);
});
},
valueTypeList() {
let list = [];
Object.values(this.optionObj).forEach(item => {
list = list.concat(item);
});
return list;
}
},
watch: {},
created() {},
methods: {
getValueName(obj) {
let value = obj.valuables[1].v;
const type = this.getValueType(obj.valuables[0]);
if (type) {
const list = this.optionObj[type] || [];
const findObj = list.find(item => {
return item.value == value;
});
if (findObj) {
value = findObj.label;
}
}
return value;
},
getElementCodeName(code) {
let name = code;
const findObj = this.getDeviceList.find(item => {
return item.code == code;
});
if (findObj) {
name = findObj.name;
}
return name;
},
getValueType(obj) {
let name = '';
const findObj = this.getDeviceAttr(obj);
if (findObj) {
name = findObj.type;
}
return name;
},
getFiledName(obj) {
let name = obj.filedName;
const findObj = this.getDeviceAttr(obj);
if (findObj) {
name = findObj.desc;
}
return name;
},
getDeviceAttr(obj) {
const type = this.deviceType(obj.elementCode);
const attrList = this.getAttributeList(type);
const findObj = attrList.find(item => {
return item.name == obj.filedName;
});
return findObj;
},
deviceType(code) {
let type = '';
const findObj = this.getDeviceList.find(item => {
return item.code == code;
});
if (findObj) {
type = findObj._type || '';
}
return type;
},
getAttributeList(type) {
let attr = [];
const obj = this.materialsList.find(item => {
return item.srcName == type;
});
if (obj) {
attr = obj.materials;
}
return attr;
},
hasSunExp(obj) {
let s = false;
if (obj.valuables[0] && obj.valuables[0].t == 'E') {