index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <CustomNav title="家属首页" leftType="scan" @scan="handleScan" :opacity="0" />
  3. <view class="page-container">
  4. <view class="content">
  5. <view class="user-info">
  6. <view class="avatar-section">
  7. <view class="avatar">
  8. <view class="avatar-frame">
  9. <image class="avatar-img" :src="avatarSrc" mode="aspectFill" />
  10. </view>
  11. </view>
  12. <view class="user-details">
  13. <text class="username">{{ user.nickname || '未登录' }}</text>
  14. <text class="user-role">家属</text>
  15. </view>
  16. <view class="qr-button" @click="onQrClick">
  17. <image src="/static/icons/remixicon/qr-code-line.svg" class="qr-icon" />
  18. </view>
  19. </view>
  20. </view>
  21. <view class="function-container">
  22. <view class="function-row">
  23. <view class="function-item blue" @click="onItemClick('家人管理')">
  24. <view class="item-content">
  25. <view class="title-row">
  26. <view class="item-line"></view>
  27. <text class="item-title">家人管理</text>
  28. </view>
  29. <text class="item-desc">管理被监护的家人</text>
  30. </view>
  31. </view>
  32. <view class="function-item green" @click="onItemClick('健康监控')">
  33. <view class="item-content">
  34. <view class="title-row">
  35. <view class="item-line"></view>
  36. <text class="item-title">健康监控</text>
  37. </view>
  38. <text class="item-desc">查看家人健康数据</text>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="function-row">
  43. <view class="function-item orange" @click="onItemClick('联系医生')">
  44. <view class="item-content">
  45. <view class="title-row">
  46. <view class="item-line"></view>
  47. <text class="item-title">联系医生</text>
  48. </view>
  49. <text class="item-desc">与医生沟通交流</text>
  50. </view>
  51. </view>
  52. <view class="function-item purple" @click="onItemClick('疑问解答')">
  53. <view class="item-content">
  54. <view class="title-row">
  55. <view class="item-line"></view>
  56. <text class="item-title">疑问解答</text>
  57. </view>
  58. <text class="item-desc">咨询健康相关问题</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="today-reminder-card">
  64. <view class="card-header">
  65. <text class="card-title">今日提醒</text>
  66. </view>
  67. <view class="card-content">
  68. <view class="reminder-item" @click="onItemClick('健康监控')">
  69. <view class="reminder-icon">
  70. <image src="/static/icons/remixicon/time-line.svg" class="icon" />
  71. </view>
  72. <view class="reminder-text">
  73. <text class="reminder-number">{{ todayReminders.medicationCount }}</text>
  74. <text class="reminder-label">用药提醒</text>
  75. </view>
  76. </view>
  77. <view class="reminder-item" @click="onItemClick('健康监控')">
  78. <view class="reminder-icon">
  79. <image src="/static/icons/remixicon/alert-line.svg" class="icon" />
  80. </view>
  81. <view class="reminder-text">
  82. <text class="reminder-number">{{ todayReminders.abnormalCount }}</text>
  83. <text class="reminder-label">异常数据</text>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="family-activity-card">
  89. <view class="card-header">
  90. <text class="card-title">家人动态</text>
  91. </view>
  92. <view class="activity-card-content">
  93. <view class="activity-item" v-for="(activity, index) in familyActivities" :key="index">
  94. <view class="activity-avatar">
  95. <image :src="activity.familyAvatar" class="avatar-img" mode="aspectFill" />
  96. </view>
  97. <view class="activity-text">
  98. <text class="activity-desc">{{ activity.desc }}</text>
  99. <text class="activity-time">{{ activity.time }}</text>
  100. </view>
  101. </view>
  102. <view v-if="familyActivities.length === 0" class="no-activity">
  103. <text>暂无家人动态</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. <TabBar />
  110. </template>
  111. <script setup lang="ts">
  112. import { ref, computed } from 'vue'
  113. import { onShow } from '@dcloudio/uni-app'
  114. import CustomNav from '@/components/custom-nav.vue'
  115. import TabBar from '@/components/tab-bar.vue'
  116. const user = ref<{ avatar?: string; nickname?: string }>({})
  117. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  118. const avatarSrc = computed(() => {
  119. const a = user.value?.avatar
  120. if (!a) return defaultAvatarUrl
  121. try {
  122. const s = String(a)
  123. if (/^(https?:\/\/|data:|wxfile:\/\/|file:\/\/|\/static\/)/i.test(s)) {
  124. return s
  125. }
  126. if (/^(\.|\/|temp)/i.test(s)) return s
  127. } catch (e) {
  128. // fallback
  129. }
  130. return defaultAvatarUrl
  131. })
  132. const todayReminders = ref({
  133. medicationCount: 0,
  134. abnormalCount: 0
  135. })
  136. const familyActivities = ref([
  137. {
  138. desc: '家人张三完成了今日用药',
  139. time: '10分钟前',
  140. familyAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  141. },
  142. {
  143. desc: '家人李四血糖数据已更新',
  144. time: '1小时前',
  145. familyAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  146. },
  147. {
  148. desc: '家人王五预约了下周复诊',
  149. time: '2小时前',
  150. familyAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  151. }
  152. ])
  153. const loadUser = () => {
  154. try {
  155. const u = uni.getStorageSync('user_info')
  156. if (u) {
  157. user.value = u
  158. }
  159. } catch (e) {
  160. // ignore
  161. }
  162. }
  163. const fetchUserInfo = async () => {
  164. try {
  165. const token = uni.getStorageSync('token')
  166. if (!token) return
  167. uni.showLoading({ title: '加载中...' })
  168. const response = await uni.request({
  169. url: 'https://wx.baiyun.work/user_info',
  170. method: 'POST',
  171. header: {
  172. 'Content-Type': 'application/json',
  173. 'Authorization': `Bearer ${token}`
  174. },
  175. data: {}
  176. })
  177. uni.hideLoading()
  178. console.log('User info response:', response)
  179. const resp = response.data as any
  180. if (response.statusCode === 401) {
  181. // Token 无效,清除并跳转登录
  182. uni.removeStorageSync('token')
  183. uni.removeStorageSync('role')
  184. user.value = {}
  185. uni.reLaunch({ url: '/pages/public/login/index' })
  186. return
  187. }
  188. if (resp && resp.code === 200 && resp.data) {
  189. user.value = resp.data
  190. uni.setStorageSync('user_info', resp.data)
  191. if (!resp.data.nickname || !resp.data.avatar) {
  192. uni.navigateTo({ url: '/pages/patient-family/profile/index' })
  193. }
  194. }
  195. } catch (err) {
  196. uni.hideLoading()
  197. console.error('Fetch user info error:', err)
  198. }
  199. }
  200. const fetchTodayReminders = async () => {
  201. try {
  202. const token = uni.getStorageSync('token')
  203. if (!token) return
  204. const response = await uni.request({
  205. url: 'https://wx.baiyun.work/family/today_reminders',
  206. method: 'GET',
  207. header: {
  208. 'Authorization': `Bearer ${token}`
  209. }
  210. })
  211. const resp = response.data as any
  212. if (resp && resp.code === 200 && resp.data) {
  213. todayReminders.value = resp.data
  214. }
  215. } catch (err) {
  216. console.error('Fetch today reminders error:', err)
  217. }
  218. }
  219. const fetchFamilyActivities = async () => {
  220. try {
  221. const token = uni.getStorageSync('token')
  222. if (!token) return
  223. const response = await uni.request({
  224. url: 'https://wx.baiyun.work/family/activities',
  225. method: 'GET',
  226. header: {
  227. 'Authorization': `Bearer ${token}`
  228. }
  229. })
  230. const resp = response.data as any
  231. if (resp && resp.code === 200 && resp.data) {
  232. familyActivities.value = resp.data
  233. }
  234. } catch (err) {
  235. console.error('Fetch family activities error:', err)
  236. }
  237. }
  238. // 如果在微信小程序端且未登录,自动跳转到登录页
  239. onShow(() => {
  240. const token = uni.getStorageSync('token')
  241. if (!token) {
  242. // 使用 uni.reLaunch 替代 navigateTo,确保页面栈被清空
  243. uni.reLaunch({ url: '/pages/public/login/index' })
  244. } else {
  245. fetchUserInfo()
  246. fetchTodayReminders()
  247. fetchFamilyActivities()
  248. }
  249. })
  250. function handleScan(res: any) {
  251. console.log('[family-index] scan result', res)
  252. const resultText = res?.result || ''
  253. if (resultText) {
  254. uni.showToast({ title: String(resultText), icon: 'none', duration: 2000 })
  255. } else {
  256. uni.showToast({ title: '未识别到有效内容', icon: 'none' })
  257. }
  258. }
  259. function onItemClick(type: string) {
  260. if (type === '家人管理') {
  261. uni.navigateTo({ url: '/pages/patient-family/family/index' })
  262. } else if (type === '健康监控') {
  263. uni.navigateTo({ url: '/pages/patient-family/health/index' })
  264. } else if (type === '联系医生') {
  265. uni.navigateTo({ url: '/pages/patient-family/doctor/index' })
  266. } else if (type === '疑问解答') {
  267. uni.navigateTo({ url: '/pages/patient-family/qa/index' })
  268. } else {
  269. uni.showToast({ title: '功能正在开发中', icon: 'none' })
  270. }
  271. }
  272. function onQrClick() {
  273. uni.showToast({ title: '二维码功能开发中', icon: 'none' })
  274. }
  275. </script>
  276. <style>
  277. .page-container {
  278. min-height: 100vh;
  279. padding-top: calc(var(--status-bar-height) + 44px);
  280. padding-bottom: 100rpx;
  281. box-sizing: border-box;
  282. justify-content: center;
  283. align-items: center;
  284. background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  285. }
  286. .content {
  287. width: 100%;
  288. }
  289. .user-info {
  290. /* background-color: #fff; */
  291. padding: 40rpx;
  292. margin-top: 0rpx;
  293. }
  294. .avatar-section {
  295. display: flex;
  296. align-items: center;
  297. }
  298. .avatar {
  299. width: 120rpx;
  300. height: 120rpx;
  301. border-radius: 50%;
  302. margin-right: 30rpx;
  303. position: relative;
  304. }
  305. .avatar-frame {
  306. width: 100%;
  307. height: 100%;
  308. border-radius: 50%;
  309. overflow: hidden;
  310. border: 4rpx solid #fff;
  311. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
  312. }
  313. .avatar-img {
  314. width: 100%;
  315. height: 100%;
  316. }
  317. .user-details {
  318. flex: 1;
  319. }
  320. .username {
  321. font-size: 36rpx;
  322. font-weight: bold;
  323. color: #333;
  324. display: block;
  325. margin-bottom: 10rpx;
  326. }
  327. .user-role {
  328. font-size: 28rpx;
  329. color: #666;
  330. display: block;
  331. }
  332. .qr-button {
  333. width: 80rpx;
  334. height: 80rpx;
  335. border-radius: 50%;
  336. background-color: #007aff;
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.3);
  341. }
  342. .qr-icon {
  343. width: 40rpx;
  344. height: 40rpx;
  345. }
  346. .function-container {
  347. padding-inline: 20rpx;
  348. margin-top: 40rpx;
  349. }
  350. .function-row {
  351. display: flex;
  352. justify-content: space-between;
  353. margin-bottom: 20rpx;
  354. }
  355. .function-row:last-child {
  356. margin-bottom: 0;
  357. }
  358. .function-item {
  359. flex: 1;
  360. height: 160rpx;
  361. background-color: #fff;
  362. border-radius: 20rpx;
  363. margin: 0 10rpx;
  364. position: relative;
  365. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  366. overflow: hidden;
  367. }
  368. .item-content {
  369. position: absolute;
  370. top: 20rpx;
  371. left: 20rpx;
  372. display: flex;
  373. flex-direction: column;
  374. }
  375. .title-row {
  376. display: flex;
  377. align-items: center;
  378. margin-bottom: 10rpx;
  379. }
  380. .item-line {
  381. width: 8rpx;
  382. height: 48rpx;
  383. margin-right: 15rpx;
  384. border-radius: 10rpx;
  385. }
  386. .blue .item-line {
  387. background-color: #3742fa;
  388. }
  389. .green .item-line {
  390. background-color: #2ed573;
  391. }
  392. .orange .item-line {
  393. background-color: #ffa502;
  394. }
  395. .purple .item-line {
  396. background-color: #9c88ff;
  397. }
  398. .item-title {
  399. font-size: 36rpx;
  400. font-weight: bold;
  401. color: #333;
  402. }
  403. .item-desc {
  404. font-size: 28rpx;
  405. color: #666;
  406. }
  407. .today-reminder-card {
  408. margin: 40rpx 20rpx 0;
  409. background-color: #fff;
  410. border-radius: 20rpx;
  411. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  412. overflow: hidden;
  413. }
  414. .card-header {
  415. padding: 30rpx 40rpx 20rpx;
  416. border-bottom: 1rpx solid #f0f0f0;
  417. }
  418. .card-title {
  419. font-size: 32rpx;
  420. font-weight: bold;
  421. color: #333;
  422. }
  423. .card-content {
  424. padding: 20rpx 40rpx 30rpx;
  425. display: flex;
  426. justify-content: space-around;
  427. }
  428. .reminder-item {
  429. display: flex;
  430. align-items: center;
  431. flex: 1;
  432. padding: 20rpx;
  433. border-radius: 12rpx;
  434. background-color: #f8f9fa;
  435. margin: 0 10rpx;
  436. }
  437. .reminder-icon {
  438. width: 60rpx;
  439. height: 60rpx;
  440. border-radius: 50%;
  441. background-color: #007aff;
  442. display: flex;
  443. align-items: center;
  444. justify-content: center;
  445. margin-right: 20rpx;
  446. }
  447. .icon {
  448. width: 30rpx;
  449. height: 30rpx;
  450. }
  451. .reminder-text {
  452. flex: 1;
  453. }
  454. .reminder-number {
  455. font-size: 36rpx;
  456. font-weight: bold;
  457. color: #007aff;
  458. display: block;
  459. }
  460. .reminder-label {
  461. font-size: 28rpx;
  462. color: #666;
  463. display: block;
  464. }
  465. .family-activity-card {
  466. margin: 40rpx 20rpx 0;
  467. background-color: #fff;
  468. border-radius: 20rpx;
  469. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  470. overflow: hidden;
  471. }
  472. .activity-card-content {
  473. padding: 20rpx 40rpx 30rpx;
  474. }
  475. .activity-item {
  476. display: flex;
  477. align-items: center;
  478. padding: 20rpx 0;
  479. border-bottom: 1rpx solid #f0f0f0;
  480. }
  481. .activity-item:last-child {
  482. border-bottom: none;
  483. }
  484. .activity-avatar {
  485. width: 80rpx;
  486. height: 80rpx;
  487. border-radius: 50%;
  488. overflow: hidden;
  489. margin-right: 20rpx;
  490. border: 2rpx solid #f0f0f0;
  491. }
  492. .activity-text {
  493. flex: 1;
  494. }
  495. .activity-desc {
  496. font-size: 30rpx;
  497. color: #333;
  498. display: block;
  499. margin-bottom: 8rpx;
  500. line-height: 1.4;
  501. }
  502. .activity-time {
  503. font-size: 24rpx;
  504. color: #999;
  505. display: block;
  506. }
  507. .no-activity {
  508. text-align: center;
  509. padding: 60rpx 0;
  510. color: #999;
  511. font-size: 28rpx;
  512. }
  513. </style>