import { getSelfRead } from '~/api/user' import { getModelTexts, getReadRanking, getSelfReadRanking } from '~/api/global' import { store } from '~/store/index' import { createStoreBindings } from 'mobx-miniprogram-bindings' import share from '~/mixins/share' Page({ behaviors: [share], /** * 页面的初始数据 */ data: { list: [], // true是人气榜,false是参赛作品 currentType: true, activityUserList: [], bannerList: [], myActivityUser: {}, explain: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getLocUserInfo() if (Object.keys(this.data.userInfo).length > 0) { this.reload() } else { getApp().callBack = (res) => { this.getLocUserInfo() this.reload() } } }, getLocUserInfo() { this.storeBindings = createStoreBindings(this, { store, fields: { userInfo: 'userInfo' }, actions: { setUser: 'setUser' } }) this.storeBindings.updateStoreBindings() }, reload() { this.getModelTexts() this.getReadRanking() }, // 获取范文 async getModelTexts() { let bannerList = await getModelTexts({ grade: this.data.userInfo.grade }) this.setData({ bannerList }) }, async getReadRanking() { let { activityUserList, myActivityUser, activity } = await getReadRanking() this.setData({ activityUserList, myActivityUser, explain: activity.explain }) }, async getSelfReadRanking() { let list = await getSelfReadRanking() this.setData({ list }) }, bannelEvent({ target }) { wx.navigateTo({ url: `/pages/reading/index?videoId=${target.dataset.id}&readingType=readMatch` }) }, jumpUserInfo({ currentTarget }) { wx.navigateTo({ url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`, }) }, jumpIntro() { wx.navigateTo({ url: `/pages/rankIntro/index?title=活动规则&img=${this.data.explain}`, }) }, selectType({ target }) { if (target.dataset.type) { let currentType = JSON.parse(target.dataset.type) if (!currentType) { this.getSelfReadRanking() } this.setData({ currentType }) } }, onShareAppMessage({ from, target }) { if (from == 'menu') { return { title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!', path: `/pages/match/index?uid=${wx.getStorageSync('uid')}`, imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg' } } }, })