tabbar.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import props from "../../miniprogram_npm/tdesign-miniprogram/action-sheet/props";
  2. import Tabbar from "../../miniprogram_npm/tdesign-miniprogram/tab-bar/tab-bar";
  3. Component({
  4. data: {
  5. tabbarHeight: 0,
  6. pageHeight: "100vh",
  7. value: "/pages/home/home",
  8. list: [
  9. {
  10. value: "/pages/home/home",
  11. label: "首页",
  12. icon: "home",
  13. path: "/pages/home/home",
  14. },
  15. {
  16. value: "/module/chats/pages/index/index",
  17. label: "健康管家",
  18. icon: "app",
  19. path: "/module/chats/pages/index/index",
  20. },
  21. {
  22. value: "/pages/mine/mine",
  23. label: "我的",
  24. icon: "chat",
  25. path: "/pages/mine/mine",
  26. },
  27. ],
  28. },
  29. properties: {
  30. tabbarValue: {
  31. type: String,
  32. value: "",
  33. },
  34. patientId: {
  35. type: Number,
  36. value: 0,
  37. },
  38. },
  39. methods: {
  40. calculatePageHeight() {
  41. const systemInfo = wx.getSystemInfoSync();
  42. const windowHeight = systemInfo.windowHeight; // 屏幕可用高度
  43. // 获取 tabbar 高度
  44. const query = wx.createSelectorQuery();
  45. query
  46. .select(".t-tabbar")
  47. .boundingClientRect((rect) => {
  48. if (rect) {
  49. const tabbarHeight = rect.height;
  50. const contentHeight = windowHeight - tabbarHeight;
  51. this.setData({
  52. pageHeight: `${contentHeight}px`,
  53. });
  54. }
  55. })
  56. .exec();
  57. },
  58. toChatsPage(page: string) {
  59. wx.redirectTo({
  60. url: `${page}?component=guide&isShowGuide=true`,
  61. });
  62. wx.setStorageSync("isAnalysis", 3);
  63. },
  64. onChange(e:any) {
  65. this.setData({
  66. value: e.detail.value,
  67. });
  68. if (e.detail.value === "/module/chats/pages/index/index") {
  69. this.toChatsPage(e.detail.value);
  70. } else {
  71. wx.redirectTo({
  72. url: `${e.detail.value}`,
  73. fail: (error) => {
  74. console.error('Navigation failed:', error);
  75. wx.showToast({
  76. title: '页面跳转失败,请重试',
  77. icon: 'none'
  78. });
  79. }
  80. });
  81. }
  82. },
  83. },
  84. lifetimes: {
  85. attached() {
  86. // 赋值
  87. this.setData({
  88. value: this.data.tabbarValue,
  89. });
  90. this.calculatePageHeight();
  91. },
  92. },
  93. });