|
| 1 | +import { defineComponent, ref } from 'vue' |
| 2 | +import { Modal, Button, addToast } from '@munet/ui' |
| 3 | +import { useI18n } from 'vue-i18n' |
| 4 | +import { errorDialogShow, errorMessage, errorDetail } from '@/utils/globalCapture' |
| 5 | + |
| 6 | +const REPO_URL = 'https://github.com/MuNET-OSS/ChuChartManager' |
| 7 | + |
| 8 | +export default defineComponent({ |
| 9 | + setup() { |
| 10 | + const { t } = useI18n() |
| 11 | + const showDetail = ref(false) |
| 12 | + |
| 13 | + const copy = async () => { |
| 14 | + try { |
| 15 | + await navigator.clipboard.writeText(`${errorMessage.value}\n\n${errorDetail.value}`) |
| 16 | + addToast({ message: t('error.copied'), type: 'success' }) |
| 17 | + } catch { |
| 18 | + addToast({ message: t('error.copyFailed'), type: 'error' }) |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + const report = () => { |
| 23 | + const title = `[Bug] ${errorMessage.value}`.slice(0, 120) |
| 24 | + const body = `## 问题描述\n\n\n## 错误信息\n\`\`\`\n${errorDetail.value}\n\`\`\`` |
| 25 | + const url = `${REPO_URL}/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}` |
| 26 | + window.open(url, '_blank') |
| 27 | + } |
| 28 | + |
| 29 | + return () => ( |
| 30 | + <Modal |
| 31 | + width="min(85vw,45em)" |
| 32 | + title={t('error.title')} |
| 33 | + v-model:show={errorDialogShow.value} |
| 34 | + > |
| 35 | + {{ |
| 36 | + default: () => ( |
| 37 | + <div class="flex flex-col gap-3"> |
| 38 | + <div class="c-#d33 break-all">{errorMessage.value}</div> |
| 39 | + |
| 40 | + <div |
| 41 | + class="text-sm op-60 cursor-pointer flex items-center gap-1" |
| 42 | + onClick={() => showDetail.value = !showDetail.value} |
| 43 | + > |
| 44 | + <div class={showDetail.value ? 'i-mdi-chevron-down' : 'i-mdi-chevron-right'} /> |
| 45 | + {t('error.detail')} |
| 46 | + </div> |
| 47 | + {showDetail.value && ( |
| 48 | + <pre class="text-xs bg-black/5 rd p-2 of-auto max-h-50vh whitespace-pre-wrap break-all m-0"> |
| 49 | + {errorDetail.value} |
| 50 | + </pre> |
| 51 | + )} |
| 52 | + </div> |
| 53 | + ), |
| 54 | + actions: () => ( |
| 55 | + <> |
| 56 | + <Button onClick={copy}>{t('error.copy')}</Button> |
| 57 | + <Button onClick={report}>{t('error.report')}</Button> |
| 58 | + </> |
| 59 | + ), |
| 60 | + }} |
| 61 | + </Modal> |
| 62 | + ) |
| 63 | + }, |
| 64 | +}) |
0 commit comments