SQL编辑器自动提示优化,拖动改变左侧菜单宽度,一些展示优化

This commit is contained in:
暮光:城中城
2021-08-07 10:00:29 +08:00
parent 51f74f60c3
commit 1dece8845d
15 changed files with 288 additions and 205 deletions

View File

@@ -10,6 +10,7 @@ export default {
tableInfo: {},
columnInfo: {},
lastCallbackArr: [],
isAutocomplete: false,
change(source) {
this.source = source;
this.lastCallbackArr = [];
@@ -51,23 +52,34 @@ export default {
}
}
},
startAutocomplete(editor) {
this.isAutocomplete = true;
editor.execCommand("startAutocomplete");
},
async getCompletions(editor, session, pos, prefix, callback) {
let callbackArr = [];
let lineStr = session.getLine(pos.row).substring(0, pos.column - 1);
let endPos = this.isAutocomplete ? pos.column : pos.column - 1;
let lineStr = session.getLine(pos.row).substring(0, endPos);
this.isAutocomplete = false;
console.log("Executor.vue getCompletionssourceId" + JSON.stringify(this.source) + ' lineStr' + lineStr, pos);
if (!!this.source.tableName) {
// 如果指定了表名,则只提示字段,其他都不用管,用在表数据查看页面
callbackArr = await this.getAssignTableColumns(this.source.dbName, this.source.tableName);
callback(null, callbackArr);
} else if (lineStr.endsWith("from ") || lineStr.endsWith("join ")) {
} else if (lineStr.endsWith("from ") || lineStr.endsWith("join ") || lineStr.endsWith("into ")
|| lineStr.endsWith("update ") || lineStr.endsWith("table ")) {
// 获取库和表
callbackArr = this.getDatabasesAndTables();
this.lastCallbackArr = callbackArr;
callback(null, callbackArr);
} else if (lineStr.endsWith(".")) {
// 获取表和字段
callbackArr = await this.getTablesAndColumns(lineStr);
this.lastCallbackArr = callbackArr;
callback(null, callbackArr);
} else if (lineStr.endsWith("select ") || lineStr.endsWith("where ") || lineStr.endsWith("and ") || lineStr.endsWith("or ")) {
} else if (lineStr.endsWith("select ") || lineStr.endsWith("where ") || lineStr.endsWith("and ")
|| lineStr.endsWith("or ") || lineStr.endsWith("set ")) {
// 获取字段
callbackArr = await this.getTableColumns(session, pos);
this.lastCallbackArr = callbackArr;
callback(null, callbackArr);

View File

@@ -0,0 +1,3 @@
.ace_editor.ace_autocomplete{
width: 400px;
}

View File

@@ -6,6 +6,7 @@ import 'brace/mode/json';
import 'brace/snippets/json';
import 'brace/theme/monokai';
import completer from './DatabaseCompleter'
import './index.css';
export default {
render: function (h) {
@@ -92,6 +93,13 @@ export default {
// console.log('change content' + content);
// editor.execCommand("startAutocomplete");
});
editor.commands.addCommand({
name: "start-autocomplete",
bindKey: {win: "Alt-Enter", mac: "Alt-Enter"},
exec: function (editor) {
completer.startAutocomplete(editor);
}
});
if (vm.options) {
editor.setOptions(vm.options);
}