foot.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // commpents/mobile-frame/mobile-main.js
  2. const app = getApp();
  3. import { system } from "../../utils/dict";
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. options: { multipleSlots: true },
  9. properties: {
  10. tabSelectid: { type: 'string', value: '' }
  11. },
  12. // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
  13. attached: function () { }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  14. ready: function () { },
  15. pageLifetimes: {
  16. // 组件所在页面的生命周期函数
  17. show: function () { this.search() },
  18. hide: function () { },
  19. resize: function () { },
  20. },
  21. /**
  22. * 组件的初始数据
  23. */
  24. data: {
  25. // 当前选中菜单
  26. active: 0,
  27. // 菜单列表
  28. menuList: []
  29. },
  30. /**
  31. * 组件的方法列表
  32. */
  33. methods: {
  34. // 跳转
  35. tabPath(e) {
  36. const that = this;
  37. that.setData({ active: e.detail });
  38. let route = that.data.menuList[e.detail];
  39. if (route) that.triggerEvent('tabPath', route)
  40. },
  41. search() {
  42. const that = this;
  43. // 监听用户是否登录
  44. wx.getStorage({
  45. key: 'token',
  46. success: res => {
  47. // 获取当前路由地址
  48. let pages = getCurrentPages();
  49. let currentPage = pages[pages.length - 1];
  50. let menu = system.filter((i) => i.type.includes(res.data.type));
  51. if (menu) {
  52. that.setData({ menuList: menu });
  53. let index = menu.findIndex((i) => i.route == currentPage.route);
  54. if (index) that.setData({ active: index });
  55. }
  56. },
  57. fail: res => {
  58. return wx.redirectTo({ url: '/pages/login/index', })
  59. }
  60. })
  61. }
  62. }
  63. })