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: "AI对话管家",
  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. console.log(this.data.pageHeight, "2222");
  57. },
  58. toChatsPage(page: string) {
  59. console.log(this.data.patientId, "patientId", page);
  60. if (!this.data?.patientId) {
  61. wx.showModal({
  62. title: "出错了",
  63. content: "错误,请重试",
  64. showCancel: false,
  65. });
  66. return;
  67. }
  68. wx.redirectTo({
  69. url: `${page}?component=guide&isShowGuide=true`,
  70. });
  71. wx.setStorageSync("isAnalysis", 3);
  72. },
  73. onChange(e) {
  74. console.log(e, "e");
  75. this.setData({
  76. value: e.detail.value,
  77. });
  78. if (e.detail.value === "/module/chats/pages/index/index") {
  79. this.toChatsPage(e.detail.value);
  80. } else {
  81. wx.redirectTo({
  82. url: `${e.detail.value}`,
  83. fail: (error) => {
  84. console.error('Navigation failed:', error);
  85. wx.showToast({
  86. title: '页面跳转失败,请重试',
  87. icon: 'none'
  88. });
  89. }
  90. });
  91. }
  92. },
  93. },
  94. lifetimes: {
  95. attached() {
  96. console.log(this.data.tabbarValue, "tabbarValuetabbarValue");
  97. this.setData({
  98. value: this.data.tabbarValue,
  99. });
  100. this.calculatePageHeight();
  101. },
  102. },
  103. });