w-vue-middle
Version:
统一公共服务组件
208 lines (201 loc) • 5.31 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2023-05-04 14:33:45
* @Desc:
*/
/**
* @Author: Jason Liu
* @description: 高级设置输出字段
*/
//const setOutColumns = require("./setOutColumns").default;
const fieldDetails = require('../fieldDetails').default;
/**
* @Author: Jason Liu
* @description: 查询条件设置
*/
const setWhereString = require('./setWhereString').default;
export default {
components: { setWhereString, fieldDetails },
props: {
value: {
type: Object,
},
referData: {
type: Object,
default: () => {
return {};
},
},
columns: {
type: Array,
default: () => {
return [];
},
},
musts: {
//必填字段
type: Array,
default: () => {
return [];
},
},
noDataMessage: {
//没数据提示
type: String,
default: $t('请选择数据表'),
},
reloadLoading: {
//数据加载
type: Boolean,
default: false,
},
},
data() {
return {
nodeData: this.value,
setColumns: false, //设置字段
mapColumns: this.columns,
setting: false,
setwhere: false,
dataKey: 0,
columnTypes: [],
filterColumnName: [{ data: '' }],
};
},
created() {
this.analysisColumns();
},
methods: {
/**
* @Author: Jason Liu
* @description: 修改数据源事件
*/
changeNodeData(value) {
this.$emit('change', this.nodeData);
},
/**
* @Author: Jason Liu
* @description: 修改数据表事件
*/
changeTableName() {
this.$emit('change', this.nodeData);
},
filterColumnMethod({ option, row }) {
let has = false;
let curVal = option.data.toLocaleLowerCase();
if (row.description) {
has = row.description.toLocaleLowerCase().indexOf(curVal) > -1;
}
return row.columnName.toLocaleLowerCase().indexOf(curVal) > -1 || has;
},
filterColumnTypeMethod({ option, row }) {
return row.columnType === option.label;
},
/**
* @Author: Jason Liu
* @description: 禁用输出列
*/
visibleOutTableColumn({ row }) {
return true;
},
checkOutTableColumn() {
return !this.nodeData.disabled;
},
/**
* @Author: Jason Liu
* @description: 设置行数据样式
*/
setRowDataClass({ row, rowIndex }) {
if (row.columnName == '') {
return 'row_warning';
}
},
/**
* @Author: Jason Liu
* @description: 设置输出字段
*/
setDataColumns() {
this.nodeData.columns = this.mapColumns.filter((item) => {
return item.checked;
});
this.changeNodeData();
},
changeFieldAttr(e, row) {
switch (e.key) {
case 'pk':
row.pk = true;
break;
case 'nopk':
row.pk = false;
break;
default:
break;
}
this.setDataColumns();
},
/**
* @Author: Jason Liu
* @description: 解析列信息
*/
analysisColumns() {
this.columnTypes = [];
let hasDiffer = false; //数据存在差异
const defchecked = this.nodeData.columns.length == 0;
let columns = JSON.DeepCopy(this.nodeData.columns);
this.mapColumns = this.mapColumns.map((column) => {
let index = columns.findIndex((old) => {
return old.columnName == column.columnName;
});
let has = this.columnTypes.findIndex((item) => {
return item.data == column.columnType;
});
if (has == -1) {
this.columnTypes.push({ data: column.columnType, label: column.columnType });
}
// if (index > -1) {
// if (columns[index] != column) { //数据存在差异的情况
// this.hasDiffer = true;
// column = columns[index];
// if (this.nodeData.mapping && this.nodeData.mapping.length > 0) {
// this.nodeData.mapping[index].target = JSON.DeepCopy(column);
// }
// }
// columns.splice(index, 1);//性能优化
// }
return {
...column,
checked: defchecked || index > -1,
formerName: column.columnName,
};
});
// .sort((o, l) => {
// if (o.pk != l.pk) {
// return o.pk ? -1 : 1;
// } else {
// return o.columnName.localeCompare(l.columnName);
// }
// });
this.dataKey++;
if (defchecked) {
this.setDataColumns();
} else if (hasDiffer) {
//发现差异数,更新配置的数据源
this.$message.warning($t('采集字段发生变化,请注意设置信息,关注业务主键!'));
this.changeNodeData();
}
},
},
watch: {
value(value) {
this.nodeData = value;
//this.analysisColumns();
},
columns(val) {
this.mapColumns = val;
this.analysisColumns();
},
nodeData() {
this.$emit('input', this.nodeData);
},
},
};