refactor(TabBar): 格式化模板代码并调整注释结构
将模板中的长属性拆分为多行以提升可读性 调整 handleTabClick 函数内的注释格式,使其更清晰
Showing
1 changed file
with
47 additions
and
56 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2026-01-29 20:33:23 | 2 | * @Date: 2026-01-29 20:33:23 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2026-01-30 20:13:36 | 4 | + * @LastEditTime: 2026-01-30 21:03:18 |
| 5 | * @FilePath: /manulife-weapp/src/components/TabBar.vue | 5 | * @FilePath: /manulife-weapp/src/components/TabBar.vue |
| 6 | * @Description: 通用底部导航栏组件,用于页面底部固定导航栏,展示页面标题。 | 6 | * @Description: 通用底部导航栏组件,用于页面底部固定导航栏,展示页面标题。 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | - <view class="fixed bottom-0 left-0 w-full bg-white shadow-[0_-4rpx_16rpx_rgba(0,0,0,0.05)] pb-[env(safe-area-inset-bottom)] z-50"> | 9 | + <view |
| 10 | + class="fixed bottom-0 left-0 w-full bg-white shadow-[0_-4rpx_16rpx_rgba(0,0,0,0.05)] pb-[env(safe-area-inset-bottom)] z-50"> | ||
| 10 | <view class="flex items-center justify-around py-[32rpx]"> | 11 | <view class="flex items-center justify-around py-[32rpx]"> |
| 11 | - <view | 12 | + <view class="flex-1 flex flex-col items-center justify-center" v-for="(item, index) in tabs" :key="index" |
| 12 | - class="flex-1 flex flex-col items-center justify-center" | 13 | + @tap="handleTabClick(item)"> |
| 13 | - v-for="(item, index) in tabs" | 14 | + <IconFont :name="item.icon" :class="[current === item.key ? 'text-blue-600' : 'text-gray-400']" size="24" /> |
| 14 | - :key="index" | 15 | + <text class="text-[20rpx] mt-[8rpx]" :class="[current === item.key ? 'text-blue-600' : 'text-gray-400']">{{ |
| 15 | - @tap="handleTabClick(item)" | 16 | + item.label }}</text> |
| 16 | - > | ||
| 17 | - <IconFont | ||
| 18 | - :name="item.icon" | ||
| 19 | - :class="[current === item.key ? 'text-blue-600' : 'text-gray-400']" | ||
| 20 | - size="24" | ||
| 21 | - /> | ||
| 22 | - <text | ||
| 23 | - class="text-[20rpx] mt-[8rpx]" | ||
| 24 | - :class="[current === item.key ? 'text-blue-600' : 'text-gray-400']" | ||
| 25 | - >{{ item.label }}</text> | ||
| 26 | </view> | 17 | </view> |
| 27 | </view> | 18 | </view> |
| 28 | </view> | 19 | </view> |
| ... | @@ -70,50 +61,50 @@ const handleTabClick = (item) => { | ... | @@ -70,50 +61,50 @@ const handleTabClick = (item) => { |
| 70 | if (item.key === 'home') { | 61 | if (item.key === 'home') { |
| 71 | go(item.path) | 62 | go(item.path) |
| 72 | } else if (item.key === 'me') { | 63 | } else if (item.key === 'me') { |
| 73 | - // Check if 'me' page exists, otherwise show toast or just go | 64 | + // Check if 'me' page exists, otherwise show toast or just go |
| 74 | - // For now, assuming me page might not exist or we just navigate | 65 | + // For now, assuming me page might not exist or we just navigate |
| 75 | - // go(item.path) | 66 | + // go(item.path) |
| 76 | - // Based on existing logic in index.vue: | 67 | + // Based on existing logic in index.vue: |
| 77 | - // Taro.redirectTo({ url: '/pages/me/index' }); | 68 | + // Taro.redirectTo({ url: '/pages/me/index' }); |
| 78 | - // But wait, standard tab bar usually uses switchTab or redirectTo. | 69 | + // But wait, standard tab bar usually uses switchTab or redirectTo. |
| 79 | - // Since this is a custom tab bar, we use useGo (which uses navigateTo usually). | 70 | + // Since this is a custom tab bar, we use useGo (which uses navigateTo usually). |
| 80 | - // Ideally for tab switching we might want reLaunch or redirectTo to avoid stack buildup. | 71 | + // Ideally for tab switching we might want reLaunch or redirectTo to avoid stack buildup. |
| 81 | - // However, useGo defaults to navigateTo. | 72 | + // However, useGo defaults to navigateTo. |
| 82 | - // Let's use reLaunch to simulate tab switching behavior if it's a "tab bar" | 73 | + // Let's use reLaunch to simulate tab switching behavior if it's a "tab bar" |
| 83 | 74 | ||
| 84 | - // Actually, let's look at index.vue logic: | 75 | + // Actually, let's look at index.vue logic: |
| 85 | - // if (item.key === 'me') Taro.redirectTo({ url: '/pages/me/index' }); | 76 | + // if (item.key === 'me') Taro.redirectTo({ url: '/pages/me/index' }); |
| 86 | - // if (item.key === 'ai') Taro.showToast({ title: '功能开发中', icon: 'none' }); | 77 | + // if (item.key === 'ai') Taro.showToast({ title: '功能开发中', icon: 'none' }); |
| 87 | 78 | ||
| 88 | - // I will replicate this logic for now but make it more generic if possible. | 79 | + // I will replicate this logic for now but make it more generic if possible. |
| 89 | - // Since 'me' and 'ai' might not be fully implemented, I will stick to what I know. | 80 | + // Since 'me' and 'ai' might not be fully implemented, I will stick to what I know. |
| 90 | - // But 'onboarding' and 'signing' pages use this tab bar too. | 81 | + // But 'onboarding' and 'signing' pages use this tab bar too. |
| 91 | 82 | ||
| 92 | - // If we are on 'onboarding' (which is seemingly a sub-page but has a tab bar), | 83 | + // If we are on 'onboarding' (which is seemingly a sub-page but has a tab bar), |
| 93 | - // clicking 'Home' should probably go back to Home. | 84 | + // clicking 'Home' should probably go back to Home. |
| 94 | 85 | ||
| 95 | - Taro.reLaunch({ url: item.path }) | 86 | + Taro.reLaunch({ url: item.path }) |
| 96 | } else if (item.key === 'ai') { | 87 | } else if (item.key === 'ai') { |
| 97 | - // 跳转到腾讯元宝AI小程序 | 88 | + // 跳转到腾讯元宝AI小程序 |
| 98 | - Taro.navigateToMiniProgram({ | 89 | + Taro.navigateToMiniProgram({ |
| 99 | - appId: 'wxXXXXXXXXXXXXXXXX', // TODO: 替换为实际的腾讯元宝小程序 AppID | 90 | + appId: 'wxXXXXXXXXXXXXXXXX', // TODO: 替换为实际的腾讯元宝小程序 AppID |
| 100 | - path: 'pages/index/index', // TODO: 元宝小程序的路径(根据实际情况填写) | 91 | + path: 'pages/index/index', // TODO: 元宝小程序的路径(根据实际情况填写) |
| 101 | - extraData: { | 92 | + extraData: { |
| 102 | - // TODO: 如果需要传递参数,在这里配置 | 93 | + // TODO: 如果需要传递参数,在这里配置 |
| 103 | - // from: 'manulife-weapp' | 94 | + // from: 'manulife-weapp' |
| 104 | - }, | 95 | + }, |
| 105 | - envVersion: 'release', // 打开正式版 | 96 | + envVersion: 'release', // 打开正式版 |
| 106 | - success: (res) => { | 97 | + success: (res) => { |
| 107 | - console.log('跳转元宝小程序成功', res) | 98 | + console.log('跳转元宝小程序成功', res) |
| 108 | - }, | 99 | + }, |
| 109 | - fail: (err) => { | 100 | + fail: (err) => { |
| 110 | - console.error('跳转元宝小程序失败', err) | 101 | + console.error('跳转元宝小程序失败', err) |
| 111 | - Taro.showToast({ | 102 | + Taro.showToast({ |
| 112 | - title: '跳转失败,请稍后重试', | 103 | + title: '跳转失败,请稍后重试', |
| 113 | - icon: 'none' | 104 | + icon: 'none' |
| 114 | - }) | 105 | + }) |
| 115 | - } | 106 | + } |
| 116 | - }) | 107 | + }) |
| 117 | } | 108 | } |
| 118 | } | 109 | } |
| 119 | </script> | 110 | </script> | ... | ... |
-
Please register or login to post a comment