| | |
| | | rawPayload: null, |
| | | loading: true, |
| | | refreshing: false, |
| | | switchingSystem: false, |
| | | countdown: REFRESH_SECONDS, |
| | | countdownTimer: null, |
| | | resizeHandler: null, |
| | |
| | | displayText: function (value, fallback) { |
| | | return value == null || value === "" ? (fallback || "") : value; |
| | | }, |
| | | showMessage: function (message, type) { |
| | | if (this.$message && typeof this.$message === "function") { |
| | | this.$message({ |
| | | message: message, |
| | | type: type || "info" |
| | | }); |
| | | return; |
| | | } |
| | | console[type === "error" ? "error" : "log"](message); |
| | | }, |
| | | networkSamplingText: function () { |
| | | var config = this.network && this.network.samplingConfig ? this.network.samplingConfig : {}; |
| | | return this.i18n("dashboard.networkSampling", "采样 {0} ms / 超时 {1} ms / 每样本 {2} 次 / 包大小 {3}", [ |
| | |
| | | this.translateLegacyText("监控系统") |
| | | ); |
| | | }, |
| | | syncParentSystemRunning: function (status) { |
| | | try { |
| | | if (window.parent && window.parent !== window) { |
| | | window.parent.systemRunning = !!status; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | }, |
| | | requestSystemSwitch: function (operatorType, password) { |
| | | var self = this; |
| | | this.switchingSystem = true; |
| | | $.ajax({ |
| | | url: baseUrl + "/console/system/switch", |
| | | headers: { |
| | | token: localStorage.getItem("token") |
| | | }, |
| | | data: { |
| | | operatorType: operatorType, |
| | | password: password || "" |
| | | }, |
| | | method: "POST", |
| | | success: function (res) { |
| | | var status; |
| | | if (res && res.code === 200) { |
| | | status = !!(res.data && res.data.status); |
| | | self.overview = Object.assign({}, self.overview, { |
| | | systemRunning: status |
| | | }); |
| | | self.syncParentSystemRunning(status); |
| | | self.showMessage( |
| | | status |
| | | ? self.i18n("dashboard.systemStarted", "系统已启动") |
| | | : self.i18n("dashboard.systemStopped", "系统已停止"), |
| | | "success" |
| | | ); |
| | | self.loadDashboard(false); |
| | | return; |
| | | } |
| | | if (res && res.code === 403) { |
| | | window.location.href = baseUrl + "/login"; |
| | | return; |
| | | } |
| | | self.showMessage( |
| | | (res && res.msg) || self.i18n("dashboard.systemSwitchFailed", "系统状态切换失败"), |
| | | "error" |
| | | ); |
| | | }, |
| | | error: function () { |
| | | self.showMessage( |
| | | self.i18n("dashboard.systemSwitchFailedDetail", "系统状态切换失败,请检查接口状态"), |
| | | "error" |
| | | ); |
| | | }, |
| | | complete: function () { |
| | | self.switchingSystem = false; |
| | | } |
| | | }); |
| | | }, |
| | | startSystem: function () { |
| | | if (this.overview.systemRunning || this.switchingSystem) { |
| | | return; |
| | | } |
| | | this.requestSystemSwitch(1); |
| | | }, |
| | | maskStopSystemPromptInput: function () { |
| | | setTimeout(function () { |
| | | var input = document.querySelector(".el-message-box__wrapper .el-message-box__input input"); |
| | | if (!input) { |
| | | return; |
| | | } |
| | | input.setAttribute("type", "text"); |
| | | input.setAttribute("name", "dashboard-stop-code"); |
| | | input.setAttribute("autocomplete", "new-password"); |
| | | input.setAttribute("autocapitalize", "off"); |
| | | input.setAttribute("autocorrect", "off"); |
| | | input.setAttribute("spellcheck", "false"); |
| | | input.setAttribute("data-form-type", "other"); |
| | | input.style.webkitTextSecurity = "disc"; |
| | | }, 30); |
| | | }, |
| | | stopSystem: function () { |
| | | var self = this; |
| | | var proceed = function (password) { |
| | | var cleanPassword = String(password == null ? "" : password).trim(); |
| | | if (!cleanPassword) { |
| | | self.showMessage(self.i18n("dashboard.stopSystemPasswordRequired", "请输入停止系统口令"), "warning"); |
| | | return; |
| | | } |
| | | self.requestSystemSwitch(0, cleanPassword); |
| | | }; |
| | | |
| | | if (!this.overview.systemRunning || this.switchingSystem) { |
| | | return; |
| | | } |
| | | |
| | | if (typeof this.$prompt === "function") { |
| | | this.$prompt( |
| | | this.i18n("dashboard.stopSystemPrompt", "请输入口令,并停止 WCS 系统"), |
| | | this.i18n("dashboard.stopSystemTitle", "停止系统"), |
| | | { |
| | | confirmButtonText: this.i18n("common.confirm", "确定"), |
| | | cancelButtonText: this.i18n("common.cancel", "取消"), |
| | | inputType: "text", |
| | | inputPattern: /\S+/, |
| | | inputErrorMessage: this.i18n("dashboard.stopSystemPasswordRequired", "请输入停止系统口令") |
| | | } |
| | | ).then(function (result) { |
| | | proceed(result && result.value); |
| | | }).catch(function () { |
| | | }); |
| | | this.maskStopSystemPromptInput(); |
| | | return; |
| | | } |
| | | |
| | | proceed(window.prompt(this.i18n("dashboard.stopSystemPrompt", "请输入口令,并停止 WCS 系统"), "")); |
| | | }, |
| | | toggleSystem: function () { |
| | | if (this.overview.systemRunning) { |
| | | this.stopSystem(); |
| | | return; |
| | | } |
| | | this.startSystem(); |
| | | }, |
| | | openDevicePingAnalysis: function () { |
| | | this.openParentMenuView( |
| | | "/views/devicePingLog/devicePingLog.html", |