UNPKG

w-vue-middle

Version:

统一公共服务组件

124 lines (122 loc) 2.96 kB
/* * @Author: Jason Liu * @Date: 2023-11-02 15:02:23 * @Desc: */ const $dataSource = require("../../api/appService/dataSource.js"); export default { props: { value: { type: String, default: undefined }, //配置信息 option: { type: Object, default: () => { return { clusterId: undefined, dbId: undefined, //数据源ID dbSchema: undefined //SchemaName }; } } }, watch: { value(val, old) { this.tableInfo = val; }, tableInfo(val) { this.$emit("input", val); }, option() { this.getTables(); } }, data() { return { loading: false, initTableList: [], tableList: [], tableInfo: this.value, title: $t("数据表") }; }, created() { this.getTables(); }, methods: { /** * @Author: y_zp * @description: 获取数据表 */ getTables(useCache = true) { this.tableList = []; this.initTableList = []; if (this.option.dbSchema) { this.loading = true; $dataSource .collectionDataInfo({ clusterId: this.option.clusterId, //集群ID collectType: "table", // 采集类型:schema、table、column dsId: this.option.dbId, schema: this.option.dbSchema, tableName: "tableName", useCache: useCache }) .then(req => { this.initTableList = req.data; this.searchTable(); }) .finally(() => { this.loading = false; }); } }, /** * @Author: y_zp * @description: 搜索数据表 */ searchTable(value) { let newList = JSON.parse(JSON.stringify(this.initTableList)); if (value) { newList = newList.filter(item => { return ( item.tableCode && item.tableCode .toLocaleLowerCase() .indexOf(value.toLocaleLowerCase()) > -1 ); }); if (newList) { newList = newList.sort((o, l) => { return o.tableCode.length - l.tableCode.length; }); } } this.tableList = newList.slice(0, 15).map(item => { return { label: item.tableCode, value: item.tableCode }; }); let curVal = this.tableList.find(item => { return item.value == this.tableInfo; }); if (!curVal && this.tableInfo) { this.tableList.unshift({ label: this.tableInfo, value: this.tableInfo }); } }, /** * @Author: y_zp * @description: 切换数据表 */ chaneTables() { this.$emit("input", this.tableInfo); this.$emit("change", this.tableInfo); } } };