UNPKG

w-vue-middle

Version:

统一公共服务组件

181 lines (175 loc) 6.42 kB
/* * @Author: Jason Liu * @Date: 2023-05-04 14:33:45 * @Desc: */ /** * @Author: Jason Liu */ const $dataIntegration = require("w-vue-middle/api/dataIntegration"); export default { 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, columns: [], // formerName:med_insti_no,//物理字段名 columnName: "eeed", //别名 lookUp: false, description: undefined, } } }, referData: { type: Object, default: () => { return { schemaId: undefined } } }, type: { type: String } }, data() { return { loading: false, nodeData: this.value, dataSchemaList: [], viewSchemaList: [], } }, computed: { formatSchema() { return function(val) { let item = this.viewSchemaList.find(v => { return v.value == val }); return item ? item.label : val; } } }, created() { this.getSelectData(); }, methods: { /** * @Author: Jason Liu * @description: 获取查询列表 */ getViewSchemaList(value = undefined) { let inList = this.dataSchemaList.filter(item => { if (value) { return item.label.toLocaleLowerCase().indexOf(value.toLocaleLowerCase()) > -1; } else { return true; } }).slice(0, 15); if (!value) { const { schemaId } = this.nodeData; if (schemaId) { let has = inList.find(item => { return item.value == schemaId }); if (!has) { const valueData = this.dataSchemaList.find(item => { item.value == schemaId }); if (!valueData) { inList.unshift({ value: schemaId, label: schemaId }); } else { inList.unshift(valueData); } } } } this.viewSchemaList = inList; }, /** * @Author: Jason Liu * @description: 获取数据源信息 */ getSelectData(useCache = true) { if (this.nodeData.dbId) { if (['mysql', 'dorisdb', 'doris'].indexOf(this.nodeData.dbType) > -1) { this.dataSchemaList = [{ value: "schema", label: "schema" }]; this.nodeData.schemaId = "schema"; this.nodeData.schema = this.nodeData.schemaId; this.getViewSchemaList(); this.$emit("change", this.nodeData); } else { this.dataSchemaList = []; this.viewSchemaList = []; let $event = $dataIntegration.collectionDataInfo; let param = { clusterId: this.nodeData.clusterId, //集群ID collectType: 'schema', // 采集类型:schema、table、column dsId: this.nodeData.dbId, schema: "schema", tableName: "tableName", useCache: useCache }; if (this.nodeData.sourceType == 0) { $event = $dataIntegration.getDbsSchema; param = this.nodeData; } this.loading = true; $event(param).then(req => { this.dataSchemaList = (req.data || []).map(item => { return { value: item.schemaCode, label: item.schemaName } }); if (!this.nodeData.schemaId && this.dataSchemaList.length > 0) { this.nodeData.schemaId = this.dataSchemaList[0].value; this.nodeData.schema = this.nodeData.schemaId; this.nodeData.tableCode = undefined; this.$emit("change", this.nodeData); } this.getViewSchemaList(); }).finally(() => { this.loading = false; }); } } else { this.dataSchemaList = []; this.getViewSchemaList(); this.nodeData.schemaId = undefined; this.nodeData.schema = undefined; this.$emit("input", this.nodeData); this.$emit("change", this.nodeData); } }, /** * @Author: Jason Liu * @description: 修改数据源事件 */ changeSchema() { this.nodeData.schema = this.nodeData.schemaId; this.$emit("input", this.nodeData); this.$emit("change", this.nodeData); }, }, watch: { "value.dbId"(val, old) { this.nodeData = this.value; this.getSelectData(); }, value(value, old) { this.nodeData = value; }, nodeData() { this.$emit("input", this.nodeData); } } }