index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. //index.js
  2. //获取应用实例
  3. import {
  4. getOpenidSessionKey
  5. } from '../../utils/httpUtil';
  6. import {
  7. formatDate
  8. } from '../../utils/util';
  9. const app = getApp()
  10. import {
  11. hotInit
  12. } from '../../component/hot/hot';
  13. import {
  14. groupInit
  15. } from '../../component/group/group';
  16. import {
  17. myInit
  18. } from '../../component/my/my';
  19. // import {
  20. // followInit
  21. // } from '../../component/follow/follow';
  22. // import '../../utils/hls';
  23. import httpRequestApi from '../../utils/APIClient';
  24. import httputil from '../../utils/httpUtil';
  25. import {
  26. GetQueryString
  27. } from '../../utils/util';
  28. Page({
  29. data: {
  30. tab: [{
  31. name: '我的',
  32. templates: 'my',
  33. },
  34. {
  35. name: '发现',
  36. templates: 'hot',
  37. },
  38. {
  39. name: '热团',
  40. templates: 'group',
  41. },
  42. // {
  43. // name: '动态',
  44. // templates: 'follow',
  45. // },
  46. ],
  47. winH: 568,
  48. myIndex: 1,
  49. followData: [],
  50. recommendPageNo: 1,
  51. recommendTotalNo: 0,
  52. followPageNo: 0,
  53. followPageTotalNo: 1,
  54. myData: {},
  55. templates: 'hot',
  56. title: 'index中的title',
  57. jurisdictionFlag: true,
  58. hotInput: '12345',
  59. mineSettingInfo: '528',
  60. hide: true,
  61. isIOS: app.globalData.isIOS,
  62. ifHaveMore: true,
  63. indexSignDialog: false,
  64. indexMissionDialog: false,
  65. unfinishedCount:0
  66. },
  67. jurisdiction: function () {
  68. //隐藏弹框
  69. this.setData({
  70. hide: !this.data.hide
  71. })
  72. //登录页信息
  73. this.onShow();
  74. },
  75. //tab点击
  76. switcher: function ({
  77. currentTarget
  78. }) {
  79. if (currentTarget.dataset.index === this.data.myIndex) return;
  80. this.updateData(currentTarget.dataset.index);
  81. },
  82. // 根据index 更新template
  83. updateData: function (index) {
  84. let myIndex = index;
  85. let templates = this.data.tab[myIndex].templates;
  86. this.setData({
  87. myIndex,
  88. templates
  89. });
  90. if (myIndex == 0) {
  91. // groupInit(this);
  92. this.setData({
  93. followPageNo: 0,
  94. })
  95. myInit(this);
  96. }
  97. if (myIndex == 1) {
  98. this.setData({
  99. recommendPageNo: 1
  100. })
  101. hotInit(this);
  102. }
  103. if (myIndex == 2) {
  104. groupInit(this);
  105. }
  106. },
  107. onLoad: function (options) {
  108. this.uid = wx.getStorageSync('uid');
  109. wx.getSystemInfo({
  110. success: (res) => {
  111. this.setData({
  112. winH: res.windowHeight
  113. });
  114. }
  115. });
  116. if (options.index) {
  117. this.updateData(options.index)
  118. }
  119. setTimeout(() => {
  120. if(wx.getStorageSync('uid')){
  121. httpRequestApi.userLoginRecord().success(res => {
  122. if (res.data.data) {
  123. // 有数据弹任务窗口
  124. if(this.data.unfinishedCount > 0){
  125. this.setData({
  126. indexSignDialog: true
  127. })
  128. }
  129. } else {
  130. // 没数据弹签到
  131. this.setData({
  132. indexMissionDialog: true
  133. })
  134. }
  135. })
  136. }
  137. }, 2800)
  138. // hotInit(this)
  139. // this.init();
  140. },
  141. onShow: function () {
  142. wx.setNavigationBarTitle({
  143. title: '小学课文朗读配音'
  144. })
  145. // this.init();
  146. getOpenidSessionKey((res) => {
  147. hotInit(this)
  148. }, (error) => {
  149. // console.log(error)
  150. this.setData({
  151. hide: !this.data.hide
  152. })
  153. return;
  154. });
  155. if (this.data.myIndex === 0) {
  156. // 从修改信息页面退回
  157. this.getUserWorksInfo(true);
  158. }
  159. },
  160. //初始化数据
  161. // init: function () {
  162. // httputil.getOpenidSessionKey((res) => {
  163. // console.log('微信的用户信息', res)
  164. // }, (error) => {
  165. // console.log(1111111111111111)
  166. // // this.jurisdiction()
  167. // wx.navigateTo({
  168. // url: '../../loginPage/loginPage'
  169. // })
  170. // });
  171. // },
  172. // 获取用户信息
  173. getUserWorksInfo: function (flag) {
  174. console.log(flag)
  175. if (flag) {
  176. httpRequestApi.getUserWorksInfo().success(res => {
  177. const str = 'myData.user.user.nickName';
  178. this.setData({
  179. [str]: res.data.data.user.nickName
  180. })
  181. })
  182. return;
  183. }
  184. const userLocal = wx.getStorageSync('user')
  185. console.log(userLocal)
  186. const str = 'myData.user';
  187. this.setData({
  188. [str]: userLocal
  189. })
  190. httpRequestApi.getUserWorksInfo().success(res => {
  191. this.data.myData.user = res.data.data;
  192. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  193. if (this.data.myData.user.myRead) {
  194. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  195. }
  196. this.setData({
  197. myData: this.data.myData,
  198. });
  199. }).fail(error => {
  200. console.log(error)
  201. })
  202. },
  203. // 触底加载
  204. onReachBottom: function () {
  205. if (this.data.myIndex === 0) {
  206. console.log(this.data.followPageTotalNo)
  207. console.log(this.data.followPageNo)
  208. this.setData({
  209. followPageNo: this.data.followPageNo + 1
  210. })
  211. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  212. this.getFollowWorks(this.data.followPageNo, 3);
  213. } else {
  214. console.log('没有更多')
  215. this.setData({
  216. ifHaveMore: false
  217. })
  218. }
  219. }
  220. // 当前在推荐页面 加载推荐
  221. // if (this.data.myIndex === 1) {
  222. // console.log(this.data.recommendPageNo)
  223. // this.setData({
  224. // recommendPageNo: this.data.recommendPageNo + 1
  225. // })
  226. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  227. // this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  228. // } else {
  229. // console.log('没有更多')
  230. // }
  231. // }
  232. },
  233. onPullDownRefresh: function () {
  234. //当前在团购页下拉加载
  235. if (this.data.myIndex === 0) {
  236. groupInit(this);
  237. }
  238. wx.showNavigationBarLoading() //在标题栏中显示加载
  239. //模拟加载
  240. setTimeout(function () {
  241. wx.hideNavigationBarLoading() //完成停止加载
  242. wx.stopPullDownRefresh() //停止下拉刷新
  243. }, 1500);
  244. },
  245. // 获取全部课本
  246. // getBookList: function () {
  247. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  248. // this.data.bookList = res.data.data.list;
  249. // res.data.data.list.forEach(element => {
  250. // this.data.selectFlag.push(true);
  251. // });
  252. // this.setData({
  253. // bookList: this.data.bookList
  254. // })
  255. // }).fail((error) => {
  256. // console.log('错误', error)
  257. // })
  258. // },
  259. goToMessage: function () {
  260. wx.navigateTo({
  261. url: `../../pages/social/insideMessage/insideMessage`
  262. });
  263. const str = 'hotData.unReadMessageNum';
  264. this.setData({
  265. [str]: 0
  266. })
  267. },
  268. toMyCollage: function (e) {
  269. if (app.globalData.isIOS) {
  270. wx.navigateTo({
  271. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  272. });
  273. } else {
  274. wx.navigateTo({
  275. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  276. });
  277. }
  278. },
  279. toMyCourse: function(){
  280. wx.navigateTo({
  281. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  282. });
  283. },
  284. goToFlower: function () {
  285. wx.navigateTo({
  286. url: `../../pages/social/littleFlower/littleFlower`
  287. });
  288. },
  289. signInBtn: function (e){
  290. this.setData({
  291. indexSignDialog: false
  292. })
  293. console.log(e.detail.formId)
  294. httpRequestApi.postFormId(e.detail.formId).success(res=>{console.log(res)})
  295. this.goToFlower();
  296. },
  297. missionBtn: function(){
  298. this.setData({
  299. indexMissionDialog: false
  300. })
  301. this.goToFlower();
  302. }
  303. })