index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //index.js
  2. //获取应用实例
  3. import {
  4. getOpenidSessionKey
  5. } from '../../utils/httpUtil';
  6. const app = getApp()
  7. import {
  8. hotInit
  9. } from '../../component/hot/hot';
  10. import {
  11. groupInit
  12. } from '../../component/group/group';
  13. import {
  14. myInit
  15. } from '../../component/my/my';
  16. import {
  17. followInit
  18. } from '../../component/follow/follow';
  19. // import '../../utils/hls';
  20. // import httpRequestApi from '../../utils/APIRequest';
  21. import httputil from '../../utils/httpUtil';
  22. Page({
  23. data: {
  24. tab: [{
  25. name: '热团',
  26. templates: 'group',
  27. },
  28. {
  29. name: '推荐',
  30. templates: 'hot',
  31. },
  32. {
  33. name: '关注',
  34. templates: 'follow',
  35. },
  36. {
  37. name: '我的',
  38. templates: 'my',
  39. }
  40. ],
  41. myIndex: 1,
  42. templates: 'hot',
  43. title: 'index中的title',
  44. jurisdictionFlag: true,
  45. hotInput: '12345',
  46. mineSettingInfo: '528',
  47. hide: true
  48. },
  49. jurisdiction: function () {
  50. console.log(1)
  51. //隐藏弹框
  52. this.setData({
  53. hide: !this.data.hide
  54. })
  55. //登录页信息
  56. this.onShow();
  57. },
  58. //tab点击
  59. switcher: function ({
  60. currentTarget
  61. }) {
  62. this.updateData(currentTarget.dataset.index);
  63. },
  64. // 根据index 更新template
  65. updateData: function (index) {
  66. let myIndex = index;
  67. let templates = this.data.tab[myIndex].templates;
  68. this.setData({
  69. myIndex,
  70. templates
  71. });
  72. if (myIndex == 0) {
  73. groupInit(this);
  74. }
  75. if (myIndex == 1) {
  76. hotInit(this);
  77. }
  78. if (myIndex == 2) {
  79. console.log('follow')
  80. followInit(this);
  81. }
  82. if (myIndex == 3) {
  83. myInit(this);
  84. }
  85. },
  86. onLoad: function (options) {
  87. if (options.index) {
  88. this.updateData(options.index)
  89. }
  90. hotInit(this)
  91. // this.init();
  92. },
  93. onShow: function () {
  94. // this.init();
  95. getOpenidSessionKey((res) => {
  96. console.log(res);
  97. }, (error) => {
  98. // console.log(error)
  99. this.setData({
  100. hide: !this.data.hide
  101. })
  102. });
  103. },
  104. //初始化数据
  105. init: function () {
  106. httputil.getOpenidSessionKey((res) => {
  107. console.log('微信的用户信息', res);
  108. // this.setData({
  109. // jurisdictionFlag: true
  110. // })
  111. // lookInit(this);
  112. }, (error) => {
  113. console.log(error);
  114. this.jurisdiction()
  115. // this.setData({
  116. // jurisdictionFlag: false
  117. // })
  118. });
  119. }
  120. })