w-vue-middle
Version:
统一公共服务组件
151 lines (145 loc) • 3.39 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2023-05-05 16:15:43
* @Desc:
*/
/*
* @Author: Jason Liu
* @Date: 2023-03-08 13:31:51
* @Desc:
*/
const dataTableSource = require('../dataTableSource').default;
const glSqlEditor = require('../glSqlEditor').default;
const $dataIntegration = require('../../api/dataIntegration');
export default {
components: { dataTableSource, glSqlEditor },
props: {
value: {
type: Object,
default: {
sourceType: 1,
dbId: undefined, //链接数据库ID
dbName: undefined, //链接数据库名称
dbType: undefined, //链接数据库类型
ip: undefined,
port: undefined,
tableId: undefined,
tableName: undefined,
tableCode: undefined,
script: undefined,
whereString: undefined,
description: undefined,
},
},
set: {
type: Boolean,
default: false,
},
},
data() {
return {
loading: false,
nodeData: this.value,
show: this.set,
tablekeys: {},
dataList: [],
columns: [],
script: undefined,
};
},
created() {},
methods: {
/**
* @Author: Jason Liu
* @description: 获取字段列表
*/
getList() {
this.dataList = [];
},
/**
* @Author: Jason Liu
* @description: 获取分析表格
*/
getTables(e = []) {
this.tablekeys = {};
this.tablekeys[this.nodeData.schemaId] = [];
e.forEach((table) => {
this.tablekeys[table.tableCode] = [];
});
},
/**
* @Author: Jason Liu
* @description: 数据解析
*/
dataAnalysis() {
this.loading = true;
const hide = this.$message.loading({
content: $t('脚本内容分析中...'),
key: 'dataAnalysis',
});
return $dataIntegration
.collectionDataInfo({
clusterId: this.nodeData.clusterId, //集群ID
collectType: 'sql', // 采集类型:schema、table、column
dsId: this.nodeData.dbId,
schema: this.nodeData.schemaId,
tableName: '',
uuid: 0,
useCache: true,
sql: this.script,
})
.then((req) => {
this.columns = req.data.meta;
this.dataList = req.data.data;
this.$message.success({
content: $t('脚本内容分析完成!'),
key: 'dataAnalysis',
});
return true;
})
.finally(() => {
this.loading = false;
});
},
/**
* @Author: Jason Liu
* @description: 函数格式化
*/
sqlFormat() {
this.script = this.script.sqlFormatter();
},
/**
* @Author: Jason Liu
* @description: 确定
*/
fixed() {
this.dataAnalysis().then((req) => {
this.nodeData.script = `${this.script}`;
this.show = false;
this.$emit('change', {
script: this.script,
data: this.nodeData,
columns: this.columns,
});
});
},
},
watch: {
value(val) {
this.nodeData = val;
},
nodeData() {
this.$emit('input', this.nodeData);
},
set(val) {
this.show = val;
if (val) {
this.loading = false;
this.script = this.nodeData.script;
}
},
show(val) {
this.$emit('show', val);
},
},
};