index.vue 2.6 KB

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