审计记录

src/components/OperLog.vue 10.0 KB
Linchun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
<!-- 调度日志 -->
<template style="background:#e6ebf5;z-index:100;">
  <div class="app-container">
    <!-- 标题 -->
    <div class="main-title" style="padding:10px 0;">
        <i class="el-icon-date" style="color:#1890ff"></i>
        <span style="padding:0 10px;">调度日志</span>
    </div>
    <!-- 分割线 -->
    <div class="border-line"></div>
    <!-- 表单查询条件 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item
        label="任务名称"
        prop="jobName"
      >
        <el-input
          v-model="queryParams.jobName"
          placeholder="请输入任务名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="任务组名"
        prop="jobGroup"
      >
        <el-select
          v-model="queryParams.jobGroup"
          placeholder="请选择任务组名"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in jobGroupOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="执行时间"
        prop="jobRangeDateTime"
      >
        <el-date-picker
          v-model="queryParams.jobRangeDateTime"
          size="small"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item
        label="执行状态"
        prop="status"
      >
        <el-select
          v-model="queryParams.status"
          placeholder="请选择执行状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
        >重置</el-button>
        <el-button
          icon="el-icon-refresh-right"
          size="mini"
          @click="handleRefresh"
        >刷新</el-button>
        <el-button
          icon="el-icon-back"
          size="mini"
          @click="handleBack"
        >返回</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格分页列表 -->
    <el-table
      v-loading="loading"
      :data="showData"
      :height="tableHeight"
      style="width:100%;"
      v-tableHeight="{bottomOffset:60}"
    >
      <el-table-column
        min-width="220px"
        label="执行时间"
        align="center"
        prop="jobRangeDateTime"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{scope.row.jobRangeDateTime.join(' ~ ')}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="任务名称"
        align="center"
        prop="jobName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="任务组名"
        align="center"
        prop="jobGroup"
        :formatter="jobGroupFormat"
      />
      <el-table-column
        label="任务地址"
        align="center"
        prop="jobAddr"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="执行状态"
        align="center"
        prop="status"
        :formatter="jobStatusFormat"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="失败原因"
        align="center"
        prop="failReason"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="任务参数"
        align="center"
        prop="taskParams"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        :show-overflow-tooltip="true"
      />
    </el-table>
    <el-pagination
      background
      v-show="total>0"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <!-- 脚垫 -->
    <div style="height:10px;"></div>
  </div>
</template>

<script>
// 引入json数据库
import lowdb from 'lowdb'
import fileSync from 'lowdb/adapters/FileSync'
let adapter = new fileSync('db.json');
const db = lowdb(adapter);
import {changeArr } from '@/utils/index'
export default {
  data () {
    return {
      tableHeight:450,
      showData:[],
      jobId:null,
      currentPage: 1,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 任务组名字典
      jobGroupOptions: [],
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jobName: undefined,
        jobAddr: undefined,
        jobGroup: undefined,
        status: undefined,
        jobRangeDateTime: undefined,
        type: undefined,
      },
    };
  },
  created () {
    this.jobGroupOptions=[
      {dictLabel:'默认',dictValue:'default'},
      {dictLabel:'系统',dictValue:'system'},
    ];
    this.statusOptions=[
      {dictLabel:'开启',dictValue:'0'},
      {dictLabel:'关闭',dictValue:'1'},
    ];
  },
  mounted () {
    //获取传参jobId
    this.jobId=this.$route.params.jobId?this.$route.params.jobId:sessionStorage.getItem('jobId');
    // 获取表格数据
    this.getList();
  },
  methods: {
    /** 查询调度日志列表 */
    getList(params,fun) {
      this.loading=true;
      params=params||{
          pageNum:this.queryParams.pageNum,
          pageSize:this.queryParams.pageSize,
          type:this.queryParams.type
      }
      let resData = db.read().get('logDB').value()[this.jobId];
      // console.log('resData',resData);
      if(params.type==='filter'){
        resData=this.getFilterData(resData);
      }
      this.showData=[];//清空列表
      this.total = resData?resData.length:0;
      if(this.total>0){
        resData=changeArr(resData,params.pageSize);//保存分组后的全部数据,默认一页10条
        this.showData=resData[params.pageNum-1];//显示第一页数据
      }
      this.loading=false;
      if(fun){
        fun();
      }
    },
    getFilterData(filterData=[]){
      // 按条件一层层过滤
      //  任务名称
      if(this.queryParams['jobName']){
        filterData=filterData.filter((item)=>{return item.jobName.indexOf(this.queryParams['jobName'])!=-1});
        // console.log('filter-jobName',filterData);
      }
      // 任务组名
      if(this.queryParams['jobGroup']){
        filterData=filterData.filter((item)=>{return item.jobGroup===this.queryParams['jobGroup']});
        // console.log('filter-jobGroup',filterData);
      }
      // 执行状态
      if(this.queryParams['status']!==undefined){
        filterData=filterData.filter((item)=>{return item.status===this.queryParams['status']});
        // console.log('filter-status',filterData);
      }
      // // 任务地址
      // if(this.queryParams['jobAddr']){
      //   filterData=filterData.filter((item)=>{return item.jobAddr.indexOf(this.queryParams['jobAddr'])!=-1});
      //   // console.log('filter-jobAddr',filterData);
      // }
      // 执行时间
      if(this.queryParams['jobRangeDateTime']&&this.queryParams['jobRangeDateTime'].length===2){
        console.log('jobRangeDateTime',this.queryParams['jobRangeDateTime']);
        filterData=filterData.filter((item)=>{
          let condition1=item.runStartTime>=this.queryParams['jobRangeDateTime'][0]&&item.runEndTime<=this.queryParams['jobRangeDateTime'][1],
              condition2=item.runStartTime<this.queryParams['jobRangeDateTime'][0]&&item.runEndTime>this.queryParams['jobRangeDateTime'][0]&&item.runEndTime<this.queryParams['jobRangeDateTime'][1],
              condition3=item.runStartTime>this.queryParams['jobRangeDateTime'][0]&&item.runEndTime>this.queryParams['jobRangeDateTime'][1];
          if(condition1||condition2||condition3){
            return true
          }
        });
        console.log('filterData',filterData);
      }
      return filterData;
    },
    selectDictLabel(datas, value) {
      var actions = [];
      Object.keys(datas).some((key) => {
        if (datas[key].dictValue == ('' + value)) {
          actions.push(datas[key].dictLabel);
          return true;
        }
      })
      return actions.join('');
    },
    // 任务组名字典翻译
    jobGroupFormat(row) {
      return this.selectDictLabel(this.jobGroupOptions, row.jobGroup);
    },
    // 执行状态字典翻译
    jobStatusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    handleQuery(){
      this.$refs['queryForm'].validate((valid) => {
        if (valid) {
          this.queryParams.type='filter';
          this.getList()
        }
      })
    },
    handleRefresh () {
      location.reload()
    },
    handleBack () {
      // window.history.go(-1);
      this.$router.push({name:'TimingTask'});
    },
    resetQuery () {
      this.$refs['queryForm'].resetFields()
      this.queryParams={
        pageNum: 1,
        pageSize: 10,
        jobName: undefined,
        jobAddr: undefined,
        jobGroup: undefined,
        status: undefined,
        jobRangeDateTime: undefined,
        type: undefined,
      },
      this.getList()
    },
    handleSizeChange (val) {
      this.queryParams.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.queryParams.pageNum = val
      this.getList()
    },
  }
}
</script>