index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import Api from '../../model/api'
  2. import User from '../../model/user'
  3. import {getDataSet, getEventParam, toast} from "../../utils/utils";
  4. import {htmlTypes, liveSources, videoTypes} from "../../model/enum";
  5. import Route from "../../model/route";
  6. const app = getApp();
  7. app.Base({
  8. data: {
  9. id: "",//用来区分是否是通过卡片分享进行来的用户,当id存在值的时候是guest
  10. homeData: {
  11. notice: {
  12. noticeContent: ''
  13. },
  14. carouselList: [],
  15. classInfo: {
  16. opened: 0,
  17. notYetOpened: 0,
  18. history: 0,
  19. },
  20. dictList: [],
  21. },
  22. tabs: [
  23. {title: "直播课程", icon: '/images/tab_live.png'},
  24. {title: "教材阅读", icon: '/images/tab_book.png', url: "/pages/book/book"},
  25. {title: "精品课程", icon: '/images/tab_course.png', url: "/pages/course/course"},
  26. {title: "社区交流", icon: '/images/tab_exchange.png'}
  27. ],
  28. active: 0,
  29. dictType: '',
  30. dictValue: '',
  31. showLiveList: false,
  32. actions: [],
  33. },
  34. async onLoad(options) {
  35. const {id, guest} = options;
  36. if (guest == 'true') {
  37. this.id = id;
  38. }
  39. const res = await Api.getIndex();
  40. const dictType = res.data.dictList[0].dictType;
  41. const dictValue = res.data.dictList[0].dictValue;
  42. this.setData({
  43. homeData: res.data,
  44. dictType,
  45. dictValue
  46. })
  47. this.selectComponent('#tabs').resize();
  48. },
  49. async onShow() {
  50. if (this.id) {
  51. let flag = await User.checkLive(this.id);
  52. if (flag){
  53. this.id = "";
  54. }
  55. }
  56. },
  57. async toNotice(e) {
  58. await User.checkLogin();
  59. Route.toNotice()
  60. },
  61. toBannerDetail(e) {
  62. const item = getEventParam(e, "item");
  63. Route.toNews(htmlTypes.BANNER, item.id, item.articleTitle, "")
  64. },
  65. async toClickGrid(e) {
  66. const title = getDataSet(e, "title");
  67. if ('直播课程' == title) {
  68. await this.findLive();
  69. } else if ('社区交流' == title) {
  70. await User.checkLogin();
  71. Route.tocCommunity()
  72. }
  73. },
  74. toNewsDetail(e) {
  75. const item = getDataSet(e, "item");
  76. const title = getDataSet(e, "title");
  77. if (item.isNews) {
  78. Route.toNews(htmlTypes.NEWS, item.id, item.title, "")
  79. } else {
  80. Route.toVideo(item.id, videoTypes.COMMON, title)
  81. }
  82. },
  83. toSchoolIntrouce() {
  84. Route.toSchoolIntrouce();
  85. },
  86. async onChange(e) {
  87. const index = getEventParam(e, "index");
  88. const dictType = this.data.homeData.dictList[index].dictType;
  89. const dictValue = this.data.homeData.dictList[index].dictValue;
  90. this.setData({
  91. active: index, dictType, dictValue
  92. }, async () => {
  93. this.changeResetData(this);
  94. })
  95. },
  96. async requestData() {
  97. const res = await Api.getNewsList({
  98. dictType: this.data.dictType,
  99. dictValue: this.data.dictValue,
  100. pageNum: this.pageNum,
  101. pageSize: this.pageSize
  102. });
  103. res.data.rows = res.data.rows.map(item => {
  104. return {
  105. title: item.articleTitle || item.videoName,
  106. visitedCount: item.visitedCount,
  107. cover: item.articleImg || item.videoImg,
  108. id: item.id,
  109. isNews: !!item.articleTitle
  110. }
  111. });
  112. return res;
  113. },
  114. async onPullDownRefresh() {
  115. const res = await Api.getIndex(true);
  116. const dictType = res.data.dictList[0].dictType;
  117. const dictValue = res.data.dictList[0].dictValue;
  118. this.setData({
  119. homeData: res.data,
  120. dictType,
  121. dictValue,
  122. active: 0
  123. })
  124. this.selectComponent('#tabs').resize();
  125. },
  126. async findLive() {
  127. await User.checkLogin();
  128. const res = await Api.getUserLiveId(true);
  129. if (res.data && res.data.length > 0) {
  130. if (res.data.length == 1) {
  131. let item = res.data[0];
  132. let id = item.scheduleId;
  133. let eId = item.eStudentId;
  134. let eName = item.eduStuName;
  135. Route.toLive(liveSources.DEFAULT,
  136. item.courseCeremoneyName,
  137. id, eId, eName,item.courseThumbnailUrl)
  138. } else {
  139. this.setData({
  140. actions: res.data.map(item => {
  141. item.name = `${item.teamName}-${item.courseCeremoneyName}`;
  142. return item;
  143. }),
  144. showLiveList: true
  145. })
  146. }
  147. } else {
  148. toast("没有进行的直播")
  149. }
  150. },
  151. onClose() {
  152. this.setData({showLiveList: false});
  153. },
  154. async onSelect(e) {
  155. const scheduleId = getEventParam(e, "scheduleId");
  156. const eStudentId = getEventParam(e, "eStudentId");
  157. const eduStuName = getEventParam(e, "eduStuName");
  158. const courseCeremoneyName = getEventParam(e, "courseCeremoneyName");
  159. const courseThumbnailUrl = getEventParam(e, "courseThumbnailUrl");
  160. Route.toLive(liveSources.DEFAULT, courseCeremoneyName,
  161. scheduleId, eStudentId, eduStuName,courseThumbnailUrl);
  162. },
  163. })