index.js 8.7 KB

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