123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- const app = getApp()
- import {
- getHotrecommendList,
- getAuthorityList,
- getCategoryList
- } from "~/api/works"
- import reachBottom from '~/mixins/reachBottom'
- import share from '~/mixins/share'
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- Page({
- behaviors: [reachBottom, share],
- data: {
- navBarHeight: app.globalData.navBarHeight,
- background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
- currentType: '2',
-
- isFixed: false,
- desktopTips: app.globalData.desktopTips,
- isIOS: app.globalData.isIOS,
- categoryList: []
- },
-
- onShow() {
- if (typeof this.getTabBar === 'function') {
- this.getTabBar().setData({
- selected: 0
- })
- }
- this.getLocUserInfo()
- if (Object.keys(this.data.userInfo).length > 0) {
- this.resetData()
- } else {
- getApp().callBack = (res) => {
- this.getLocUserInfo()
- this.resetData()
- }
- }
- let {
- desktopTips
- } = app.globalData
- if (desktopTips) {
- setTimeout(() => {
- this.setData({
- desktopTips: false
- })
- wx.setStorage({
- key: "preDesktopTime",
- data: new Date()
- })
- }, 6000)
- }
- },
- onUnload() {
- this.storeBindings.destroyStoreBindings()
- },
- onReachBottom() {
- this.loadMore()
- },
- async getLocUserInfo() {
- this.storeBindings = createStoreBindings(this, {
- store,
- fields: {
- userInfo: 'userInfo'
- },
- })
- this.storeBindings.updateStoreBindings()
- },
- loadMore() {
- if (!this.data.userInfo.grade) {
- return
- }
- if (this.data.currentType == '2') {
- this.getData(getHotrecommendList, {
- grade: this.data.userInfo.grade
- })
- } else if (this.data.currentType == '1') {
- this.getData(getAuthorityList, {
- grade: this.data.userInfo.grade
- })
- }
- this.getCategoryList()
- },
- 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}`,
- })
- },
- jumpSearch() {
- wx.navigateTo({
- url: '/pages/childClassify/index?type=search',
- })
- },
-
- onPageScroll(e) {
- if (e.scrollTop >= 103 && !this.data.isFixed) {
- this.setData({
- isFixed: true
- })
- } else if (e.scrollTop < 103 && this.data.isFixed) {
- this.setData({
- isFixed: false
- })
- }
- },
- async getCategoryList() {
- let grade = this.data.userInfo.grade
- let categoryList = await getCategoryList({
- grade
- })
- this.setData({
- categoryList
- })
- },
- selectType({
- target
- }) {
- if (target.dataset.type) {
- if (target.dataset.type == '3') {
- this.selectComponent('#worksList').resetAudio()
- }
- this.setData({
- currentType: target.dataset.type
- })
- if (target.dataset.type != '3') {
- this.resetData()
- }
- }
- },
- closeDesktop() {
- this.setData({
- desktopTips: false
- })
- wx.setStorage({
- key: "preDesktopTime",
- data: new Date()
- })
- }
- })
|