index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <avue-crud
  3. :data="list"
  4. :option="option"
  5. :page="page"
  6. @current-change="currentChange"
  7. @size-change="sizeChange">
  8. <template slot="menuLeft">
  9. <el-button
  10. type="primary"
  11. size="small"
  12. icon="el-icon-upload"
  13. @click="send">上传服务器</el-button>
  14. <el-button
  15. type="danger"
  16. size="small"
  17. icon="el-icon-delete"
  18. @click="clear">清空本地日志</el-button>
  19. </template>
  20. <template
  21. slot-scope="scope"
  22. slot="type">
  23. <el-tag
  24. type="danger"
  25. size="small">{{ scope.label }}</el-tag>
  26. </template>
  27. <template
  28. slot-scope="props"
  29. slot="expand">
  30. <pre class="code">
  31. {{ props.row.stack }}
  32. </pre>
  33. </template>
  34. </avue-crud>
  35. </template>
  36. <script>
  37. import { mapGetters } from 'vuex'
  38. import option from '@/const/logs/index'
  39. export default {
  40. name: 'ErrLogs',
  41. data() {
  42. return {
  43. page: {
  44. currentPage: 1,
  45. pageSize: 10,
  46. // 默认不分页,若记录数超过pageSize条,则分页
  47. total: 0
  48. },
  49. option: option,
  50. list: []
  51. }
  52. },
  53. created() {
  54. },
  55. mounted() {
  56. this.getList();
  57. },
  58. computed: {
  59. ...mapGetters(['logsList', 'logsLen'])
  60. },
  61. methods: {
  62. sizeChange(pageSize) {
  63. this.page.pageSize = pageSize;
  64. this.getList();
  65. },
  66. currentChange(currentPage) {
  67. this.page.currentPage = currentPage;
  68. this.getList();
  69. },
  70. getList() {
  71. const total = this.logsLen;
  72. const pageSize = this.page.pageSize;
  73. if (total <= pageSize) {
  74. this.list = this.logsList;
  75. } else {
  76. // 超过一页记录,开启分页
  77. const currentPage = this.page.currentPage;
  78. this.list = this.logsList.slice((currentPage - 1) * pageSize, currentPage * pageSize);
  79. this.page.total = total;
  80. }
  81. },
  82. send() {
  83. this.$confirm('确定上传本地日志到服务器?', '提示', {
  84. confirmButtonText: '确定',
  85. cancelButtonText: '取消',
  86. type: 'warning'
  87. }).then(() => {
  88. this.$store.dispatch('SendLogs').then(() => {
  89. this.$parent.$parent.box = false
  90. this.$message.success( '发送成功!')
  91. })
  92. }).catch(() => {
  93. })
  94. },
  95. clear() {
  96. this.$confirm('确定清空本地日志记录?', '提示', {
  97. confirmButtonText: '确定',
  98. cancelButtonText: '取消',
  99. type: 'warning'
  100. }).then(() => {
  101. this.$store.commit('CLEAR_LOGS')
  102. this.$parent.$parent.box = false
  103. this.$message.success( '清空成功!')
  104. }).catch(() => {
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .code {
  112. font-size: 12px;
  113. display: block;
  114. font-family: monospace;
  115. white-space: pre;
  116. margin: 0 1em;
  117. }
  118. </style>