home.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //index.js
  2. import * as requestAPI from '../../models/dataModel'
  3. import { menuList } from '../../menu/menu'
  4. //获取应用实例
  5. const app = getApp()
  6. Page({
  7. data: {
  8. isLogin: false,
  9. menuList: []
  10. },
  11. onLoad() {
  12. },
  13. onShow() {
  14. if(wx.getStorageSync('token') && this.data.menuList.length===0) {
  15. requestAPI.getMenu().then(res=>{
  16. let tempList = []
  17. if(res&&res.data&&res.data.data) {
  18. // for(let i of res.data.data) {
  19. // let filterList = menuList.filter(item => {
  20. // return item.name === i.name
  21. // })
  22. // tempList = tempList.concat(filterList)
  23. // }
  24. tempList = menuList
  25. this.setData({
  26. menuList: tempList,
  27. isLogin: true
  28. })
  29. }
  30. })
  31. }
  32. },
  33. getLink: function(event) {
  34. wx.navigateTo({
  35. url: `/pages/${event.currentTarget.dataset.item.url}/index`,
  36. })
  37. }
  38. //事件处理函数
  39. // getmenu: function () {
  40. // wx.request({
  41. // url: 'http://192.168.20.53:9999/admin/menu/tree',
  42. // method: 'get',
  43. // header: {
  44. // 'Authorization': 'Bearer ' + wx.getStorageSync('token')
  45. // },
  46. // success(r) {
  47. // console.log(r)
  48. // console.log(r)
  49. // }
  50. // })
  51. // }
  52. })