UNPKG

w-vue-middle

Version:

统一公共服务组件

299 lines (285 loc) 10.5 kB
/* * @Author: Jason Liu * @Date: 2023-05-04 14:33:45 * @Desc: */ //输出字段 const outputField = require("../outputField").default; /** * @Author: Jason Liu */ const $dataIntegration = require("w-vue-middle/api/dataIntegration"); export default { components: { outputField }, props: { value: { type: Object, default: () => { return { id: undefined, name: undefined, code: undefined, type: undefined, sourceType: 1, dbId: undefined, //链接数据库ID dbName: undefined, //链接数据库名称 dbType: undefined, //链接数据库类型 ip: undefined, port: undefined, schema: undefined, schemaId: undefined, tableId: undefined, tableName: undefined, tableCode: undefined, asName: undefined, columns: [], // formerName:med_insti_no,//物理字段名 columnName: "eeed", //别名 lookUp: false, description: undefined, } } }, referData: { type: Object, default: () => { return { tableCode: undefined, asName: undefined, } } }, type: { type: String } }, data() { return { loading: false, columnLoading: false, nodeData: this.value, tableList: [], showTable: [], columns: [], timestampColumns: [] } }, created() { this.getSelectData(); }, methods: { /** * @Author: Jason Liu * @description: 获取数据源信息 */ getSelectData(useCache = true) { if (this.nodeData.schemaId) { let $event = $dataIntegration.collectionDataInfo; let param = { clusterId: this.nodeData.clusterId, //集群ID collectType: 'table', // 采集类型:schema、table、column dsId: this.nodeData.dbId, schema: this.nodeData.schemaId, tableName: "tableName", useCache: useCache }; if (this.nodeData.sourceType == 0) { $event = $dataIntegration.getDbsSchema; param = { dbId: this.nodeData.dbId, schemaCode: this.nodeData.schemaId } } this.loading = true; $event(param).then(req => { this.tableList = (req.data || []).map(item => { return { data: item, value: item.tableCode, label: item.tableCode } }); this.searchCollectionDatas(); }).finally(() => { this.getSourceColumns(); this.loading = false; }); } else { this.tableList = []; this.nodeData.tableCode = undefined; this.nodeData.tableName = undefined; this.nodeData.tableId = undefined; this.nodeData.asName = undefined; this.changeNodeData(); } }, /** * @Author: Jason Liu * @description: 搜索采集的表格内容 */ searchCollectionDatas(value) { let templist = this.tableList; let addValue = true; //是否把当前数据添加显示 if (value) { templist = templist.filter(item => { return item.label.toLocaleLowerCase().indexOf(value.toLocaleLowerCase()) > -1; }); } if (templist) { if (value) { templist = templist.sort((o, l) => { return o.label.length - l.label.length }) } this.showTable = templist.slice(0, 20).map(item => { if (item.value == this.nodeData.tableCode) { addValue = false; } return item; }); if (addValue && this.nodeData.tableCode) { this.showTable.unshift({ label: this.nodeData.tableCode, value: this.nodeData.tableCode }); } } }, /** * @Author: Jason Liu * @description: 修改数据源事件 */ changeNodeData(value) { this.$emit("change", this.nodeData); }, /** * @Author: Jason Liu * @description: 修改数据源事件 */ changeTable() { let table = this.tableList.find(table => { return table.value == this.nodeData.tableCode }); if (table) { this.nodeData.tableId = table.data.tableId; } else { this.nodeData.tableId = `${this.nodeData.tableCode}`; } this.nodeData.tableName = this.nodeData.tableCode; this.nodeData.asName = `${this.nodeData.tableCode}`; this.nodeData.columns = []; this.changeNodeData(); this.getSourceColumns(); }, /** * @Author: Jason Liu * @description: 修改表别名 */ changeAsName() { this.nodeData.columns = this.nodeData.columns.map(column => { column.tableAsName = this.nodeData.asName; return column; }); this.changeNodeData(); }, /** * @Author: Jason Liu * @description: 刷新获取数据源事件 */ getSourceColumns(useCache = true) { if (this.nodeData.tableCode) { let $event = $dataIntegration.collectionDataInfo; let param = { clusterId: this.nodeData.clusterId, //集群ID collectType: 'column', // 采集类型:schema、table、column dsId: this.nodeData.dbId, schema: this.nodeData.schemaId, tableName: this.nodeData.tableCode, useCache: useCache }; if (this.nodeData.sourceType == 0) { $event = $dataIntegration.getDbsInfoColumns; param = this.nodeData; } this.columnLoading = true; $event(param).then(req => { let temp = (req.data || []).map(column => { let oldcolumn = this.nodeData.columns.find(old => { return old.asName == (column.asName || column.columnName) }); if (oldcolumn) { oldcolumn = { ...oldcolumn, ...column, pk: oldcolumn.pk }; return oldcolumn } else { return { asName: column.asName || column.columnName, tableAsName: this.nodeData.asName, tableCode: this.nodeData.tableCode, tableId: this.nodeData.tableId, tableName: this.nodeData.tableName, ...column } } }); let columns = this.nodeData.columns; if (!useCache || temp.length > 0) { //避免幽灵数据 this.nodeData.columns = temp.filter(column => { return columns.findIndex(item => { return item.columnName.toLocaleLowerCase() == column.columnName.toLocaleLowerCase(); }) > -1; }); } this.changeNodeData(); this.columns = temp; this.getTimestampColumns(); }).finally(() => { this.columnLoading = false; }) } }, /** * @Author: Jason Liu * @description: 获取时间时间字段列 */ getTimestampColumns() { this.timestampColumns = this.columns .filter((item) => { return ( ['timestamp', 'TIMESTAMP'].indexOf(item.columnType) > -1 ); }) .map((item) => { return { value: item.columnName, label: item.columnName, }; }); this.timestampColumns.unshift({ value: "new()", label: "new()", }); }, }, watch: { columns(val) { this.$emit("columns", this.columns); }, "value.tableCode"(val, old) { this.nodeData = this.value; this.getSelectData(); }, "value.schemaId"(val, old) { this.nodeData = this.value; this.getSelectData(); }, value(value, old) { this.nodeData = value; }, nodeData() { this.$emit("input", this.nodeData); } } }