my.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const util = require('../../utils/util.js');
  5. const APIClient = require('../../utils/APIClient.js');
  6. const login = require('../../utils/loginSchedule.js');
  7. Page({
  8. data: {
  9. motto: ['我的','本周推荐','语文','数学','中文','英语','科学','艺术'],
  10. navBtnSelectIdx: 0,
  11. left: 0,
  12. //questionsPreviewing: false,
  13. //questionsShare: false,
  14. data: {},
  15. grade: "",
  16. time: "",
  17. rankData: {},
  18. share: false,
  19. studyLog: [],
  20. height: '',
  21. flag: true,
  22. productionData: {},
  23. num2: 0,
  24. productionMore: '',
  25. canvasHeight: '',
  26. loginType: 1
  27. },
  28. lower: function (e) {
  29. //console.log(e);
  30. //console.log(e.detail.scrollTop)
  31. // if (320 <= e.detail.scrollTop && e.detail.scrollTop <= 1000){
  32. // this.setData({ questionsPreviewing: true, questionsShare: false});
  33. // }else {
  34. // this.setData({ questionsPreviewing: false });
  35. // }
  36. // if (1090 <= e.detail.scrollTop) {
  37. // this.setData({ questionsPreviewing: false, questionsShare: true});
  38. // } else {
  39. // this.setData({ questionsShare: false });
  40. // }
  41. },
  42. jurisdiction: function () {
  43. //隐藏弹框
  44. this.setData({
  45. flag: !this.data.flag
  46. })
  47. //登录页信息
  48. this.onShow();
  49. },
  50. /*点击获取canvas高度*/
  51. onGetHeight: function (e) {
  52. const canvasHeight = this.selectComponent("#chat").data.canvasHeight;
  53. this.setData({
  54. canvasHeight,
  55. })
  56. },
  57. /*更改年级*/
  58. setgrade: function (e) {
  59. this.setGrade.showPopup()
  60. },
  61. onLoad: function (options) {
  62. console.log(options.type, options.type == "noTV" )
  63. if(options.type == "noTV") {
  64. this.setData({
  65. loginType: ""
  66. })
  67. }
  68. console.log(this.data.loginType)
  69. //获取更改年级组件
  70. this.setGrade = this.selectComponent("#set-grade");
  71. console.log(this.setGrade)
  72. //获取分享过来的值跳转页面
  73. const ind = options.ind;
  74. const postsId = options.postId || '';
  75. //判断ind的值移动到到艺术
  76. if(ind) {
  77. this.setData({
  78. navBtnSelectIdx: ind
  79. })
  80. //移动nav
  81. if (ind <= 2) {
  82. this.setData({ left: 0 });
  83. }
  84. if(ind > 2){
  85. this.setData({left: 200 });
  86. }
  87. }
  88. },
  89. onShow: function () {
  90. //登录页信息
  91. login.getOpenidSessionKey(res => {
  92. APIClient.getMySchedule({
  93. uid: res.data.data.uid
  94. }).success(res => {
  95. console.log(res)
  96. this.setData({
  97. data: res.data.data,
  98. grade: util.gradeUpper(res.data.data.users.grade),
  99. test:util.day(),
  100. time: util.day(res.data.data.timeSpend),
  101. studyLog: util.studyTime(res.data.data.studyLog)
  102. })
  103. if(res.data.data.studyLog.length > 10) {
  104. this.setData({
  105. height: '680'
  106. })
  107. }
  108. })
  109. //获取排名
  110. APIClient.getFriendSchedule('wx/friendsRank/user', {
  111. uid: res.data.data.uid
  112. }).success(res => {
  113. console.log(res)
  114. this.setData({
  115. rankData: res.data.data,
  116. })
  117. })
  118. }, () => {
  119. this.setData({
  120. flag: !this.data.flag
  121. })
  122. }, this.data.loginType);
  123. /* 分享 */
  124. const columnId = util.column('6').columnId;
  125. this.distinction(2, columnId, 1, 2, res => {
  126. if(res.data.success) {
  127. console.log(res.data.data)
  128. this.setData({
  129. productionData: res.data.data
  130. })
  131. if(res.data.data) {
  132. if(res.data.data.totalSize > 2) {
  133. this.setData({
  134. productionMore: true
  135. })
  136. }
  137. }
  138. }
  139. });
  140. },
  141. /* 区分答疑和分享 */
  142. distinction: function(type, columnId, pageNo, pageSize, success) {
  143. login.getOpenidSessionKey(function(res) {
  144. //console.log(res.data.data.uid);
  145. APIClient.getProductionSchedule({
  146. uid: res.data.data.uid
  147. }, {
  148. "type": type,
  149. "pageNo": pageNo,
  150. "pageSize": pageSize
  151. }).success(success)
  152. }, function() {
  153. });
  154. },
  155. /*点击加载更多*/
  156. onMyEvent: function(e){
  157. const columnId = util.column('6').columnId;
  158. this.data.num2++
  159. this.setData({
  160. num: this.data.num2
  161. })
  162. this.distinction(2, columnId, 1, 5*this.data.num2, res => {
  163. if(res.data.success) {
  164. console.log(res.data.data)
  165. this.setData({
  166. productionData: res.data.data,
  167. })
  168. if(5*this.data.num2 > res.data.data.totalSize) {
  169. this.setData({
  170. productionMore: ''
  171. })
  172. }
  173. }
  174. });
  175. },
  176. /* 转发*/
  177. onShareAppMessage: function (ops) {
  178. if (ops.from === 'button') {
  179. // 来自页面内转发按钮
  180. console.log(ops.target)
  181. }
  182. const postId = ops.target.dataset.postid;
  183. const imageUrl= ops.target.dataset.imageurl[0];
  184. return {
  185. title: '小学王者班',
  186. path: `pages/transmit/transmit?ind=7&postId=${postId}`,
  187. imageUrl,
  188. success: function (res) {
  189. // 转发成功
  190. console.log("转发成功:" + JSON.stringify(res));
  191. },
  192. fail: function (res) {
  193. // 转发失败
  194. console.log("转发失败:" + JSON.stringify(res));
  195. }
  196. }
  197. }
  198. })