index.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="p-4">
  3. <template v-for="src in imgList" :key="src">
  4. <img :src="src" v-show="false" />
  5. </template>
  6. <DetailModal :info="rowInfo" @register="registerModal" />
  7. <BasicTable @register="register" class="error-handle-table">
  8. <template #toolbar>
  9. <a-button @click="fireVueError" type="primary">
  10. {{ t('sys.errorLog.fireVueError') }}
  11. </a-button>
  12. <a-button @click="fireResourceError" type="primary">
  13. {{ t('sys.errorLog.fireResourceError') }}
  14. </a-button>
  15. <a-button @click="fireAjaxError" type="primary">
  16. {{ t('sys.errorLog.fireAjaxError') }}
  17. </a-button>
  18. </template>
  19. <template #action="{ record }">
  20. <TableAction :actions="[{ label: t('sys.errorLog.tableActionDesc'), onClick: handleDetail.bind(null, record) }]" />
  21. </template>
  22. </BasicTable>
  23. </div>
  24. </template>
  25. <script lang="ts" setup>
  26. import type { ErrorLogInfo } from '/#/store';
  27. import { watch, ref, nextTick } from 'vue';
  28. import DetailModal from './DetailModal.vue';
  29. import { BasicTable, useTable, TableAction } from '/@/components/Table/index';
  30. import { useModal } from '/@/components/Modal';
  31. import { useMessage } from '/@/hooks/web/useMessage';
  32. import { useI18n } from '/@/hooks/web/useI18n';
  33. import { useErrorLogStore } from '/@/store/modules/errorLog';
  34. import { fireErrorApi } from '/@/api/demo/error';
  35. import { getColumns } from './data';
  36. import { cloneDeep } from 'lodash-es';
  37. const rowInfo = ref<ErrorLogInfo>();
  38. const imgList = ref<string[]>([]);
  39. const { t } = useI18n();
  40. const errorLogStore = useErrorLogStore();
  41. const [register, { setTableData }] = useTable({
  42. title: t('sys.errorLog.tableTitle'),
  43. columns: getColumns(),
  44. actionColumn: {
  45. width: 80,
  46. title: 'Action',
  47. dataIndex: 'action',
  48. slots: { customRender: 'action' },
  49. },
  50. });
  51. const [registerModal, { openModal }] = useModal();
  52. watch(
  53. () => errorLogStore.getErrorLogInfoList,
  54. (list) => {
  55. nextTick(() => {
  56. setTableData(cloneDeep(list));
  57. });
  58. },
  59. {
  60. immediate: true,
  61. }
  62. );
  63. const { createMessage } = useMessage();
  64. if (import.meta.env.DEV) {
  65. createMessage.info(t('sys.errorLog.enableMessage'));
  66. }
  67. // 查看详情
  68. function handleDetail(row: ErrorLogInfo) {
  69. rowInfo.value = row;
  70. openModal(true);
  71. }
  72. function fireVueError() {
  73. throw new Error('fire vue error!');
  74. }
  75. function fireResourceError() {
  76. imgList.value.push(`${new Date().getTime()}.png`);
  77. }
  78. async function fireAjaxError() {
  79. await fireErrorApi();
  80. }
  81. </script>