const api = require("../../utils/api"); const CHANNELS = [ { k: "three_lines", name: "三句话", tip: "这题错在… 关键是… 下次遇到先…" }, { k: "ai_voice", name: "讲给 AI 听", tip: "假装我是你同桌,我没听懂" }, { k: "steps", name: "写步骤", tip: "一步一步写下来" }, { k: "find_error", name: "找错", tip: "别人这么做错了,你挑出来" }, { k: "make_question", name: "出题", tip: "自己出一道同类型的" }, ]; // 换行用字符码拼:WXML 的属性值里写不了 \n(会被编译器当成非法转义)。 const NL = String.fromCharCode(10); const PLACEHOLDER = { three_lines: "这题错在…" + NL + "关键是…" + NL + "下次遇到先…", ai_voice: "假装我是你同桌:你为什么要先算这一步?", steps: "第一步…" + NL + "第二步…" + NL + "所以我最后得出的答案是…", find_error: "先说他在哪一步错了,再说你会怎么改", make_question: "出一道同类型的题,写上答案和最关键的那一步", }; Page({ data: { mid: "", item: null, channels: CHANNELS, channel: "three_lines", ph: PLACEHOLDER.three_lines, text: "", submitting: false, result: null, loading: true, }, onLoad(query) { if (!api.requireChild()) return; this.setData({ mid: query.mid || "" }); this.load(); }, load() { const child = getApp().globalData.child; api .get("/api/mistakes?child_id=" + child.id) .then((d) => { const item = (d.items || []).find((m) => m.id === this.data.mid) || null; this.setData({ item, loading: false }); }) .catch((e) => { api.toastError(e); this.setData({ loading: false }); }); }, pickChannel(e) { const k = e.currentTarget.dataset.k; this.setData({ channel: k, ph: PLACEHOLDER[k] || "", result: null }); }, onInput(e) { this.setData({ text: e.detail.value }); }, onSubmit() { const text = (this.data.text || "").trim(); if (text.length < 8) { wx.showToast({ title: "太短了,多说两句", icon: "none" }); return; } if (this.data.submitting) return; this.setData({ submitting: true }); api .post("/api/mistakes/" + this.data.mid + "/explain", { child_id: getApp().globalData.child.id, channel: this.data.channel, text, }) .then((r) => this.setData({ result: r, submitting: false })) .catch((e) => { api.toastError(e); this.setData({ submitting: false }); }); }, onBack() { wx.reLaunch({ url: "/pages/home/home" }); }, onRetry() { this.setData({ result: null, text: "" }); }, });