zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <avue-crud
    :data="list"
    :option="option"
    :page="page"
    @current-change="currentChange"
    @size-change="sizeChange">
    <template slot="menuLeft">
      <el-button
        type="primary"
        size="small"
        icon="el-icon-upload"
        @click="send">上传服务器</el-button>
      <el-button
        type="danger"
        size="small"
        icon="el-icon-delete"
        @click="clear">清空本地日志</el-button>
    </template>
    <template
      slot-scope="scope"
      slot="type">
      <el-tag
        type="danger"
        size="small">{{ scope.label }}</el-tag>
    </template>
    <template
      slot-scope="props"
      slot="expand">
      <pre class="code">
        {{ props.row.stack }}
      </pre>
    </template>
  </avue-crud>
</template>
 
<script>
import { mapGetters } from 'vuex'
import option from '@/const/logs/index'
export default {
  name: 'ErrLogs',
  data() {
    return {
      // 默认不分页,若记录数超过,则分页
      onePageMaxSize: 10,
      page: {
        currentPage: 1,
        pageSize: 20,
        total: 0
      },
      option: option,
      list: []
    }
  },
  created() {
 
  },
  mounted() {
    this.getList();
  },
  computed: {
    ...mapGetters(['logsList', 'logsLen'])
  },
  methods: {
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getList();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.getList();
    },
    getList() {
      const total = this.logsLen;
      if (total <= this.onePageMaxSize) {
        this.list = this.logsList;
      } else {
        const currentPage = this.page.currentPage;
        const pageSize = this.page.pageSize;
        this.list = this.logsList.slice((currentPage - 1) * pageSize, currentPage * pageSize);
        this.page.total = total;
      }
    },
    send() {
      this.$confirm('确定上传本地日志到服务器?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal:false,
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('SendLogs').then(() => {
          this.$parent.$parent.box = false
          this.$message.success( '发送成功!')
        })
      }).catch(() => {
 
      })
    },
    clear() {
      this.$confirm('确定清空本地日志记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal:false,
        type: 'warning'
      }).then(() => {
        this.page.currentPage = 1;
        this.page.total = 0;
        this.$store.commit('CLEAR_LOGS')
        this.$parent.$parent.box = false
        this.$message.success( '清空成功!')
      }).catch(() => {
 
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
.code {
  font-size: 12px;
  display: block;
  font-family: monospace;
  white-space: pre;
  margin: 0 1em;
}
</style>