foot.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. frameStyle: { type: Object }
  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. const { index } = e.currentTarget.dataset;
  38. that.setData({ active: index });
  39. let route = that.data.menuList[index];
  40. if (route) that.triggerEvent('tabPath', route)
  41. },
  42. search() {
  43. const that = this;
  44. // 获取当前路由地址
  45. let pages = getCurrentPages();
  46. let currentPage = pages[pages.length - 1];
  47. let menu = system.filter((i) => i.type.includes('0'));
  48. if (menu) {
  49. that.setData({ menuList: menu });
  50. let index = menu.findIndex((i) => i.route == currentPage.route);
  51. if (index) that.setData({ active: index });
  52. }
  53. // 监听用户是否登录
  54. // wx.getStorage({
  55. // key: 'token',
  56. // success: res => {
  57. // // 获取当前路由地址
  58. // let pages = getCurrentPages();
  59. // let currentPage = pages[pages.length - 1];
  60. // let menu = system.filter((i) => i.type.includes(res.data.type));
  61. // if (menu) {
  62. // that.setData({ menuList: menu });
  63. // let index = menu.findIndex((i) => i.route == currentPage.route);
  64. // if (index) that.setData({ active: index });
  65. // }
  66. // },
  67. // fail: res => {
  68. // return wx.redirectTo({ url: '/pages/login/index', })
  69. // }
  70. // })
  71. }
  72. }
  73. })