index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. let util = require('../../utils/util')
  2. let api = require('../../config/api')
  3. let app = getApp()
  4. Page({
  5. data: {
  6. fixed: false,
  7. userInfo: { nickname: '点击登录', avatar: '/static/images/avatar.png' },
  8. userMenus: [
  9. { url: '/packageUser/collect/collect', name: '收藏', value: 0 },
  10. { url: '/packageUser/footprint/footprint', name: '浏览足迹', value: 0 }
  11. ],
  12. categoryList: [
  13. { pic: "https://www.qdeasydo.com/api/folder/500f9715-cf28-485e-8df3-11bd5127935c", id: 100101307 },
  14. { pic: "https://www.qdeasydo.com/api/folder/6eb7bb4a-dbea-489f-a010-416bf6a8ddd2", id: 100101311 },
  15. { pic: "https://www.qdeasydo.com/api/folder/e061f829-268c-437e-8734-9a34b5c4b2f6", id: 100101313 },
  16. { pic: "https://www.qdeasydo.com/api/folder/2ac688c9-3218-4b1d-a3f3-83f0b420cb3e", id: 100101316 }
  17. ]
  18. },
  19. onLoad: function() {
  20. this.setData({ navHeight: app.globalData.navHeight })
  21. },
  22. onShow: function() {
  23. let userInfo = { nickname: '点击登录', avatar: '/static/images/avatar.png' }
  24. if (wx.getStorageSync('token')) {
  25. userInfo = { ...this.data.userInfo, ...wx.getStorageSync('userInfo') }
  26. this.getUser()
  27. }
  28. this.setData({ userInfo })
  29. },
  30. // 获取用户的登录信息
  31. getUser() {
  32. util.showLoad('加载中')
  33. util.request(api.UserIndex).then(res => {
  34. util.hideLoad()
  35. if (res.errno === 0) {
  36. let { userMenus } = this.data
  37. let { collectCount, footPrintCount } = res.data
  38. userMenus[0].value = collectCount
  39. userMenus[1].value = footPrintCount
  40. this.setData({ userMenus })
  41. } else util.showErrorToast(res.errmsg)
  42. }).catch(() => {
  43. util.hideLoad()
  44. util.showErrorToast('网络连接失败')
  45. })
  46. },
  47. onPageScroll({ scrollTop }) {
  48. const fixed = scrollTop > app.globalData.navHeight ? true : false
  49. this.setData({ fixed })
  50. },
  51. redirect({ currentTarget }) {
  52. const { url } = currentTarget.dataset
  53. if (!wx.getStorageSync('token')) {
  54. wx.navigateTo({ url: '/packageLogin/login/login' })
  55. return
  56. }
  57. wx.navigateTo({ url })
  58. },
  59. toCategory({ currentTarget }) {
  60. const { id } = currentTarget.dataset
  61. app.globalData.menuId = id
  62. wx.switchTab({ url: '/pages/catalog/catalog' })
  63. }
  64. })