123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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
- },
- lifetimes: {
- attached() {
- if (!this.data.userInfo.grade) {
- let timer = setInterval(() => {
- if (this.data.userInfo.uid && !this.data.userInfo.grade) {
- this.showGrade()
- clearInterval(timer)
- }
- }, 500)
- }
- }
- },
- methods: {
- closeGrade() {
- if (!this.data.userInfo.grade) {
- return
- }
- 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)
- },
- }
- })
|