ZZJ
2022-06-23 feaf0a9778879ef211c5587a513ba4cbdabb52d0
src/pages/syslog/views/systemLog.vue
@@ -1,326 +1,459 @@
<template>
  <div class="all">
    <div class="backup-content">
      <div class="backup-center" ref="left">
        <div class="menu-item" @click="openRight(0)">
          <div class="con">
            <span class="icon iconfont">&#xe646;</span>
            <span class="menu-text">自动备份设置</span>
  <div class="sys-log" v-loading="loading" :element-loading-text="loadingText">
    <div class="top">
      <div class="first">
        <div class="time-option">
          <div class="title">周期:</div>
          <div class="opts">
            <div
              :class="activeDateChoise == i ? 'opt-active' : ''"
              class="opt"
              v-for="(item, i) in dateArr"
              :key="i"
              @click="choseRange(item, i)"
            >
              {{ item }}
            </div>
          </div>
        </div>
        <div class="menu-item" @click="openRight(1)">
          <div class="con">
            <span class="icon iconfont">&#xe646;</span>
            <span class="menu-text">从备份中恢复</span>
          </div>
        <div class="search">
          <el-input
            placeholder="搜索"
            v-model="fuzzySearch"
            size="small"
            class="input-with-select"
            @keyup.enter.native="getVaSystemLog(1)"
          >
            <span class="icon iconfont icon_clear" @click="clearSearch" slot="append" v-if="fuzzySearch">
              &#xe785;
            </span>
            <span class="icon iconfont icon_search" @click="getVaSystemLog(1)" slot="append">
              &#xe714;
            </span>
          </el-input>
        </div>
      </div>
      <div class="backup-right">
        <div class="auto" v-if="activePage == 0">
          <div class="bar">
            <div class="name">自动备份</div>
            <el-switch
              v-model="isBackUp"
              active-color="rgba(61, 104, 225, 1)"
              @change="switchChange"
            >
            </el-switch>
          </div>
          <div class="bar">
            <div class="name">备份目录</div>
            <input type="file" id="file_input" webkitdirectory directory />
          </div>
          <div class="bar">
            <div class="name">备份间隔 / 天</div>
            <el-input
              v-model="interval"
              :placeholder="'请输入天数'"
              @change="handleChange"
              size="small"
            ></el-input>
            <!-- :controls="false" -->
          </div>
          <div class="bar">
            <div class="name">备份数据保存时间 / 天</div>
            <el-input
              v-model="lifeSpan"
              placeholder="请输入天数"
              @change="handleChange"
              size="small"
            ></el-input>
          </div>
          <div class="bar">
            <div class="name">自动备份</div>
            <el-button type="primary" size="small" @click="backUpNow"
              >立即备份</el-button
            >
          </div>
      <div class="second">
        <div class="bar">
          <div class="name">级别:</div>
          <el-select v-model="level" placeholder="请选择" size="small" @change="getVaSystemLog">
            <el-option v-for="(item, index) in levelOptions" :key="index" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="recover" v-if="activePage == 1">
          <div class="title">显示备份的文件范围:{{ 5 }}</div>
          <div class="table-head">
            <span class="line1">自动备份时间</span>
            <span class="line1">备份文件名称</span>
            <span class="line2">操作</span>
          </div>
          <div class="bar" v-for="(item, i) in fileList" :key="i">
            <span class="time">{{ item.time }}</span>
            <span class="time">{{ item.name }}</span>
            <span class="operation">恢复</span>
          </div>
        <div class="bar">
          <div class="name">进程</div>
          <el-select
            v-model="procName"
            placeholder="请选择"
            size="small"
            @change="getVaSystemLog(1)"
            clearable
            multiple
          >
            <el-option v-for="(item, index) in procOptions" :key="index" :label="item" :value="item"> </el-option>
          </el-select>
        </div>
      </div>
    </div>
    <div class="table">
      <el-table
        class="tableBox"
        ref="multipleTable"
        highlight-current-row
        :data="tableData"
        :header-cell-style="{ background: '#f8f8f8', color: '#222222' }"
        style="width: 100%"
        border
        :row-class-name="tableRowClassName"
      >
        <template slot="empty">
          <img :src="png" class="empty_img" alt="" />
        </template>
        <el-table-column :align="'center'" label="序号" type="index" width="100"> </el-table-column>
        <el-table-column :align="'center'" sortable prop="level" label="级别" width="100px">
          <template slot-scope="scope">
            <span>{{ scope.row.level | leverFilter }}</span>
          </template>
        </el-table-column>
        <el-table-column :align="'center'" sortable prop="procName" label="进程" width="150px"></el-table-column>
        <el-table-column :align="'center'" sortable prop="procID" label="进程号" width="150px"></el-table-column>
        <!-- <el-table-column
          :align="'center'"
          prop="hostName"
          min-width="100px"
          label="主机名"
          width="150px"
        ></el-table-column> -->
        <el-table-column sortable :align="'center'" prop="createDate" label="日期时间" width="200px"></el-table-column>
        <el-table-column prop="info" label="详细信息"></el-table-column>
      </el-table>
    </div>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[15, 30, 50, 100]"
      :page-size="15"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
import { queryVaSystemLog, queryProcName } from "@/api/log"
import { pad0 } from "@/api/utils"
const levelOptions = [
  {
    value: 0,
    label: "全部",
    style: ""
  },
  {
    value: 1,
    label: "严重",
    style: "error-row"
  },
  {
    value: 2,
    label: "错误",
    style: "error-row"
  },
  {
    value: 3,
    label: "警告",
    style: "warning-row"
  },
  {
    value: 4,
    label: "信息",
    style: ""
  },
  {
    value: 5,
    label: "调试",
    style: ""
  }
]
export default {
  mounted() {},
  data() {
    return {
      langList: [
        { name: "简体中文" },
        { name: "英文" },
        { name: "繁体中文(香港)" },
      ],
      fileList: [
        { time: "2010-10-02 12:30:09", name: "文件1" },
        { time: "2010-10-02 12:30:09", name: "文件12121212121" },
        { time: "2010-10-02", name: "文件2211" },
        { time: "2011", name: "备份文件2" },
      ],
      activePage: 0,
      interval: "",
      lifeSpan: "",
      options: [
        {
          value: "选项1",
          label: "手动",
        },
        {
          value: "选项2",
          label: "自动",
        },
      ],
      isBackUp: true,
    };
      png: require("../../../../public/images/syslog/没数据.png"),
      loading: false,
      loadingText: "",
      tableData: [],
      dateArr: ["今日", "近三天", "近七天", "近一个月", "近六个月"],
      procOptions: [],
      hostNameOptions: [],
      levelOptions: levelOptions,
      value: "",
      page: 1,
      pageSize: 15,
      activeDateChoise: 0,
      procName: [],
      level: 0,
      timeStart: "",
      timeEnd: "",
      fuzzySearch: "",
      total: 0
    }
  },
  filters: {
    leverFilter(val) {
      for (let i = 0; i < levelOptions.length; i++) {
        if (levelOptions[i].value === val) {
          return levelOptions[i].label
        }
      }
    }
  },
  mounted() {
    this.getTimeRange(24 * 60 * 60 * 1000)
    this.getVaSystemLog()
    this.getOptions()
  },
  methods: {
    openRight(typ) {
      const es = document.getElementsByClassName("menu-item");
      es[this.activePage].style.backgroundColor = "#f8f8f8";
      es[this.activePage].style.color = "rgba(54, 54, 54, 1)";
      es[typ].style.backgroundColor = "rgba(61, 104, 225, 1)";
      es[typ].style.color = "#fff";
      this.activePage = typ;
    tableRowClassName({ row, rowIndex }) {
      for (let i = 0; i < levelOptions.length; i++) {
        if (levelOptions[i].value === row.level) {
          return levelOptions[i].style
        }
      }
    },
    handleChange() {},
    backUpNow() {
      this.$confirm("您是否确认立即备份所有应用的配置数据?", "立即备份", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        this.$message({
          type: "success",
          message: "备份成功",
        });
      });
      //  .then((resp) => {
      //         if (resp.success) {
      //           this.$message({
      //             type: "success",
      //             message: "删除数据成功",
      //           });
      //           this.loading = false;
      //         }
      //       })
      //       .catch((err) => {
      //         this.$message({
      //           type: "error",
      //           message: "删除数据失败!",
      //         });
      //         this.loading = false;
      //       });
    handleSizeChange(val) {
      this.pageSize = val
      this.getVaSystemLog()
    },
    switchChange(val) {
      console.log(val);
    handleCurrentChange(val) {
      this.page = val
      this.getVaSystemLog()
    },
  },
};
    getOptions() {
      queryProcName().then((res) => {
        this.procOptions = res.data
      })
    },
    choseRange(item, i) {
      switch (item) {
        case "今日":
          this.getTimeRange(24 * 60 * 60 * 1000)
          break
        case "近三天":
          this.getTimeRange(24 * 60 * 60 * 1000 * 3)
          break
        case "近七天":
          this.getTimeRange(24 * 60 * 60 * 1000 * 7)
          break
        case "近一个月":
          this.getTimeRange(24 * 60 * 60 * 1000 * 30)
          break
        case "近六个月":
          this.getTimeRange(24 * 60 * 60 * 1000 * 30 * 6)
          break
        default:
          break
      }
      this.activeDateChoise = i
      this.getVaSystemLog()
    },
    getVaSystemLog(typ) {
      if (typ == 1) {
        this.page = 1
      }
      queryVaSystemLog({
        timeStart: this.timeStart,
        timeEnd: this.timeEnd,
        level: this.level,
        procName: this.procName,
        fuzzySearch: this.fuzzySearch,
        page: this.page,
        pageSize: this.pageSize
      }).then((res) => {
        this.tableData = res.data.logs
        this.total = res.data.total
      })
    },
    getTimeStr(date) {
      var month = pad0(date.getMonth() + 1) //月
      var day = pad0(date.getDate()) //日
      return `${date.getFullYear()}-${month}-${day}`
    },
    getTimeRange(gap) {
      var date = new Date() //当前时间
      var preDay = new Date(new Date().getTime() - gap + 24 * 60 * 60 * 1000)
      this.timeStart = this.getTimeStr(preDay) + " 00:00:00"
      this.timeEnd = this.getTimeStr(date) + " 23:59:59"
    },
    clearSearch() {
      this.fuzzySearch = ""
      this.getVaSystemLog(1)
    }
  }
}
</script>
<style lang="scss">
.all {
.sys-log {
  margin: 0 auto;
  padding: 0px 8px 10px 5px;
  border-top: 1px solid #e1e0e6;
  background-color: rgba(242, 242, 247, 1);
  width: 100%;
}
.backup-content {
  height: 100%;
  display: flex;
  flex-direction: row;
  flex: 1;
  flex-basis: auto;
  box-sizing: border-box;
  .backup-center {
    height: 100%;
    width: 280px;
    overflow: auto;
    box-sizing: border-box;
    flex-shrink: 0;
    padding: 10px;
    border-right: 5px solid #f8f8f8;
    .menu-item {
      background-color: #f8f8f8;
      height: 50px;
      margin-bottom: 10px;
      border-radius: 8px;
      line-height: 50px;
      box-sizing: border-box;
      font-size: 14px;
      cursor: pointer;
      padding: 0 20px;
  flex-direction: column;
  overflow: auto;
  .top {
    height: 132px;
    background: #fff;
    border-radius: 5px;
    .first {
      display: flex;
      justify-content: space-between;
      .con {
        .iconfont {
      align-items: center;
      height: 45px;
      padding: 20px 20px 0 20px;
      .time-option {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .title {
          margin-right: 10px;
          min-width: fit-content;
          font-weight: bold;
          font-size: 12px;
        }
        .menu-text {
          font-size: 15px;
        .opts {
          display: flex;
          justify-content: space-between;
          .opt {
            box-sizing: border-box;
            border: 2px solid #efeff6;
            min-width: fit-content;
            width: 100px;
            height: 36px;
            padding: 0 15px;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 2px;
            line-height: 32px;
            font-size: 12px;
            color: #333;
          }
          .opt:hover {
            border-color: #4e94ff;
          }
          .opt-active {
            color: #fff;
            background-color: #4e94ff;
            border-color: #4e94ff;
          }
        }
      }
      .search {
        width: 280px;
        height: 36px;
        display: flex;
        align-items: center;
        .input-with-select {
          width: 100%;
          height: 100%;
          input {
            height: 100%;
            border-radius: 18px 0 0 18px;
            border: 2px solid #f2f2f7;
            border-right: none;
            &:focus,
            &:focus + .el-input-group__append {
              border-color: #409eff;
            }
          }
          .el-input-group__append {
            transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
            background-color: #fff;
            border: 2px solid #f2f2f7;
            border-radius: 0 18px 18px 0;
            border-left: none;
          }
        }
        span {
          cursor: pointer;
          color: rgb(47, 45, 61);
          font-weight: 700;
          font-size: 19px;
        }
      }
    }
    .second {
      display: flex;
      margin: 15px 0 20px 0;
      padding: 0 20px;
      .bar {
        display: flex;
        align-items: baseline;
        width: fit-content;
        margin-right: 30px;
        min-width: 120px;
        .el-select {
          width: 200px;
          height: 36px;
          .el-input {
            width: 100%;
            height: 100%;
            input {
              width: 100%;
              height: 100%;
              border: 2px solid #f2f2f7;
              border-radius: 20px;
            }
          }
        }
        .name {
          margin-right: 15px;
          min-width: fit-content;
          font-weight: bold;
          font-size: 12px;
        }
      }
    }
  }
  .backup-right {
    flex: 1;
    flex-basis: auto;
    overflow: auto;
    box-sizing: border-box;
    position: relative;
    padding: 20px 40px;
    .el-form-item.is-required:not(.is-no-asterisk)
      > .el-form-item__label:before,
    .el-form-item.is-required:not(.is-no-asterisk)
      .el-form-item__label-wrap
      > .el-form-item__label:before {
      display: none;
  .table {
    margin-top: 16px;
    border-radius: 5px;
    padding: 12px;
    background-color: rgb(255, 255, 255);
    .empty_img {
      margin: 80px auto;
      width: 164px;
    }
    .el-select {
      width: 100%;
    }
    .el-form-item {
      margin-bottom: 10px;
      height: 50px;
      background: #f8f8f8;
      padding: 4px 20px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      border-radius: 10px;
      .el-form-item__label {
        text-align: left;
        line-height: 42px;
    .tableBox {
      border: none;
      &::before,
      &::after {
        display: none;
      }
    }
    .el-form-item__content {
      line-height: 40px;
      position: relative;
      font-size: 14px;
    }
    .ip-input-container {
      max-width: none !important;
    }
    .auto {
      .bar {
        display: flex;
        align-items: center;
        height: 50px;
        padding: 0 25px;
        background-color: #f8f8f8;
        justify-content: space-between;
        border-radius: 12px;
        margin-bottom: 10px;
        .name {
          font-size: 15px;
          text-align: left;
          min-width: 180px;
      tr {
        td:first-child {
          border-radius: 4px 0 0 4px;
        }
        .el-input {
          width: 100%;
          .el-input {
            height: auto;
          }
          .el-input__inner {
            border: none;
            border-radius: 8px;
            background-color: rgba(240, 240, 240, 1);
            text-align: left;
          }
        td:last-child {
          border-radius: 0 4px 4px 0;
        }
        &.current-row td {
          background-color: #4e94ff !important;
          color: #fff;
        }
        &:hover td {
          background-color: rgb(242, 242, 247);
        }
      }
    }
    .recover {
      .title {
        font-size: 13px;
        color: #868686;
        text-align: left;
        padding: 0 10px;
        margin-bottom: 10px;
      }
      .table-head {
        height: 30px;
        line-height: 30px;
        display: flex;
        // justify-content: space-between;
        box-sizing: border-box;
        font-size: 15px;
        padding: 0 10px;
        margin-bottom: 5px;
        .line1 {
          flex: 4;
          text-align: left;
        }
        .line2 {
          flex: 1;
          text-align: right;
        }
      }
      .bar {
      th {
        padding: 0 !important;
        height: 40px;
        background-color: rgba(248, 248, 248, 1);
        display: flex;
        box-sizing: border-box;
        padding: 0 10px;
        align-items: center;
        border-radius: 8px;
        color: #797979;
        font-size: 14px;
        margin-bottom: 10px;
        .time {
          width: 45%;
          text-align: left;
        }
        .operation {
          color: rgba(26, 115, 232, 1);
          cursor: pointer;
          width: 10%;
          text-align: right;
        }
        line-height: 40px;
        border-color: #fff !important;
        border-right: 2px solid #fff;
        border-radius: 4px;
        font-size: 12px;
        background: #f2f2f7;
      }
      td {
        padding: 0 !important;
        height: 34px;
        line-height: 34px;
        border: none;
        font-size: 12px;
      }
    }
    .save-btn {
      background-color: #3d68e1;
      width: 240px;
      height: 40px;
      margin: 0 auto;
      border-radius: 10px;
      color: #fff;
      line-height: 40px;
      font-size: 14px;
      margin-top: 20px;
    }
  }
  .el-pagination {
    padding: 20px 5px;
    height: 100%;
    box-sizing: border-box;
    background-color: white;
  }
  .el-table .warning-row {
    background: oldlace;
  }
  .el-table .error-row {
    background: #f7b9b9;
  }
}
</style>