index.js 2.1 KB

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