home-frame.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const app = getApp()
  2. import { menu } from "../../utils/site";
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. options: { multipleSlots: true },
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. // 平台信息
  15. basicInfo: {},
  16. list: [],
  17. active: 0
  18. },
  19. pageLifetimes: {
  20. show: function () {
  21. const that = this;
  22. that.search()
  23. },
  24. hide: function () { },
  25. resize: function () { },
  26. },
  27. /**
  28. * 组件的方法列表
  29. */
  30. methods: {
  31. // 查询基本信息
  32. async search() {
  33. const that = this;
  34. // 获取当前路由地址
  35. let pages = getCurrentPages();
  36. let currentPage = pages[pages.length - 1];
  37. let list = menu.sort((a, b) => {
  38. return a.sort - b.sort
  39. });
  40. that.setData({ list })
  41. let routeInfo = list.find((i) => i.route == currentPage.route);
  42. if (routeInfo) {
  43. let index = list.findIndex((i) => i.route == currentPage.route);
  44. that.setData({ active: index })
  45. }
  46. },
  47. toPath(index) {
  48. const that = this;
  49. let active = index.currentTarget.dataset.index;
  50. that.setData({ active });
  51. let route = that.data.list[active];
  52. if (route) that.triggerEvent('toPath', route)
  53. }
  54. }
  55. })