2026-04-19 10:04:00 +08:00
|
|
|
const app = getApp()
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
settings: null,
|
2026-04-19 11:56:49 +08:00
|
|
|
loading: false,
|
|
|
|
|
error: '',
|
2026-04-19 10:04:00 +08:00
|
|
|
},
|
|
|
|
|
onShow() {
|
2026-04-19 11:56:49 +08:00
|
|
|
this.loadSettings()
|
|
|
|
|
},
|
|
|
|
|
loadSettings() {
|
|
|
|
|
if (!app.globalData.openid) {
|
|
|
|
|
this.setData({ error: '请先登录' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.setData({ loading: true, error: '' })
|
2026-04-19 10:04:00 +08:00
|
|
|
wx.request({
|
|
|
|
|
url: `${app.globalData.baseUrl}/api/v1/settings`,
|
2026-04-19 11:56:49 +08:00
|
|
|
header: { 'X-OpenID': app.globalData.openid },
|
2026-04-19 10:04:00 +08:00
|
|
|
success: (res) => {
|
2026-04-19 11:56:49 +08:00
|
|
|
this.setData({ settings: res.data?.data || null })
|
2026-04-19 10:04:00 +08:00
|
|
|
},
|
2026-04-19 11:56:49 +08:00
|
|
|
fail: () => this.setData({ error: '设置加载失败' }),
|
|
|
|
|
complete: () => this.setData({ loading: false }),
|
2026-04-19 10:04:00 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
save() {
|
2026-04-19 11:56:49 +08:00
|
|
|
if (!app.globalData.openid) {
|
|
|
|
|
wx.showToast({ title: '请先登录', icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-19 10:04:00 +08:00
|
|
|
const settings = this.data.settings || {}
|
|
|
|
|
wx.request({
|
|
|
|
|
url: `${app.globalData.baseUrl}/api/v1/settings`,
|
|
|
|
|
method: 'PUT',
|
2026-04-19 11:56:49 +08:00
|
|
|
header: { 'Content-Type': 'application/json', 'X-OpenID': app.globalData.openid },
|
2026-04-19 10:04:00 +08:00
|
|
|
data: settings,
|
|
|
|
|
success: () => wx.showToast({ title: '已保存', icon: 'success' }),
|
2026-04-19 11:56:49 +08:00
|
|
|
fail: () => wx.showToast({ title: '保存失败', icon: 'none' }),
|
2026-04-19 10:04:00 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|