feat: establish teaching feedback mini program

Connect student profiles, defaults, and feedback records to the Rust API. Configure the WeChat AppID, custom tab bar, and local development workflow for version 0.1.0.
This commit is contained in:
2026-07-15 15:36:51 +08:00
commit 0a07538dce
37 changed files with 2550 additions and 0 deletions

83
pages/defaults/index.ts Normal file
View File

@@ -0,0 +1,83 @@
import { getApiErrorMessage, getProfileDefaults, updateProfileDefaults } from '../../utils/api'
import type { StudentProfileDefaults } from '../../utils/types'
const grades = ['艺术类', '幼儿园', '一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
const subjects = ['美术', '书法', '音乐', '舞蹈', '语文', '数学', '英语']
const initialDefaults: StudentProfileDefaults = {
grade: '艺术类',
subject: '美术',
lessonDurationMinutes: 60
}
type PickerEvent = { detail: { value: string | number } }
type InputEvent = { detail: { value: string } }
function normalizeDuration(value: number): number {
if (Number.isNaN(value)) return 60
return Math.min(360, Math.max(15, Math.round(value / 15) * 15))
}
Page({
data: {
defaults: initialDefaults,
grades,
subjects,
loading: false,
saving: false,
errorMessage: ''
},
onShow() {
void this.loadDefaults()
},
async loadDefaults(showSuccess = false) {
this.setData({ loading: true, errorMessage: '' })
try {
this.setData({ defaults: await getProfileDefaults() })
if (showSuccess) wx.showToast({ title: '预设已刷新', icon: 'success' })
} catch (error) {
this.setData({ errorMessage: getApiErrorMessage(error) })
} finally {
this.setData({ loading: false })
}
},
onReload() {
void this.loadDefaults(true)
},
onGradeChange(event: PickerEvent) {
this.setData({ 'defaults.grade': grades[Number(event.detail.value)] })
},
onSubjectChange(event: PickerEvent) {
this.setData({ 'defaults.subject': subjects[Number(event.detail.value)] })
},
onDurationInput(event: InputEvent) {
this.setData({ 'defaults.lessonDurationMinutes': normalizeDuration(Number(event.detail.value)) })
},
onDurationChange(event: PickerEvent) {
this.setData({ 'defaults.lessonDurationMinutes': normalizeDuration(Number(event.detail.value)) })
},
async save() {
const defaults = {
...this.data.defaults,
lessonDurationMinutes: normalizeDuration(this.data.defaults.lessonDurationMinutes)
}
this.setData({ saving: true })
try {
const saved = await updateProfileDefaults(defaults)
this.setData({ defaults: saved, errorMessage: '' })
wx.showToast({ title: '预设项已保存', icon: 'success' })
setTimeout(() => wx.navigateBack(), 450)
} catch (error) {
wx.showToast({ title: getApiErrorMessage(error), icon: 'none' })
} finally {
this.setData({ saving: false })
}
}
})