w-vue-middle
Version:
统一公共服务组件
379 lines (355 loc) • 13.6 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2023-05-04 14:33:45
* @Desc:
*/
//数据源选择
const dataSourcesSelection = require('../dataSourcesSelection').default;
//schema选择
const dataSchemaSelection = require('../dataSchemaSelection').default;
const setDistinctSql = require('./setDistinctSql').default;
//脚本关联设置器
const setTableJoin = require('./setTableJoin').default;
const fieldDetails = require('../fieldDetails').default;
export default {
components: {
dataSourcesSelection,
dataSchemaSelection,
setTableJoin,
setDistinctSql,
fieldDetails,
},
props: {
value: {
type: Object,
default: {
id: undefined,
name: undefined,
code: undefined,
type: 'TableJoin',
tableId: undefined,
tableName: undefined,
tableCode: undefined,
asName: undefined, //选择的数据表名称
columns: [], // formerName:med_insti_no,//物理字段名 columnName: "eeed", //别名
tables: [], //关联的表信息 { tableid, tableName,tableCode, asName: "a", columns, isMain }, //isMain是否主表
joins: [], //绑定的关系信息
lookUp: false,
description: undefined,
},
},
referData: {
type: Object,
default: () => {
return undefined;
},
},
getSource: {
type: Function,
default: () => {
return false;
},
},
},
data() {
return {
nodeData: this.value,
loading: false,
tables: [], //表格列表
columns: [],
setMap: false, //设置关联
sourceColumns: [],
mapTables: [],
setJoin: false,
dataKey: 1111,
isError: false,
viewSetDistinct: false,
};
},
created() {
this.getSources();
},
methods: {
/**
* @Author: Jason Liu
* @description: 获取来源列表
*/
getSources(isSend = false) {
this.isError = false;
if (this.nodeData.tableCode) {
this.loading = true;
let source = this.getSource();
if (source && source.length > 0) {
this.dataKey++;
let mainIndex = -1; //主表数据
this.sourceColumns = [];
let temp = [];
let newTables = [];
source.forEach((info, i) => {
let node = info.data;
if (node.type == 'KafaInputs' || node.type == 'ApiInputs') {
node.tables.forEach((table) => {
let notuse = true;
if (temp.indexOf(table.asName) > -1) {
//已存在内容,无需后续操作
} else {
temp.push(table.asName);
}
this.nodeData.joins.forEach((join) => {
if (join.right.tableId == table.id) {
notuse = false;
} else {
join.conditions.forEach((condition) => {
if (
condition.left.tableId == table.id ||
condition.right.tableId == table.id
) {
notuse = false;
}
});
}
});
let columns = node.columns.filter((column) => {
if (column.tableCode == table.tableCode) {
this.sourceColumns.push({
id: `${table.tableCode}.${column.columnName}`,
parentId: table.asName,
tableCode: table.tableCode,
tableId: table.tableId,
tableAsName: table.tableCode,
tableName: table.tableCode,
asName: column.columnName,
notuse: notuse, //未使用
...column,
});
return true;
} else {
return false;
}
});
let result = {
nodeId: node.id, //数据源ID
type: node.type,
dbId: undefined,
isMain: false,
schema: undefined,
schemaId: undefined,
sourceCode: node.code,
tableCode: table.tableCode,
tableId: table.tableId,
asName: table.asName,
tableName: table.tableName,
notuse: notuse, //未使用
columns: columns,
};
let callTables = this.nodeData.tables.find((item) => {
return (
item.dbId == node.dbId &&
node.schemaId == item.schemaId &&
node.tableCode == item.tableCode
);
});
if (callTables && callTables.isMain) {
result.isMain = true;
mainIndex = i;
}
newTables.push(result);
});
} else {
if (temp.indexOf(node.asName) > -1) {
//已存在内容,无需后续操作
} else {
temp.push(node.asName);
}
//let tables = this.nodeData.tables;
let callTables = this.nodeData.tables.find((item) => {
return item.nodeId == node.id && node.asName == item.asName;
});
if (node.columns) {
node.columns.forEach((column) => {
this.sourceColumns.push({
...column,
id: `${node.asName}.${column.columnName}`,
parentId: node.asName,
tableCode: node.tableCode,
tableId: node.tableId,
tableAsName: node.asName || node.tableCode,
tableName: node.tableName,
asName: column.columnName,
});
});
}
let result = {
nodeId: node.id, //数据源ID
columns: node.columns,
dbId: undefined, //node.dbId,
isMain: false,
schema: undefined, // node.schema,
schemaId: undefined, //node.schemaId,Ï
sourceCode: node.code,
tableCode: node.tableCode || node.asName,
tableId: node.tableId,
asName: node.asName,
tableName: node.tableName,
};
if (callTables && callTables.isMain) {
result.isMain = true;
mainIndex = i;
}
newTables.push(result);
}
});
if (temp.length != newTables.length) {
this.isError = true;
this.$message.warning($t('来源表重名了,请调整来源表别名!'));
} else {
this.nodeData.columns = [...this.sourceColumns];
if (mainIndex == -1) {
newTables[0].isMain = true;
}
newTables.forEach((table) => {
let id = table.asName;
if (table.type == 'KafaInputs' || table.type == 'ApiInputs') {
id = table.tableId;
}
this.sourceColumns.push({
id: id,
parentId: undefined,
isMain: table.isMain,
tableCode: table.tableCode,
tableId: table.tableId,
tableName: table.tableName,
asName: table.asName,
notuse: table.notuse, //是否使用 true 标识没有使用
});
});
this.nodeData.joins.forEach((join) => {
//关联表一一检查数据的更新情况
newTables.forEach((table) => {
if (table.type == 'KafaInputs' || table.type == 'ApiInputs') {
return false;
} else {
//以下是老数据的兼容处理
if (join.right.nodeId == table.nodeId) {
join.right.asName = table.asName || table.tableCode; //方式asName变卦
join.right.tableCode = table.tableCode;
join.right.tableId = table.tableId;
join.right.tableName = table.tableName;
} else if (!join.right.nodeId) {
//没有nodeId的兼容处理
if (join.right.asName == table.asName) {
join.right.nodeId = table.nodeId;
} else if (!join.right.asName) {
if (join.right.tableCode == table.tableCode) {
join.right.nodeId = table.nodeId;
join.right.asName = table.tableCode;
join.right.tableId = table.tableId;
join.right.tableName = table.tableName;
}
}
}
join.conditions.forEach((condition) => {
if (condition.left) {
if (condition.left.nodeId == table.nodeId) {
if (condition.left.asName != table.asName) {
//数据源相同,别名不相同
condition.left.asName = table.asName; //方式asName变卦
condition.left.tableCode = table.tableCode;
condition.left.tableId = table.tableId;
condition.left.tableName = table.tableName;
condition.leftmap[0] = table.asName;
condition.left.column = {
...condition.left.column,
nodeId: table.nodeId,
tableAsName: table.asName,
tableCode: table.tableCode,
tableId: table.tableId,
tableName: table.tableName,
};
}
} else if (!condition.left.nodeId) {
if (condition.left.asName == table.asName) {
condition.left.nodeId = table.nodeId;
condition.left.column.nodeId = table.nodeId;
}
}
if (condition.right.nodeId == table.nodeId) {
if (condition.right.asName != table.asName) {
//数据源相同,别名不相同
condition.right.asName = table.asName; //方式asName变卦
condition.right.tableCode = table.tableCode;
condition.right.tableId = table.tableId;
condition.right.tableName = table.tableName;
condition.rightmap[0] = table.asName;
condition.right.column = {
...condition.right.column,
nodeId: table.nodeId,
tableAsName: table.asName,
tableCode: table.tableCode,
tableId: table.tableId,
tableName: table.tableName,
};
}
} else if (!condition.right.nodeId) {
if (condition.right.asName == table.asName) {
condition.right.nodeId = table.nodeId;
condition.right.column.nodeId = table.nodeId;
}
}
}
});
}
});
});
this.nodeData.tables = newTables;
this.changeNodeData();
}
} else if (isSend) {
this.$message.warning($t('请指定来源输入信息'));
this.nodeData.tables = [];
this.nodeData.joins = [];
this.changeNodeData();
} else {
this.nodeData.tables = [];
this.nodeData.joins = [];
this.changeNodeData();
}
}
setTimeout(() => {
this.loading = false;
}, 500);
},
/**
* @Author: Jason Liu
* @description: 修改数据源事件
*/
changeNodeData() {
this.$emit('change', this.nodeData);
},
changeJoinData() {
this.$emit('input', this.nodeData);
this.changeNodeData();
this.getSources();
},
/**
* @Author: Jason Liu
* @description: 刷新表格事件
*/
changeTableData() {
this.nodeData.tableId = this.nodeData.tableCode;
this.nodeData.tableName = this.nodeData.tableCode;
this.nodeData.asName = this.nodeData.tableCode;
this.$emit('input', this.nodeData);
this.changeNodeData();
},
},
watch: {
value(value) {
this.nodeData = value;
this.getSources();
},
nodeData() {
this.$emit('input', this.nodeData);
},
},
};