sql执行器支持库表字段的智能提示
This commit is contained in:
@@ -4,6 +4,7 @@ var URL = {
|
||||
getSelfUserInfo: '/user/info/selfInfo',
|
||||
getUserBaseInfo: '/zyplayer-doc-wiki/common/user/base',
|
||||
|
||||
getEditorData: '/zyplayer-doc-db/doc-db/getEditorData',
|
||||
datasourceList: '/zyplayer-doc-db/doc-db/getDataSourceList',
|
||||
databaseList: '/zyplayer-doc-db/doc-db/getDatabaseList',
|
||||
tableList: '/zyplayer-doc-db/doc-db/getTableList',
|
||||
|
||||
@@ -16,7 +16,7 @@ var SnippetManager = function() {
|
||||
|
||||
(function() {
|
||||
oop.implement(this, EventEmitter);
|
||||
|
||||
|
||||
this.getTokenizer = function() {
|
||||
function TabstopToken(str, _, stack) {
|
||||
str = str.substr(1);
|
||||
@@ -125,7 +125,7 @@ var SnippetManager = function() {
|
||||
var s = editor.session;
|
||||
switch(name) {
|
||||
case "CURRENT_WORD":
|
||||
var r = s.getWordRange();
|
||||
var r = s.getWordRange();
|
||||
case "SELECTION":
|
||||
case "SELECTED_TEXT":
|
||||
return s.getTextRange(r);
|
||||
@@ -239,7 +239,7 @@ var SnippetManager = function() {
|
||||
var line = editor.session.getLine(cursor.row);
|
||||
var tabString = editor.session.getTabString();
|
||||
var indentString = line.match(/^\s*/)[0];
|
||||
|
||||
|
||||
if (cursor.column < indentString.length)
|
||||
indentString = indentString.slice(0, cursor.column);
|
||||
|
||||
@@ -272,7 +272,7 @@ var SnippetManager = function() {
|
||||
return;
|
||||
|
||||
var value = tokens.slice(i + 1, i1);
|
||||
var isNested = value.some(function(t) {return typeof t === "object";});
|
||||
var isNested = value.some(function(t) {return typeof t === "object";});
|
||||
if (isNested && !ts.value) {
|
||||
ts.value = value;
|
||||
} else if (value.length && (!ts.value || typeof ts.value !== "string")) {
|
||||
@@ -306,7 +306,7 @@ var SnippetManager = function() {
|
||||
expanding[id] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var ts = tabstops[id];
|
||||
var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
|
||||
arg.unshift(i + 1, Math.max(0, i1 - i));
|
||||
@@ -342,16 +342,16 @@ var SnippetManager = function() {
|
||||
var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
|
||||
tabstopManager.addTabstops(tabstops, range.start, end, selectionId);
|
||||
};
|
||||
|
||||
|
||||
this.insertSnippet = function(editor, snippetText) {
|
||||
var self = this;
|
||||
if (editor.inVirtualSelectionMode)
|
||||
return self.insertSnippetForSelection(editor, snippetText);
|
||||
|
||||
|
||||
editor.forEachSelection(function() {
|
||||
self.insertSnippetForSelection(editor, snippetText);
|
||||
}, null, {keepOrder: true});
|
||||
|
||||
|
||||
if (editor.tabstopManager)
|
||||
editor.tabstopManager.tabNext();
|
||||
};
|
||||
@@ -360,7 +360,7 @@ var SnippetManager = function() {
|
||||
var scope = editor.session.$mode.$id || "";
|
||||
scope = scope.split("/").pop();
|
||||
if (scope === "html" || scope === "php") {
|
||||
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
||||
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
||||
scope = "html";
|
||||
var c = editor.getCursorPosition();
|
||||
var state = editor.session.getState(c.row);
|
||||
@@ -376,7 +376,7 @@ var SnippetManager = function() {
|
||||
scope = "php";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return scope;
|
||||
};
|
||||
|
||||
@@ -400,7 +400,7 @@ var SnippetManager = function() {
|
||||
editor.tabstopManager.tabNext();
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
this.expandSnippetForSelection = function(editor, options) {
|
||||
var cursor = editor.getCursorPosition();
|
||||
var line = editor.session.getLine(cursor.row);
|
||||
@@ -456,10 +456,10 @@ var SnippetManager = function() {
|
||||
var snippetMap = this.snippetMap;
|
||||
var snippetNameMap = this.snippetNameMap;
|
||||
var self = this;
|
||||
|
||||
if (!snippets)
|
||||
|
||||
if (!snippets)
|
||||
snippets = [];
|
||||
|
||||
|
||||
function wrapRegexp(src) {
|
||||
if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
|
||||
src = "(?:" + src + ")";
|
||||
@@ -504,10 +504,10 @@ var SnippetManager = function() {
|
||||
s.guard = "\\b";
|
||||
s.trigger = lang.escapeRegExp(s.tabTrigger);
|
||||
}
|
||||
|
||||
|
||||
if (!s.trigger && !s.guard && !s.endTrigger && !s.endGuard)
|
||||
return;
|
||||
|
||||
|
||||
s.startRe = guardedRegexp(s.trigger, s.guard, true);
|
||||
s.triggerRe = new RegExp(s.trigger);
|
||||
|
||||
@@ -519,7 +519,7 @@ var SnippetManager = function() {
|
||||
addSnippet(snippets);
|
||||
else if (Array.isArray(snippets))
|
||||
snippets.forEach(addSnippet);
|
||||
|
||||
|
||||
this._signal("registerSnippets", {scope: scope});
|
||||
};
|
||||
this.unregister = function(snippets, scope) {
|
||||
@@ -736,9 +736,9 @@ var TabstopManager = function(editor) {
|
||||
ts = this.tabstops[this.index];
|
||||
if (!ts || !ts.length)
|
||||
return;
|
||||
|
||||
|
||||
this.selectedTabstop = ts;
|
||||
if (!this.editor.inVirtualSelectionMode) {
|
||||
if (!this.editor.inVirtualSelectionMode) {
|
||||
var sel = this.editor.multiSelect;
|
||||
sel.toSingleRange(ts.firstNonLinked.clone());
|
||||
for (var i = ts.length; i--;) {
|
||||
@@ -751,7 +751,7 @@ var TabstopManager = function(editor) {
|
||||
} else {
|
||||
this.editor.selection.setRange(ts.firstNonLinked);
|
||||
}
|
||||
|
||||
|
||||
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
||||
};
|
||||
this.addTabstops = function(tabstops, start, end) {
|
||||
@@ -770,7 +770,7 @@ var TabstopManager = function(editor) {
|
||||
var ranges = this.ranges;
|
||||
tabstops.forEach(function(ts, index) {
|
||||
var dest = this.$openTabstops[index] || ts;
|
||||
|
||||
|
||||
for (var i = ts.length; i--;) {
|
||||
var p = ts[i];
|
||||
var range = Range.fromPoints(p.start, p.end || p.start);
|
||||
@@ -797,7 +797,7 @@ var TabstopManager = function(editor) {
|
||||
}
|
||||
this.addTabstopMarkers(dest);
|
||||
}, this);
|
||||
|
||||
|
||||
if (arg.length > 2) {
|
||||
if (this.tabstops.length)
|
||||
arg.push(arg.splice(2, 1)[0]);
|
||||
@@ -865,7 +865,7 @@ changeTracker.setPosition = function(row, column) {
|
||||
};
|
||||
changeTracker.update = function(pos, delta, $insertRight) {
|
||||
this.$insertRight = $insertRight;
|
||||
this.pos = pos;
|
||||
this.pos = pos;
|
||||
this.onChange(delta);
|
||||
};
|
||||
|
||||
@@ -1059,11 +1059,11 @@ var AcePopup = function(parentNode) {
|
||||
|
||||
function addToken(value, className) {
|
||||
value && tokens.push({
|
||||
type: (data.className || "") + (className || ""),
|
||||
type: (data.className || "") + (className || ""),
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var lower = caption.toLowerCase();
|
||||
var filterText = (popup.filterText || "").toLowerCase();
|
||||
var lastIndex = 0;
|
||||
@@ -1080,7 +1080,7 @@ var AcePopup = function(parentNode) {
|
||||
}
|
||||
}
|
||||
addToken(caption.slice(lastIndex, caption.length), "");
|
||||
|
||||
|
||||
if (data.meta)
|
||||
tokens.push({type: "completion-meta", value: data.meta});
|
||||
|
||||
@@ -1349,7 +1349,7 @@ var Autocomplete = function() {
|
||||
this.popup.setData(this.completions.filtered, this.completions.filterText);
|
||||
|
||||
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
||||
|
||||
|
||||
var renderer = editor.renderer;
|
||||
this.popup.setRow(this.autoSelect ? 0 : -1);
|
||||
if (!keepPopupPosition) {
|
||||
@@ -1662,7 +1662,7 @@ var Autocomplete = function() {
|
||||
if (el.parentNode)
|
||||
el.parentNode.removeChild(el);
|
||||
};
|
||||
|
||||
|
||||
this.onTooltipClick = function(e) {
|
||||
var a = e.target;
|
||||
while (a && a != this.tooltipNode) {
|
||||
@@ -1706,7 +1706,7 @@ var FilteredList = function(array, filterText) {
|
||||
this.filterText = str;
|
||||
matches = this.filterCompletions(matches, this.filterText);
|
||||
matches = matches.sort(function(a, b) {
|
||||
return b.exactMatch - a.exactMatch || b.$score - a.$score
|
||||
return b.exactMatch - a.exactMatch || b.$score - a.$score
|
||||
|| (a.caption || a.value) < (b.caption || b.value);
|
||||
});
|
||||
var prev = null;
|
||||
@@ -1772,7 +1772,7 @@ exports.FilteredList = FilteredList;
|
||||
|
||||
ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module) {
|
||||
var Range = require("../range").Range;
|
||||
|
||||
|
||||
var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
|
||||
|
||||
function getWordIndex(doc, pos) {
|
||||
@@ -1783,7 +1783,7 @@ ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/
|
||||
var prefixPos = getWordIndex(doc, pos);
|
||||
var words = doc.getValue().split(splitRegex);
|
||||
var wordScores = Object.create(null);
|
||||
|
||||
|
||||
var currentWord = words[prefixPos];
|
||||
|
||||
words.forEach(function(word, idx) {
|
||||
@@ -1879,7 +1879,18 @@ exports.setCompleters = function(val) {
|
||||
if (val) completers.push.apply(completers, val);
|
||||
};
|
||||
exports.addCompleter = function(completer) {
|
||||
completers.push(completer);
|
||||
// zyplayer此处有修改,去除由于页面跳转多包含的completer
|
||||
var newCompleters = [];
|
||||
for (var i = 0; i < completers.length; i++) {
|
||||
if (!!completers[i].needDestory) {
|
||||
continue;
|
||||
}
|
||||
newCompleters.push(completers[i]);
|
||||
}
|
||||
newCompleters.push(completer);
|
||||
completers = newCompleters;
|
||||
// 原生代码:
|
||||
// completers.push(completer);
|
||||
};
|
||||
exports.textCompleter = textCompleter;
|
||||
exports.keyWordCompleter = keyWordCompleter;
|
||||
|
||||
@@ -57,7 +57,11 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!--人员权限弹窗-->
|
||||
<el-dialog title="权限编辑" :visible.sync="dbSourceAuthDialogVisible" width="900px">
|
||||
<el-dialog :visible.sync="dbSourceAuthDialogVisible" width="900px" :close-on-click-modal="false">
|
||||
<span slot="title">
|
||||
<span>权限编辑</span>
|
||||
<span style="margin-left: 10px;color: #999;font-size: 12px;"><i class="el-icon-info"></i> 添加删除或编辑之后记得点击保存哦~</span>
|
||||
</span>
|
||||
<el-row>
|
||||
<el-select v-model="dbSourceAuthNewUser" filterable remote reserve-keyword
|
||||
placeholder="请输入名字、邮箱、账号搜索用户" :remote-method="getSearchUserList"
|
||||
@@ -119,13 +123,15 @@
|
||||
methods: {
|
||||
editDbAuth(row) {
|
||||
this.newDatasource = JSON.parse(JSON.stringify(row));
|
||||
app.dbSourceAuthDialogVisible = true;
|
||||
this.loadDbAuthUserList();
|
||||
},
|
||||
loadDbAuthUserList() {
|
||||
app.dbSourceAuthNewUser = [];
|
||||
app.dbSourceAuthUserList = [];
|
||||
app.dbSourceAuthDialogVisible = true;
|
||||
var param = {sourceId: app.newDatasource.id};
|
||||
this.common.post(this.apilist1.dbUserAuthList, param, function (json) {
|
||||
app.dbSourceAuthUserList = json.data || [];
|
||||
app.dbSourceAuthDialogVisible = true;
|
||||
});
|
||||
},
|
||||
saveUserDbSourceAuth() {
|
||||
|
||||
@@ -81,6 +81,9 @@
|
||||
choiceDatasourceId: "",
|
||||
databaseList: [],
|
||||
choiceDatabase: "",
|
||||
editorDbInfo: [],
|
||||
editorDbTableInfo: {},
|
||||
editorColumnInfo: {},
|
||||
|
||||
sqlExecuting: false,
|
||||
executeResultList: [],
|
||||
@@ -96,9 +99,10 @@
|
||||
},
|
||||
mounted: function () {
|
||||
app = this;
|
||||
window.tableMetaInfo = "";
|
||||
app.sqlExecutorEditor = app.initAceEditor("sqlExecutorEditor", 20);
|
||||
this.loadDatasourceList();
|
||||
// 下面两行先后顺序不能改
|
||||
this.addEditorCompleter();
|
||||
app.sqlExecutorEditor = app.initAceEditor("sqlExecutorEditor", 20);
|
||||
},
|
||||
methods: {
|
||||
initAceEditor(editor, minLines) {
|
||||
@@ -155,7 +159,7 @@
|
||||
});
|
||||
},
|
||||
inputFavoriteSql(content) {
|
||||
this.sqlExecutorEditor.setValue(content);
|
||||
this.sqlExecutorEditor.setValue(content, 1);
|
||||
this.historyDrawerVisible = false;
|
||||
},
|
||||
doExecutorSql() {
|
||||
@@ -204,10 +208,20 @@
|
||||
app.datasourceList = json.data || [];
|
||||
if (app.datasourceList.length > 0) {
|
||||
app.choiceDatasourceId = app.datasourceList[0].id;
|
||||
app.loadEditorData();
|
||||
}
|
||||
});
|
||||
},
|
||||
loadEditorData() {
|
||||
this.common.post(this.apilist1.getEditorData, {sourceId: this.choiceDatasourceId}, function (json) {
|
||||
var data = json.data || {};
|
||||
app.editorDbInfo = data.db || [];
|
||||
app.editorDbTableInfo = data.table || {};
|
||||
app.editorColumnInfo = data.column || {};
|
||||
});
|
||||
},
|
||||
datasourceChangeEvents() {
|
||||
this.loadEditorData();
|
||||
// this.common.post(this.apilist1.databaseList, {sourceId: this.choiceDatasourceId}, function (json) {
|
||||
// app.databaseList = json.data || [];
|
||||
// });
|
||||
@@ -215,6 +229,99 @@
|
||||
databaseChangeEvents() {
|
||||
|
||||
},
|
||||
addEditorCompleter() {
|
||||
var languageTools = ace.require("ace/ext/language_tools");
|
||||
languageTools.addCompleter({
|
||||
needDestory: true, // 一定得加上这个参数~不然页面生命周期内页面的切换,编辑器会有多个相同的completer
|
||||
getCompletions: function (editor, session, pos, prefix, callback) {
|
||||
var isFound = false;
|
||||
var callbackArr = [];
|
||||
var lineStr = session.getLine(pos.row).substring(0, pos.column - 1);
|
||||
if (lineStr.endsWith("from ") || lineStr.endsWith("join ")) {
|
||||
// 库
|
||||
for (var i = 0; i < app.editorDbInfo.length; i++) {
|
||||
callbackArr.push({caption: app.editorDbInfo[i].dbName, snippet: app.editorDbInfo[i].dbName, meta: "database", type: "snippet", score : 1000});
|
||||
}
|
||||
// 所有表
|
||||
for (var key in app.editorDbTableInfo) {
|
||||
var tableInfo = app.editorDbTableInfo[key];
|
||||
for (var i = 0; i < tableInfo.length; i++) {
|
||||
var caption = (!!tableInfo[i].tableComment) ? tableInfo[i].tableName + "-" + tableInfo[i].tableComment : tableInfo[i].tableName;
|
||||
callbackArr.push({caption: caption, snippet: tableInfo[i].tableName, meta: "table", type: "snippet", score : 1000});
|
||||
}
|
||||
}
|
||||
callback(null, callbackArr);
|
||||
} else if (lineStr.endsWith(".")) {
|
||||
// 匹配 库名. 搜索表名
|
||||
for (var i = 0; i < app.editorDbInfo.length; i++) {
|
||||
if (lineStr.endsWith(app.editorDbInfo[i].dbName + ".")) {
|
||||
var tableInfo = app.editorDbTableInfo[app.editorDbInfo[i].dbName];
|
||||
if (!!tableInfo) {
|
||||
for (var i = 0; i < tableInfo.length; i++) {
|
||||
var caption = (!!tableInfo[i].tableComment) ? tableInfo[i].tableName + "-" + tableInfo[i].tableComment : tableInfo[i].tableName;
|
||||
callbackArr.push({caption: caption, snippet: tableInfo[i].tableName, meta: "table", type: "snippet", score : 1000});
|
||||
}
|
||||
isFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 未找到,匹配 表名. 搜索字段名
|
||||
if (!isFound) {
|
||||
for (var key in app.editorColumnInfo) {
|
||||
if (!lineStr.endsWith(key + ".")) {
|
||||
continue;
|
||||
}
|
||||
var columnInfo = app.editorColumnInfo[key];
|
||||
if (!!columnInfo) {
|
||||
for (var i = 0; i < columnInfo.length; i++) {
|
||||
var caption = (!!columnInfo[i].description) ? columnInfo[i].name + "-" + columnInfo[i].description : columnInfo[i].name;
|
||||
callbackArr.push({caption: caption, snippet: columnInfo[i].name, meta: "column", type: "snippet", score : 1000});
|
||||
}
|
||||
isFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(null, callbackArr);
|
||||
} else if (lineStr.endsWith("select ") || lineStr.endsWith("where ") || lineStr.endsWith("and ")) {
|
||||
var queryText = "";
|
||||
// 往前加
|
||||
for (var i = pos.row; i >= 0; i--) {
|
||||
var tempLine = session.getLine(i);
|
||||
queryText = tempLine + " " + queryText;
|
||||
if (tempLine.indexOf(";") >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 往后加
|
||||
for (var i = pos.row + 1; i < session.getLength(); i++) {
|
||||
var tempLine = session.getLine(i);
|
||||
queryText = queryText + " " + tempLine;
|
||||
if (tempLine.indexOf(";") >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 所有表,找下面的字段列表
|
||||
for (var key in app.editorDbTableInfo) {
|
||||
var tableInfo = app.editorDbTableInfo[key];
|
||||
for (var i = 0; i < tableInfo.length; i++) {
|
||||
if (queryText.indexOf(tableInfo[i].tableName) < 0) {
|
||||
continue;
|
||||
}
|
||||
var columnInfo = app.editorColumnInfo[tableInfo[i].tableName];
|
||||
if (!!columnInfo) {
|
||||
for (var i = 0; i < columnInfo.length; i++) {
|
||||
var caption = (!!columnInfo[i].description) ? columnInfo[i].name + "-" + columnInfo[i].description : columnInfo[i].name;
|
||||
callbackArr.push({caption: caption, snippet: columnInfo[i].name, meta: "column", type: "snippet", score : 1000});
|
||||
}
|
||||
isFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(null, callbackArr);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user