|
| 1 | +<template> |
| 2 | + <div class="blog-container"> |
| 3 | + <main> |
| 4 | + <div class="card"> |
| 5 | + <div class="card-body" style="padding: 22px"> |
| 6 | + <h1 style="margin: 0; font-size: 26px; font-weight: 900; letter-spacing: -0.02em">问题反馈</h1> |
| 7 | + <p style="margin: 12px 0 0; color: var(--muted); line-height: 1.8"> |
| 8 | + 欢迎提交使用中的问题/建议(同一 IP 每天仅可提交一次)。 |
| 9 | + </p> |
| 10 | + |
| 11 | + <div style="margin-top: 18px"> |
| 12 | + <div class="field"> |
| 13 | + <div class="label">姓名</div> |
| 14 | + <input v-model.trim="name" class="input" type="text" maxlength="50" placeholder="请输入姓名" /> |
| 15 | + </div> |
| 16 | + |
| 17 | + <div class="field"> |
| 18 | + <div class="label">问题</div> |
| 19 | + <textarea |
| 20 | + v-model.trim="content" |
| 21 | + class="textarea" |
| 22 | + rows="6" |
| 23 | + maxlength="2000" |
| 24 | + placeholder="请尽量描述清楚:发生了什么、期望什么、复现步骤(如有)" |
| 25 | + /> |
| 26 | + </div> |
| 27 | + |
| 28 | + <div style="display: flex; justify-content: flex-end; margin-top: 14px"> |
| 29 | + <button class="btn primary" :disabled="submitting" @click="submit"> |
| 30 | + {{ submitting ? '提交中...' : '提交反馈' }} |
| 31 | + </button> |
| 32 | + </div> |
| 33 | + |
| 34 | + <div v-if="error" class="error" style="margin-top: 12px">{{ error }}</div> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + </main> |
| 39 | + </div> |
| 40 | +</template> |
| 41 | + |
| 42 | +<script setup> |
| 43 | +import { ref } from 'vue' |
| 44 | +import { createFeedback } from '../api/feedback' |
| 45 | +import { showMessage } from '../utils/message' |
| 46 | +
|
| 47 | +const name = ref('') |
| 48 | +const content = ref('') |
| 49 | +const submitting = ref(false) |
| 50 | +const error = ref('') |
| 51 | +
|
| 52 | +async function submit() { |
| 53 | + if (submitting.value) return |
| 54 | + error.value = '' |
| 55 | +
|
| 56 | + if (!name.value || name.value.trim().length < 1) { |
| 57 | + error.value = '请填写姓名' |
| 58 | + return |
| 59 | + } |
| 60 | +
|
| 61 | + if (!content.value || content.value.trim().length < 2) { |
| 62 | + error.value = '请填写问题内容(至少 2 个字符)' |
| 63 | + return |
| 64 | + } |
| 65 | +
|
| 66 | + submitting.value = true |
| 67 | + try { |
| 68 | + await createFeedback({ |
| 69 | + submitterName: name.value.trim(), |
| 70 | + content: content.value.trim() |
| 71 | + }) |
| 72 | + showMessage('已收到你的反馈,感谢!') |
| 73 | + name.value = '' |
| 74 | + content.value = '' |
| 75 | + } catch (e) { |
| 76 | + const traceId = e?.traceId ? `traceId ${e.traceId}` : '' |
| 77 | + const prefix = e?.code ? `错误码 ${e.code}` : e?.httpStatus ? `HTTP ${e.httpStatus}` : '' |
| 78 | + const head = [prefix, traceId].filter(Boolean).join(',') |
| 79 | + error.value = head ? `${head}:${e?.message || '提交失败'}` : e?.message || '提交失败' |
| 80 | + } finally { |
| 81 | + submitting.value = false |
| 82 | + } |
| 83 | +} |
| 84 | +</script> |
| 85 | +
|
0 commit comments