tabbar.ts 2.4 KB

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