ElderProfileDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <template>
  2. <el-dialog
  3. v-model="visible"
  4. title="长者档案"
  5. width="600px"
  6. class="large-screen-dialog elder-profile-dialog"
  7. :close-on-click-modal="false"
  8. @close="handleClose"
  9. >
  10. <!-- 加载状态 -->
  11. <div v-if="loading" class="loading-container">
  12. <el-icon class="is-loading">
  13. <Loading />
  14. </el-icon>
  15. <p>加载中...</p>
  16. </div>
  17. <!-- 档案内容 -->
  18. <div v-else-if="elderData" class="profile-content">
  19. <!-- 基本信息卡片 -->
  20. <div class="profile-header">
  21. <!-- 头像 -->
  22. <div class="avatar-section">
  23. <div class="avatar">
  24. {{ elderData.name?.charAt(0) || '长' }}
  25. </div>
  26. </div>
  27. <!-- 基本信息 -->
  28. <div class="basic-info">
  29. <div class="info-row">
  30. <span class="label">姓名:</span>
  31. <span class="value">{{ elderData.name }}</span>
  32. </div>
  33. <div class="info-row">
  34. <span class="label">年龄:</span>
  35. <span class="value">{{ elderData.age }}岁</span>
  36. </div>
  37. <div class="info-row">
  38. <span class="label">性别:</span>
  39. <span class="value">{{ elderData.gender }}</span>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- 联系方式 -->
  44. <div class="contact-section">
  45. <h4 class="section-title">联系方式</h4>
  46. <div class="contact-info">
  47. <div class="contact-item">
  48. <span class="label">长者电话:</span>
  49. <span class="value">{{ elderData.elderPhone || '暂无' }}</span>
  50. </div>
  51. <div class="contact-item">
  52. <span class="label">家属电话:</span>
  53. <span class="value">{{ elderData.relativePhone || '暂无' }}</span>
  54. </div>
  55. <div class="contact-item">
  56. <span class="label">地址:</span>
  57. <span class="value">{{ elderData.address || '暂无' }}</span>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- 预警历史 -->
  62. <div class="warning-section">
  63. <h4 class="section-title">
  64. 预警历史
  65. <span v-if="elderData.warningData?.length" class="warning-count">
  66. ({{ elderData.warningData.length }})
  67. </span>
  68. </h4>
  69. <div v-if="elderData.warningData && elderData.warningData.length > 0" class="warning-list">
  70. <div v-for="(warning, index) in elderData.warningData" :key="index" class="warning-item">
  71. <div class="warning-header">
  72. <span class="event-type">{{ warning.eventType }}</span>
  73. <span class="time">{{ formatTime(warning.happensAt) }}</span>
  74. </div>
  75. <div class="warning-message">{{ warning.message }}</div>
  76. </div>
  77. </div>
  78. <div v-else class="empty-state">
  79. <p>暂无预警记录</p>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- 错误状态 -->
  84. <div v-else class="error-container">
  85. <p>加载失败,请重试</p>
  86. </div>
  87. </el-dialog>
  88. </template>
  89. <script lang="ts" setup>
  90. import { ref, computed, watch } from 'vue'
  91. import { ElMessage } from 'element-plus'
  92. import { Loading } from '@element-plus/icons-vue'
  93. import fetchHttp from '@/config/axios/fetchHttp'
  94. import { getAccessToken } from '@/utils/auth'
  95. import { formatToDateTime } from '@/utils/dateUtil'
  96. // 类型定义
  97. interface WarningRecord {
  98. eventType: string
  99. message: string
  100. happensAt: string
  101. }
  102. interface ElderProfileData {
  103. id?: number
  104. name: string
  105. avatar?: string
  106. age: number
  107. gender: string
  108. relativePhone?: string
  109. elderPhone?: string
  110. address?: string
  111. warningData?: WarningRecord[]
  112. }
  113. // Props 和 Emits
  114. interface Props {
  115. modelValue: boolean
  116. elderId?: number
  117. }
  118. const props = withDefaults(defineProps<Props>(), {
  119. elderId: 0
  120. })
  121. const emit = defineEmits<{
  122. 'update:modelValue': [value: boolean]
  123. }>()
  124. // 响应式数据
  125. const loading = ref(false)
  126. const elderData = ref<ElderProfileData | null>(null)
  127. const visible = computed({
  128. get: () => props.modelValue,
  129. set: (value: boolean) => {
  130. emit('update:modelValue', value)
  131. }
  132. })
  133. // 监听 elderId 变化,自动加载数据
  134. watch(
  135. () => props.elderId,
  136. (newId) => {
  137. if (newId && visible.value) {
  138. fetchElderDetail(newId)
  139. }
  140. }
  141. )
  142. // 监听 visible 变化
  143. watch(
  144. () => visible.value,
  145. (newVisible) => {
  146. if (newVisible && props.elderId) {
  147. fetchElderDetail(props.elderId)
  148. }
  149. }
  150. )
  151. // 方法
  152. const formatTime = (time: string | number) => {
  153. if (!time) return '未知'
  154. return formatToDateTime(time)
  155. }
  156. // 生成假数据
  157. const generateMockData = (elderId: number): ElderProfileData => {
  158. const names = ['王奶奶', '李爷爷', '张奶奶', '刘爷爷', '陈奶奶', '杨爷爷']
  159. const genders = ['女', '男']
  160. const addresses = [
  161. '北京市朝阳区建国路1号',
  162. '上海市浦东新区世纪大道100号',
  163. '广州市天河区珠江新城',
  164. '深圳市南山区科技园路1号',
  165. '杭州市西湖区文三路477号'
  166. ]
  167. const eventTypes = ['跌倒预警', '心率异常', '血压偏高', '离床预警', '体温异常']
  168. const messages = [
  169. '检测到长者跌倒,请立即查看',
  170. '心率过高,建议就医检查',
  171. '血压偏高,请注意休息',
  172. '长者离床时间过长,请关注',
  173. '体温异常,建议测量体温'
  174. ]
  175. const warningData: WarningRecord[] = [
  176. {
  177. eventType: eventTypes[Math.floor(Math.random() * eventTypes.length)],
  178. message: messages[Math.floor(Math.random() * messages.length)],
  179. happensAt: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toISOString()
  180. },
  181. {
  182. eventType: eventTypes[Math.floor(Math.random() * eventTypes.length)],
  183. message: messages[Math.floor(Math.random() * messages.length)],
  184. happensAt: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toISOString()
  185. },
  186. {
  187. eventType: eventTypes[Math.floor(Math.random() * eventTypes.length)],
  188. message: messages[Math.floor(Math.random() * messages.length)],
  189. happensAt: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toISOString()
  190. }
  191. ]
  192. return {
  193. id: elderId,
  194. name: names[elderId % names.length],
  195. age: 65 + (elderId % 20),
  196. gender: genders[elderId % 2],
  197. elderPhone: `1${Math.floor(Math.random() * 9) + 3}${String(Math.floor(Math.random() * 1000000000)).padStart(9, '0')}`,
  198. relativePhone: `1${Math.floor(Math.random() * 9) + 3}${String(Math.floor(Math.random() * 1000000000)).padStart(9, '0')}`,
  199. address: addresses[elderId % addresses.length],
  200. warningData: warningData
  201. }
  202. }
  203. const fetchElderDetail = async (elderId: number) => {
  204. if (!elderId) return
  205. loading.value = true
  206. try {
  207. const res = await fetchHttp.get(
  208. `/api/pc/admin/getElderDetail?elderId=${elderId}`,
  209. {},
  210. {
  211. headers: {
  212. Authorization: `Bearer ${getAccessToken()}`
  213. }
  214. }
  215. )
  216. if (res) {
  217. elderData.value = res
  218. } else {
  219. // 接口暂无数据,使用假数据
  220. console.log('接口暂无数据,使用假数据')
  221. elderData.value = generateMockData(elderId)
  222. }
  223. } catch (error) {
  224. console.error('获取长者档案失败:', error)
  225. // 接口出错,使用假数据
  226. elderData.value = generateMockData(elderId)
  227. } finally {
  228. loading.value = false
  229. }
  230. }
  231. const handleClose = () => {
  232. elderData.value = null
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. $primary-color: #1a73e8;
  237. $secondary-color: #00c6ff;
  238. $accent-color: #7b61ff;
  239. $text-light: #fff;
  240. $text-gray: #8a8f98;
  241. $success-color: #26de81;
  242. $warning-color: #fd9644;
  243. $danger-color: #ff6b6b;
  244. .elder-profile-dialog {
  245. :deep(.el-dialog__header) {
  246. padding: 20px !important;
  247. background: linear-gradient(90deg, $primary-color, $accent-color) !important;
  248. border-radius: 12px 12px 0 0 !important;
  249. }
  250. :deep(.el-dialog__title) {
  251. font-size: 18px !important;
  252. font-weight: 600 !important;
  253. color: white !important;
  254. }
  255. :deep(.el-dialog__body) {
  256. padding: 24px !important;
  257. }
  258. :deep(.el-dialog__close) {
  259. color: white !important;
  260. }
  261. }
  262. .loading-container,
  263. .error-container {
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. justify-content: center;
  268. padding: 40px 20px;
  269. text-align: center;
  270. color: $text-gray;
  271. .el-icon {
  272. font-size: 32px;
  273. margin-bottom: 16px;
  274. color: $primary-color;
  275. &.is-loading {
  276. animation: spin 1s linear infinite;
  277. }
  278. }
  279. p {
  280. margin: 0;
  281. font-size: 14px;
  282. }
  283. }
  284. @keyframes spin {
  285. 0% {
  286. transform: rotate(0deg);
  287. }
  288. 100% {
  289. transform: rotate(360deg);
  290. }
  291. }
  292. .profile-content {
  293. display: flex;
  294. flex-direction: column;
  295. gap: 24px;
  296. }
  297. // 档案头部
  298. .profile-header {
  299. display: flex;
  300. gap: 20px;
  301. padding: 20px;
  302. background: linear-gradient(135deg, rgb(26 115 232 / 15%), rgb(123 97 255 / 10%));
  303. border-radius: 12px;
  304. border: 1px solid rgb(255 255 255 / 10%);
  305. .avatar-section {
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. .avatar {
  310. width: 80px;
  311. height: 80px;
  312. border-radius: 50%;
  313. background: linear-gradient(135deg, $primary-color, $accent-color);
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. font-size: 32px;
  318. font-weight: bold;
  319. color: white;
  320. box-shadow: 0 4px 15px rgb(26 115 232 / 30%);
  321. }
  322. }
  323. .basic-info {
  324. flex: 1;
  325. display: flex;
  326. flex-direction: column;
  327. justify-content: center;
  328. gap: 12px;
  329. .info-row {
  330. display: flex;
  331. gap: 12px;
  332. .label {
  333. color: $text-gray;
  334. min-width: 60px;
  335. font-weight: 500;
  336. }
  337. .value {
  338. color: $text-light;
  339. font-weight: 600;
  340. }
  341. }
  342. }
  343. }
  344. // 联系方式
  345. .contact-section {
  346. padding: 20px;
  347. background: rgb(255 255 255 / 4%);
  348. border: 1px solid rgb(255 255 255 / 10%);
  349. border-radius: 12px;
  350. .section-title {
  351. margin: 0 0 16px 0;
  352. font-size: 14px;
  353. font-weight: 600;
  354. color: $secondary-color;
  355. text-transform: uppercase;
  356. letter-spacing: 1px;
  357. }
  358. .contact-info {
  359. display: flex;
  360. flex-direction: column;
  361. gap: 12px;
  362. .contact-item {
  363. display: flex;
  364. gap: 12px;
  365. .label {
  366. color: $text-gray;
  367. min-width: 80px;
  368. font-weight: 500;
  369. }
  370. .value {
  371. color: $text-light;
  372. flex: 1;
  373. word-break: break-all;
  374. }
  375. }
  376. }
  377. }
  378. // 预警历史
  379. .warning-section {
  380. padding: 20px;
  381. background: rgb(255 255 255 / 4%);
  382. border: 1px solid rgb(255 255 255 / 10%);
  383. border-radius: 12px;
  384. .section-title {
  385. margin: 0 0 16px 0;
  386. font-size: 14px;
  387. font-weight: 600;
  388. color: $secondary-color;
  389. text-transform: uppercase;
  390. letter-spacing: 1px;
  391. .warning-count {
  392. color: $warning-color;
  393. font-weight: 700;
  394. }
  395. }
  396. .warning-list {
  397. display: flex;
  398. flex-direction: column;
  399. gap: 12px;
  400. max-height: 300px;
  401. overflow-y: auto;
  402. .warning-item {
  403. padding: 12px;
  404. background: rgb(253 150 68 / 10%);
  405. border-left: 3px solid $warning-color;
  406. border-radius: 6px;
  407. display: flex;
  408. flex-direction: column;
  409. gap: 8px;
  410. .warning-header {
  411. display: flex;
  412. justify-content: space-between;
  413. align-items: center;
  414. .event-type {
  415. color: $warning-color;
  416. font-weight: 600;
  417. font-size: 13px;
  418. padding: 2px 8px;
  419. background: rgb(253 150 68 / 20%);
  420. border-radius: 4px;
  421. }
  422. .time {
  423. color: $text-gray;
  424. font-size: 12px;
  425. }
  426. }
  427. .warning-message {
  428. color: $text-light;
  429. font-size: 13px;
  430. line-height: 1.5;
  431. }
  432. }
  433. }
  434. .empty-state {
  435. padding: 40px 20px;
  436. text-align: center;
  437. color: $text-gray;
  438. p {
  439. margin: 0;
  440. font-size: 14px;
  441. }
  442. }
  443. }
  444. // 滚动条样式
  445. .warning-list::-webkit-scrollbar {
  446. width: 6px;
  447. }
  448. .warning-list::-webkit-scrollbar-track {
  449. background: rgb(255 255 255 / 5%);
  450. border-radius: 3px;
  451. }
  452. .warning-list::-webkit-scrollbar-thumb {
  453. background: rgb(26 115 232 / 50%);
  454. border-radius: 3px;
  455. &:hover {
  456. background: rgb(26 115 232 / 70%);
  457. }
  458. }
  459. </style>