统一前端错误读取和调试日志
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -79,13 +80,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
CreateAnnouncementRequest,
|
||||
UpdateAnnouncementRequest,
|
||||
} from '@/features/admin/api/adminAnnouncements'
|
||||
import { debugError } from '@/shared/utils/debug'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
@@ -89,7 +90,7 @@ async function handleSave() {
|
||||
await formRef.value.validate()
|
||||
emit('save', formData.value)
|
||||
} catch (error) {
|
||||
console.error('表单验证失败', error)
|
||||
debugError('表单验证失败', error)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -94,13 +95,6 @@ function isGroupPartial(perms: Permission[]) {
|
||||
return perms.some(p => selectedPermIds.value.includes(p.id)) && !isGroupAllSelected(perms)
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
const resourceLabels: Record<string, string> = {
|
||||
dashboard: '仪表盘',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -52,13 +53,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
@@ -64,13 +65,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -69,13 +70,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -110,13 +111,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -127,13 +128,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -128,13 +129,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -110,13 +111,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -183,13 +184,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -77,13 +78,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -88,13 +89,6 @@ async function handleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ref, type Ref } from 'vue'
|
||||
import { debugError } from '@/shared/utils/debug'
|
||||
|
||||
interface AdminQueryOptions<T> {
|
||||
fetchFn: () => Promise<T>
|
||||
@@ -25,7 +26,7 @@ export function useAdminQuery<T>(options: AdminQueryOptions<T>): AdminQueryResul
|
||||
data.value = await options.fetchFn()
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : '加载失败'
|
||||
console.error('Failed to load data:', e)
|
||||
debugError('加载后台表格数据失败', e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
@@ -114,13 +115,6 @@ async function handleArbitrate() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { CopyDocument } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
@@ -104,13 +105,6 @@ async function openScreenshot(url: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { Check, Close, Picture, Refresh, Search, WarningFilled } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
@@ -548,13 +549,6 @@ async function openScreenshot(url: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Lock, User } from '@element-plus/icons-vue'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
@@ -51,13 +52,6 @@ async function handleLogin() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -93,13 +94,6 @@ async function handleChangePassword() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
const statusLabel: Record<string, string> = {
|
||||
active: '启用',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
@@ -87,13 +88,6 @@ async function submitAction() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function orderRentedAt() {
|
||||
return order.value?.rented_at
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -85,13 +86,6 @@ async function handleUnfreeze(row: AdminUserItem) {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function moneyCent(value: number | string | undefined) {
|
||||
return formatCent(Number(value || 0))
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Warning,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { fetchAnnouncementDetail, type Announcement } from '@/features/announcement'
|
||||
import { debugError } from '@/shared/utils/debug'
|
||||
import { formatDateTime } from '@/shared/utils/time'
|
||||
import { marked } from 'marked'
|
||||
|
||||
@@ -51,7 +52,7 @@ async function loadAnnouncement() {
|
||||
try {
|
||||
announcement.value = await fetchAnnouncementDetail(id)
|
||||
} catch (err) {
|
||||
console.error('加载公告失败', err)
|
||||
debugError('加载公告失败', err)
|
||||
router.push('/announcements')
|
||||
} finally {
|
||||
loading.value = false
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Warning,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { fetchAnnouncements, type Announcement } from '@/features/announcement'
|
||||
import { debugError } from '@/shared/utils/debug'
|
||||
import { formatDateTime } from '@/shared/utils/time'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -43,7 +44,7 @@ async function loadAnnouncements() {
|
||||
announcements.value = result.items
|
||||
total.value = result.total
|
||||
} catch (err) {
|
||||
console.error('加载公告失败', err)
|
||||
debugError('加载公告失败', err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ChatLineRound, Iphone } from '@element-plus/icons-vue'
|
||||
import { onUnmounted, reactive, ref } from 'vue'
|
||||
@@ -67,13 +68,6 @@ async function handleLogin() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
@@ -208,13 +209,6 @@ async function saveProfile() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function confirmLogout() {
|
||||
showSettings.value = false
|
||||
|
||||
@@ -4,6 +4,7 @@ import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import { fetchPostRentalNotice, type PostRentalNotice } from '@/features/orders/api/orders'
|
||||
import { debugError } from '@/shared/utils/debug'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
|
||||
const session = useSessionStore()
|
||||
@@ -24,7 +25,7 @@ async function loadNotice() {
|
||||
try {
|
||||
notice.value = await fetchPostRentalNotice()
|
||||
} catch (error) {
|
||||
console.error('Failed to load post rental notice:', error)
|
||||
debugError('加载租后须知失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import {
|
||||
Camera,
|
||||
CircleCheckFilled,
|
||||
@@ -145,13 +146,6 @@ async function saveProfile() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import {
|
||||
CircleCheckFilled,
|
||||
CreditCard,
|
||||
@@ -108,13 +109,6 @@ async function handleSubmit() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import type { ChatEvent } from './useChatSSE'
|
||||
import { debugError } from '@/shared/utils/debug'
|
||||
|
||||
export type NotificationPermission = 'default' | 'granted' | 'denied'
|
||||
|
||||
@@ -119,7 +120,7 @@ export function useDesktopNotification(scope: 'user' | 'admin') {
|
||||
notification.close()
|
||||
}, 5000)
|
||||
} catch (error) {
|
||||
console.error('Failed to show notification:', error)
|
||||
debugError('桌面通知发送失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +206,6 @@ function speakText(text: string) {
|
||||
utterance.volume = 1
|
||||
window.speechSynthesis.speak(utterance)
|
||||
} catch (error) {
|
||||
console.error('Failed to speak notification:', error)
|
||||
debugError('语音提醒播放失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
@@ -274,13 +275,6 @@ function updateAgreementReadState(type: 'virtual' | 'renter') {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
// 手动锁定/解锁背景滚动
|
||||
watch(agreementVisible, visible => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { computed, nextTick, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { showToast, showDialog } from 'vant'
|
||||
@@ -255,13 +256,6 @@ function updateAgreementReadState(type: 'virtual' | 'renter') {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
async function copyListingCode() {
|
||||
if (!listing.value) return
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { onMounted, ref, computed } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { showDialog, showToast } from 'vant'
|
||||
@@ -111,13 +112,6 @@ function openPaymentCashier(payment: PaymentOrder) {
|
||||
})
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function money(value: unknown) {
|
||||
return formatMoney(Number(value || 0))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
@@ -101,13 +102,6 @@ async function handlePay(order: Order) {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function orderRole(order: Order) {
|
||||
if (order.renter_id === session.userId) return '租客'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
@@ -828,13 +829,6 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function parseOnlineTime(value: string) {
|
||||
const match = /^(\d{2}):(\d{2})$/.exec(value)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
@@ -218,13 +219,6 @@ function openRechargePayURL() {
|
||||
window.open(payURL, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function walletBizTypeLabel(type: string) {
|
||||
const map: Record<string, string> = {
|
||||
|
||||
@@ -2,6 +2,7 @@ import axios, { type AxiosResponse, type InternalAxiosRequestConfig, type AxiosE
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { showToast } from 'vant'
|
||||
import { apiMonitor } from './monitor'
|
||||
import { debugError, debugLog } from '@/shared/utils/debug'
|
||||
|
||||
function showError(message: string) {
|
||||
const isMobile = window.location.pathname.startsWith('/m')
|
||||
@@ -24,7 +25,7 @@ declare module 'axios' {
|
||||
// 开发环境日志记录
|
||||
function logRequest(config: InternalAxiosRequestConfig) {
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`[API Request] ${config.method?.toUpperCase()} ${config.url}`, {
|
||||
debugLog(`[API Request] ${config.method?.toUpperCase()} ${config.url}`, {
|
||||
params: config.params,
|
||||
data: config.data,
|
||||
headers: config.headers,
|
||||
@@ -38,7 +39,7 @@ function logRequest(config: InternalAxiosRequestConfig) {
|
||||
function logResponse(response: AxiosResponse) {
|
||||
if (import.meta.env.DEV) {
|
||||
const duration = response.config._startTime ? Date.now() - response.config._startTime : 0
|
||||
console.log(
|
||||
debugLog(
|
||||
`[API Response] ${response.config.method?.toUpperCase()} ${response.config.url} (${duration}ms)`,
|
||||
{
|
||||
status: response.status,
|
||||
@@ -63,7 +64,7 @@ function logResponse(response: AxiosResponse) {
|
||||
function logError(error: AxiosError) {
|
||||
if (import.meta.env.DEV) {
|
||||
const duration = error.config?._startTime ? Date.now() - error.config._startTime : 0
|
||||
console.error(
|
||||
debugError(
|
||||
`[API Error] ${error.config?.method?.toUpperCase()} ${error.config?.url} (${duration}ms)`,
|
||||
{
|
||||
status: error.response?.status,
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
* API 性能监控
|
||||
* 记录和分析 API 请求性能
|
||||
*/
|
||||
import {
|
||||
debugGroup,
|
||||
debugGroupEnd,
|
||||
debugLog,
|
||||
debugTable,
|
||||
debugWarn,
|
||||
} from '@/shared/utils/debug'
|
||||
|
||||
interface RequestMetrics {
|
||||
url: string
|
||||
@@ -29,7 +36,7 @@ class ApiMonitor {
|
||||
|
||||
// 开发环境下,慢请求警告
|
||||
if (import.meta.env.DEV && metric.duration > 1000) {
|
||||
console.warn(`[API 慢请求] ${metric.method} ${metric.url} 耗时 ${metric.duration}ms`)
|
||||
debugWarn(`[API 慢请求] ${metric.method} ${metric.url} 耗时 ${metric.duration}ms`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,12 +112,12 @@ class ApiMonitor {
|
||||
* 打印性能报告
|
||||
*/
|
||||
printReport() {
|
||||
console.group('📊 API 性能报告')
|
||||
console.log('总请求数:', this.metrics.length)
|
||||
console.log('平均响应时间:', this.getAverageResponseTime(), 'ms')
|
||||
console.log('成功率:', this.getSuccessRate(), '%')
|
||||
console.log('最慢的 5 个请求:')
|
||||
console.table(
|
||||
debugGroup('API 性能报告')
|
||||
debugLog('总请求数:', this.metrics.length)
|
||||
debugLog('平均响应时间:', this.getAverageResponseTime(), 'ms')
|
||||
debugLog('成功率:', this.getSuccessRate(), '%')
|
||||
debugLog('最慢的 5 个请求:')
|
||||
debugTable(
|
||||
this.getSlowestRequests(5).map(m => ({
|
||||
方法: m.method,
|
||||
URL: m.url,
|
||||
@@ -118,9 +125,9 @@ class ApiMonitor {
|
||||
状态: m.status,
|
||||
}))
|
||||
)
|
||||
console.log('按 URL 统计:')
|
||||
console.table(this.getStatsByUrl())
|
||||
console.groupEnd()
|
||||
debugLog('按 URL 统计:')
|
||||
debugTable(this.getStatsByUrl())
|
||||
debugGroupEnd()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,5 +137,5 @@ export const apiMonitor = new ApiMonitor()
|
||||
// 开发环境下暴露到 window 对象,方便调试
|
||||
if (import.meta.env.DEV) {
|
||||
;(window as any).__apiMonitor = apiMonitor
|
||||
console.log('💡 使用 __apiMonitor.printReport() 查看 API 性能报告')
|
||||
debugLog('使用 __apiMonitor.printReport() 查看 API 性能报告')
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { onUnmounted, ref } from 'vue'
|
||||
import { showToast } from 'vant'
|
||||
import { sendSmsCode } from '@/features/auth/api/auth'
|
||||
@@ -51,13 +52,6 @@ export function useSmsCountdown() {
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
return {
|
||||
countDown,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
type DebugConsole = Pick<
|
||||
Console,
|
||||
'log' | 'warn' | 'error' | 'group' | 'groupEnd' | 'table'
|
||||
>
|
||||
|
||||
function runInDev(method: keyof DebugConsole, args: unknown[]) {
|
||||
if (!import.meta.env.DEV) return
|
||||
console[method](...args)
|
||||
}
|
||||
|
||||
export function debugLog(...args: unknown[]) {
|
||||
runInDev('log', args)
|
||||
}
|
||||
|
||||
export function debugWarn(...args: unknown[]) {
|
||||
runInDev('warn', args)
|
||||
}
|
||||
|
||||
export function debugError(...args: unknown[]) {
|
||||
runInDev('error', args)
|
||||
}
|
||||
|
||||
export function debugGroup(...args: unknown[]) {
|
||||
runInDev('group', args)
|
||||
}
|
||||
|
||||
export function debugGroupEnd() {
|
||||
runInDev('groupEnd', [])
|
||||
}
|
||||
|
||||
export function debugTable(data?: unknown, columns?: string[]) {
|
||||
if (!import.meta.env.DEV) return
|
||||
console.table(data, columns)
|
||||
}
|
||||
@@ -3,8 +3,17 @@
|
||||
*/
|
||||
export function readError(error: unknown, fallback: string): string {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
const response = (
|
||||
error as {
|
||||
response?: {
|
||||
data?: {
|
||||
message?: string
|
||||
error?: string
|
||||
}
|
||||
}
|
||||
}
|
||||
).response
|
||||
return response?.data?.message || response?.data?.error || fallback
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return error.message || fallback
|
||||
|
||||
Reference in New Issue
Block a user