|
|
@@ -1,74 +1,71 @@
|
|
|
<template>
|
|
|
<view class="tab-bar">
|
|
|
- <view class="tab-item" @click="onTabClick(0)">
|
|
|
- <!-- <uni-icons type="home" size="20" color="#666"></uni-icons> -->
|
|
|
- <image src="/static/icons/remixicon/home-3-line.svg" class="icon" mode="widthFix" />
|
|
|
- <text class="tab-text">首页</text>
|
|
|
- </view>
|
|
|
- <view class="tab-item" @click="onTabClick(1)">
|
|
|
- <image src="/static/icons/remixicon/line-chart-line.svg" class="icon" mode="widthFix" />
|
|
|
- <!-- <uni-icons type="bars" size="20" color="#666"></uni-icons> -->
|
|
|
- <text class="tab-text">健康</text>
|
|
|
- </view>
|
|
|
- <view class="tab-item" @click="onTabClick(2)">
|
|
|
- <image src="/static/icons/remixicon/account-circle-line.svg" class="icon" mode="widthFix" />
|
|
|
- <!-- <uni-icons type="person" size="20" color="#666"></uni-icons> -->
|
|
|
- <text class="tab-text">用户</text>
|
|
|
+ <view v-for="(tab, index) in currentTabs" :key="index" class="tab-item" @click="onTabClick(index)">
|
|
|
+ <image :src="tab.icon" class="icon" mode="widthFix" />
|
|
|
+ <text class="tab-text">{{ tab.text }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
+import { computed } from 'vue'
|
|
|
import { isLoggedIn as checkLogin, getRole } from '../composables/useAuth'
|
|
|
-const onTabClick = (index: number) => {
|
|
|
- console.log('Tab clicked:', index)
|
|
|
|
|
|
- switch (index) {
|
|
|
- case 0: // 慢病首页
|
|
|
- try {
|
|
|
- const logged = checkLogin()
|
|
|
- const role = logged ? getRole() : null
|
|
|
- if (logged && role === 3) {
|
|
|
- uni.switchTab({ url: '/pages/patient/index/index' })
|
|
|
- } else {
|
|
|
- uni.switchTab({ url: '/pages/public/index/index' })
|
|
|
- }
|
|
|
- } catch (err) {
|
|
|
- console.error('tab click index redirect error', err)
|
|
|
- uni.switchTab({ url: '/pages/public/index/index' })
|
|
|
- }
|
|
|
- break
|
|
|
- case 1: // 健康数据
|
|
|
- try {
|
|
|
- // 本地判断:已登录且 role===3 则跳转到患者端健康页(使用 switchTab,因为该页属于 tab)
|
|
|
- // 未登录或非患者则降级到公共健康页
|
|
|
- // TODO: 后续支持根据其他角色(医生/患者家属等)跳转到各自的健康页
|
|
|
- const logged = checkLogin()
|
|
|
- const role = logged ? getRole() : null
|
|
|
- if (logged && role === 3) {
|
|
|
- uni.switchTab({ url: '/pages/patient/health/index' })
|
|
|
- } else {
|
|
|
- uni.switchTab({ url: '/pages/public/health/index' })
|
|
|
- }
|
|
|
- } catch (err) {
|
|
|
- console.error('tab click health redirect error', err)
|
|
|
- uni.switchTab({ url: '/pages/public/health/index' })
|
|
|
- }
|
|
|
- break
|
|
|
- case 2: // 个人中心
|
|
|
- try {
|
|
|
- const logged = checkLogin()
|
|
|
- const role = logged ? getRole() : null
|
|
|
- if (logged && role === 3) {
|
|
|
- uni.switchTab({ url: '/pages/patient/profile/index' })
|
|
|
- } else {
|
|
|
- uni.switchTab({ url: '/pages/public/profile/index' })
|
|
|
- }
|
|
|
- } catch (err) {
|
|
|
- console.error('tab click profile redirect error', err)
|
|
|
- uni.switchTab({ url: '/pages/public/profile/index' })
|
|
|
- }
|
|
|
- break
|
|
|
+type TabConfig = {
|
|
|
+ icon: string
|
|
|
+ text: string
|
|
|
+ url: string
|
|
|
+}
|
|
|
+
|
|
|
+type RoleTabs = {
|
|
|
+ [key: number | string]: TabConfig[]
|
|
|
+}
|
|
|
+
|
|
|
+// 根据角色定义不同的tab配置
|
|
|
+const roleTabs: RoleTabs = {
|
|
|
+ // 未登录
|
|
|
+ null: [
|
|
|
+ { icon: '/static/icons/remixicon/home-3-line.svg', text: '首页', url: '/pages/public/index/index' },
|
|
|
+ { icon: '/static/icons/remixicon/line-chart-line.svg', text: '健康', url: '/pages/public/health/index' },
|
|
|
+ { icon: '/static/icons/remixicon/account-circle-line.svg', text: '我的', url: '/pages/public/profile/index' }
|
|
|
+ ],
|
|
|
+ // 医生
|
|
|
+ 2: [
|
|
|
+ { icon: '/static/icons/remixicon/home-3-line.svg', text: '首页', url: '/pages/doctor/index/index' },
|
|
|
+ { icon: '/static/icons/remixicon/settings-line.svg', text: '后台', url: '/pages/public/health/index' }, // 暂时使用公共健康页,后续可创建医生患者管理页
|
|
|
+ { icon: '/static/icons/remixicon/account-circle-line.svg', text: '我的', url: '/pages/public/profile/index' } // 暂时使用公共profile,后续可创建医生profile
|
|
|
+ ],
|
|
|
+ // 患者
|
|
|
+ 3: [
|
|
|
+ { icon: '/static/icons/remixicon/home-3-line.svg', text: '首页', url: '/pages/patient/index/index' },
|
|
|
+ { icon: '/static/icons/remixicon/line-chart-line.svg', text: '健康', url: '/pages/patient/health/index' },
|
|
|
+ { icon: '/static/icons/remixicon/account-circle-line.svg', text: '我的', url: '/pages/patient/profile/index' }
|
|
|
+ ],
|
|
|
+ // 患者家属
|
|
|
+ 4: [
|
|
|
+ { icon: '/static/icons/remixicon/home-3-line.svg', text: '首页', url: '/pages/patient-family/index/index' },
|
|
|
+ { icon: '/static/icons/remixicon/line-chart-line.svg', text: '健康', url: '/pages/public/health/index' }, // 暂时使用公共健康页,后续可创建家属健康页
|
|
|
+ { icon: '/static/icons/remixicon/account-circle-line.svg', text: '我的', url: '/pages/public/profile/index' } // 暂时使用公共profile,后续可创建家属profile
|
|
|
+ ]
|
|
|
+}
|
|
|
+
|
|
|
+// 获取当前用户的tabs配置
|
|
|
+const currentTabs = computed(() => {
|
|
|
+ const logged = checkLogin()
|
|
|
+ const role = logged ? getRole() : null
|
|
|
+ return roleTabs[role as keyof RoleTabs] || roleTabs.null
|
|
|
+})
|
|
|
+
|
|
|
+const onTabClick = (index: number) => {
|
|
|
+ const tab = currentTabs.value[index]
|
|
|
+ if (tab) {
|
|
|
+ try {
|
|
|
+ uni.switchTab({ url: tab.url })
|
|
|
+ } catch (err) {
|
|
|
+ console.error('tab click redirect error', err)
|
|
|
+ // fallback到公共首页
|
|
|
+ uni.switchTab({ url: '/pages/public/index/index' })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|