2019-08-21 20:39:43 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="data-executor-vue">
|
2020-05-12 22:29:29 +08:00
|
|
|
|
<div style="padding: 0 10px 10px;height: 100%;box-sizing: border-box;">
|
2019-08-21 20:39:43 +08:00
|
|
|
|
<el-card style="margin-bottom: 10px;">
|
2021-06-20 00:41:28 +08:00
|
|
|
|
<ace-editor v-model="sqlExecutorContent" ref="sqlEditor" @init="sqlExecutorInit" lang="sql" theme="monokai" width="100%" height="500" :options="sqlEditorConfig" :source="executorSource" style="margin-bottom: 10px;"></ace-editor>
|
2019-08-21 20:39:43 +08:00
|
|
|
|
<div>
|
2019-08-21 23:17:04 +08:00
|
|
|
|
<el-button v-if="sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small" icon="el-icon-video-pause">取消执行</el-button>
|
2019-09-02 22:47:24 +08:00
|
|
|
|
<el-tooltip v-else effect="dark" content="Ctrl+R、Ctrl+Enter" placement="top">
|
|
|
|
|
|
<el-button v-on:click="doExecutorSql" type="primary" plain size="small" icon="el-icon-video-play">执行</el-button>
|
|
|
|
|
|
</el-tooltip>
|
2020-05-12 22:29:29 +08:00
|
|
|
|
<el-button icon="el-icon-brush" size="small" @click="formatterSql">SQL美化</el-button>
|
2019-09-28 15:25:52 +08:00
|
|
|
|
<el-button v-on:click="addFavorite('')" plain size="small" icon="el-icon-star-off">收藏</el-button>
|
2020-05-24 13:00:43 +08:00
|
|
|
|
<div style="float: right;">
|
|
|
|
|
|
<el-select v-model="choiceDatasourceId" @change="datasourceChangeEvents" size="small" filterable placeholder="请选择数据源" style="width: 300px;margin-left: 10px;">
|
|
|
|
|
|
<el-option v-for="item in datasourceOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
2019-09-28 15:25:52 +08:00
|
|
|
|
</el-select>
|
2021-06-20 00:41:28 +08:00
|
|
|
|
<el-select v-model="choiceDatabase" @change="databaseChangeEvents" size="small" filterable placeholder="请选择数据库" style="width: 200px;margin-left: 10px;">
|
|
|
|
|
|
<el-option v-for="item in databaseList" :key="item.dbName" :label="item.dbName" :value="item.dbName"></el-option>
|
|
|
|
|
|
</el-select>
|
2019-08-21 20:39:43 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<div v-if="sqlParams.length > 0" class="sql-params">
|
|
|
|
|
|
<el-input :placeholder="'请输入'+param.key+'的值'" v-model="param.value" v-for="param in sqlParams">
|
|
|
|
|
|
<template slot="prepend">{{param.key}}</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</div>
|
2019-08-21 20:39:43 +08:00
|
|
|
|
</el-card>
|
|
|
|
|
|
<el-card>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<div style="position: relative;">
|
2021-05-24 22:42:01 +08:00
|
|
|
|
<div style="position: absolute;right: 0;z-index: 1;">
|
|
|
|
|
|
<!-- 复制选中行 -->
|
|
|
|
|
|
<el-dropdown @command="handleCopyCheckLineCommand" v-show="this.choiceResultObj[this.executeShowTable] && this.choiceResultObj[this.executeShowTable].length > 0">
|
2021-06-05 16:38:27 +08:00
|
|
|
|
<el-button type="primary" size="small" icon="el-icon-document-copy">
|
2021-05-24 22:42:01 +08:00
|
|
|
|
复制选中行<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-dropdown-menu slot="dropdown">
|
|
|
|
|
|
<el-dropdown-item command="insert">SQL Inserts</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item command="update">SQL Updates</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item command="json">JSON</el-dropdown-item>
|
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-tabs v-model="executeShowTable">
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<el-tab-pane label="执行历史" name="tabHistory">
|
|
|
|
|
|
<el-table :data="myHistoryListList" stripe border style="width: 100%; margin-bottom: 5px;">
|
|
|
|
|
|
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
|
|
|
|
|
|
<el-table-column prop="content" label="SQL">
|
|
|
|
|
|
<template slot-scope="scope">
|
2021-07-17 12:22:51 +08:00
|
|
|
|
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row)" :title="scope.row.content">{{scope.row.content}}</pre>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="操作" width="160px">
|
|
|
|
|
|
<template slot-scope="scope">
|
2021-07-17 12:22:51 +08:00
|
|
|
|
<el-button size="mini" type="primary" @click="inputFavoriteSql(scope.row)">输入</el-button>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<el-button size="mini" type="success" @click="addFavorite(scope.row.content)" style="margin-left: 10px;">收藏</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
<el-tab-pane label="我的收藏" name="tabFavorite">
|
|
|
|
|
|
<el-table :data="myFavoriteList" stripe border style="width: 100%; margin-bottom: 5px;" v-infinite-scroll>
|
|
|
|
|
|
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
|
|
|
|
|
|
<el-table-column prop="content" label="SQL">
|
|
|
|
|
|
<template slot-scope="scope">
|
2021-07-17 12:22:51 +08:00
|
|
|
|
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row)" :title="scope.row.content">{{scope.row.content}}</pre>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="操作" width="160px">
|
|
|
|
|
|
<template slot-scope="scope">
|
2021-07-17 12:22:51 +08:00
|
|
|
|
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row)">输入</el-button>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<el-button size="mini" type="danger" v-on:click="delFavorite(scope.row)" style="margin-left: 10px;">删除</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
<el-tab-pane label="信息" name="tabInfo" v-if="!!executeResultInfo">
|
2021-07-11 18:57:35 +08:00
|
|
|
|
<pre style="white-space: pre-wrap;">{{executeResultInfo}}</pre>
|
2019-09-01 18:41:17 +08:00
|
|
|
|
</el-tab-pane>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<el-tab-pane label="错误" name="tabError" v-if="!!executeError">
|
|
|
|
|
|
<div style="color: #f00;">{{executeError}}</div>
|
2019-09-01 18:41:17 +08:00
|
|
|
|
</el-tab-pane>
|
2021-06-27 22:45:30 +08:00
|
|
|
|
<template v-else>
|
|
|
|
|
|
<el-tab-pane :label="'结果'+resultItem.index" :name="resultItem.name" v-for="resultItem in executeResultList" v-if="!!resultItem.index">
|
|
|
|
|
|
<div v-if="!!resultItem.errMsg" style="color: #f00;">{{resultItem.errMsg}}</div>
|
|
|
|
|
|
<div v-else-if="resultItem.dataList.length <= 0" style="text-align: center; color: #aaa; padding: 20px 0;">暂无数据</div>
|
|
|
|
|
|
<el-table v-else :data="resultItem.dataList" stripe border style="width: 100%; margin-bottom: 5px;" class="execute-result-table" max-height="600"
|
|
|
|
|
|
@selection-change="handleSelectionChange">
|
|
|
|
|
|
<el-table-column type="selection" width="55"></el-table-column>
|
|
|
|
|
|
<el-table-column type="index" width="50"></el-table-column>
|
|
|
|
|
|
<el-table-column v-for="item in resultItem.dataCols" :prop="item.prop" :label="item.prop" :width="item.width">
|
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
|
<textarea readonly :value="scope.row[item.prop]" class="el-textarea__inner" rows="1"></textarea>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
</template>
|
2019-09-01 18:41:17 +08:00
|
|
|
|
</el-tabs>
|
2019-08-21 20:39:43 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
2021-05-29 22:18:15 +08:00
|
|
|
|
<!--选择导出为update的条件列弹窗-->
|
|
|
|
|
|
<el-dialog :visible.sync="exportConditionVisible" width="500px" title="选择更新语句条件">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
更新条件列:
|
|
|
|
|
|
<el-select v-model="conditionDataColsChoice" multiple placeholder="请选择" style="width: 370px;">
|
|
|
|
|
|
<el-option v-for="item in conditionDataCols" :key="item.prop" :label="item.prop" :value="item.prop"></el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
|
|
|
<el-button @click="exportConditionVisible = false">取 消</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="doCopyCheckLineUpdate">确 定</el-button>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</el-dialog>
|
2020-05-12 22:29:29 +08:00
|
|
|
|
<span id="widthCalculate" style="visibility: hidden; white-space: nowrap;position: fixed;"></span>
|
2019-08-21 20:39:43 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-05-24 22:42:01 +08:00
|
|
|
|
import copyFormatter from './copy/index'
|
2020-05-12 22:29:29 +08:00
|
|
|
|
import sqlFormatter from "sql-formatter"
|
2020-05-23 12:21:23 +08:00
|
|
|
|
import datasourceApi from '../../common/api/datasource'
|
2021-06-20 00:41:28 +08:00
|
|
|
|
import aceEditor from "../../common/lib/ace-editor";
|
2021-06-27 22:45:30 +08:00
|
|
|
|
import sqlParser from "./parser/SqlParser";
|
2020-05-23 12:21:23 +08:00
|
|
|
|
|
2019-08-21 20:39:43 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
datasourceList: [],
|
|
|
|
|
|
choiceDatasourceId: "",
|
2020-05-24 13:00:43 +08:00
|
|
|
|
datasourceOptions: [],
|
|
|
|
|
|
datasourceGroupList: [],
|
|
|
|
|
|
choiceDatasourceGroup: "",
|
|
|
|
|
|
|
2019-08-21 20:39:43 +08:00
|
|
|
|
databaseList: [],
|
|
|
|
|
|
choiceDatabase: "",
|
2021-05-24 22:42:01 +08:00
|
|
|
|
editorDbProduct: "",
|
2019-08-24 23:13:43 +08:00
|
|
|
|
editorDbInfo: [],
|
|
|
|
|
|
editorDbTableInfo: {},
|
|
|
|
|
|
editorColumnInfo: {},
|
2019-08-21 20:39:43 +08:00
|
|
|
|
|
2019-08-21 23:17:04 +08:00
|
|
|
|
sqlExecuting: false,
|
2019-08-21 20:39:43 +08:00
|
|
|
|
executeResultList: [],
|
2019-09-01 18:41:17 +08:00
|
|
|
|
executeResultInfo: "",
|
2021-06-27 22:45:30 +08:00
|
|
|
|
executeShowTable: "tabHistory",
|
2019-08-21 20:39:43 +08:00
|
|
|
|
sqlExecutorEditor: {},
|
|
|
|
|
|
nowExecutorId: 1,
|
|
|
|
|
|
executeError: "",
|
2019-08-21 23:17:04 +08:00
|
|
|
|
// 收藏及历史
|
|
|
|
|
|
myFavoriteList: [],
|
|
|
|
|
|
myHistoryListList: [],
|
2021-05-24 22:42:01 +08:00
|
|
|
|
// 选择复制
|
|
|
|
|
|
choiceResultObj: {},
|
2021-05-29 22:18:15 +08:00
|
|
|
|
//
|
|
|
|
|
|
exportConditionVisible: false,
|
|
|
|
|
|
conditionDataCols: [],
|
|
|
|
|
|
conditionDataColsChoice: [],
|
2021-06-20 00:41:28 +08:00
|
|
|
|
// 编辑器
|
|
|
|
|
|
sqlExecutorContent: '',
|
|
|
|
|
|
sqlEditorConfig: {
|
|
|
|
|
|
wrap: true,
|
|
|
|
|
|
autoScrollEditorIntoView: true,
|
|
|
|
|
|
enableBasicAutocompletion: true,
|
|
|
|
|
|
enableSnippets: true,
|
|
|
|
|
|
enableLiveAutocompletion: true,
|
|
|
|
|
|
minLines: 15,
|
|
|
|
|
|
maxLines: 40,
|
|
|
|
|
|
},
|
|
|
|
|
|
executorSource: {},
|
2021-06-27 22:45:30 +08:00
|
|
|
|
// sql参数
|
|
|
|
|
|
sqlParams: [],
|
|
|
|
|
|
sqlParamWaiting: false,
|
|
|
|
|
|
sqlParamHistory: {},
|
2019-08-21 20:39:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-06-20 00:41:28 +08:00
|
|
|
|
components: {
|
|
|
|
|
|
'ace-editor': aceEditor
|
|
|
|
|
|
},
|
2019-08-21 20:39:43 +08:00
|
|
|
|
mounted: function () {
|
|
|
|
|
|
this.loadDatasourceList();
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2021-06-20 00:41:28 +08:00
|
|
|
|
sqlExecutorInit(editor) {
|
|
|
|
|
|
this.sqlExecutorEditor = editor;
|
|
|
|
|
|
this.sqlExecutorEditor.setFontSize(16);
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
this.sqlExecutorEditor.commands.addCommand({
|
|
|
|
|
|
name: "execute-sql",
|
|
|
|
|
|
bindKey: {win: "Ctrl-R|Ctrl-Shift-R|Ctrl-Enter", mac: "Command-R|Command-Shift-R|Command-Enter"},
|
|
|
|
|
|
exec: function (editor) {
|
|
|
|
|
|
that.doExecutorSql();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-06-27 22:45:30 +08:00
|
|
|
|
editor.on('change', () => {
|
|
|
|
|
|
if (!this.sqlParamWaiting) {
|
|
|
|
|
|
this.sqlParamWaiting = true;
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let content = editor.getValue();
|
|
|
|
|
|
let paramArr = sqlParser.parserArr(content, [
|
|
|
|
|
|
{start: '${', end: '}'}, {start: '#{', end: '}'}
|
|
|
|
|
|
]);
|
|
|
|
|
|
this.sqlParams = [];
|
|
|
|
|
|
paramArr.forEach(item => {
|
|
|
|
|
|
this.sqlParams.push({key: item, value: this.sqlParamHistory[item] || ''});
|
|
|
|
|
|
});
|
|
|
|
|
|
this.sqlParamWaiting = false;
|
2021-07-11 18:57:35 +08:00
|
|
|
|
}, 300);
|
2021-06-27 22:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-06-20 00:41:28 +08:00
|
|
|
|
},
|
2019-08-21 20:39:43 +08:00
|
|
|
|
cancelExecutorSql() {
|
2020-05-23 12:21:23 +08:00
|
|
|
|
datasourceApi.executeSqlCancel({executeId: this.nowExecutorId}).then(() => {
|
|
|
|
|
|
this.$message.success("取消成功");
|
2019-08-21 20:39:43 +08:00
|
|
|
|
});
|
|
|
|
|
|
},
|
2019-08-21 23:17:04 +08:00
|
|
|
|
loadHistoryAndFavoriteList() {
|
|
|
|
|
|
this.loadHistoryList();
|
|
|
|
|
|
this.loadFavoriteList();
|
|
|
|
|
|
},
|
|
|
|
|
|
loadFavoriteList() {
|
2020-05-23 12:21:23 +08:00
|
|
|
|
datasourceApi.favoriteList({sourceId: this.choiceDatasourceId}).then(json => {
|
|
|
|
|
|
this.myFavoriteList = json.data || [];
|
2019-08-21 23:17:04 +08:00
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
loadHistoryList() {
|
2020-05-23 12:21:23 +08:00
|
|
|
|
datasourceApi.historyList({sourceId: this.choiceDatasourceId}).then(json => {
|
|
|
|
|
|
this.myHistoryListList = json.data || [];
|
2019-08-21 23:17:04 +08:00
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
addFavorite(sqlValue) {
|
|
|
|
|
|
if (!sqlValue) {
|
|
|
|
|
|
sqlValue = this.sqlExecutorEditor.getSelectedText();
|
|
|
|
|
|
if (!sqlValue) {
|
|
|
|
|
|
sqlValue = this.sqlExecutorEditor.getValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-17 12:22:51 +08:00
|
|
|
|
let sqlParamObj = {};
|
|
|
|
|
|
this.sqlParams.forEach(item => {
|
|
|
|
|
|
if (!!item.value) {
|
|
|
|
|
|
sqlParamObj[item.key] = item.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let param = {
|
|
|
|
|
|
name: '我的收藏',
|
|
|
|
|
|
content: sqlValue,
|
|
|
|
|
|
paramJson: JSON.stringify(sqlParamObj),
|
|
|
|
|
|
datasourceId: this.choiceDatasourceId
|
|
|
|
|
|
};
|
|
|
|
|
|
datasourceApi.updateFavorite(param).then(() => {
|
|
|
|
|
|
this.$message.success("收藏成功");
|
|
|
|
|
|
this.loadFavoriteList();
|
|
|
|
|
|
});
|
2019-08-21 23:17:04 +08:00
|
|
|
|
},
|
|
|
|
|
|
delFavorite(row) {
|
2020-05-23 12:21:23 +08:00
|
|
|
|
datasourceApi.updateFavorite({id: row.id, yn: 0}).then(() => {
|
|
|
|
|
|
this.$message.success("删除成功");
|
|
|
|
|
|
this.loadFavoriteList();
|
2019-08-21 23:17:04 +08:00
|
|
|
|
});
|
|
|
|
|
|
},
|
2021-07-17 12:22:51 +08:00
|
|
|
|
inputFavoriteSql(item) {
|
|
|
|
|
|
this.sqlExecutorEditor.setValue(item.content, 1);
|
|
|
|
|
|
if (!!item.paramJson) {
|
|
|
|
|
|
let paramJson = JSON.parse(item.paramJson);
|
|
|
|
|
|
for (let key in paramJson) {
|
|
|
|
|
|
this.sqlParamHistory[key] = paramJson[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2020-05-12 22:29:29 +08:00
|
|
|
|
formatterSql() {
|
|
|
|
|
|
let dataSql = this.sqlExecutorEditor.getSelectedText();
|
|
|
|
|
|
if (!!dataSql) {
|
|
|
|
|
|
let range = this.sqlExecutorEditor.getSelectionRange();
|
|
|
|
|
|
this.sqlExecutorEditor.remove(range);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dataSql = this.sqlExecutorEditor.getValue();
|
|
|
|
|
|
this.sqlExecutorEditor.setValue('', 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!!dataSql) {
|
|
|
|
|
|
dataSql = sqlFormatter.format(dataSql);
|
|
|
|
|
|
this.sqlExecutorEditor.insert(dataSql);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2019-08-21 20:39:43 +08:00
|
|
|
|
doExecutorSql() {
|
|
|
|
|
|
if (!this.choiceDatasourceId) {
|
2020-05-12 22:29:29 +08:00
|
|
|
|
this.$message.error("请先选择数据源");
|
2019-08-21 20:39:43 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-05-12 22:29:29 +08:00
|
|
|
|
this.executeError = "";
|
|
|
|
|
|
this.executeUseTime = "";
|
|
|
|
|
|
this.executeResultList = [];
|
2021-06-27 22:45:30 +08:00
|
|
|
|
let sqlParamObj = {};
|
|
|
|
|
|
this.sqlParams.forEach(item => {
|
|
|
|
|
|
if (!!item.value) {
|
|
|
|
|
|
sqlParamObj[item.key] = item.value;
|
|
|
|
|
|
this.sqlParamHistory[item.key] = item.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-08-21 20:39:43 +08:00
|
|
|
|
this.nowExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000);
|
2021-06-27 22:45:30 +08:00
|
|
|
|
let sqlValue = this.sqlExecutorEditor.getSelectedText();
|
2019-08-21 23:17:04 +08:00
|
|
|
|
if (!sqlValue) {
|
|
|
|
|
|
sqlValue = this.sqlExecutorEditor.getValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
this.sqlExecuting = true;
|
2020-05-23 12:21:23 +08:00
|
|
|
|
datasourceApi.queryExecuteSql({
|
2019-08-21 20:39:43 +08:00
|
|
|
|
sourceId: this.choiceDatasourceId,
|
2021-06-20 00:41:28 +08:00
|
|
|
|
dbName: this.choiceDatabase,
|
2019-08-21 20:39:43 +08:00
|
|
|
|
executeId: this.nowExecutorId,
|
2019-08-21 23:17:04 +08:00
|
|
|
|
sql: sqlValue,
|
2021-06-27 22:45:30 +08:00
|
|
|
|
params: JSON.stringify(sqlParamObj),
|
2020-05-23 12:21:23 +08:00
|
|
|
|
}).then(json => {
|
|
|
|
|
|
this.sqlExecuting = false;
|
2019-08-21 20:39:43 +08:00
|
|
|
|
if (json.errCode != 200) {
|
2021-07-11 18:57:35 +08:00
|
|
|
|
this.executeShowTable = 'tabError';
|
2020-05-23 12:21:23 +08:00
|
|
|
|
this.executeError = json.errMsg;
|
2019-08-21 20:39:43 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-06-27 22:45:30 +08:00
|
|
|
|
let resultList = json.data || [];
|
|
|
|
|
|
let executeResultList = [];
|
|
|
|
|
|
let executeResultInfo = "", itemIndex = 1;
|
|
|
|
|
|
for (let i = 0; i < resultList.length; i++) {
|
|
|
|
|
|
let objItem = JSON.parse(resultList[i]);
|
2020-05-23 12:21:23 +08:00
|
|
|
|
executeResultInfo += this.getExecuteInfoStr(objItem);
|
2021-06-27 22:45:30 +08:00
|
|
|
|
let resultItem = this.dealExecuteResult(objItem);
|
2019-09-02 22:47:24 +08:00
|
|
|
|
if (resultItem.updateCount < 0) {
|
|
|
|
|
|
resultItem.index = itemIndex;
|
2021-06-27 22:45:30 +08:00
|
|
|
|
resultItem.name = 'tab' + itemIndex;
|
2019-09-02 22:47:24 +08:00
|
|
|
|
itemIndex++;
|
|
|
|
|
|
}
|
2019-09-01 18:41:17 +08:00
|
|
|
|
executeResultList.push(resultItem);
|
2019-08-21 20:39:43 +08:00
|
|
|
|
}
|
2021-06-27 22:45:30 +08:00
|
|
|
|
this.executeShowTable = (itemIndex === 1) ? "tabInfo" : "tab1";
|
2020-05-23 12:21:23 +08:00
|
|
|
|
this.executeResultInfo = executeResultInfo;
|
|
|
|
|
|
this.executeResultList = executeResultList;
|
2021-06-27 22:45:30 +08:00
|
|
|
|
this.loadHistoryList();
|
2019-08-21 20:39:43 +08:00
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
loadDatasourceList() {
|
2020-05-23 12:21:23 +08:00
|
|
|
|
datasourceApi.datasourceList({}).then(json => {
|
|
|
|
|
|
this.datasourceList = json.data || [];
|
2020-05-24 13:00:43 +08:00
|
|
|
|
this.datasourceOptions = this.datasourceList;
|
|
|
|
|
|
let datasourceGroupList = [];
|
|
|
|
|
|
this.datasourceList.filter(item => !!item.groupName).forEach(item => datasourceGroupList.push(item.groupName || ''));
|
|
|
|
|
|
this.datasourceGroupList = Array.from(new Set(datasourceGroupList));
|
2020-05-23 12:21:23 +08:00
|
|
|
|
if (this.datasourceList.length > 0) {
|
|
|
|
|
|
this.choiceDatasourceId = this.datasourceList[0].id;
|
2021-06-20 00:41:28 +08:00
|
|
|
|
this.executorSource = {sourceId: this.choiceDatasourceId};
|
|
|
|
|
|
this.loadDatabaseList();
|
2021-06-20 17:47:46 +08:00
|
|
|
|
this.loadSourceBaseInfo();
|
2021-06-27 22:45:30 +08:00
|
|
|
|
this.loadHistoryAndFavoriteList();
|
2019-08-21 23:17:04 +08:00
|
|
|
|
}
|
2019-08-21 20:39:43 +08:00
|
|
|
|
});
|
2021-06-20 00:41:28 +08:00
|
|
|
|
},
|
|
|
|
|
|
loadDatabaseList() {
|
|
|
|
|
|
datasourceApi.databaseList({sourceId: this.choiceDatasourceId}).then(json => {
|
|
|
|
|
|
this.databaseList = json.data || [];
|
|
|
|
|
|
if (this.databaseList.length > 0) {
|
|
|
|
|
|
// 排除系统库
|
|
|
|
|
|
let sysDbName = ["information_schema", "master", "model", "msdb", "tempdb"];
|
|
|
|
|
|
let notSysDbItem = this.databaseList.find(item => sysDbName.indexOf(item.dbName) < 0);
|
|
|
|
|
|
this.choiceDatabase = (!!notSysDbItem) ?notSysDbItem.dbName : this.databaseList[0].dbName;
|
|
|
|
|
|
this.executorSource = {sourceId: this.choiceDatasourceId, dbName: this.choiceDatabase};
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-08-21 20:39:43 +08:00
|
|
|
|
},
|
2021-06-20 17:47:46 +08:00
|
|
|
|
loadSourceBaseInfo() {
|
|
|
|
|
|
datasourceApi.getSourceBaseInfo({sourceId: this.choiceDatasourceId}).then(json => {
|
2020-05-23 12:21:23 +08:00
|
|
|
|
let data = json.data || {};
|
2021-05-24 22:42:01 +08:00
|
|
|
|
this.editorDbProduct = data.product || '';
|
2019-08-24 23:13:43 +08:00
|
|
|
|
});
|
|
|
|
|
|
},
|
2020-05-24 13:00:43 +08:00
|
|
|
|
sourceGroupChangeEvents() {
|
|
|
|
|
|
let datasourceOptions = [];
|
|
|
|
|
|
for (let i = 0; i < this.datasourceList.length; i++) {
|
|
|
|
|
|
let item = this.datasourceList[i];
|
|
|
|
|
|
if (!this.choiceDatasourceGroup || this.choiceDatasourceGroup == item.groupName) {
|
|
|
|
|
|
datasourceOptions.push(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.datasourceOptions = datasourceOptions;
|
2021-06-01 22:34:21 +08:00
|
|
|
|
if (datasourceOptions.length > 0) {
|
|
|
|
|
|
this.choiceDatasourceId = datasourceOptions[0].id;
|
2021-06-20 00:41:28 +08:00
|
|
|
|
this.executorSource = {sourceId: this.choiceDatasourceId};
|
|
|
|
|
|
this.loadDatabaseList();
|
2021-06-20 17:47:46 +08:00
|
|
|
|
this.loadSourceBaseInfo();
|
2021-06-27 22:45:30 +08:00
|
|
|
|
this.loadHistoryAndFavoriteList();
|
2021-06-01 22:34:21 +08:00
|
|
|
|
}
|
2020-05-24 13:00:43 +08:00
|
|
|
|
},
|
2019-08-21 20:39:43 +08:00
|
|
|
|
datasourceChangeEvents() {
|
2021-06-20 00:41:28 +08:00
|
|
|
|
this.executorSource = {sourceId: this.choiceDatasourceId};
|
|
|
|
|
|
this.loadDatabaseList();
|
2021-06-20 17:47:46 +08:00
|
|
|
|
this.loadSourceBaseInfo();
|
2021-06-27 22:45:30 +08:00
|
|
|
|
this.loadHistoryAndFavoriteList();
|
2019-08-21 20:39:43 +08:00
|
|
|
|
},
|
|
|
|
|
|
databaseChangeEvents() {
|
2021-06-20 00:41:28 +08:00
|
|
|
|
this.executorSource = {sourceId: this.choiceDatasourceId, dbName: this.choiceDatabase};
|
2019-09-01 18:41:17 +08:00
|
|
|
|
},
|
|
|
|
|
|
getExecuteInfoStr(resultData) {
|
|
|
|
|
|
var resultStr = resultData.sql;
|
2019-09-02 22:47:24 +08:00
|
|
|
|
resultStr += "\n> 状态:" + ((!!resultData.errMsg) ? "ERROR" : "OK");
|
|
|
|
|
|
if (resultData.updateCount >= 0) {
|
|
|
|
|
|
resultStr += "\n> 影响行数:" + resultData.updateCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
resultStr += "\n> 耗时:" + (resultData.useTime || 0) / 1000 + "s";
|
2019-09-01 18:41:17 +08:00
|
|
|
|
resultStr += "\n\n";
|
|
|
|
|
|
return resultStr;
|
|
|
|
|
|
},
|
|
|
|
|
|
dealExecuteResult(resultData) {
|
|
|
|
|
|
var dataList = resultData.result || [];
|
|
|
|
|
|
var executeResultCols = [];
|
|
|
|
|
|
if (dataList.length > 0) {
|
|
|
|
|
|
var propData = dataList[0];
|
|
|
|
|
|
for (var key in propData) {
|
|
|
|
|
|
// 动态计算宽度~自己想的一个方法,666
|
|
|
|
|
|
document.getElementById("widthCalculate").innerText = key;
|
|
|
|
|
|
var width1 = document.getElementById("widthCalculate").offsetWidth;
|
|
|
|
|
|
document.getElementById("widthCalculate").innerText = propData[key];
|
|
|
|
|
|
var width2 = document.getElementById("widthCalculate").offsetWidth;
|
|
|
|
|
|
var width = (width1 > width2) ? width1 : width2;
|
2019-10-06 21:57:20 +08:00
|
|
|
|
width = (width < 50) ? 50 : width;
|
2019-09-01 18:41:17 +08:00
|
|
|
|
width = (width > 200) ? 200 : width;
|
2019-10-06 21:57:20 +08:00
|
|
|
|
executeResultCols.push({prop: key, width: width + 25});
|
2019-09-01 18:41:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var resultObj = {};
|
|
|
|
|
|
resultObj.dataList = dataList;
|
|
|
|
|
|
resultObj.dataCols = executeResultCols;
|
|
|
|
|
|
resultObj.useTime = resultData.useTime || 0;
|
|
|
|
|
|
resultObj.errMsg = resultData.errMsg || "";
|
2019-09-02 22:47:24 +08:00
|
|
|
|
resultObj.updateCount = resultData.updateCount;
|
2019-09-01 18:41:17 +08:00
|
|
|
|
return resultObj;
|
2019-08-21 20:39:43 +08:00
|
|
|
|
},
|
2021-05-24 22:42:01 +08:00
|
|
|
|
handleSelectionChange(val) {
|
|
|
|
|
|
this.$set(this.choiceResultObj, this.executeShowTable, val);
|
|
|
|
|
|
},
|
2021-05-29 22:18:15 +08:00
|
|
|
|
doCopyCheckLineUpdate() {
|
|
|
|
|
|
let choiceData = this.choiceResultObj[this.executeShowTable] || [];
|
|
|
|
|
|
if (choiceData.length > 0) {
|
|
|
|
|
|
let dataCols = this.executeResultList.find(item => item.name === this.executeShowTable).dataCols;
|
2021-06-20 17:47:46 +08:00
|
|
|
|
let copyData = copyFormatter.format('update', this.editorDbProduct, dataCols, choiceData, this.conditionDataColsChoice);
|
2021-05-29 22:18:15 +08:00
|
|
|
|
this.conditionDataColsChoice = [];
|
|
|
|
|
|
this.exportConditionVisible = false;
|
|
|
|
|
|
this.$copyText(copyData).then(
|
|
|
|
|
|
res => this.$message.success("内容已复制到剪切板!"),
|
|
|
|
|
|
err => this.$message.error("抱歉,复制失败!")
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-05-24 22:42:01 +08:00
|
|
|
|
handleCopyCheckLineCommand(type) {
|
|
|
|
|
|
let choiceData = this.choiceResultObj[this.executeShowTable] || [];
|
|
|
|
|
|
if (choiceData.length > 0) {
|
|
|
|
|
|
let dataCols = this.executeResultList.find(item => item.name === this.executeShowTable).dataCols;
|
2021-05-29 22:18:15 +08:00
|
|
|
|
if (type === 'update') {
|
|
|
|
|
|
// 选择更新的条件列
|
|
|
|
|
|
this.conditionDataCols = dataCols;
|
|
|
|
|
|
this.exportConditionVisible = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-06-20 17:47:46 +08:00
|
|
|
|
let copyData = copyFormatter.format(type, this.editorDbProduct, dataCols, choiceData, '');
|
2021-05-24 22:42:01 +08:00
|
|
|
|
this.$copyText(copyData).then(
|
|
|
|
|
|
res => this.$message.success("内容已复制到剪切板!"),
|
|
|
|
|
|
err => this.$message.error("抱歉,复制失败!")
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-08-21 20:39:43 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
.data-executor-vue .ace-monokai .ace_print-margin{
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
.data-executor-vue .el-card__body{
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
}
|
2021-06-27 22:45:30 +08:00
|
|
|
|
.data-executor-vue .sql-params{
|
|
|
|
|
|
}
|
|
|
|
|
|
.data-executor-vue .sql-params .el-input-group{
|
|
|
|
|
|
width: auto;margin: 10px 10px 0 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
.data-executor-vue .sql-params .el-input__inner{
|
|
|
|
|
|
width: 200px;
|
|
|
|
|
|
}
|
2019-08-21 23:17:04 +08:00
|
|
|
|
.data-executor-vue .el-table td, .el-table th{
|
|
|
|
|
|
padding: 6px 0;
|
|
|
|
|
|
}
|
2019-08-27 23:21:58 +08:00
|
|
|
|
.data-executor-vue .execute-result-table .el-input__inner{
|
2019-08-27 22:53:41 +08:00
|
|
|
|
height: 25px;
|
|
|
|
|
|
line-height: 25px;
|
|
|
|
|
|
padding: 0 5px;
|
|
|
|
|
|
}
|
2019-09-28 15:25:52 +08:00
|
|
|
|
.data-executor-vue .execute-result-table .el-textarea__inner{
|
2020-05-08 22:32:54 +08:00
|
|
|
|
height: 27px;
|
|
|
|
|
|
min-height: 27px;
|
2019-09-28 15:25:52 +08:00
|
|
|
|
line-height: 25px;
|
|
|
|
|
|
padding: 0 5px;
|
2020-05-08 22:32:54 +08:00
|
|
|
|
resize: none;
|
2019-09-28 15:25:52 +08:00
|
|
|
|
}
|
2021-07-11 18:57:35 +08:00
|
|
|
|
.data-executor-vue .sql-content-line{
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
overflow:hidden;
|
|
|
|
|
|
text-overflow:ellipsis;
|
|
|
|
|
|
display:-webkit-box;
|
|
|
|
|
|
-webkit-line-clamp:2;
|
|
|
|
|
|
-webkit-box-orient:vertical;
|
|
|
|
|
|
}
|
2019-08-28 22:19:12 +08:00
|
|
|
|
.data-executor-vue .execute-use-time{
|
|
|
|
|
|
font-size: 12px;margin-right: 10px;
|
|
|
|
|
|
}
|
2019-08-21 23:17:04 +08:00
|
|
|
|
.data-executor-vue-out .el-tabs__nav-scroll{
|
|
|
|
|
|
padding-left: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.data-executor-vue-out .el-button+.el-button{
|
|
|
|
|
|
margin-left: 0px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.data-executor-vue-out .el-table__body-wrapper{
|
|
|
|
|
|
height: calc(100vh - 180px);
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
}
|
2019-08-21 20:39:43 +08:00
|
|
|
|
</style>
|