index.vue 10.7 KB
<template>
  <div class="box">
    <div class="innerBox operationLog">
      <search-top 
        :searchForm="searchForm" 
        :searchData="searchData"
        @search="handleSearch">
      </search-top>
      <div class="user-btn">
        <permission-button
          btnType="all"
          :btnData="btnData"
          @btnClick="btnClick">
        </permission-button>
      </div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="logTableData"
        style="width: 100%; "
        :cell-style="cellStyle"
        :header-cell-style="{background:'#f5f7fa'}"
        @row-click="handleRowClick"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          v-for="(item, index) in tableColumn"
          :key="index"
          :prop="item.prop"
          :label="item.label"
          >
          <template slot-scope="scope">
            <template>
              {{logTableData[scope.$index][item.prop]?logTableData[scope.$index][item.prop]:'--'}}
            </template>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="pageIndex"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="pageSize"
        layout="total, slot, ->, prev, pager, next, sizes, jumper"
        :total="total">
        <span class="el-pagination__total">第{{pageIndex}}/{{Math.ceil(total/pageSize)}}页</span>
      </el-pagination>
    </div>
  </div>
</template>

<script>
import store from "@/store"
import SearchTop from '@/components/SearchTop'
import permissionButton from "@/components/PermissionButton"
import { getOperationLogList, deleteOperationLog, exportOperationLog ,getDictDataListByKey} from '@/api/system'

export default {
  name: "operationLog",
  components: {
    SearchTop,
    permissionButton
  },
  data() {
    return {
      // 分页参数
      pageIndex: 1,
      pageSize: 10,
      total: 20,
      multipleSelection: [],
      selectAll: [],
      selectSum: 0,
      // form表单绑定的值
      searchParams: {
        'beginDate':this.$Common.filterTime(new Date()).slice(0,10),
        'endDate':this.$Common.filterTime(new Date()).slice(0,10),
      },
      searchForm: {
        name: '',
        number: '',
        time:[this.$Common.filterTime(new Date()).slice(0,10),this.$Common.filterTime(new Date()).slice(0,10)],
        option: ''
      },
      // select组件的option选项
      optionValue: [],
      // 表单信息;modelValue的值需与searchForm的属性一一对应。
      searchData: [
        { modelValue: 'name', label: '系统菜单:', type: 'input' },
        { modelValue: 'number', label: '操作账号:', type: 'input' },
        { modelValue: 'time', label: '操作时间:', type: 'time' ,},
        { modelValue: 'option', label: '操作类型:', type: 'select', optionValue: '' }
      ],
      // 表格参数
      tableColumn: [
        { prop: 'id', label: '日志编号' },
        { prop: 'menuName', label: '系统菜单',width:200 },
        { prop: 'operateTypeName', label: '操作类型' },
        { prop: 'createBy', label: '操作账号' },
        { prop: 'orgName', label: '所属组织' },
        { prop: 'ip', label: '主机IP' },
        { prop: 'address', label: '操作地点' },
        { prop: 'remark', label: '操作状态',width:100  },
        { prop: 'createTime', label: '创建时间',width:200  }
      ],
      logTableData: [],
      loading: true,

      // 按钮
      btnData: [
        // {
        //   type: "primary",
        //   name: "删除",
        //   pType: "delete"
        // }, {
        //   type: "primary",
        //   name: "导出",
        //   pType: "export"
        // }
      ]
    }
  },
  mounted() {
    this.getList();
    this.getDictDataListByKey();

    //权限按钮
    var allBtn = this.$Common.filterAsycRouter(this.$store.getters.asycRouters,'/system/operationLog');
    if(allBtn&&allBtn.length>0){
      //清空默认的的
      this.listBtnData = []
      this.btnData = []
      
      allBtn.map( item => {
        // if(item.pType == 'x'){
        //   item.type = 'text';
        //   this.listBtnData.push(item)
        // }
        if(item.pType == 'delete' || item.pType == 'export'){
          this.btnData.push({
            'type': "primary",
            'name':item.name,
            'pType': item.pType,
          })
        }
      })
    }

  },
  methods: {
    //获取 服务类型  数据
    getDictDataListByKey() {
      // {'1':"GPS"},{'2':"导航"},{'3':"后视镜"},{'4':"记录仪"},{'5':"座椅"},{'6':"贴膜"}];
      // this.searchData[3].optionValue = [
      //   { value: 'new', label: '新增' },
      //   { value: 'delete', label: '删除' },
      //   { value: 'down', label: '导出' }
      // ];
      // return
      getDictDataListByKey({'dictType':'sys_log_operate_type'}).then( response => {
        var arr = []
        response.data.items.map( item => {
          arr.push({
            // 'value':item.id,
            'value':item.dataKey,
            'label':item.dataValue,
          })
        })
        this.searchData[3].optionValue = arr;
      }).catch( error => {})
    },
    //重置 数据 
    clearAllData(type){
      console.log('=-------------清楚查询数据')
      this.pageIndex = 1;
      
      var arr = ['name','character','time','status']
      var arrAsyc = ['userName','phoneNumber','operateType','userStatus','sTime','eTime']

      switch(type){
        case 'search':
          //增加 修改 删除 tree 得重置查询条件
          let obj = {};
          let obj2 = {};
          arrAsyc.map( item => {
            obj[item] = ''
          })
          arr.map( item => {
            obj2[item] = ''
          })
          this.$set(this,'searchParams',obj)
          this.$set(this,'searchForm',obj2)
        break;
        case 'select':
          this.selectAll = [];
          this.selectSum = 0;
        break;
      }
    },
    getParams() {
      this.searchParams.pageSize = this.pageSize
      this.searchParams.pageIndex = this.pageIndex
      return this.searchParams
    },
    mergeAllSelection() {
      console.log('删除接口---------mergeAllSelection-----------------------',this.selectAll)
      let arr = []
      for(var i in this.selectAll) {
        this.selectAll[i].length && arr.push(...this.selectAll[i])
      }
      return arr
    },
    // 接口-start
    getList() {
      this.logTableData = [];
      this.loading = true 
      const params = this.getParams()
      // console.log('查询List--')
      // console.log(params)
      getOperationLogList(params).then(res => {
        this.logTableData = res.data.items
        this.total = res.data.page.totalCount
        this.loading = false 

        this.$nextTick(() => {
          if(this.selectAll[this.pageIndex]) {
            for(var tableIndex in this.logTableData) {
              for(var selectIndex in this.selectAll[this.pageIndex]) {
                if(this.logTableData[tableIndex].id == this.selectAll[this.pageIndex][selectIndex].id) {
                  this.$refs.multipleTable.toggleRowSelection(this.logTableData[tableIndex])
                }
              }
            }
          }
        })
      }).catch(err => {})
    },
    deleteOperationLog() {
      // console.log('删除接口--')
      const ids = []
      this.selectAll.forEach(element => {
        element.forEach(item => {
          ids.push(item.id)
        })
      })
      deleteOperationLog({'ids':ids}).then(res => {
        console.log(res.data,'-------------------------log delete back ')
        if(res.code == 200){
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        }else{
          that.$message({
            type: "error",
            message: response.message
          });
        }
        this.getList();
        //清除 查询 order 条件
        this.clearAllData('select');
      })
    },
    exportOperationLog() {
      let arr = this.mergeAllSelection()
      // console.log(arr)
      exportOperationLog().then(res => {
        console.log('导出List--')
        console.log(res.data)
        this.$message({
          message: '导出成功',
          type: 'success'
        })
      })
    },
    // 接口-end
    // 查询;获取到用户输入
    handleSearch(params) {
      //清除 查询 order 条件
      this.clearAllData('select');

      let obj = {};
      obj.menuName = params.name;
      obj.createBy = params.number;
      obj.operateType = params.option;
      obj.beginDate = params.time ? params.time[0] : undefined;
      obj.endDate = params.time ? params.time[1] : undefined;
      
      this.searchParams = obj
      this.getList()
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getList()
    },
    selectValChange() {
      !this.selectAll[this.pageIndex]
      ? 
      this.selectSum = this.selectSum + this.multipleSelection.length
      : 
      this.selectSum = this.selectSum - this.selectAll[this.pageIndex].length + this.multipleSelection.length;
      this.selectAll[this.pageIndex] = this.multipleSelection;
    },
    handleCurrentChange(val) {
      this.selectValChange()
      this.pageIndex = val
      this.getList()
    },
    handleRowClick(row, e, col) {
      this.$Common.rowClick(this, row, col)
    },
    handleSelectionChange(val, row) {
      this.multipleSelection = val
    },
    handleDelete() {
      !this.selectSum
      ?
      this.$message({
        message: '请选择要删除的数据!',
        type: 'warning'
      })
      :
      this.$confirm("是否删除当前"+this.selectSum+"条记录?", '提示', {
        type: 'error',
        confirmButtonText: "继续",
        showCancelButton: false
      }).then(() => {
        this.deleteOperationLog()
        // console.log('删除接口--')
      }).catch(() => {})
    },
    cellStyle({row, column, rowIndex, columnIndex}) {
      const rowGray = [0, 1]
      const colGreen = [6]
      const colBlue = [7, 8]
      if(rowGray.includes(rowIndex) && colGreen.includes(columnIndex)) {
        return 'color:#BFBFBF'
      }
      if(colGreen.includes(columnIndex)) {
        return 'color:#00A854'
      }
      if(colBlue.includes(columnIndex)) {
        return 'color:#1890FF'
      }
    },
    // 按钮事件
    btnClick(pType) {
      this.selectValChange()
      switch(pType) {
        case 'delete':
          this.handleDelete()
          break
        case 'export':
          this.exportOperationLog()
          break
      }
    }
  }
}
</script>

<style>
.operationLog .el-pagination {
  padding: 20px;
}
.operationLog .el-table tr {
  cursor: pointer;
  height: 57px;
}
</style>