fix: 老师选择改为精确输入匹配,不暴露老师列表
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 15s
Test / e2e-test (push) Successful in 50s

输入老师的 display_name 或 username 精确匹配才能发送请求。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 21:59:11 +00:00
parent 1ca9bc1758
commit fe74f45bca

View File

@@ -56,15 +56,17 @@
<label class="form-label">描述你的健康需求</label>
<textarea v-model="planHealthDesc" class="form-textarea" rows="4"
placeholder="例如:家里有老人膝盖痛,小孩经常感冒咳嗽,我自己想改善睡眠..."></textarea>
<label class="form-label" style="margin-top:12px">选择老师</label>
<select v-model="planTeacherId" class="form-select">
<option value="">请选择</option>
<option v-for="t in plansStore.teachers" :key="t.id" :value="t.id">
{{ t.display_name }}
</option>
</select>
<label class="form-label" style="margin-top:12px">输入老师的名字</label>
<input v-model="planTeacherName" class="form-input" placeholder="请输入老师告诉你的名字"
@input="matchTeacher" />
<div v-if="matchedTeacher" class="teacher-matched">
已匹配{{ matchedTeacher.display_name }}
</div>
<div v-else-if="planTeacherName.trim() && !matchedTeacher" class="teacher-no-match">
未找到该老师请确认名字是否正确
</div>
<button class="btn-primary" style="width:100%;margin-top:16px"
:disabled="!planHealthDesc.trim() || !planTeacherId"
:disabled="!planHealthDesc.trim() || !matchedTeacher"
@click="submitPlanRequest">
发送请求
</button>
@@ -311,7 +313,16 @@ async function toggleOil(name) {
// Plan request
const showPlanRequest = ref(false)
const planHealthDesc = ref('')
const planTeacherId = ref('')
const planTeacherName = ref('')
const matchedTeacher = ref(null)
function matchTeacher() {
const name = planTeacherName.value.trim()
if (!name) { matchedTeacher.value = null; return }
matchedTeacher.value = plansStore.teachers.find(t =>
t.display_name === name || t.username === name
) || null
}
const shoppingTotal = computed(() =>
plansStore.shoppingList.filter(i => !i.in_inventory).reduce((s, i) => s + i.total_cost, 0).toFixed(2)
@@ -319,10 +330,11 @@ const shoppingTotal = computed(() =>
async function submitPlanRequest() {
try {
await plansStore.createPlan(planHealthDesc.value, planTeacherId.value)
await plansStore.createPlan(planHealthDesc.value, matchedTeacher.value.id)
showPlanRequest.value = false
planHealthDesc.value = ''
planTeacherId.value = ''
planTeacherName.value = ''
matchedTeacher.value = null
ui.showToast('已发送方案请求')
} catch {
ui.showToast('发送失败')
@@ -629,5 +641,6 @@ onMounted(async () => {
.overlay-header h3 { margin: 0; font-size: 16px; }
.form-label { display: block; font-size: 13px; color: #6b6375; margin-bottom: 4px; font-weight: 500; }
.form-textarea { width: 100%; border: 1.5px solid #e5e4e7; border-radius: 8px; padding: 8px; font-size: 13px; font-family: inherit; resize: vertical; box-sizing: border-box; }
.form-select { width: 100%; border: 1.5px solid #e5e4e7; border-radius: 8px; padding: 8px; font-size: 13px; font-family: inherit; box-sizing: border-box; }
.teacher-matched { color: #2e7d5a; font-size: 13px; margin-top: 4px; font-weight: 500; }
.teacher-no-match { color: #c62828; font-size: 12px; margin-top: 4px; }
</style>