113 lines
4.1 KiB
JavaScript
113 lines
4.1 KiB
JavaScript
|
|
var sqlViewer = CodeMirror.fromTextArea(document.getElementById('dbContentText'), {
|
|
mode: "text/x-mysql",
|
|
indentWithTabs: true,
|
|
smartIndent: true,
|
|
lineNumbers: true,
|
|
matchBrackets: true,
|
|
autofocus: true,
|
|
readOnly: true
|
|
});
|
|
|
|
var vue = new Vue({
|
|
el: "#dbUpdateDiv",
|
|
data: {
|
|
updateList: [],
|
|
checkAll: false,
|
|
filter: { version: '', dbschema: '', upstate: '', versionItems: [] }
|
|
},
|
|
mounted: function () {
|
|
this.getUpdateList();
|
|
},
|
|
methods: {
|
|
//获取升级列表列表
|
|
getUpdateList() {
|
|
var thisObj = this;
|
|
main.post("/Admin/DbUpdate/AjaxGetUpdateList").done(function (resp) {
|
|
thisObj.checkAll = false;
|
|
thisObj.updateList = resp.data;
|
|
let verSet = new Set();
|
|
Object.assign(thisObj.filter, { versionItems: [], dbschemaItems: [] })
|
|
thisObj.updateList.forEach(x => {
|
|
x.checked = false;
|
|
verSet.add(x.Version);
|
|
});
|
|
thisObj.filter.versionItems = Array.from(verSet);
|
|
}).fail(function () {
|
|
main.alert("加载失败");
|
|
});
|
|
},
|
|
changeItemChecked() {
|
|
this.checkAll = this.updateList.every(x => x.checked);
|
|
},
|
|
changeAllChecked() {
|
|
let checked = this.checkAll;
|
|
this.updateList.forEach(x => {
|
|
x.checked = checked;
|
|
});
|
|
},
|
|
//查看脚本内容
|
|
viewUpdateContent(upkey) {
|
|
if (upkey) {
|
|
upkey = [upkey];
|
|
} else {
|
|
upkey = this.updateList.filter(x => x.checked).map(x => x.UpKey);
|
|
if (!upkey.length) {
|
|
return main.alert("请至少选择一项!");
|
|
}
|
|
}
|
|
main.post("/Admin/DbUpdate/AjaxGetUpdateContent", { upKeyList: upkey }).done(function (resp) {
|
|
sqlViewer.getDoc().setValue(resp.data);
|
|
$("#dbContentModal").modal('show');
|
|
sqlViewer.refresh();
|
|
});
|
|
},
|
|
//执行脚本内容
|
|
executeUpdate(item) {
|
|
let confirmMsg, upkeyList, upMap = {}, isUpdateDone = item === "isUpdateDone";
|
|
if (item && !isUpdateDone) {
|
|
upkeyList = [item.UpKey];
|
|
upMap[item.UpKey] = item;
|
|
confirmMsg = item.UpState < 1 ? "确定要执行更新吗?" : "确定要重新执行吗?";
|
|
} else {
|
|
upkeyList = this.updateList.filter(x => x.checked).map(x => {
|
|
upMap[x.UpKey] = x; return x.UpKey;
|
|
});
|
|
if (!upkeyList.length) {
|
|
return main.alert("请至少选择一项!");
|
|
}
|
|
confirmMsg = "确定要执行批量更新吗?";
|
|
}
|
|
|
|
main.confirm(confirmMsg, function () {
|
|
$("#waitMeModal").modal("show");
|
|
let postData = { upKeyList: upkeyList, isUpdateDone: isUpdateDone };
|
|
main.post("/Admin/DbUpdate/AjaxExecuteUpdate", postData).done(function (resp) {
|
|
resp.data.forEach(x => {
|
|
let item = upMap[x.UpKey];
|
|
if (item) {
|
|
item.UpState = x.UpState;
|
|
item.UpResult = x.UpResult;
|
|
}
|
|
});
|
|
}).always(() => {
|
|
$("#waitMeModal").modal("hide");
|
|
});
|
|
});
|
|
},
|
|
itemStatusClass(item) {
|
|
if (item.UpState < 0) {
|
|
return "text-danger";
|
|
}
|
|
|
|
if (item.UpState > 0) {
|
|
return "text-muted";
|
|
}
|
|
},
|
|
isShowItem(item) {
|
|
return (this.filter.version && item.Version !== this.filter.version)
|
|
|| (this.filter.dbschema && item.DbSchema !== this.filter.dbschema)
|
|
|| (this.filter.upstate == true && item.UpState > 0) ? "display:none" : "display:table-row";
|
|
}
|
|
}
|
|
}); |