123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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'
- // numA: () => store.numA, // 绑定字段第一种方式
- // numB: (store) => store.numB, // 绑定字段第二种方式
- // sum: 'sum' // 绑定字段第三种方式
- },
- 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
- },
- attached: function () {
- // console.log(wx.getStorage(user));
- },
- methods: {
- // 选择年级
- 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)
- },
- }
- })
|