index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <CustomNav title="首页" leftType="scan" @scan="handleScan" />
  3. <view class="content">
  4. <!-- 原始页面已移至此文件,保留以备参考 -->
  5. <swiper class="banner-swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :circular="true">
  6. <swiper-item v-for="(img, idx) in bannerImages" :key="idx">
  7. <image :src="img" class="banner-img" mode="aspectFill" />
  8. </swiper-item>
  9. </swiper>
  10. <view class="card-list">
  11. <view class="card" v-for="(card, idx) in cards" :key="idx">
  12. <view class="card-title">{{ card.title }}</view>
  13. <view class="card-desc">{{ card.desc }}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <TabBar />
  18. </template>
  19. <script setup lang="ts">
  20. import { ref } from 'vue'
  21. import { onShow } from '@dcloudio/uni-app'
  22. import CustomNav from '@/components/custom-nav.vue'
  23. import TabBar from '@/components/tab-bar.vue'
  24. import { isLoggedIn as checkLogin, getRole } from '@/composables/useAuth'
  25. const title = ref('Hello')
  26. const bannerImages = [
  27. '/static/carousel/BHFIIABBCDJII-5kCEkD6zh9.png',
  28. '/static/carousel/BHFIIABBDGHEA-wtWLrLS75o.png',
  29. '/static/carousel/BHFIIABBHJBAH-yDeckRiiQP.png'
  30. ]
  31. const cards = [
  32. { title: '健康档案', desc: '管理您的健康信息' },
  33. { title: '慢病管理', desc: '查看慢病相关数据' },
  34. { title: '健康咨询', desc: '在线咨询医生' },
  35. { title: '用药提醒', desc: '设置用药提醒' }
  36. ]
  37. onShow(() => {
  38. try {
  39. const logged = checkLogin()
  40. if (!logged) {
  41. return
  42. }
  43. const r = getRole()
  44. if (r === 3) {
  45. console.log('[index] redirecting to patient index, role=', r)
  46. uni.reLaunch({ url: '/pages/patient/index/index' })
  47. return
  48. }
  49. } catch (err) {
  50. console.error('检查登录态时出错:', err)
  51. }
  52. })
  53. function handleScan(res: any) {
  54. console.log('[index] scan result', res)
  55. const resultText = res?.result || ''
  56. if (resultText) {
  57. uni.showToast({ title: String(resultText), icon: 'none', duration: 2000 })
  58. } else {
  59. uni.showToast({ title: '未识别到有效内容', icon: 'none' })
  60. }
  61. }
  62. </script>
  63. <style>
  64. .content {
  65. display: flex;
  66. flex-direction: column;
  67. align-items: center;
  68. justify-content: flex-start;
  69. padding-top: calc(var(--status-bar-height) + 44px);
  70. height: calc(100vh - var(--status-bar-height) - 44px);
  71. background: #f7f8fa;
  72. }
  73. .banner-swiper {
  74. width: 670rpx;
  75. max-width: 100vw;
  76. height: 400rpx;
  77. margin: 20rpx auto 30rpx auto;
  78. border-radius: 16rpx;
  79. overflow: hidden;
  80. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.08);
  81. background: #fff;
  82. }
  83. .banner-img {
  84. width: 100%;
  85. height: 100%;
  86. display: block;
  87. }
  88. .card-list {
  89. width: 90%;
  90. display: flex;
  91. flex-direction: column;
  92. gap: 32rpx;
  93. padding: 0 40rpx;
  94. margin: 0 auto;
  95. }
  96. .card {
  97. background: #fff;
  98. border-radius: 16rpx;
  99. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  100. padding: 40rpx 32rpx;
  101. box-sizing: border-box;
  102. display: flex;
  103. flex-direction: column;
  104. }
  105. .card-title {
  106. font-size: 36rpx;
  107. font-weight: bold;
  108. color: #333;
  109. margin-bottom: 16rpx;
  110. }
  111. .card-desc {
  112. font-size: 28rpx;
  113. color: #888;
  114. }
  115. .text-area {
  116. display: flex;
  117. justify-content: center;
  118. }
  119. .title {
  120. font-size: 36rpx;
  121. color: #8f8f94;
  122. }
  123. </style>