UNPKG

w-vue-middle

Version:

统一公共服务组件

272 lines (267 loc) 9.35 kB
/* * @Author: Jason Liu * @Date: 2023-03-08 13:31:51 * @Desc: */ const $dataIntegration = require("w-vue-middle/api/dataIntegration"); import draggable from "vuedraggable"; const { sourceSelection } = require("w-vue-middle/dataSourceService"); const { jobVariable } = require("w-vue-middle/jobProcessService"); export default { components: { draggable, sourceSelection, jobVariable }, name: "dataTableSource", props: { value: { type: Object, default: { sourceType: 1, dbId: undefined, //链接数据库ID dbName: undefined, //链接数据库名称 dbType: undefined, //链接数据库类型 ip: undefined, port: undefined, tableId: undefined, tableName: undefined, tableCode: undefined, }, }, }, data() { return { loading: false, dataLoading: false, dataList: [], viewDataList: [], functionList: [], //函数列表 viewFunctionList: [], viewFunctionKey: 0, sourceList: [], //数据源列表 sourceInfo: [], //数据源选择信息 tableName: undefined, //查询的表名称 activeName: undefined, nodeData: this.value, tableKey: 0 } }, created() { this.getTableList(); this.getFunctionList(); }, methods: { loadedVariable(e = []) { this.$emit("variables", e); }, getFunctionList() { this.functionList = []; $dataIntegration.getSQlFunctonList().then((req) => { req.data.forEach((item, i) => { item.id = `fun_${i}`; this.functionList.push({ id: item.id, name: item.name, parentId: null }); item.sub.forEach((fun, j) => { fun.id = `${i}_${j}`; fun.parentId = i; let subFun = { ...fun, id: `${i}_${j}`, parentId: item.id } this.functionList.push(subFun); }); }); this.searchFunctionList(); // this.functionList.forEach((fun) => { // fun.sub.forEach((sub) => { // this.tablesColumns[sub.sqlFunc] = []; // }); // }); }).finally(() => { this.$emit("functions", this.functionList); }); }, /** * @Author: Jason Liu * @description: 查询函数名称 */ filterFunName({ option, row }) { let val = option.data.toLocaleUpperCase(); if (row.name) { return row.name.toLocaleUpperCase().indexOf(val) > -1; } else { return row.sqlFunc.toLocaleUpperCase().indexOf(val) > -1; } }, /** * @Author: Jason Liu * @description: 查询函数列表 */ searchFunctionList(e) { if (e) { let strValue = e.toLocaleUpperCase(); this.viewFunctionList = this.functionList.filter(row => { if (row.name) { return row.name.toLocaleUpperCase().indexOf(strValue) > -1; } else { return row.sqlFunc.toLocaleUpperCase().indexOf(strValue) > -1; } }); } else { this.viewFunctionList = this.functionList; } this.viewFunctionKey++; }, /** * @Author: Jason Liu * @description: 获取字段信息 */ getColumnList({ row }) { const { clusterId, dbId, schemaId, sourceType } = this.nodeData; return $dataIntegration.getSourceColumns({ clusterId, dbId, schemaId, sourceType, tableCode: row.tableCode }).then(req => { this.$emit("columns", { tableCode: row.tableCode, columns: req.data }); return req.data; }) }, /** * @Author: Jason Liu * @description: 数据源列表 */ getTableList(e) { 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: true }; if (this.nodeData.sourceType == 0) { $event = $dataIntegration.getDbsSchema; param = { dbId: this.nodeData.dbId, schemaCode: this.nodeData.schema || this.nodeData.schemaId } } this.dataLoading = true; $event(param).then(req => { this.dataList = (req.data || []).map(table => { return { id: table.tableCode, name: table.tableName, tableCode: table.tableCode, tableName: table.tableName, hasChild: true, parentId: undefined } }); this.searchTableList(); this.$emit("table", this.dataList); }).finally(() => { this.dataLoading = false; }); } else { this.dataList = []; this.$emit("table", this.dataList); } }, /** * @Author: Jason Liu * @description: 点击表格事件 */ clickTable(row) { this.activeName = row.tableName; this.$emit("clickTable", row, this.nodeData); }, /** * @Author: Jason Liu * @description: 查询设置 */ filterTableName({ option, row }) { const refValue = option.data.toLocaleUpperCase(); if (row.tableCode) { return row.tableCode.toLocaleUpperCase().indexOf(refValue) > -1; } else { return row.columnName.toLocaleUpperCase().indexOf(refValue) > -1; } //return true; }, /** * @Author: Jason Liu * @description: 查询数据列表 */ searchTableList(e) { if (e) { const refValue = e.toLocaleUpperCase(); this.viewDataList = this.dataList.filter(row => { if (row.tableCode) { return row.tableCode.toLocaleUpperCase().indexOf(refValue) > -1; } else { return row.columnName.toLocaleUpperCase().indexOf(refValue) > -1; } }); } else { this.viewDataList = this.dataList; } this.tableKey++; }, cloneEntry(row) { return { key: `${(new Date()).getTime()}`, ...row, }; }, /** * @Author: Jason Liu * @description: 开始克隆事件 */ cloneStart(e) { this.$emit("start", e); }, /** * @Author: Jason Liu * @description: 结束克隆事件 */ cloneEnd(e) { this.$emit("end", e); }, /** * @Author: Jason Liu * @description: 移动事件 */ cloneMove(e) { this.$emit("move", e); }, /** * @Author: Jason Liu * @description: 导入sql脚本 */ inputTableScript(row) { let param = { clusterId: this.nodeData.clusterId, //集群ID tableName: row.tableCode, dsId: this.nodeData.dbId, schema: this.nodeData.schemaId, collectType: "column", useCache: true }; row.loading = true; $dataIntegration.getModelSqlScript(param).then(req => { this.$emit("inputScript", req.data); }) }, }, watch: { value(val) { this.nodeData = val; this.getTableList(); }, nodeData() { this.$emit("input", this.nodeData); }, } }