|
@@ -0,0 +1,140 @@
|
|
|
|
+<template>
|
|
|
|
+ <el-dialog
|
|
|
|
+ :title="dialogTitle"
|
|
|
|
+ :visible.sync="logDialogVisible"
|
|
|
|
+ width="70%"
|
|
|
|
+ :before-close="handleClose"
|
|
|
|
+ >
|
|
|
|
+ <div class="log-container">
|
|
|
|
+ <el-input
|
|
|
|
+ type="textarea"
|
|
|
|
+ :rows="20"
|
|
|
|
+ readonly
|
|
|
|
+ v-model="logContent"
|
|
|
|
+ class="log-content"
|
|
|
|
+ ></el-input>
|
|
|
|
+ </div>
|
|
|
|
+ <span slot="footer" class="dialog-footer">
|
|
|
|
+ <!-- <el-button @click="close">关闭</el-button> -->
|
|
|
|
+ <el-button type="primary" @click="toggleAutoRefresh">
|
|
|
|
+ {{ autoRefresh ? "停止自动刷新" : "开始自动刷新" }}
|
|
|
|
+ </el-button>
|
|
|
|
+ <!-- <el-button @click="clearLog">清空日志</el-button> -->
|
|
|
|
+ </span>
|
|
|
|
+ </el-dialog>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import { getStatic } from "@/api/biz/common";
|
|
|
|
+
|
|
|
|
+export default {
|
|
|
|
+ props: {
|
|
|
|
+ // 日志文件路径
|
|
|
|
+ currentLogUrl: {
|
|
|
|
+ type: String,
|
|
|
|
+ required: true,
|
|
|
|
+ },
|
|
|
|
+ // 刷新间隔时间(毫秒)
|
|
|
|
+ refreshInterval: {
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 5000,
|
|
|
|
+ },
|
|
|
|
+ // 对话框标题
|
|
|
|
+ dialogTitle: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: "日志查看器",
|
|
|
|
+ },
|
|
|
|
+ // 控制对话框显示
|
|
|
|
+ logDialogVisible: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ logContent: "",
|
|
|
|
+ autoRefresh: false,
|
|
|
|
+ intervalId: null,
|
|
|
|
+ lastContentLength: 0,
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ watch: {
|
|
|
|
+ logDialogVisible(newVal) {
|
|
|
|
+ if (newVal) {
|
|
|
|
+ this.fetchLog();
|
|
|
|
+ this.startAutoRefresh();
|
|
|
|
+ } else {
|
|
|
|
+ this.stopAutoRefresh();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ methods: {
|
|
|
|
+ handleClose(done) {
|
|
|
|
+ this.$emit("update:logDialogVisible", false);
|
|
|
|
+ done();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ close() {
|
|
|
|
+ this.$emit("update:logDialogVisible", false);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ toggleAutoRefresh() {
|
|
|
|
+ if (this.autoRefresh) {
|
|
|
|
+ this.stopAutoRefresh();
|
|
|
|
+ } else {
|
|
|
|
+ this.fetchLog();
|
|
|
|
+ this.startAutoRefresh();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ startAutoRefresh() {
|
|
|
|
+ this.autoRefresh = true;
|
|
|
|
+ this.intervalId = setInterval(() => {
|
|
|
|
+ this.fetchLog();
|
|
|
|
+ }, this.refreshInterval);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ stopAutoRefresh() {
|
|
|
|
+ this.autoRefresh = false;
|
|
|
|
+ if (this.intervalId) {
|
|
|
|
+ clearInterval(this.intervalId);
|
|
|
|
+ this.intervalId = null;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchLog() {
|
|
|
|
+ getStatic({ filePath: this.currentLogUrl }).then((response) => {
|
|
|
|
+ this.logContent = response;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ clearLog() {
|
|
|
|
+ this.logContent = "";
|
|
|
|
+ this.lastContentLength = 0;
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ beforeDestroy() {
|
|
|
|
+ this.stopAutoRefresh();
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style scoped>
|
|
|
|
+.log-container {
|
|
|
|
+ margin: -20px 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.log-content {
|
|
|
|
+ font-family: monospace;
|
|
|
|
+ white-space: pre;
|
|
|
|
+ font-size: 14px;
|
|
|
|
+ line-height: 1.5;
|
|
|
|
+ background-color: #f5f5f5;
|
|
|
|
+ padding: 10px;
|
|
|
|
+ border-radius: 4px;
|
|
|
|
+}
|
|
|
|
+</style>
|