123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- getCategoryList,
- getResourceList
- } from "~/api/works"
- import share from '~/mixins/share'
- import reachBottom from '~/mixins/reachBottom'
- import {
- store
- } from '~/store/index'
- Page({
- behaviors: [reachBottom, share],
- data: {
- categoryList: [],
- listOptions: {},
- isFixed: false
- },
- onShow() {
- if (typeof this.getTabBar === 'function') {
- this.getTabBar().setData({
- selected: 1
- })
- }
- this.getLocUserInfo()
- if (Object.keys(this.data.userInfo).length > 0) {
- this.requestAgain()
- } else {
- getApp().callBack = (res) => {
- this.getLocUserInfo()
- this.requestAgain()
- }
- }
- },
- requestAgain() {
- this.resetData()
- this.getCategoryList()
- },
- async loadMore() {
- if (!this.data.userInfo.grade) {
- return
- }
- let data = await getResourceList({
- grade: this.data.userInfo.grade
- })
- this.setData({
- listOptions: data,
- })
- console.log(data, );
- },
- async getCategoryList() {
- let grade = this.data.userInfo.grade
- let categoryList = await getCategoryList({
- grade
- })
- this.setData({
- categoryList
- })
- },
- jumpChildClassify({
- currentTarget
- }) {
- let firstInfo = currentTarget.dataset.item
- let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
- wx.navigateTo({
- url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
- })
- },
- onUnload() {
- this.storeBindings.destroyStoreBindings()
- },
- async getLocUserInfo() {
- this.storeBindings = createStoreBindings(this, {
- store,
- fields: {
- userInfo: 'userInfo'
- },
- })
- this.storeBindings.updateStoreBindings()
- },
- onUnload() {
- this.storeBindings.destroyStoreBindings()
- },
- /**
- * 监听页面滚动事件
- */
- onPageScroll(e) {
- if (e.scrollTop >= 6 && !this.data.isFixed) {
- this.setData({
- isFixed: true
- })
- } else if (e.scrollTop < 6 && this.data.isFixed) {
- this.setData({
- isFixed: false
- })
- }
- },
- })
|