index.js 8.7 KB

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