<!--
 * @Author: zwq
 * @Date: 2023-01-04 10:29:40
 * @LastEditors: zwq
 * @LastEditTime: 2023-02-28 11:01:49
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
      <base-table
        :table-props="tableProps"
        :page="listQuery.page"
        :limit="listQuery.limit"
        :table-data="tableData"
      />
      <pagination
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getDataList"
      />
    </div>
  </el-card>
</template>

<script>
import basicPage from "@/mixins/basic-page";
import i18n from "@/i18n";
import Cookies from 'js-cookie'
import qs from 'qs'
const tableProps = [
  {
    prop: "requestUri",
    label: i18n.t("logError.requestUri"),
  },
  {
    prop: "requestMethod",
    label: i18n.t("logError.requestMethod"),
  },
  {
    prop: "requestParams",
    label: i18n.t("logError.requestParams"),
  },
  {
    prop: "ip",
    label: i18n.t("logError.ip"),
  },
  {
    prop: "userAgent",
    label: i18n.t("logError.userAgent"),
  },
  {
    prop: "createDate",
    label: i18n.t("logError.createDate"),
  },
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/sys/log/error/page",
        exportUrl: "/sys/log/error/export",
      },
      tableProps,
      formConfig: [
        {
          type: "button",
          btnName: i18n.t("export"),
          name: "export",
          color: "primary",
        },
      ],
    };
  },
  components: {},
  methods:{
    //search-bar点击
    buttonClick(val) {
      switch (val.btnName) {
        case "export":
          this.exportHandle();
          break;
        default:
          console.log(val)
       }
    },
    // 导出
    exportHandle(name) {
      this.$http
        .get(this.urlOptions.exportUrl, { responseType: "blob" })
        .then(({ data: res }) => {
          var date = new Date();
          var year = date.getFullYear();
          var month = date.getMonth() + 1;
          var strDate = date.getDate();
          if (month >= 1 && month <= 9) {
            month = "0" + month;
          }
          if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
          }
          var currentdate = year + "-" + month + "-" + strDate;
          const blob = new Blob([res]);
          const downloadElement = document.createElement("a");
          const href = window.URL.createObjectURL(blob); // 创建下载的链接
          downloadElement.href = href;
          downloadElement.download = `${name + currentdate}.xls`; // 下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); // 点击下载
          document.body.removeChild(downloadElement); // 下载完成移除元素
          window.URL.revokeObjectURL(href);
        })
        .catch(() => { });
    }
  }
};
</script>
