w-vue-middle
Version:
统一公共服务组件
157 lines (150 loc) • 5.12 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 outputField = require("../outputField").default;
const sqlScriptSource = require("./sqlScriptSource").default;
const $dataIntegration = require("w-vue-middle/api/dataIntegration");
export default {
components: { dataSourcesSelection, outputField, dataSchemaSelection, sqlScriptSource },
props: {
value: {
type: Object,
},
referData: {
type: Object,
default: () => {
return undefined
}
},
referJobType: {
type: String,
default: "init"
},
getSource: {
type: Function,
default: () => {
return false
}
}
},
data() {
return {
nodeData: this.value,
loading: false,
tables: [], //表格列表
columns: [],
setScript: false
}
},
created() {
// this.getTableList();
this.getSourceColumns();
},
methods: {
/**
* @Author: Jason Liu
* @description: 获取来源列表
*/
getSourceColumns() {
if (this.nodeData.script) {
this.loading = true;
let places = undefined;
if (this.nodeData.places && this.nodeData.places.length > 0) {
places = this.nodeData.places.filter(item => {
return !!item.key;
});
}
$dataIntegration.collectionDataInfo({
clusterId: this.nodeData.clusterId, //集群ID
collectType: 'sql', // 采集类型:schema、table、column
dsId: this.nodeData.dbId,
schema: this.nodeData.schemaId,
tableName: '',
uuid: 0,
useCache: false,
sql: this.nodeData.script,
places: places
}).then(req => {
//this.nodeData.columns = req.meta;
this.columns = req.data.meta.map(column => {
return {
asName: column.asName || column.columnName,
tableAsName: this.nodeData.asName,
tableCode: this.nodeData.tableCode,
tableId: this.nodeData.tableId,
tableName: this.nodeData.tableName,
...column
}
});
this.changeNodeData();
}).finally(() => {
this.loading = false;
});
}
},
changeTableName() {
this.nodeData.tableId = this.nodeData.tableName;
this.nodeData.tableCode = this.nodeData.tableName;
this.nodeData.asName = this.nodeData.tableName;
this.nodeData.columns = this.nodeData.columns.map(column => {
return {
...column,
tableAsName: this.nodeData.asName,
tableCode: this.nodeData.tableCode,
tableId: this.nodeData.tableId,
tableName: this.nodeData.tableName,
};
});
this.changeNodeData();
},
/**
* @Author: Jason Liu
* @description: 修改schema事件
*/
changeSchema() {
this.changeNodeData();
},
/**
* @Author: Jason Liu
* @description: 脚本信息
*/
changeScript(e) {
if (e.columns.length) {
this.columns = e.columns;
this.nodeData.columns = JSON.DeepCopy(e.columns.map(column => {
return {
asName: column.asName || column.columnName,
tableAsName: this.nodeData.asName,
tableCode: this.nodeData.tableCode,
tableId: this.nodeData.tableId,
tableName: this.nodeData.tableName,
...column
}
}));
}
this.changeNodeData();
},
/**
* @Author: Jason Liu
* @description: 修改数据源事件
*/
changeNodeData(value) {
this.$emit("change", this.nodeData);
},
},
watch: {
value(value) {
this.nodeData = value;
},
nodeData() {
this.$emit("input", this.nodeData);
}
}
}