123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- const app = getApp()
- import {
- getCategoryList,
- getResourceList
- } from "~/api/works"
- import {
- getBannerList
- } from '~/api/global'
- import event from '~/mixins/event'
- import share from '~/mixins/share'
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- Page({
- behaviors: [share, event],
- data: {
- navBarHeight: app.globalData.navBarHeight,
- desktopTips: app.globalData.desktopTips,
- bannerList: [],
- categoryList: [],
- listOptions: {},
- },
- onLoad(options) {
- this.getLocUserInfo()
- if (Object.keys(this.data.userInfo).length > 0) {
- this.requestAgain()
- } else {
- getApp().callBack = (res) => {
- this.getLocUserInfo()
- this.requestAgain()
- }
- }
- let {
- desktopTips
- } = app.globalData
- if (desktopTips) {
- setTimeout(() => {
- this.setData({
- desktopTips: false
- })
- wx.setStorage({
- key: "preDesktopTime",
- data: new Date()
- })
- }, 6000)
- }
- this.requestMessage()
- },
- onShow() {
- if (typeof this.getTabBar === 'function') {
- this.getTabBar().setData({
- selected: 2
- })
- }
- },
- requestAgain() {
- this.getBannerList()
- this.getResource()
- this.getCategoryList()
- },
- async getLocUserInfo() {
- this.storeBindings = createStoreBindings(this, {
- store,
- fields: {
- userInfo: 'userInfo'
- },
- })
- this.storeBindings.updateStoreBindings()
- },
- async getCategoryList() {
- let grade = this.data.userInfo.grade
- let categoryList = await getCategoryList({
- grade
- })
- this.setData({
- categoryList
- })
- },
- async getResource() {
- let data = await getResourceList({
- grade: this.data.userInfo.grade
- })
- this.setData({
- listOptions: data,
- })
- },
- async getBannerList() {
- let bannerList = await getBannerList({
- grade: this.data.userInfo.grade,
- })
- this.setData({
- bannerList,
- })
- },
- jumpChildClassify({
- currentTarget
- }) {
- let firstInfo = currentTarget.dataset.item
- wx.navigateTo({
- url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
- })
- },
- showTips() {
- wx.showModal({
- title: '新栏目更新中',
- content: '敬请期待….',
- showCancel: false,
- confirmColor: '#333333',
- success(res) {}
- })
- },
- closeDesktop() {
- this.setData({
- desktopTips: false
- })
- wx.setStorage({
- key: "preDesktopTime",
- data: new Date()
- })
- },
- jumpSearch() {
- wx.navigateTo({
- url: '/pages/childClassify/index?type=search',
- })
- },
- requestMessage() {
- /* wx.requestSubscribeMessage({
- tmplIds: [''],
- success(res) {}
- }) */
- },
- onUnload() {
- this.storeBindings.destroyStoreBindings()
- },
- })
|