dialogue.vue
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<template>
<show-time />
<view class="inquire-group">
<image class="avatar" :src="projectConfig.Al_avatar"></image>
<view class="group-wrap">
<view class="group-item" v-for="item in recommendList" :key="item.id" @click="clickKeywordSearch(item.title)">
<view class="item-title">{{item.title}} </view>
<view class="item-content">{{item.content}}</view>
</view>
</view>
</view>
<view class="inquire-group">
<image class="avatar" :src="projectConfig.Al_avatar"></image>
<view class="dialogue">
<view class="top">{{projectConfig.Al_name}}</view>
<view class="inquire">{{projectConfig.Al_name}}为您服务,请输入您的问题。</view>
</view>
</view>
<show-time />
<view class="dialogue-wrap" v-for="(item,index) in chatLog" :key="index" ref="messageListContainer">
<show-time />
<view class="response-group inquire-group">
<view class="dialogue answer-inner">
<view class="top answer-name">{{userinfo.nickname}}</view>
<text selectable="true">
<view class="answer-dialogue">{{item.message }}</view>
</text>
</view>
<image class="avatar" style="margin-right: 0;" :src="userinfo.avatar"></image>
</view>
<show-time />
<view class="inquire-group">
<image class="avatar" :src="projectConfig.Al_avatar"></image>
<view class="dialogue">
<view class="top">{{projectConfig.Al_name}}</view>
<text selectable="true">
<view class="inquire">{{item.response}}</view>
</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref, watch, nextTick } from 'vue'
import showTime from '@/components/show-time.vue'
import { getRecorm } from '@/services/modules/home.js'
const emits = defineEmits(['clickKeywordSearch'])
const props = defineProps({
chatLog: {
type: Array,
default: () => ([])
},
projectConfig: {
type: Object,
default: () => ({})
},
userinfo: {
type: Object,
default: () => ({})
}
})
fetchRecorm()
function clickKeywordSearch(item) {
emits('clickKeywordSearch', item)
}
const recommendList = ref([])
async function fetchRecorm() {
const res = await getRecorm()
recommendList.value = res.data
// console.log('获取推荐文案', res)
}
// const messageListContainer = ref(null);
// watch(
// () => props.chatLog,
// (newVal) => {
// nextTick(() => {
// console.log(messageListContainer.value)
// messageListContainer.value[newVal.length - 1].scrollIntoView(); // 关键代码
// });
// }, {
// deep: true,
// }
// )
// // 在视图加载后将页面滚动到底部
// const scrollToBottom = () => {
// // 获取消息列表容器的DOM元素
// const container = messageListContainer.value;
// // 在下一个DOM更新周期中执行滚动
// nextTick(() => {
// container.scrollTop = container.scrollHeight;
// })
// }
// defineExpose({
// scrollToBottom
// })
</script>
<style lang="scss">
.inquire-group {
@include flex();
.avatar {
@include common-icon-wh(80rpx);
margin-right: 20rpx;
border-radius: 50%;
}
.dialogue {
.top {
font-size: 24rpx;
}
.inquire {
word-break: break-all;
width: 462rpx;
padding: 32rpx;
height: auto;
margin-top: 8rpx;
box-sizing: border-box;
border-radius: 0 16rpx 16rpx 16rpx;
background: #242228ff;
}
}
}
.group-wrap {
@include flexCj();
flex: 1;
flex-wrap: wrap;
.group-item {
padding: 24rpx 16rpx;
box-sizing: border-box;
width: 276rpx;
height: 160rpx;
border-radius: 12rpx;
background: #242228ff;
margin-bottom: 18rpx;
.item-title {
font-size: 26rpx;
font-weight: 700;
}
.item-content {
word-break: break-all;
@include oneLine(2);
color: #ffffff8c;
font-size: 24rpx;
}
}
}
.response-group {
.answer-inner {
margin-left: auto;
.answer-name {
text-align: right;
}
}
.answer-dialogue {
word-break: break-all;
width: 416rpx;
padding: 32rpx;
margin-top: 8rpx;
box-sizing: border-box;
border-radius: 16rpx 0 16rpx 16rpx;
background: #dda372ff;
}
}
</style>