index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div v-if="errorLogs.length > 0">
  3. <el-badge
  4. :value="errorLogs.length"
  5. @click.native="dialogTableVisible = true"
  6. >
  7. <el-button type="danger">
  8. <vab-icon :icon="['fas', 'bug']" />
  9. </el-button>
  10. </el-badge>
  11. <el-dialog
  12. :visible.sync="dialogTableVisible"
  13. append-to-body
  14. width="70%"
  15. title="vue-admin-beautiful异常捕获(温馨提示:错误必须解决)"
  16. >
  17. <el-table :data="errorLogs">
  18. <el-table-column label="报错路由">
  19. <template slot-scope="{ row }">
  20. <a :href="row.url" target="_blank">
  21. <el-tag type="success">{{ row.url }}</el-tag>
  22. </a>
  23. </template>
  24. </el-table-column>
  25. <el-table-column label="错误信息">
  26. <template slot-scope="{ row }">
  27. <el-tag type="danger">{{ decodeUnicode(row.err.message) }}</el-tag>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="错误详情" width="120">
  31. <template slot-scope="scope">
  32. <el-popover placement="top-start" trigger="hover">
  33. <div style="color: red">
  34. {{ scope.row.err.stack }}
  35. </div>
  36. <el-button slot="reference">查看</el-button>
  37. </el-popover>
  38. </template>
  39. </el-table-column>
  40. <el-table-column width="380" label="操作">
  41. <template slot-scope="{ row }">
  42. <a
  43. v-for="(item, index) in searchList"
  44. :key="index"
  45. :href="item.url + decodeUnicode(row.err.message)"
  46. target="_blank"
  47. >
  48. <el-button style="margin-left: 5px" type="primary">
  49. <vab-icon :icon="['fas', 'search']" />
  50. {{ item.title }}
  51. </el-button>
  52. </a>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <span slot="footer" class="dialog-footer">
  57. <el-button @click="dialogTableVisible = false">取 消</el-button>
  58. <el-button type="danger" icon="el-icon-delete" @click="clearAll">
  59. 暂不显示
  60. </el-button>
  61. </span>
  62. </el-dialog>
  63. </div>
  64. </template>
  65. <script>
  66. import { abbreviation, title } from '@/config'
  67. import { mapGetters } from 'vuex'
  68. export default {
  69. name: 'VabErrorLog',
  70. data() {
  71. return {
  72. dialogTableVisible: false,
  73. title: title,
  74. abbreviation: abbreviation,
  75. searchList: [
  76. {
  77. title: '百度搜索',
  78. url: 'https://www.baidu.com/baidu?wd=',
  79. },
  80. {
  81. title: '谷歌搜索',
  82. url: 'https://www.google.com/search?q=',
  83. },
  84. {
  85. title: 'Magi搜索',
  86. url: 'https://magi.com/search?q=',
  87. },
  88. ],
  89. }
  90. },
  91. computed: {
  92. ...mapGetters({
  93. errorLogs: 'errorLog/errorLogs',
  94. }),
  95. },
  96. methods: {
  97. clearAll() {
  98. this.dialogTableVisible = false
  99. this.$store.dispatch('errorLog/clearErrorLog')
  100. },
  101. decodeUnicode(str) {
  102. str = str.replace(/\\/g, '%')
  103. str = unescape(str)
  104. str = str.replace(/%/g, '\\')
  105. str = str.replace(/\\/g, '')
  106. return str
  107. },
  108. },
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. ::v-deep {
  113. .el-badge {
  114. .el-button {
  115. display: flex;
  116. align-items: center;
  117. justify-items: center;
  118. height: 28px;
  119. }
  120. }
  121. }
  122. </style>