index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. //隐藏弹框
  51. this.setData({
  52. hide: !this.data.hide
  53. })
  54. //登录页信息
  55. this.onShow();
  56. },
  57. //tab点击
  58. switcher: function ({
  59. currentTarget
  60. }) {
  61. this.updateData(currentTarget.dataset.index);
  62. },
  63. // 根据index 更新template
  64. updateData: function (index) {
  65. let myIndex = index;
  66. let templates = this.data.tab[myIndex].templates;
  67. this.setData({
  68. myIndex,
  69. templates
  70. });
  71. if (myIndex == 0) {
  72. groupInit(this);
  73. }
  74. if (myIndex == 1) {
  75. hotInit(this);
  76. }
  77. if (myIndex == 2) {
  78. console.log('follow')
  79. followInit(this);
  80. }
  81. if (myIndex == 3) {
  82. myInit(this);
  83. }
  84. },
  85. onLoad: function (options) {
  86. if (options.index) {
  87. this.updateData(options.index)
  88. }
  89. hotInit(this)
  90. // this.init();
  91. },
  92. onShow: function () {
  93. // this.init();
  94. getOpenidSessionKey((res) => {
  95. }, (error) => {
  96. // console.log(error)
  97. this.setData({
  98. hide: !this.data.hide
  99. })
  100. });
  101. },
  102. //初始化数据
  103. init: function () {
  104. httputil.getOpenidSessionKey((res) => {
  105. console.log('微信的用户信息', res);
  106. // this.setData({
  107. // jurisdictionFlag: true
  108. // })
  109. // lookInit(this);
  110. }, (error) => {
  111. console.log(error);
  112. this.jurisdiction()
  113. // this.setData({
  114. // jurisdictionFlag: false
  115. // })
  116. });
  117. }
  118. })