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. getOpenidNoLogin((res) => {
  177. hotInit(this)
  178. }, (error) => {
  179. // console.log(error)
  180. wx.setStorageSync('userSourseType', 'normal')
  181. this.setData({
  182. hide: !this.data.hide
  183. })
  184. return;
  185. });
  186. if (this.data.myIndex === 0) {
  187. // 从修改信息页面退回
  188. this.getUserWorksInfo(true);
  189. }
  190. },
  191. onHide: function() {
  192. const str = 'hotData.inputFocus'
  193. this.setData({
  194. [str]: false
  195. });
  196. },
  197. //初始化数据
  198. // init: function () {
  199. // httputil.getOpenidSessionKey((res) => {
  200. // console.log('微信的用户信息', res)
  201. // }, (error) => {
  202. // console.log(1111111111111111)
  203. // // this.jurisdiction()
  204. // wx.navigateTo({
  205. // url: '../../loginPage/loginPage'
  206. // })
  207. // });
  208. // },
  209. // 获取用户信息
  210. getUserWorksInfo: function(flag) {
  211. console.log(flag)
  212. if (flag) {
  213. httpRequestApi.getUserWorksInfo().success(res => {
  214. // const str = 'myData.user.user.nickName';
  215. // const avatarStr = 'myData.user.user.avatar';
  216. // this.setData({
  217. // [str]: res.data.data.user.nickName,
  218. // [avatarStr]: res.data.data.user.avatar
  219. // })
  220. })
  221. return;
  222. }
  223. const userLocal = wx.getStorageSync('user')
  224. console.log(userLocal)
  225. const str = 'myData.user';
  226. this.setData({
  227. [str]: userLocal
  228. })
  229. httpRequestApi.getUserWorksInfo().success(res => {
  230. this.data.myData.user = res.data.data;
  231. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  232. if (this.data.myData.user.myRead) {
  233. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  234. }
  235. this.setData({
  236. myData: this.data.myData,
  237. });
  238. }).fail(error => {
  239. console.log(error)
  240. })
  241. },
  242. // 触底加载
  243. onReachBottom: function() {
  244. console.log(this.data.myIndex)
  245. if (this.data.myIndex === 0) {
  246. this.setData({
  247. followPageNo: this.data.followPageNo + 1
  248. })
  249. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  250. this.getFollowWorks(this.data.followPageNo, 3);
  251. } else {
  252. console.log('没有更多')
  253. this.setData({
  254. ifHaveMore: false
  255. })
  256. }
  257. }
  258. // 当前在推荐页面 加载推荐
  259. if (this.data.myIndex === 1) {
  260. console.log(this.data.recommendPageNo)
  261. console.log(this.data.recommendTotalNo)
  262. this.setData({
  263. recommendPageNo: this.data.recommendPageNo + 1
  264. })
  265. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  266. this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  267. } else {
  268. console.log('没有更多')
  269. }
  270. }
  271. },
  272. onPullDownRefresh: function() {
  273. //当前在团购页下拉加载
  274. if (this.data.myIndex === 0) {
  275. // groupInit(this);
  276. }
  277. wx.showNavigationBarLoading() //在标题栏中显示加载
  278. //模拟加载
  279. setTimeout(function() {
  280. wx.hideNavigationBarLoading() //完成停止加载
  281. wx.stopPullDownRefresh() //停止下拉刷新
  282. }, 1500);
  283. },
  284. // 获取全部课本
  285. // getBookList: function () {
  286. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  287. // this.data.bookList = res.data.data.list;
  288. // res.data.data.list.forEach(element => {
  289. // this.data.selectFlag.push(true);
  290. // });
  291. // this.setData({
  292. // bookList: this.data.bookList
  293. // })
  294. // }).fail((error) => {
  295. // console.log('错误', error)
  296. // })
  297. // },
  298. goToMessage: function() {
  299. wx.navigateTo({
  300. url: `../../pages/social/insideMessage/insideMessage`
  301. });
  302. const str = 'hotData.unReadMessageNum';
  303. this.setData({
  304. [str]: 0
  305. })
  306. },
  307. toMyCollage: function(e) {
  308. if (app.globalData.isIOS) {
  309. wx.navigateTo({
  310. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  311. });
  312. } else {
  313. wx.navigateTo({
  314. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  315. });
  316. }
  317. },
  318. toMyCourse: function() {
  319. wx.navigateTo({
  320. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  321. });
  322. },
  323. goToFlower: function() {
  324. wx.navigateTo({
  325. url: `../../pages/social/littleFlower/littleFlower`
  326. });
  327. },
  328. signInBtn: function(e) {
  329. this.setData({
  330. indexSignDialog: false
  331. })
  332. console.log(e.detail.formId)
  333. httpRequestApi.postFormId(e.detail.formId).success(res => {
  334. console.log(res)
  335. })
  336. this.goToFlower();
  337. },
  338. missionBtn: function() {
  339. this.setData({
  340. indexMissionDialog: false
  341. })
  342. this.goToFlower();
  343. }
  344. })