import { requestJson } from '@/services/api.uts' export type FeedbackItem = { id: string, content: string, status: string, reply: string, createdAt: string, updatedAt: string } export type FeedbackPage = { items: FeedbackItem[], page: number, total: number, hasMore: boolean } function feedbackView(data: UTSJSONObject): FeedbackItem { const id = data.getString('id') ?? ''; const content = data.getString('content') ?? '' if (id.length == 0) throw new Error('反馈响应不完整') return { id, content, status: data.getString('status') ?? 'pending', reply: data.getString('reply') ?? '', createdAt: data.getString('createdAt') ?? '', updatedAt: data.getString('updatedAt') ?? '' } } export function feedbackKey(): string { return 'feedback_' + Date.now().toString() + '_' + Math.floor(Math.random() * 1000000000).toString() } export function feedbackStatus(status: string): string { if (status == 'pending') return '待处理' if (status == 'processing') return '处理中' if (status == 'resolved') return '已回复' if (status == 'closed') return '已关闭' return '待核对' } export async function submitFeedback(content: string, requestId: string): Promise { const attachmentIds: string[] = [] return feedbackView(await requestJson('/feedback', 'POST', { content, requestId, attachmentIds })) } export async function fetchFeedback(page: number): Promise { const data = await requestJson('/feedback', 'GET', { page: page.toString(), pageSize: '20' }) const rows = data['items'] as UTSJSONObject[] | null if (rows == null) throw new Error('反馈记录加载失败') return { items: rows.map((item: UTSJSONObject): FeedbackItem => feedbackView(item)), page: data.getNumber('page') ?? page, total: data.getNumber('total') ?? 0, hasMore: data.getBoolean('hasMore') ?? false } }