w-vue-middle
Version:
统一公共服务组件
285 lines (278 loc) • 7.29 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2023-05-05 16:15:43
* @Desc:
*/
/*
* @Author: Jason Liu
* @Date: 2023-05-05 16:15:43
* @Desc:
*/
/*
* @Author: Jason Liu
* @Date: 2023-03-08 13:31:51
* @Desc:
*/
const glSqlEditor = require('w-vue-middle/components/glSqlEditor').default;
const { wSqlEditor, wSqlDiffEditor } = require('w-vue-middle/monacoEditor');
const dataTableSource = require('../dataTableSource').default;
const $dataIntegration = require('w-vue-middle/api/dataIntegration');
const $userService = require('w-vue-middle/api/userService');
export default {
components: { dataTableSource, glSqlEditor, wSqlEditor, wSqlDiffEditor },
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,
places: [],
},
},
referData: {
type: Object,
default: () => {
return undefined;
},
},
referJobType: {
type: String,
default: 'init',
},
set: {
type: Boolean,
default: false,
},
},
data() {
return {
loading: false,
nodeData: this.value,
show: this.set,
tablekeys: {},
dataList: [],
columns: [],
recordList: [],
referScript: undefined,
resultScript: undefined,
activeKey: '1',
places: [],
sqlHelpInfo: {
show: false,
loading: false,
info: {},
},
};
},
created() {
this.tablekeys = {};
},
methods: {
/**
* @Author: Jason Liu
* @description: 导入sql脚本
*/
inputScript(e) {
this.resultScript = e;
},
/**
* @Author: Jason Liu
* @description: 添加占位符
*/
addAlaces() {
this.places.push({ key: undefined, value: undefined });
},
/**
* @Author: Jason Liu
* @description: 获取字段列表
*/
getList() {
this.dataList = [];
},
/**
* @Author: Jason Liu
* @description: 分析函数信息
*/
getFunction(e = []) {
e.forEach((fun) => {
if (fun.sqlFunc) {
this.tablekeys[fun.sqlFunc] = [];
}
});
},
/**
* @Author: Jason Liu
* @description: 获取分析表格
*/
getTables(e = []) {
this.tablekeys[this.nodeData.schemaId] = [];
e.forEach((table) => {
this.tablekeys[this.nodeData.schemaId].push(table.tableCode);
this.tablekeys[table.tableCode] = [];
});
},
getColumns({ tableCode, columns = [] }) {
this.tablekeys[tableCode] = columns.map((item) => {
return item.columnName;
});
},
getVariables(e = []) {
console.log(e);
e.forEach((item) => {
this.tablekeys[item.code] = [];
});
},
/**
* @Author: Jason Liu
* @description: 数据解析
*/
dataAnalysis(useCache = true) {
this.loading = true;
this.recordList.unshift({
time: moment().format('lll'),
info: $t('脚本内容分析中...'),
});
const hide = this.$message.loading({
content: $t('脚本内容分析中...'),
key: 'dataAnalysis',
});
let places = undefined;
if (this.places.length > 0) {
places = this.places.filter((item) => {
return !!item.key;
});
}
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: useCache,
sql: this.resultScript,
places: places,
})
.then((req) => {
this.columns = req.data.meta;
this.dataList = req.data.data;
this.recordList.unshift({
time: moment().format('lll'),
info: `${$t('返回')}${req.data.data.length}${$t('条')}${$t('数据')}`
});
this.recordList.unshift({
time: moment().format('lll'),
info: $t('脚本内容分析完成!'),
});
this.$message.success({
content: $t('脚本内容分析完成!'),
key: 'dataAnalysis',
});
return true;
})
.catch((e) => {
this.recordList.unshift({
time: moment().format('lll'),
info: $t('脚本解析异常:{e}', { e: e }),
});
})
.finally(() => {
this.loading = false;
});
},
/**
* @Author: Jason Liu
* @description: 函数格式化
*/
sqlFormat() {
this.resultScript = this.resultScript.sqlFormatter();
},
/**
* @Author: Jason Liu
* @description: 确定
*/
fixed() {
this.dataAnalysis().then((req) => {
this.nodeData.script = `${this.resultScript}`;
this.nodeData.places = this.places;
this.show = false;
this.$emit('change', {
script: this.resultScript,
data: this.nodeData,
columns: this.columns,
});
});
},
/**
* @Author: Jason Liu
* @description: 保存脚本数据
*/
save() {
this.nodeData.script = `${this.resultScript}`;
this.show = false;
this.nodeData.places = this.places;
this.$emit('change', {
script: this.resultScript,
data: this.nodeData,
columns: this.columns,
});
},
/**
* @Author: Jason Liu
* @description: 删除占位符
*/
deletePlaces(row) {
let index = this.places.findIndex((e) => {
return e._X_ROW_KEY == row._X_ROW_KEY;
});
this.places.splice(index, 1);
},
/**
* @Author: y_zp
* @description: 脚本说明
*/
toSqlHelp() {
this.sqlHelpInfo.show = true;
this.sqlHelpInfo.loading = true;
$userService
.sysHelpDetailByName($t('SQL脚本输入'))
.then((req) => {
this.sqlHelpInfo.info = req.data || { content: $t('暂无数据') };
})
.finally(() => {
this.sqlHelpInfo.loading = false;
});
},
},
watch: {
value(val) {
this.nodeData = val;
},
nodeData() {
this.$emit('input', this.nodeData);
},
set(val) {
this.show = val;
if (val) {
this.loading = false;
this.places = this.nodeData.places || [];
this.resultScript = this.nodeData.script;
this.referScript = this.referData.script;
}
},
show(val) {
this.$emit('show', val);
},
},
};