index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if (!this.data.jurisdictionFlag) {
  37. return false;
  38. }
  39. let ind = currentTarget.dataset.ind;
  40. let templates = this.data.tab[ind].templates;
  41. //console.log(this.data[ind])
  42. this.setData({
  43. ind,
  44. templates
  45. })
  46. if (ind == 1) {
  47. searchInit(this);
  48. }
  49. if (ind == 2) {
  50. myInit(this);
  51. }
  52. },
  53. jurisdiction: function () {
  54. setTimeout(()=>{
  55. this.init();
  56. },1000)
  57. },
  58. onLoad: function (options) {
  59. if (options.id) {
  60. wx.setStorageSync('uid', options.uid);
  61. }
  62. if(options.ind) {
  63. let ind = options.ind;
  64. let templates = this.data.tab[ind].templates;
  65. this.setData({
  66. templates,
  67. ind,
  68. })
  69. if (ind == 1) {
  70. searchInit(this);
  71. }
  72. if (ind == 2) {
  73. myInit(this);
  74. }
  75. }
  76. this.init();
  77. },
  78. //初始化数据
  79. init: function (uid) {
  80. httputil.getOpenidSessionKey((res) => {
  81. console.log('微信的用户信息', res);
  82. wx.setStorageSync('userInfo', res)
  83. this.setData({
  84. jurisdictionFlag: true
  85. })
  86. lookInit(this);
  87. },(error) => {
  88. console.log(error);
  89. this.setData({
  90. jurisdictionFlag: false
  91. })
  92. });
  93. }
  94. })