const app = getApp() import { setUserInfo } from '~/api/user' import { storeBindingsBehavior } from 'mobx-miniprogram-bindings' import { store } from '~/store/index' Component({ // 自动绑定 behaviors: [storeBindingsBehavior], storeBindings: { store, fields: { userInfo: 'userInfo' }, actions: { setUser: 'setUser' } }, properties: { title: { type: String, value: '朗读小咖秀', } }, data: { navBarHeight: app.globalData.navBarHeight, menuRight: app.globalData.menuRight, menuTop: app.globalData.menuTop, menuHeight: app.globalData.menuHeight, isGradeShow: false, temporaryGrade: null }, methods: { closeGrade() { this.setData({ isGradeShow: false, }) }, // 选择年级 selectGrade({ target }) { let code = target.dataset.code if (!code) { return } this.setData({ temporaryGrade: code }) }, showGrade() { this.setData({ isGradeShow: true, temporaryGrade: this.data.userInfo.grade }) }, // 修改年级 async changeGrade(e) { const grade = this.data.temporaryGrade if (!grade) { return wx.showToast({ title: '请选择年级', icon: 'none', duration: 2000 }) } this.setData({ isGradeShow: false, }) let res = await setUserInfo({ grade }, 'put') this.setUser(res) setTimeout(() => { this.triggerEvent('reload') }, 300) }, } })