index.js 1.8 KB

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