tabbar.ts 2.6 KB

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