dialogDetail.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='对话记录' bgColor="transparent"></cus-header>
  4. <div class="list" v-if="list.length">
  5. <div class="l_item" v-for="(item,index) in list" :key="index">
  6. <div class="time">{{item.date}}</div>
  7. <div v-for="(pre,idx) in item.items" :key="idx">
  8. <div class="pre adf my" v-if="pre.chatType===1">
  9. <div class="text my">{{pre.content}}</div>
  10. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/6edb131a-66f9-4a2a-a865-7b74e3dd52ed.png"></image>
  11. </div>
  12. <div class="pre adf ai" v-else-if="pre.chatType===2">
  13. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/bcde7118-fc4e-4fa6-96ca-ebe1e0beba2f.png"></image>
  14. <div class="text ai">{{pre.content}}</div>
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. <template v-else>
  20. <page-empty :height="'calc(100vh - 200rpx)'"></page-empty>
  21. </template>
  22. </view>
  23. </template>
  24. <script>
  25. import pageEmpty from '@/components/pageEmpty/index.vue'
  26. export default {
  27. components:{pageEmpty},
  28. data(){
  29. return {
  30. agentId:'',
  31. deviceId:'',
  32. sessionId:'',
  33. list:[]
  34. }
  35. },
  36. onLoad(option) {
  37. this.agentId = option?.agentId;
  38. this.deviceId = option?.deviceId;
  39. this.sessionId = option?.sessionId;
  40. this.getList();
  41. },
  42. methods:{
  43. getList(){
  44. this.$api.get(`/agent/${this.agentId}/${this.deviceId}/chat-history/${this.sessionId}`).then(res=>{
  45. if(res.data.code!==0) return this.$showToast(res.data.msg)
  46. this.list = this.groupedMessages(res.data.data||[])
  47. })
  48. },
  49. groupedMessages(data) {
  50. const groups = {};
  51. data.forEach(msg => {
  52. const dateKey = msg.createdAt;
  53. if (!groups[dateKey]) {
  54. groups[dateKey] = {
  55. date: dateKey,
  56. items: []
  57. }
  58. }
  59. groups[dateKey].items.push(msg);
  60. });
  61. return Object.values(groups).sort((a, b) =>
  62. new Date(a.date) - new Date(b.date)
  63. );
  64. }
  65. }
  66. }
  67. </script>
  68. <style scoped lang="less">
  69. .page{
  70. background: #F7F6F9;
  71. padding: 0 30rpx 40rpx;
  72. box-sizing: border-box;
  73. .list{
  74. .l_item{
  75. margin-top: 48rpx;
  76. .time{
  77. font-family: PingFangSC, PingFang SC;
  78. font-weight: 400;
  79. font-size: 24rpx;
  80. color: #8D8D8D;
  81. line-height: 24rpx;
  82. text-align: center;
  83. }
  84. .pre{
  85. margin-top: 32rpx;
  86. image{
  87. width: 78rpx;
  88. height: 78rpx;
  89. border-radius: 50%;
  90. }
  91. .text{
  92. max-width: calc(100% - 98rpx);
  93. padding: 24rpx;
  94. font-family: PingFangSC, PingFang SC;
  95. font-weight: 400;
  96. font-size: 28rpx;
  97. line-height: 48rpx;
  98. border-radius: 20rpx;
  99. box-sizing: border-box;
  100. }
  101. &.my{
  102. justify-content: flex-end;
  103. .text{
  104. background: #72832B;
  105. color: #FFFFFF;
  106. }
  107. image{
  108. margin-left: 20rpx;
  109. }
  110. }
  111. &.ai{
  112. .text{
  113. background: #FFFFFF;
  114. color: #252525;
  115. }
  116. image{
  117. margin-right: 20rpx;
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. </style>