Files
zeronline b01a5f91c3
CI / Server (Go) (push) Has been cancelled
CI / Web (Next.js) (push) Has been cancelled
CI / Mobile (React Native) (push) Has been cancelled
CI / Admin (React) (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
提交修改
2026-06-29 16:49:54 +08:00

27 lines
1.2 KiB
JavaScript

const api = require('../../../services/api')
const app = getApp()
Page({
data: { name: '', category: 'study', cycleType: 'daily', dailyGoal: '', privacy: 2, submitting: false, themeMode: 'light' },
onShow() {
this.setData({ themeMode: app.globalData.themeMode })
},
onNameInput(e) { this.setData({ name: e.detail.value }) },
onGoalInput(e) { this.setData({ dailyGoal: e.detail.value }) },
setCategory(e) { this.setData({ category: e.currentTarget.dataset.cat }) },
setCycle(e) { this.setData({ cycleType: e.currentTarget.dataset.cycle }) },
setPrivacy(e) { this.setData({ privacy: parseInt(e.currentTarget.dataset.val) }) },
async onSubmit() {
if (!this.data.name.trim()) { wx.showToast({ title: '请输入名称', icon: 'none' }); return }
this.setData({ submitting: true })
try {
await api.post('/api/checkin/items', {
name: this.data.name.trim(), category: this.data.category,
cycleType: this.data.cycleType, dailyGoal: this.data.dailyGoal || undefined, privacy: this.data.privacy
})
wx.showToast({ title: '创建成功' })
wx.navigateBack()
} catch(e) { wx.showToast({ title: e.message || '创建失败', icon: 'none' }) }
this.setData({ submitting: false })
}
})