zhangzengfei
2022-01-24 9941b6b14fc01ad49c9581c0eab75ac9b29da691
完善系统日志功能
3个文件已修改
552 ■■■■■ 已修改文件
src/api/log.ts 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/syslog/views/operationLog.vue 220 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/syslog/views/systemLog.vue 297 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/log.ts
@@ -1,4 +1,4 @@
import request from "@/scripts/httpRequest";
import request from "@/scripts/httpRequest"
// /data/api-v//
@@ -7,34 +7,47 @@
    url: "/data/api-v/log/queryOperationLog",
    method: "post",
    data
  });
};
  })
}
export const getOperations = (query: any) => {
  return request({
    url: "/data/api-v/log/operations",
    method: "get",
    params: query
  });
};
  })
}
export const getModules = (query: any) => {
  return request({
    url: "/data/api-v/log/modules",
    method: "get",
    params: query
  });
};
  })
}
export const queryScheduleLog = (data: any) => {
  return request({
    url: "/data/api-v/log/queryScheduleLog",
    method: "post",
    data
  });
};
  })
}
export const queryDataPushLog = (data: any) => {
  return request({
    url: "/data/api-v/log/ruleServerLog",
    method: "post",
    data
  });
};
  })
}
export const queryVaSystemLog = (data: any) => {
  return request({
    url: "/data/api-v/log/vaSystemLog",
    method: "post",
    data
  })
}
export const queryProcName = () => {
  return request({
    url: "/data/api-v/log/procNames",
    method: "get"
  })
}
src/pages/syslog/views/operationLog.vue
@@ -25,20 +25,10 @@
            class="input-with-select"
            @keyup.enter.native="getOperationLog(1)"
          >
            <span
              class="icon iconfont icon_clear"
              @click="clearSearch"
              slot="append"
              v-if="fuzzySearch"
            >
            <span class="icon iconfont icon_clear" @click="clearSearch" slot="append" v-if="fuzzySearch">
              &#xe785;
            </span>
            <span
              class="icon iconfont icon_search"
              @click="getOperationLog(1)"
              slot="append"
              v-else
            >
            <span class="icon iconfont icon_search" @click="getOperationLog(1)" slot="append" v-else>
              &#xe714;
            </span>
@@ -54,19 +44,9 @@
        <div class="bar">
          <div class="name">操作模块:</div>
          <el-select
            v-model="curModule"
            placeholder="请选择"
            size="small"
            @change="moduleChange"
          >
          <el-select v-model="curModule" placeholder="请选择" size="small" @change="moduleChange">
            <el-option label="全部" :value="''"> </el-option>
            <el-option
              v-for="(item, i) in moduleOptions"
              :key="i"
              :label="item.proc_name"
              :value="item.proc_name"
            >
            <el-option v-for="(item, i) in moduleOptions" :key="i" :label="item.proc_name" :value="item.proc_name">
            </el-option>
          </el-select>
        </div>
@@ -80,30 +60,13 @@
            @change="getOperationLog(1)"
          >
            <!-- :disabled="gongnengOptions.length==0" -->
            <el-option
              v-for="(item, i) in gongnengOptions"
              :key="i"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
            <el-option v-for="(item, i) in gongnengOptions" :key="i" :label="item.name" :value="item.name"> </el-option>
          </el-select>
        </div>
        <div class="bar">
          <div class="name">操作结果:</div>
          <el-select
            v-model="result"
            placeholder="请选择"
            size="small"
            @change="getOperationLog(1)"
          >
            <el-option
              v-for="(item, i) in resultOptions"
              :key="i"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          <el-select v-model="result" placeholder="请选择" size="small" @change="getOperationLog(1)">
            <el-option v-for="(item, i) in resultOptions" :key="i" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </div>
      </div>
@@ -121,8 +84,7 @@
        <template slot="empty">
          <img :src="png" class="empty_img" alt="" />
        </template>
        <el-table-column :align="'center'" label="序号" type="index" width="50">
        </el-table-column>
        <el-table-column :align="'center'" label="序号" type="index" width="50"> </el-table-column>
        <el-table-column
          :align="'center'"
          sortable
@@ -130,41 +92,12 @@
          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="function"
          label="操作功能"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          sortable
          prop="result"
          label="操作结果"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          prop="msg"
          min-width="100px"
          label="详细信息"
        ></el-table-column>
        <el-table-column
          :align="'center'"
          sortable
          prop="ip"
          label="IP"
        ></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="function" label="操作功能"></el-table-column>
        <el-table-column :align="'center'" sortable prop="result" label="操作结果"></el-table-column>
        <el-table-column :align="'center'" prop="msg" min-width="100px" label="详细信息"></el-table-column>
        <el-table-column :align="'center'" sortable prop="ip" label="IP"></el-table-column>
      </el-table>
    </div>
@@ -182,9 +115,9 @@
</template>
<script>
import { deleteDate } from "@/api/system";
import { pad0 } from "@/api/utils";
import { queryOperationLog, getOperations, getModules } from "@/api/log";
import { deleteDate } from "@/api/system"
import { pad0 } from "@/api/utils"
import { queryOperationLog, getOperations, getModules } from "@/api/log"
export default {
  name: "operationLog",
@@ -201,16 +134,16 @@
      resultOptions: [
        {
          value: "",
          label: "全部",
          label: "全部"
        },
        {
          value: "成功",
          label: "成功",
          label: "成功"
        },
        {
          value: "失败",
          label: "失败",
        },
          label: "失败"
        }
      ],
      value: "",
      page: 1,
@@ -222,75 +155,74 @@
      timeStart: "",
      timeEnd: "",
      fuzzySearch: "",
      total: 0,
    };
      total: 0
    }
  },
  mounted() {
    this.getTimeRange();
    this.getOperationLog();
    this.getOptions();
    this.getTimeRange()
    this.getOperationLog()
    this.getOptions()
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOperationLog();
      this.pageSize = val
      this.getOperationLog()
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getOperationLog();
      this.page = val
      this.getOperationLog()
    },
    moduleChange(val) {
      this.getOperationLog(1);
      this.gongneng = "";
      this.getOperationLog(1)
      this.gongneng = ""
      getOperations({
        module: this.curModule,
        module: this.curModule
      }).then((res) => {
        this.gongnengOptions = res.data;
      });
        this.gongnengOptions = res.data
      })
    },
    getOptions() {
      getModules().then((res) => {
        const indexArr = [];
        const indexArr = []
        res.data.forEach((item, index) => {
          if (item.proc_name == "") {
            indexArr.push(index);
            indexArr.push(index)
          }
        });
        })
        if (indexArr.length != 0) {
          indexArr.forEach((i) => {
            res.data.splice(i);
          });
            res.data.splice(i)
          })
        }
        this.moduleOptions = res.data;
        console.log(this.moduleOptions);
      });
        this.moduleOptions = res.data
      })
    },
    choseRange(item, i) {
      switch (item) {
        case "今日":
          this.getTimeRange();
          break;
          this.getTimeRange()
          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.getOperationLog(1)
      this.activeDateChoise = i
    },
    getOperationLog(typ) {
      if (typ == 1) {
        this.page = 1;
        this.page = 1
      }
      queryOperationLog({
        timeStart: this.timeStart,
@@ -300,34 +232,32 @@
        module: this.curModule,
        function: this.gongneng,
        result: this.result,
        fuzzySearch: this.fuzzySearch,
        fuzzySearch: this.fuzzySearch
      }).then((res) => {
        this.tableData = res.data.logs;
        this.total = res.data.total;
        this.png = require("../../../../public/images/syslog/没数据.png");
      });
        this.tableData = res.data.logs
        this.total = res.data.total
        this.png = require("../../../../public/images/syslog/没数据.png")
      })
    },
    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()) //日
      var hour = pad0(date.getHours()) //时
      var minute = pad0(date.getMinutes()) //分
      var second = pad0(date.getSeconds()) //秒
      return `${date.getFullYear()}-${month}-${day} ${hour}:${minute}:${second}`
    },
    getTimeRange(gap) {
      var preDay;
      preDay = gap
        ? new Date(new Date().getTime() - gap)
        : new Date(new Date().setHours(0, 0, 0, 0));
      this.timeStart = this.getTimeStr(preDay);
      var preDay
      preDay = gap ? new Date(new Date().getTime() - gap) : new Date(new Date().setHours(0, 0, 0, 0))
      this.timeStart = this.getTimeStr(preDay)
    },
    clearSearch() {
      this.fuzzySearch = "";
      this.getOperationLog(1);
    },
  },
};
      this.fuzzySearch = ""
      this.getOperationLog(1)
    }
  }
}
</script>
<style lang="scss">
.op-log {
src/pages/syslog/views/systemLog.vue
@@ -23,30 +23,14 @@
            v-model="fuzzySearch"
            size="small"
            class="input-with-select"
            @keyup.enter.native="getOperationLog(1)"
            @keyup.enter.native="getVaSystemLog(1)"
          >
            <span
              class="icon iconfont icon_clear"
              @click="clearSearch"
              slot="append"
              v-if="fuzzySearch"
            >
            <span class="icon iconfont icon_clear" @click="clearSearch" slot="append" v-if="fuzzySearch">
              &#xe785;
            </span>
            <span
              class="icon iconfont icon_search"
              @click="getOperationLog(1)"
              slot="append"
              v-else
            >
            <span class="icon iconfont icon_search" @click="getVaSystemLog(1)" slot="append" v-else>
              &#xe714;
            </span>
            <!-- <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOperationLog(1)"
            ></el-button> -->
          </el-input>
        </div>
      </div>
@@ -54,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, index) in levelOptions"
              :key="index"
              :label="item.proc_name"
              :value="item.proc_name"
            >
          <el-select v-model="level" placeholder="请选择" size="small" @change="levelChange">
            <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, index) in hostNameOptions"
              :key="index"
              :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>
@@ -98,47 +67,29 @@
        :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="50">
        </el-table-column> -->
        <el-table-column
        <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>
@@ -156,10 +107,40 @@
</template>
<script>
import { deleteDate } from "@/api/system";
import { getModules } from "@/api/log";
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() {
@@ -167,54 +148,53 @@
      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
    },
    handleCurrentChange(val) {
      this.page = val;
      // this.getOperationLog();
      this.page = val
    },
    levelChange(val) {
      // this.getOperationLog(1);
      // this.hostName = "";
      // getOperations({
      //   module: this.level,
@@ -223,72 +203,69 @@
      // });
    },
    getOptions() {
      getModules().then((res) => {
        this.levelOptions = res.data;
        this.png = require("../../../../public/images/syslog/没数据.png");
      });
      queryProcName().then((res) => {
        this.procOptions = res.data
        // this.png = require("../../../../public/images/syslog/没数据.png")
      })
    },
    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
    },
    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,
        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()) //日
      var hour = pad0(date.getHours()) //时
      var minute = pad0(date.getMinutes()) //分
      var second = pad0(date.getSeconds()) //秒
      return `${date.getFullYear()}-${month}-${day} ${hour}:${minute}:${second}`
    },
    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)
      this.timeStart = this.getTimeStr(preDay)
      this.timeEnd = this.getTimeStr(date)
    },
    clearSearch() {
      this.fuzzySearch = "";
      this.getOperationLog(1);
    },
  },
};
      this.fuzzySearch = ""
      this.getVaSystemLog(1)
    }
  }
}
</script>
<style lang="scss">
.sys-log {
@@ -478,5 +455,13 @@
    box-sizing: border-box;
    background-color: white;
  }
  .el-table .warning-row {
    background: oldlace;
  }
  .el-table .error-row {
    background: #f7b9b9;
  }
}
</style>