historyComponent.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <script setup lang="ts">
  2. import { ref, inject } from 'vue'
  3. import { Search, Delete, Paperclip } from '@element-plus/icons-vue'
  4. import { ElMessageBox, ElMessage } from 'element-plus'
  5. import { getChatList,deleteChat } from '@/api/index.js'
  6. import { storeToRefs } from 'pinia';
  7. import { useMsgStore } from '@/store/modules/msg.ts'
  8. import { useUserStore } from '@/store/modules/user'
  9. const userStore = useUserStore()
  10. const drawer = ref(false)
  11. const count = ref(0)
  12. const input = ref('')
  13. const loading = ref(false)
  14. const dataList = ref<any[]>([])
  15. // 获取父组件提供的 Hook 实例
  16. const emit = defineEmits(['currentData'])
  17. const { msgUuid, messages ,page} = storeToRefs(useMsgStore())
  18. const props = defineProps({
  19. msgUuid: {
  20. type: String,
  21. default: ''
  22. },
  23. })
  24. watch(drawer, (newVal) => {
  25. if (newVal) {
  26. loading.value = true
  27. // getChatList({
  28. // page: 1,
  29. // size: 100,
  30. // sort: ['createTime,desc']
  31. // }).then(res => {
  32. // dataList.value = res.data.list
  33. // }).finally(res => loading.value = false)
  34. }
  35. })
  36. function handleDeleteStore(e: any, item: any,name:string) {
  37. e.stopPropagation()
  38. if (dataList.value.length < 2) {
  39. ElMessage({
  40. message: '不可删除',
  41. grouping: true,
  42. showClose: true
  43. })
  44. return
  45. }
  46. ElMessageBox.confirm(
  47. '此操作无法撤销。',
  48. `要删【${name.substring(0,20)}】对话吗?`,
  49. {
  50. confirmButtonText: '确认',
  51. cancelButtonText: '取消',
  52. type: 'warning',
  53. showClose: false,
  54. center: true
  55. }
  56. ).then(() => {
  57. loading.value = true
  58. deleteChat([item]).then((res: any) => {
  59. loading.value = true
  60. if (item === msgUuid.value) {
  61. messages.value = []
  62. page.value = 1
  63. }
  64. getChatList({
  65. page: 1,
  66. size: 100,
  67. sort: ['createTime,desc']
  68. }).then(res => {
  69. dataList.value = res.data.list
  70. }).finally(res => loading.value = false)
  71. }).catch(() => {
  72. })
  73. })
  74. }
  75. defineExpose({
  76. drawer
  77. })
  78. </script>
  79. <template>
  80. <el-drawer style="height: 70%" v-model="drawer" direction="btt" :show-close="true" :close-on-click-modal="false"
  81. :destroy-on-close="true" :close-on-press-escape="false" class="custom_drawer">
  82. <template #header>
  83. <div class="his_flex"><span class="his_title">历史聊天</span><span class="his_count">({{ dataList.length }})</span>
  84. </div>
  85. </template>
  86. <div style="height: 100%;overflow: hidden;" v-loading="loading">
  87. <div class="his_delete">
  88. <!-- <el-input style="margin-right: 12px" v-model="input" placeholder="搜索" clearable :prefix-icon="Search"
  89. :disabled="true" /> -->
  90. <!-- <el-tooltip effect="dark" content="删除全部" placement="top">
  91. <el-button :icon="Delete" circle @click="handleDeleteDB" />
  92. </el-tooltip> -->
  93. </div>
  94. <div class="his_content">
  95. 1212
  96. <!-- <template v-for="item in dataList" :key="item.conversationId">-->
  97. <!-- <div :class="`his_list ${msgUuid === item.conversationId ? 'his_list_change' : '' }`"-->
  98. <!-- @click="emit('currentData', item.conversationId)">-->
  99. <!-- <p class="ellipsis" style="color:#000000;font-weight: 900;">{{ item?.content ?? '&#45;&#45;' }}</p>-->
  100. <!-- <p class="his_list_op">-->
  101. <!-- <span style="color: #000">{{ item?.createTime }}</span>-->
  102. <!-- <el-tooltip effect="dark" content="删除" placement="top">-->
  103. <!-- <el-button :disabled="msgUuid === item.conversationId" :icon="Delete" link-->
  104. <!-- @click="(e: any) => handleDeleteStore(e, item.conversationId, item?.content)" />-->
  105. <!-- </el-tooltip>-->
  106. <!-- </p>-->
  107. <!-- </div>-->
  108. <!-- </template>-->
  109. </div>
  110. </div>
  111. </el-drawer>
  112. </template>
  113. <style lang="scss">
  114. .his_flex {
  115. display: flex;
  116. align-items: center;
  117. }
  118. .custom_drawer {
  119. height: 70vh !important;
  120. border-top-left-radius: 15px;
  121. border-top-right-radius: 15px;
  122. .el-drawer__header {
  123. padding: 16px;
  124. margin-bottom: 0;
  125. }
  126. .el-drawer__close-btn, .el-drawer__body {
  127. padding: 0;
  128. }
  129. .el-drawer__body {
  130. overflow: hidden;
  131. height: 100%;
  132. }
  133. }
  134. .his_title {
  135. display: inline-block;
  136. color: #000000;
  137. font-size: 20px;
  138. font-weight: 900;
  139. margin-right: 3px;
  140. height: 24px;
  141. line-height: 24px;
  142. }
  143. .his_count {
  144. display: inline-block;
  145. height: 24px;
  146. line-height: 24px;
  147. }
  148. .his_delete {
  149. padding: 0 12px 10px;
  150. display: flex;
  151. position: sticky;
  152. align-items: center;
  153. justify-content: space-between;
  154. .is-circle {
  155. border-radius: 8px;
  156. }
  157. }
  158. .his_content {
  159. height: calc(100% - 40px);
  160. overflow: auto;
  161. padding: 0 12px;
  162. .ellipsis {
  163. white-space: nowrap; /* 强制文本不换行 */
  164. overflow: hidden; /* 隐藏溢出内容 */
  165. text-overflow: ellipsis; /* 显示省略号 */
  166. width: 100%; /* 设置宽度(必须) */
  167. }
  168. .his_list {
  169. font-size: 12px;
  170. padding: 5px 10px;
  171. border-radius: 8px;
  172. margin-bottom: 4px;
  173. box-shadow: 0 0 6px rgba(122, 89, 255, .16);
  174. cursor: pointer;
  175. .his_list_op {
  176. display: flex;
  177. justify-content: space-between;
  178. align-items: center;
  179. }
  180. }
  181. .his_list:hover {
  182. background-color: rgba(122, 89, 255, .06);
  183. }
  184. .his_list_change {
  185. background-color: rgba(122, 89, 255, .2) !important;
  186. }
  187. }
  188. </style>