kydc/settings/settings.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

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