index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="p-4">
  3. <template v-for="src in imgListRef" :key="src">
  4. <img :src="src" v-show="false" />
  5. </template>
  6. <DetailModal :info="rowInfoRef" @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">
  30. import { defineComponent, watch, ref, nextTick } from 'vue';
  31. import DetailModal from './DetailModal.vue';
  32. import { BasicTable, useTable, TableAction } from '/@/components/Table/index';
  33. import { useModal } from '/@/components/Modal/index';
  34. import { useMessage } from '/@/hooks/web/useMessage';
  35. import { useI18n } from '/@/hooks/web/useI18n';
  36. import { errorStore, ErrorInfo } from '/@/store/modules/error';
  37. import { fireErrorApi } from '/@/api/demo/error';
  38. import { getColumns } from './data';
  39. import { cloneDeep } from 'lodash-es';
  40. import { isDevMode } from '/@/utils/env';
  41. export default defineComponent({
  42. name: 'ErrorHandler',
  43. components: { DetailModal, BasicTable, TableAction },
  44. setup() {
  45. const rowInfoRef = ref<ErrorInfo>();
  46. const imgListRef = ref<string[]>([]);
  47. const { t } = useI18n();
  48. const [register, { setTableData }] = useTable({
  49. title: t('sys.errorLog.tableTitle'),
  50. columns: getColumns(),
  51. actionColumn: {
  52. width: 80,
  53. title: 'Action',
  54. dataIndex: 'action',
  55. slots: { customRender: 'action' },
  56. },
  57. });
  58. const [registerModal, { openModal }] = useModal();
  59. watch(
  60. () => errorStore.getErrorInfoState,
  61. (list) => {
  62. nextTick(() => {
  63. setTableData(cloneDeep(list));
  64. });
  65. },
  66. {
  67. immediate: true,
  68. }
  69. );
  70. const { createMessage } = useMessage();
  71. if (isDevMode()) {
  72. createMessage.info(t('sys.errorLog.enableMessage'));
  73. }
  74. // 查看详情
  75. function handleDetail(row: ErrorInfo) {
  76. rowInfoRef.value = row;
  77. openModal(true);
  78. }
  79. function fireVueError() {
  80. throw new Error('fire vue error!');
  81. }
  82. function fireResourceError() {
  83. imgListRef.value.push(`${new Date().getTime()}.png`);
  84. }
  85. async function fireAjaxError() {
  86. await fireErrorApi();
  87. }
  88. return {
  89. register,
  90. registerModal,
  91. handleDetail,
  92. fireVueError,
  93. fireResourceError,
  94. fireAjaxError,
  95. imgListRef,
  96. rowInfoRef,
  97. t,
  98. };
  99. },
  100. });
  101. </script>