index.js 1.9 KB

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