Blame view

src/views/sys/error-log/index.vue 3.1 KB
vben authored
1
2
<template>
  <div class="p-4">
3
    <template v-for="src in imgList" :key="src">
vben authored
4
5
      <img :src="src" v-show="false" />
    </template>
6
    <DetailModal :info="rowInfo" @register="registerModal" />
vben authored
7
8
    <BasicTable @register="register" class="error-handle-table">
      <template #toolbar>
vben authored
9
10
11
12
13
14
15
16
17
        <a-button @click="fireVueError" type="primary">
          {{ t('sys.errorLog.fireVueError') }}
        </a-button>
        <a-button @click="fireResourceError" type="primary">
          {{ t('sys.errorLog.fireResourceError') }}
        </a-button>
        <a-button @click="fireAjaxError" type="primary">
          {{ t('sys.errorLog.fireAjaxError') }}
        </a-button>
vben authored
18
19
      </template>
      <template #action="{ record }">
vben authored
20
21
22
23
24
        <TableAction
          :actions="[
            { label: t('sys.errorLog.tableActionDesc'), onClick: handleDetail.bind(null, record) },
          ]"
        />
vben authored
25
26
27
28
29
30
31
32
33
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts">
  import { defineComponent, watch, ref, nextTick } from 'vue';

  import DetailModal from './DetailModal.vue';
vben authored
34
35
  import { BasicTable, useTable, TableAction } from '/@/components/Table/index';
vben authored
36
  import { useModal } from '/@/components/Modal/index';
vben authored
37
  import { useMessage } from '/@/hooks/web/useMessage';
vben authored
38
  import { useI18n } from '/@/hooks/web/useI18n';
vben authored
39
40
41
42
43
44
45
46

  import { errorStore, ErrorInfo } from '/@/store/modules/error';

  import { fireErrorApi } from '/@/api/demo/error';

  import { getColumns } from './data';

  import { cloneDeep } from 'lodash-es';
vben authored
47
  import { isDevMode } from '/@/utils/env';
vben authored
48
49
50
51
52

  export default defineComponent({
    name: 'ErrorHandler',
    components: { DetailModal, BasicTable, TableAction },
    setup() {
53
54
      const rowInfo = ref<ErrorInfo>();
      const imgList = ref<string[]>([]);
vben authored
55
56
      const { t } = useI18n();
vben authored
57
vben authored
58
      const [register, { setTableData }] = useTable({
vben authored
59
        title: t('sys.errorLog.tableTitle'),
vben authored
60
61
62
        columns: getColumns(),
        actionColumn: {
          width: 80,
vben authored
63
          title: 'Action',
vben authored
64
65
66
67
68
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });
      const [registerModal, { openModal }] = useModal();
vben authored
69
vben authored
70
71
72
73
74
75
76
77
78
79
80
      watch(
        () => errorStore.getErrorInfoState,
        (list) => {
          nextTick(() => {
            setTableData(cloneDeep(list));
          });
        },
        {
          immediate: true,
        }
      );
vben authored
81
82
      const { createMessage } = useMessage();
      if (isDevMode()) {
83
        createMessage.info(t('sys.errorLog.enableMessage'));
vben authored
84
      }
vben authored
85
86
      // 查看详情
      function handleDetail(row: ErrorInfo) {
87
        rowInfo.value = row;
vben authored
88
89
90
91
92
93
94
95
        openModal(true);
      }

      function fireVueError() {
        throw new Error('fire vue error!');
      }

      function fireResourceError() {
96
        imgList.value.push(`${new Date().getTime()}.png`);
vben authored
97
98
99
100
101
102
103
104
105
106
107
108
109
      }

      async function fireAjaxError() {
        await fireErrorApi();
      }

      return {
        register,
        registerModal,
        handleDetail,
        fireVueError,
        fireResourceError,
        fireAjaxError,
110
111
        imgList,
        rowInfo,
vben authored
112
        t,
vben authored
113
114
115
116
      };
    },
  });
</script>