UNPKG

w-vue-middle

Version:

统一公共服务组件

119 lines (115 loc) 3.75 kB
/* * @Author: Jason Liu * @Date: 2023-07-17 16:10:28 * @Desc: */ //数据开发服务 const $dataSource = require("w-vue-middle/api/appService/dataSource.js"); export default { props: { value: { type: Object, default: () => { return { dbId: undefined, //数据源ID dbType: undefined, // 类型 dbSchema: undefined, //SchemaName schemaId: undefined }; } }, }, data() { return { loading: false, dataSource: [], //数据源信息 sourceRoute: [], } }, created() { this.getDatasourceList(); }, methods: { /** * @Author: Jason Liu * @description: 转换数据源信息 */ parseDbData() { if (this.value && this.value.dbId) { this.sourceRoute = [this.value.dbId, this.value.dbSchema] } else { this.sourceRoute = []; } }, /** * @Author: Jason Liu * @description: 采集数据表信息 */ getDatasourceList() { this.loading = true; $dataSource .getDatasourceList() .then((req) => { this.dataSource = req.data .filter((item) => { return !!item.schemas; }) .map((item) => { let option = { value: item.datasourceId, label: item.name, isLeaf: !!item.schemas, type: item.type }; if (item.schemas) { option.children = item.schemas.map((schema) => { return { value: schema.schemaCode, label: schema.schemaCode }; }); } return option; }); // 返回schemaId if(this.value && this.value.dbId) { this.returnData(); } }) .finally(() => { this.loading = false; }); }, /** * @Author: Jason Liu * @description: 返回数据 */ returnData() { let itemVal = this.dataSource.find(item => { return item.value == this.sourceRoute[0] }) let itemSchema = itemVal.children.find(item => { return item.value == this.sourceRoute[1] }) this.$emit("input", { ...this.value, dbId: this.sourceRoute[0], //数据源ID dbSchema: this.sourceRoute[1], //SchemaName dbType: itemVal.type.toLocaleUpperCase(), schemaId: itemSchema.id || "" }); }, /** * @Author: Jason Liu * @description: 修改数据源事件 */ changeDataSource() { this.returnData(); this.$emit("change") }, filter(inputValue, path) { return path.some( (option) => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1 ); }, }, watch: { value(val) { this.parseDbData(); } }, }