<template>
  <div class="system-logs h-full w-full">
    <TableHeader>
      <div slot="right" class="flex">
        <el-input
          size="small"
          v-model="searchVal"
          style="width: 200px"
          class="mr-[10px]"
          placeholder="请输入请求地址搜索"
          @keyup.native.enter="handleSearch"
        ></el-input>
        <el-button size="small" type="primary" @click="handleSearch"
          >搜 索</el-button
        >
        <el-button size="small" @click="handleReset">重 置</el-button>
      </div>
    </TableHeader>
    <!-- 表格 -->
    <div class="table-content">
      <y-table
        ref="MyTable"
        :loading="loading"
        :data="tableData"
        :column="column"
        border
        tooltip-effect="dark"
        :max-height="600"
        :row-key="(row) => row.id"
      ></y-table>
    </div>
    <Pagination
      :total="total"
      :current.sync="current"
      :size.sync="size"
      @get="getlogsList"
    ></Pagination>
  </div>
</template>

<script>
import TableHeader from "@/components/TableHeader.vue";
import { getlogsList } from "@/api/system";
export default {
  components: {
    TableHeader,
  },
  data() {
    return {
      column: [
        {
          label: "序号",
          type: "index",
          width: "55",
          align: "center",
          index: (index) => {
            return (this.current - 1) * this.size + index + 1;
          },
        },

        {
          label: "用户名称",
          prop: "userName",
          align: "center",
        },
        {
          label: "登录名称",
          prop: "loginName",
          align: "center",
        },
        {
          label: "请求地址",
          prop: "requestUrl",
          align: "center",
        },
        {
          label: "操作内容",
          prop: "content",
          align: "center",
        },
        {
          label: "操作IP地址",
          prop: "ip",
          align: "center",
        },
        {
          label: "操作时间",
          prop: "logDate",
          align: "center",
          formatter: (row) => {
            return this.$moment(row.logDate).format("YYYY-MM-DD HH:mm:ss");
          },
        },
      ],
      searchVal: "",
      tableData: [],
      current: 1,
      size: 10,
      total: 10,
      loading: false,
      selectKeys: [],
      dict: {}, // 字典
    };
  },
  created() {
    this.getlogsList();
  },
  computed: {},
  methods: {
    // 系统事项列表
    async getlogsList() {
      this.loading = true;
      let res = await getlogsList({
        page: this.current,
        size: this.size,
        requestUrl: `%${this.searchVal}%`,
      });
      if (res.data.code == 1) {
        let { data, total, dict } = res.data.data;
        this.dict = dict;
        if (!data.length && this.current > 1) {
          this.current -= 1;
          this.getlogsList();
        }
        this.tableData = data;
        this.total = total;
      }
      this.loading = false;
    },

    // 搜索
    handleSearch() {
      this.current = 1;
      this.$clearSelection("MyTable");
      this.getlogsList();
    },
    // 重置
    handleReset() {
      this.searchVal = "";
      this.current = 1;
      this.$clearSelection("MyTable");
      this.getlogsList();
    },
  },
};
</script>

<style lang="less" scoped></style>
