index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <page-layer>
  3. <template #main>
  4. <div style="display: flex">
  5. <!-- 左边部分 -->
  6. <div class="left-pane">
  7. <div class="divider-line">
  8. <div class="divider-text">
  9. <div class="avatar-box__inner">
  10. <el-avatar :size="80" :src="userInfo.avatar" @error="errorHandler">
  11. <img :src="makeTextPortrait()"/>
  12. </el-avatar>
  13. </div>
  14. </div>
  15. <div class="psninfo-box">
  16. {{ userInfo.name }}&nbsp;{{ userInfo.deptName }}
  17. <MyClock :show-logo="false" size="small"/>
  18. </div>
  19. </div>
  20. <div style="display: flex; flex-wrap: wrap; height: calc(100vh - 200px); overflow-y: auto">
  21. <Inpatient v-for="(itm, index) in briefs" :key="index" :brief="itm"/>
  22. </div>
  23. </div>
  24. <!-- 右下角消息弹窗 -->
  25. <div class="message-popup">
  26. <el-button
  27. class="popup-trigger"
  28. icon="Message"
  29. type="primary"
  30. circle
  31. @click="isPopupShow = !isPopupShow"
  32. ></el-button>
  33. <div class="popup-content" v-if="isPopupShow">
  34. <div class="popup-header">
  35. <span class="header-title">系统消息</span>
  36. <el-button
  37. class="close-btn"
  38. icon="Close"
  39. type="text"
  40. @click="isPopupShow = false"
  41. ></el-button>
  42. </div>
  43. <div class="check-more" @click="fetchMoreMessages" :class="{ disabled: loading }">
  44. 查看更多
  45. <el-loading v-if="loading" size="small" />
  46. <span v-if="noMore && !loading" class="no-more-text">没有更多消息</span>
  47. </div>
  48. <div class="message-list">
  49. <el-timeline v-for="item in messages" :key="item.id">
  50. <el-timeline-item :timestamp="item.simpledate" placement="top" icon="Warning" color="orange">
  51. <el-card>
  52. <div style="margin-bottom: 12px; font-size: 16px; font-weight: bold">{{ item.title }}</div>
  53. <div v-html="item.content"></div>
  54. </el-card>
  55. </el-timeline-item>
  56. </el-timeline>
  57. <div v-if="messages.length === 0 && !loading" class="empty-message">
  58. 暂无消息
  59. </div>
  60. <div v-if="loading && messages.length === 0" class="loading-message">
  61. <el-loading size="small" />
  62. <span>加载中...</span>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. </page-layer>
  70. </template>
  71. <script setup>
  72. import {onActivated, onMounted, ref} from 'vue'
  73. import {selectSystemMessages} from '../../api/messages/index'
  74. import {formatDate} from '@/utils/date'
  75. import {genTextPortrait} from '@/utils/portrait'
  76. import {isInpatientStaff} from '@/utils/permission'
  77. import {selectInpatientBriefs} from '../../api/dashboard/index'
  78. import MyClock from '@/components/MyClock.vue'
  79. import Inpatient from '@/components/dashboard/Inpatient.vue'
  80. import PageLayer from "@/layout/PageLayer";
  81. import {useUserStore} from "@/pinia/user-store";
  82. const messages = ref([])
  83. const loading = ref(false)
  84. const noMore = ref(false) // 仅作为UI提示,不阻止查询
  85. // 确保每次点击都触发查询
  86. const fetchMoreMessages = () => {
  87. if (loading.value) return; // 仅在加载中时阻止重复点击
  88. loading.value = true;
  89. noMore.value = false; // 每次查询前重置"没有更多"状态
  90. let lastdate = 'latest'
  91. if (messages.value.length > 0) {
  92. // 确保日期格式正确,与后端要求一致
  93. lastdate = formatDate(messages.value[0].simpledate, 'YYYY-MM-DD HH:mm:ss');
  94. }
  95. selectSystemMessages(lastdate)
  96. .then((res) => {
  97. if (res.length > 0) {
  98. // 新消息添加到列表前面
  99. messages.value.unshift(...res);
  100. noMore.value = false;
  101. } else {
  102. // 结果为空时仅更新UI提示,不阻止下次查询
  103. noMore.value = true;
  104. }
  105. })
  106. .catch((error) => {
  107. console.error('获取消息失败:', error);
  108. // 错误情况下也允许用户再次尝试
  109. })
  110. .finally(() => {
  111. loading.value = false;
  112. });
  113. }
  114. const userInfo = useUserStore().userInfo
  115. const errorHandler = () => {
  116. return true
  117. }
  118. const makeTextPortrait = () => {
  119. return genTextPortrait(userInfo.name)
  120. }
  121. onActivated(() => {
  122. loading.value = true;
  123. selectSystemMessages('latest')
  124. .then((res) => {
  125. messages.value = res;
  126. noMore.value = res.length === 0;
  127. })
  128. .finally(() => {
  129. loading.value = false;
  130. });
  131. })
  132. const briefs = ref([])
  133. onMounted(() => {
  134. if (isInpatientStaff()) {
  135. selectInpatientBriefs(userInfo.deptCode).then((list) => {
  136. briefs.value = list
  137. })
  138. }
  139. })
  140. const isPopupShow = ref(false)
  141. </script>
  142. <style lang="scss" scoped>
  143. .left-pane {
  144. margin-top: 20px;
  145. width: 100%;
  146. background-image: linear-gradient(#d0ddee, #64b6e6);
  147. height: 120px;
  148. border-radius: 6px;
  149. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  150. }
  151. .message-popup {
  152. position: fixed;
  153. bottom: 30px;
  154. right: 30px;
  155. z-index: 1000;
  156. .popup-trigger {
  157. width: 60px;
  158. height: 60px;
  159. font-size: 24px;
  160. box-shadow: 0 4px 12px rgba(16, 128, 240, 0.3);
  161. }
  162. .popup-content {
  163. width: 400px;
  164. max-height: 600px;
  165. background: #fff;
  166. border-radius: 8px;
  167. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  168. margin-bottom: 10px;
  169. overflow: hidden;
  170. .popup-header {
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: center;
  174. padding: 12px 16px;
  175. border-bottom: 1px solid #e5e7eb;
  176. background: #f8fafc;
  177. .header-title {
  178. font-size: 16px;
  179. font-weight: 600;
  180. color: #1e293b;
  181. }
  182. .close-btn {
  183. color: #64748b;
  184. &:hover {
  185. color: #0f172a;
  186. }
  187. }
  188. }
  189. .check-more {
  190. width: 100%;
  191. text-align: right;
  192. padding: 8px 16px;
  193. color: #409eff;
  194. cursor: pointer;
  195. display: flex;
  196. justify-content: flex-end;
  197. align-items: center;
  198. gap: 8px;
  199. &:hover {
  200. color: #165dff;
  201. }
  202. &.disabled {
  203. cursor: not-allowed;
  204. opacity: 0.7;
  205. }
  206. .no-more-text {
  207. color: #94a3b8;
  208. font-size: 14px;
  209. }
  210. }
  211. .message-list {
  212. padding: 0 16px 16px;
  213. max-height: calc(600px - 50px);
  214. overflow-y: auto;
  215. }
  216. .empty-message {
  217. text-align: center;
  218. padding: 20px;
  219. color: #94a3b8;
  220. }
  221. .loading-message {
  222. text-align: center;
  223. padding: 20px;
  224. color: #94a3b8;
  225. display: flex;
  226. justify-content: center;
  227. align-items: center;
  228. gap: 8px;
  229. }
  230. }
  231. }
  232. .avatar-box__inner {
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. width: 86px;
  237. height: 86px;
  238. border-radius: 43px;
  239. border-bottom: 3px solid #1080f0;
  240. z-index: 600;
  241. }
  242. .divider-line {
  243. display: block;
  244. height: 1px;
  245. width: 100%;
  246. margin: 70px 0 50px 0;
  247. background-color: #4297ec88;
  248. position: relative;
  249. }
  250. .divider-text {
  251. left: 12px;
  252. -webkit-transform: translateY(-55%);
  253. transform: translateY(-55%);
  254. position: absolute;
  255. font-weight: 500;
  256. color: black;
  257. font-size: 14px;
  258. }
  259. .psninfo-box {
  260. display: flex;
  261. left: 108px;
  262. -webkit-transform: translateY(-120%);
  263. transform: translateY(-120%);
  264. position: absolute;
  265. font-weight: 500;
  266. color: rgb(3, 72, 94);
  267. font-size: 20px;
  268. font-weight: bold;
  269. }
  270. </style>