index.vue 2.8 KB

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