UNPKG

w-vue-middle

Version:

统一公共服务组件

206 lines (201 loc) 5.17 kB
/* * @Author: Jason Liu * @Date: 2023-05-04 14:33:45 * @Desc: */ /** * @Author: Jason Liu */ const $dataIntegration = require('w-vue-middle/api/dataIntegration'); const $userService = require('w-vue-middle/api/userService'); export default { props: { value: { type: Object, default: () => { return { id: undefined, name: $t('ES输出'), code: undefined, type: 'EsOutput', sourceType: 1, dbId: undefined, //链接数据库ID dbName: undefined, //链接数据库名称 dbType: undefined, //链接数据库类型 ip: undefined, port: undefined, tableId: undefined, tableName: undefined, tableCode: undefined, columns: [], // formerName:med_insti_no,//物理字段名 columnName: "eeed", //别名 lookUp: false, description: undefined, }; }, }, referData: { type: Object, default: () => { return { dbId: undefined, }; }, }, type: { type: String, }, }, computed: { formatSourceType() { return function (val) { let item = this.dataSourceType.find((v) => { return v.value == val; }); return item ? item.label : '--'; }; }, formatDataSource() { return function (val) { let item = this.dataSourceList.find((v) => { return v.dbId == val; }); return item ? item.sourceName : val; }; }, }, data() { return { loading: false, nodeData: this.value, dataSourceType: [], //数据源来源 dataSourceList: [], entrust: { cancel: undefined }, }; }, created() { this.getDataSourceType(); this.getSelectData(); }, methods: { /** * @Author: Jason Liu * @description: 查看数据源配置信息 */ viewSourceInfo(e) { if (e) { this.changeDataSource(); } }, /** * @Author: Jason Liu * @description: 获取数据类型 */ getDataSourceType() { $userService .getSysDictData({ pageNum: 1, pageSize: 1000000, queryParams: { F_isEnable_eq: 0, F_isDel_eq: 0, F_dictType_eq: 'sys_job_data_sources', }, }) .then((req) => { this.dataSourceType = req.data.map((item) => { return { label: item.dictLabel, value: Number(item.dictValue), }; }); }); }, /** * @Author: Jason Liu * @description: 获取数据源信息 */ getSelectData() { let $event = $dataIntegration.getNewDatasourceList; if (this.nodeData.sourceType == 0) { $event = $dataIntegration.getDbsData; } else if (!this.nodeData.sourceType) { this.nodeData.sourceType = '1'; } if (this.entrust.cancel) { this.entrust.cance(); //断开数据连接 } this.loading = true; $event( { pageNum: 1, pageSize: 10000, queryParams: { F_isDel_eq: 0, F_isEnable_eq: 0, F_type_eq: this.type, }, }, this.entrust, ) .then((req) => { this.dataSourceList = (req.data || []).map((item) => { return { dbId: item.datasourceId, sourceName: item.name || item.dbName, dbType: item.type, ...item, }; }); if (this.nodeData.dbId) { } this.$emit('updateSource', this.nodeData); }) .finally(() => { this.loading = false; }); }, /** * @Author: Jason Liu * @description: 修改数据源事件 */ changeDataSource() { let selDb = this.dataSourceList.find((item) => { return item.dbId == this.nodeData.dbId; }); this.nodeData = { ...this.nodeData, clusterId: selDb.clusterId, dbId: selDb.dbId, dbName: selDb.dbName, sourceName: selDb.dbName, dbType: selDb.dbType, ip: selDb.ip, port: selDb.port, }; this.$emit('change', this.nodeData); }, /** * @Author: Jason Liu * @description: 修改数据源事件 */ changeDataSourceType() { this.nodeData.dbId = undefined; this.nodeData.dbName = undefined; this.nodeData.sourceName = undefined; this.nodeData.dbType = undefined; this.nodeData.ip = undefined; this.nodeData.port = undefined; this.getSelectData(); this.$emit('input', this.nodeData); this.$emit('change', this.nodeData); }, }, watch: { value(value) { this.nodeData = value; }, nodeData() { this.$emit('input', this.nodeData); }, }, };