123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import Api from '../../model/api'
- import User from '../../model/user'
- import {getDataSet, getEventParam, toast} from "../../utils/utils";
- import {htmlTypes, liveSources, videoTypes} from "../../model/enum";
- import Route from "../../model/route";
- const app = getApp();
- app.Base({
- data: {
- id: "",//用来区分是否是通过卡片分享进行来的用户,当id存在值的时候是guest
- homeData: {
- notice: {
- noticeContent: ''
- },
- carouselList: [],
- classInfo: {
- opened: 0,
- notYetOpened: 0,
- history: 0,
- },
- dictList: [],
- },
- tabs: [
- {title: "直播课程", icon: '/images/tab_live.png'},
- {title: "教材阅读", icon: '/images/tab_book.png', url: "/pages/book/book"},
- {title: "精品课程", icon: '/images/tab_course.png', url: "/pages/course/course"},
- {title: "社区交流", icon: '/images/tab_exchange.png'}
- ],
- active: 0,
- dictType: '',
- dictValue: '',
- showLiveList: false,
- actions: [],
- },
- async onLoad(options) {
- const {id, guest} = options;
- if (guest == 'true') {
- this.id = id;
- }
- const res = await Api.getIndex();
- const dictType = res.data.dictList[0].dictType;
- const dictValue = res.data.dictList[0].dictValue;
- this.setData({
- homeData: res.data,
- dictType,
- dictValue
- })
- this.selectComponent('#tabs').resize();
- },
- async onShow() {
- if (this.id) {
- let flag = await User.checkLive(this.id);
- if (flag){
- this.id = "";
- }
- }
- },
- async toNotice(e) {
- await User.checkLogin();
- Route.toNotice()
- },
- toBannerDetail(e) {
- const item = getEventParam(e, "item");
- Route.toNews(htmlTypes.BANNER, item.id, item.articleTitle, "")
- },
- async toClickGrid(e) {
- const title = getDataSet(e, "title");
- if ('直播课程' == title) {
- await this.findLive();
- } else if ('社区交流' == title) {
- await User.checkLogin();
- Route.tocCommunity()
- }
- },
- toNewsDetail(e) {
- const item = getDataSet(e, "item");
- const title = getDataSet(e, "title");
- if (item.isNews) {
- Route.toNews(htmlTypes.NEWS, item.id, item.title, "")
- } else {
- Route.toVideo(item.id, videoTypes.COMMON, title)
- }
- },
- toSchoolIntrouce() {
- Route.toSchoolIntrouce();
- },
- async onChange(e) {
- const index = getEventParam(e, "index");
- const dictType = this.data.homeData.dictList[index].dictType;
- const dictValue = this.data.homeData.dictList[index].dictValue;
- this.setData({
- active: index, dictType, dictValue
- }, async () => {
- this.changeResetData(this);
- })
- },
- async requestData() {
- const res = await Api.getNewsList({
- dictType: this.data.dictType,
- dictValue: this.data.dictValue,
- pageNum: this.pageNum,
- pageSize: this.pageSize
- });
- res.data.rows = res.data.rows.map(item => {
- return {
- title: item.articleTitle || item.videoName,
- visitedCount: item.visitedCount,
- cover: item.articleImg || item.videoImg,
- id: item.id,
- isNews: !!item.articleTitle
- }
- });
- return res;
- },
- async onPullDownRefresh() {
- const res = await Api.getIndex(true);
- const dictType = res.data.dictList[0].dictType;
- const dictValue = res.data.dictList[0].dictValue;
- this.setData({
- homeData: res.data,
- dictType,
- dictValue,
- active: 0
- })
- this.selectComponent('#tabs').resize();
- },
- async findLive() {
- await User.checkLogin();
- const res = await Api.getUserLiveId(true);
- if (res.data && res.data.length > 0) {
- if (res.data.length == 1) {
- let item = res.data[0];
- let id = item.scheduleId;
- let eId = item.eStudentId;
- let eName = item.eduStuName;
- Route.toLive(liveSources.DEFAULT,
- item.courseCeremoneyName,
- id, eId, eName,item.courseThumbnailUrl)
- } else {
- this.setData({
- actions: res.data.map(item => {
- item.name = `${item.teamName}-${item.courseCeremoneyName}`;
- return item;
- }),
- showLiveList: true
- })
- }
- } else {
- toast("没有进行的直播")
- }
- },
- onClose() {
- this.setData({showLiveList: false});
- },
- async onSelect(e) {
- const scheduleId = getEventParam(e, "scheduleId");
- const eStudentId = getEventParam(e, "eStudentId");
- const eduStuName = getEventParam(e, "eduStuName");
- const courseCeremoneyName = getEventParam(e, "courseCeremoneyName");
- const courseThumbnailUrl = getEventParam(e, "courseThumbnailUrl");
- Route.toLive(liveSources.DEFAULT, courseCeremoneyName,
- scheduleId, eStudentId, eduStuName,courseThumbnailUrl);
- },
- })
|