Blame view

src/views/sys/error-log/index.vue 2.63 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
      </template>
    </BasicTable>
  </div>
</template>
30
<script lang="ts" setup>
Vben authored
31
  import type { ErrorLogInfo } from '/#/store';
32
  import { watch, ref, nextTick } from 'vue';
vben authored
33
  import DetailModal from './DetailModal.vue';
vben authored
34
  import { BasicTable, useTable, TableAction } from '/@/components/Table/index';
35
  import { useModal } from '/@/components/Modal';
vben authored
36
  import { useMessage } from '/@/hooks/web/useMessage';
vben authored
37
  import { useI18n } from '/@/hooks/web/useI18n';
Vben authored
38
  import { useErrorLogStore } from '/@/store/modules/errorLog';
vben authored
39
40
41
42
  import { fireErrorApi } from '/@/api/demo/error';
  import { getColumns } from './data';
  import { cloneDeep } from 'lodash-es';
43
44
  const rowInfo = ref<ErrorLogInfo>();
  const imgList = ref<string[]>([]);
vben authored
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  const { t } = useI18n();
  const errorLogStore = useErrorLogStore();
  const [register, { setTableData }] = useTable({
    title: t('sys.errorLog.tableTitle'),
    columns: getColumns(),
    actionColumn: {
      width: 80,
      title: 'Action',
      dataIndex: 'action',
      slots: { customRender: 'action' },
    },
  });
  const [registerModal, { openModal }] = useModal();
vben authored
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  watch(
    () => errorLogStore.getErrorLogInfoList,
    (list) => {
      nextTick(() => {
        setTableData(cloneDeep(list));
      });
    },
    {
      immediate: true,
    }
  );
  const { createMessage } = useMessage();
  if (import.meta.env.DEV) {
    createMessage.info(t('sys.errorLog.enableMessage'));
  }
  // 查看详情
  function handleDetail(row: ErrorLogInfo) {
    rowInfo.value = row;
    openModal(true);
  }
vben authored
80
81
82
83
  function fireVueError() {
    throw new Error('fire vue error!');
  }
vben authored
84
85
86
87
  function fireResourceError() {
    imgList.value.push(`${new Date().getTime()}.png`);
  }
vben authored
88
89
90
91
  async function fireAjaxError() {
    await fireErrorApi();
  }
vben authored
92
</script>