zhangzengfei
2022-07-20 4a800a8fc83c6bd1f86a8e847b079a51a7532c09
src/pages/syslog/views/systemLog.vue
@@ -23,19 +23,14 @@
            v-model="fuzzySearch"
            size="small"
            class="input-with-select"
            @keyup.enter.native="getVaSystemLog(1)"
          >
            <span
              class="icon iconfont"
              @click="getOperationLog(1)"
              slot="append"
            >
            <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-button
              slot="append"
              icon="el-icon-search"
              @click="getOperationLog(1)"
            ></el-button> -->
          </el-input>
        </div>
      </div>
@@ -43,37 +38,22 @@
        <div class="bar">
          <div class="name">级别:</div>
          <el-select
            v-model="level"
            placeholder="请选择"
            size="small"
            @change="levelChange"
          >
            <el-option label="全部" :value="''"> </el-option>
            <el-option
              v-for="item in levelOptions"
              :key="item.proc_name"
              :label="item.proc_name"
              :value="item.proc_name"
            >
          <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="bar">
          <div class="name">主机名:</div>
          <div class="name">进程</div>
          <el-select
            v-model="hostName"
            v-model="procName"
            placeholder="请选择"
            size="small"
            @change="getOperationLog(1)"
            @change="getVaSystemLog(1)"
            clearable
            multiple
          >
            <el-option
              v-for="item in hostNameOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
            <el-option v-for="(item, index) in procOptions" :key="index" :label="item" :value="item"> </el-option>
          </el-select>
        </div>
      </div>
@@ -86,44 +66,30 @@
        :data="tableData"
        :header-cell-style="{ background: '#f8f8f8', color: '#222222' }"
        style="width: 100%"
        border
        :row-class-name="tableRowClassName"
      >
        <!-- <el-table-column :align="'center'" label="序号" type="index" width="50">
        </el-table-column> -->
        <el-table-column
        <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'"
          sortable
          prop="add_time"
          label="级别"
        ></el-table-column>
        <el-table-column
          sortable
          :align="'center'"
          prop="userName"
          label="日期时间"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          sortable
          prop="module"
          label="进程"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          prop="procName"
          label="详细信息"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          sortable
          prop="result"
          label="进程号"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          prop="msg"
          prop="hostName"
          min-width="100px"
          label="主机名"
        ></el-table-column>
          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>
@@ -141,132 +107,157 @@
</template>
<script>
import { deleteDate } from "@/api/system";
import { pad0 } from "@/api/utils";
import {} from "@/api/log";
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 {
  data() {
    return {
      png: require("../../../../public/images/syslog/没数据.png"),
      loading: false,
      loadingText: "",
      input3: "",
      tableData: [],
      dateArr: ["今日", "近三天", "近七天", "近一个月", "近六个月"],
      levelOptions: [],
      procOptions: [],
      hostNameOptions: [],
      resultOptions: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "成功",
          label: "成功",
        },
        {
          value: "失败",
          label: "失败",
        },
      ],
      levelOptions: levelOptions,
      value: "",
      page: 1,
      pageSize: 15,
      activeDateChoise: 0,
      hostName: "",
      result: "",
      level: "",
      procName: [],
      level: 0,
      timeStart: "",
      timeEnd: "",
      fuzzySearch: "",
      total: 0,
    };
      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.getOperationLog();
    this.getOptions();
    this.getTimeRange(24 * 60 * 60 * 1000)
    this.getVaSystemLog()
    this.getOptions()
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      for (let i = 0; i < levelOptions.length; i++) {
        if (levelOptions[i].value === row.level) {
          return levelOptions[i].style
        }
      }
    },
    handleSizeChange(val) {
      this.pageSize = val;
      // this.getOperationLog();
      this.pageSize = val
      this.getVaSystemLog()
    },
    handleCurrentChange(val) {
      this.page = val;
      // this.getOperationLog();
    },
    levelChange(val) {
      // this.getOperationLog(1);
      // this.hostName = "";
      // getOperations({
      //   module: this.level,
      // }).then((res) => {
      //   this.hostNameOptions = res.data;
      // });
      this.page = val
      this.getVaSystemLog()
    },
    getOptions() {
      getModules().then((res) => {
        this.levelOptions = res.data;
      });
      queryProcName().then((res) => {
        this.procOptions = res.data
      })
    },
    choseRange(item, i) {
      switch (item) {
        case "今日":
          this.getTimeRange(24 * 60 * 60 * 1000);
          break;
          this.getTimeRange(24 * 60 * 60 * 1000)
          break
        case "近三天":
          this.getTimeRange(24 * 60 * 60 * 1000 * 3);
          break;
          this.getTimeRange(24 * 60 * 60 * 1000 * 3)
          break
        case "近七天":
          this.getTimeRange(24 * 60 * 60 * 1000 * 7);
          break;
          this.getTimeRange(24 * 60 * 60 * 1000 * 7)
          break
        case "近一个月":
          this.getTimeRange(24 * 60 * 60 * 1000 * 30);
          break;
          this.getTimeRange(24 * 60 * 60 * 1000 * 30)
          break
        case "近六个月":
          this.getTimeRange(24 * 60 * 60 * 1000 * 30 * 6);
          break;
          this.getTimeRange(24 * 60 * 60 * 1000 * 30 * 6)
          break
        default:
          break;
          break
      }
      // this.getOperationLog(1);
      this.activeDateChoise = i;
      this.activeDateChoise = i
      this.getVaSystemLog()
    },
    getOperationLog(typ) {
    getVaSystemLog(typ) {
      if (typ == 1) {
        this.page = 1;
        this.page = 1
      }
      // queryOperationLog({
      //   timeStart: this.timeStart,
      //   timeEnd: this.timeEnd,
      //   page: this.page,
      //   pageSize: this.pageSize,
      //   module: this.level,
      //   function: this.hostName,
      //   result: this.result,
      //   fuzzySearch: this.fuzzySearch,
      // }).then((res) => {
      //   this.tableData = res.data.logs;
      //   this.total = res.data.total;
      // });
      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()); //日
      var hour = pad0(date.getHours()); //时
      var minute = pad0(date.getMinutes()); //分
      var second = pad0(date.getSeconds()); //秒
      return `${date.getFullYear()}-${month}-${day} ${hour}:${minute}:${second}`;
      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);
      this.timeStart = this.getTimeStr(preDay);
      this.timeEnd = this.getTimeStr(date);
      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">
.sys-log {
@@ -404,17 +395,49 @@
    margin-top: 16px;
    border-radius: 5px;
    padding: 12px;
    background-color: white;
    background-color: rgb(255, 255, 255);
    .empty_img {
      margin: 80px auto;
      width: 164px;
    }
    .tableBox {
      border: none;
      &::before,
      &::after {
        display: none;
      }
      tr {
        td:first-child {
          border-radius: 4px 0 0 4px;
        }
        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);
        }
      }
      th {
        padding: 0 !important;
        height: 40px;
        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;
      }
    }
  }
@@ -424,5 +447,13 @@
    box-sizing: border-box;
    background-color: white;
  }
  .el-table .warning-row {
    background: oldlace;
  }
  .el-table .error-row {
    background: #f7b9b9;
  }
}
</style>