index.vue 9.03 KB
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="仓库" prop="warehouseCode">
        <el-select
          v-model="queryParams.warehouseCode"
          placeholder="仓库"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in warehouseOptions"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="登录地址" prop="ipaddr">
        <el-input
          v-model="queryParams.ipaddr"
          placeholder="请输入登录地址"
          clearable
          style="width: 240px"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名称"
          clearable
          style="width: 240px"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="登录状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="登录时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:logininfor:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:logininfor:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :col-data="colData"
        @selectData="selectData"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="访问编号"
        align="center"
        prop="infoId"
        width="120"
        v-if="colData[0].istrue"
      />
      <el-table-column
        label="仓库"
        align="center"
        prop="warehouseCode"
        v-if="colData[1].istrue"
        width="150"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          {{ warehouseCodeFormat(scope.row, scope.column) }}
        </template>
      </el-table-column>
      <el-table-column
        label="用户名称"
        align="center"
        prop="userName"
        width="150"
        :show-overflow-tooltip="true"
        v-if="colData[2].istrue"
      />
      <el-table-column
        label="地址"
        align="center"
        prop="ipaddr"
        :show-overflow-tooltip="true"
        width="180"
        v-if="colData[3].istrue"
      />
      <el-table-column
        label="状态"
        align="center"
        prop="status"
        width="150"
        v-if="colData[4].istrue"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            :type="scope.row.status == 0 ? 'success' : 'danger'"
            round
            >{{ statusFormat(scope.row, scope.column) }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        label="描述"
        align="center"
        prop="msg"
        width="200"
        :show-overflow-tooltip="true"
        v-if="colData[5].istrue"
      />
      <el-table-column
        label="访问时间"
        align="center"
        prop="accessTime"
        min-width="180"
        v-if="colData[6].istrue"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accessTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { list, delLogininfor } from "@/api/system/logininfor";
import { getWarehouseByUserCode } from "@/api/system/warehouse";

export default {
  name: "Logininfor",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 状态数据字典
      statusOptions: [],
      // 仓库数据字典
      warehouseOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        warehouseCode: undefined,
        ipaddr: undefined,
        userName: undefined,
        status: undefined,
      },
      // istrue属性存放列的状态
      colData: [
        { title: "访问编号", istrue: false },
        { title: "仓库", istrue: true },
        { title: "用户名称", istrue: true },
        { title: "地址", istrue: true },
        { title: "状态", istrue: true },
        { title: "描述", istrue: true },
        { title: "访问时间", istrue: true, disabled: true },
      ],
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_common_status").then((response) => {
      this.statusOptions = response.data;
    });
    getWarehouseByUserCode(this.$store.getters.name).then((response) => {
      this.warehouseOptions = response.data;
    });
  },
  beforeUpdate() {
    this.$nextTick(() => {
      this.$refs["table"].doLayout();
    });
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      list(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 登录状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 仓库字典翻译
    warehouseCodeFormat(row, column) {
      return this.selectCommonLabel(this.warehouseOptions, row.warehouseCode);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.infoId);
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const infoIds = row.infoId || this.ids;
      this.$confirm(
        row.infoId
          ? "是否确认删除这条登录日志信息吗?"
          : "是否确认删除选中的" + this.ids.length + "条数据项?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delLogininfor(infoIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/logininfor/export",
        {
          ...this.queryParams,
        },
        `logininfor_${new Date().getTime()}.xlsx`
      );
    },
    /** 表格切换字段显示操作 */
    selectData(val) {
      if (val) {
        this.colData.filter((i) => {
          if (val.indexOf(i.title) !== -1) {
            i.istrue = true;
          } else {
            i.istrue = false;
          }
        });
      }
    },
  },
};
</script>