EmrChatBox.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <el-dialog v-model="dialog"
  3. :title="`聊天室 ${userSize} 人`"
  4. width="70%"
  5. @closed="emits('closed')">
  6. <div class="chat_room_dialog">
  7. <div class="left">
  8. <el-table :data="props.userList" :height="getWindowSize.h / 1.5">
  9. <el-table-column prop="name" label="姓名">
  10. <template #default="{row}">
  11. <span v-if="row.code === userData.code">本人</span>
  12. </template>
  13. </el-table-column>
  14. <el-table-column prop="deptName" label="科室"/>
  15. </el-table>
  16. </div>
  17. <div class="right">
  18. <el-scrollbar :height="getWindowSize.h / 1.8 " ref="scrollbarRef">
  19. <div ref="innerRef">
  20. <div v-for="item in chatHistory" class="list">
  21. <div class="chat_right"
  22. v-if="whetherInPerson(item.code)">
  23. <div style="display: flex; ">
  24. <div style="font-size: 12px;margin-right: 10px">
  25. <div style="text-align: right">
  26. {{ item.date }} {{ item.deptName }} {{ item.name }}
  27. </div>
  28. <div class="message_str" style="float: right;">
  29. {{ item.message }}
  30. </div>
  31. </div>
  32. <div>
  33. <el-avatar shape="square" :src="item.avatar" :size="30"/>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="chat_left" v-else>
  38. <div style="display: flex;">
  39. <div>
  40. <el-avatar shape="square" :src="item.avatar" :size="30"/>
  41. </div>
  42. <div style="font-size: 12px;margin-left: 10px">
  43. <div>{{ item.name }} {{ item.deptName }} {{ item.date }}</div>
  44. <div class="message_str" :class="judgmentQMy(item.message) ? 'specify_me' : '' ">
  45. {{ item.message }}
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </el-scrollbar>
  53. <div>
  54. <el-input type="textarea"
  55. :rows="3"
  56. v-model="messageStr"
  57. @keydown.enter.stop="clickSend"/>
  58. <div style="float: right">
  59. <el-button @click="modifyTheCurrentMedicalRecord">修改当前病历</el-button>
  60. <el-button @click="clickSend">发送</el-button>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </el-dialog>
  66. </template>
  67. <script setup lang="ts">
  68. import {getWindowSize} from "@/utils/window-size";
  69. import {getChatHistoryBySid, sendAMessage} from "@/api/zhu-yuan-yi-sheng/emr-socket";
  70. import {stringIsBlank} from "@/utils/blank-utils";
  71. import {xcMessage} from "@/utils/xiaochan-element-plus";
  72. import {useUserStore} from "@/pinia/user-store";
  73. import {ElScrollbar} from "element-plus";
  74. import {useCompRef} from "@/utils/useCompRef";
  75. import {defineComponent} from "vue";
  76. const userData = useUserStore().userInfo
  77. defineComponent({
  78. name: "EmrChatBox",
  79. })
  80. const chatHistory = ref([])
  81. const props = defineProps<{
  82. userList: any[],
  83. sid: string | null,
  84. currentEditorUser: {
  85. name: string
  86. } | null,
  87. userSize: number
  88. }>()
  89. const emits = defineEmits(['closed'])
  90. const dialog = ref(true)
  91. const messageStr = ref('')
  92. const scrollbarRef = useCompRef(ElScrollbar)
  93. const innerRef = ref<HTMLDivElement | null>(null)
  94. const clickSend = async () => {
  95. if (stringIsBlank(messageStr.value)) {
  96. return xcMessage.error('不能发送空白消息。')
  97. }
  98. await sendAMessage(props.sid, 'message', messageStr.value)
  99. messageStr.value = ''
  100. await queryJump()
  101. }
  102. const modifyTheCurrentMedicalRecord = async () => {
  103. if (props.currentEditorUser === null) {
  104. return xcMessage.error('当前没有人正在编辑');
  105. }
  106. if (stringIsBlank(props.currentEditorUser.name)) {
  107. return xcMessage.error('当前没有人正在编辑');
  108. }
  109. await sendAMessage(props.sid, 'message', '@' + props.currentEditorUser.name + ' 申请修改病历,请尽快保存,后离开当前病历【系统自动发送】');
  110. messageStr.value = ''
  111. await queryJump()
  112. }
  113. const queryJump = async () => {
  114. chatHistory.value = await getChatHistoryBySid(props.sid) as any[]
  115. await nextTick()
  116. scrollbarRef.value!.setScrollTop(innerRef.value!.scrollHeight)
  117. }
  118. const whetherInPerson = (code) => {
  119. return userData.code === code
  120. }
  121. const judgmentQMy = (val) => {
  122. return val.startsWith('@' + userData.name)
  123. }
  124. onMounted(async () => {
  125. await nextTick()
  126. await queryJump()
  127. })
  128. defineExpose({
  129. queryJump
  130. })
  131. </script>
  132. <style scoped lang="scss">
  133. .chat_room_dialog {
  134. display: flex;
  135. width: 100%;
  136. .left {
  137. width: 200px;
  138. }
  139. .right {
  140. flex: 1;
  141. height: max-content;
  142. }
  143. }
  144. .list {
  145. width: 100%;
  146. .specify_me {
  147. background-color: red;
  148. color: white;
  149. }
  150. .chat_right {
  151. display: flex;
  152. justify-content: flex-end;
  153. padding: 5px 10px;
  154. }
  155. .chat_left {
  156. display: flex;
  157. padding: 5px 10px;
  158. }
  159. .message_str {
  160. border: 1px solid #000;
  161. padding: 5px;
  162. width: max-content;
  163. border-radius: 5px;
  164. }
  165. }
  166. .chat_history_div {
  167. height: max-content;
  168. display: flex;
  169. .user_info {
  170. padding: 0 10px;
  171. }
  172. .message {
  173. border: 1px solid #000;
  174. padding: 5px;
  175. width: max-content;
  176. border-radius: 10px;
  177. }
  178. }
  179. </style>