index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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">
  30. import type { ErrorLogInfo } from '/#/store';
  31. import { defineComponent, 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/index';
  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. export default defineComponent({
  42. name: 'ErrorHandler',
  43. components: { DetailModal, BasicTable, TableAction },
  44. setup() {
  45. const rowInfo = ref<ErrorLogInfo>();
  46. const imgList = ref<string[]>([]);
  47. const { t } = useI18n();
  48. const errorLogStore = useErrorLogStore();
  49. const [register, { setTableData }] = useTable({
  50. title: t('sys.errorLog.tableTitle'),
  51. columns: getColumns(),
  52. actionColumn: {
  53. width: 80,
  54. title: 'Action',
  55. dataIndex: 'action',
  56. slots: { customRender: 'action' },
  57. },
  58. });
  59. const [registerModal, { openModal }] = useModal();
  60. watch(
  61. () => errorLogStore.getErrorLogInfoList,
  62. (list) => {
  63. nextTick(() => {
  64. setTableData(cloneDeep(list));
  65. });
  66. },
  67. {
  68. immediate: true,
  69. }
  70. );
  71. const { createMessage } = useMessage();
  72. if (import.meta.env.DEV) {
  73. createMessage.info(t('sys.errorLog.enableMessage'));
  74. }
  75. // 查看详情
  76. function handleDetail(row: ErrorLogInfo) {
  77. rowInfo.value = row;
  78. openModal(true);
  79. }
  80. function fireVueError() {
  81. throw new Error('fire vue error!');
  82. }
  83. function fireResourceError() {
  84. imgList.value.push(`${new Date().getTime()}.png`);
  85. }
  86. async function fireAjaxError() {
  87. await fireErrorApi();
  88. }
  89. return {
  90. register,
  91. registerModal,
  92. handleDetail,
  93. fireVueError,
  94. fireResourceError,
  95. fireAjaxError,
  96. imgList,
  97. rowInfo,
  98. t,
  99. };
  100. },
  101. });
  102. </script>