index.js 1.7 KB

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