chatBox.vue
8.04 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<template>
<view class="uni-padding-wrap">
<view class="" style="position:fixed;bottom: 0rpx;left: 0;width: 100%;">
<form @submit="commitComments">
<view style="display: flex;justify-content: space-between;;padding: 10px;">
<input class="contentTextArea" name="commentContent" v-model="sumshop.chatContent" placeholder="请输入"></input>
<button class="commitButton" formType="submit">发送</button>
</view>
</form>
</view>
<view class="uni-comment" v-show="commentsList.length!=0" id="words" >
<view :class="item.messageType==2?'uni-comment-list':'uni-comment-listTWO'" v-for="(item,index) in commentsList" :key="index" >
<view style="text-align: right;margin-top: 10rpx;" v-if="item.messageType==1">
<view class="uni-comment-top" style="margin-right: 10px;">
<view>{{item.userName==''||item.userName==null?'匿名':item.userName}}</view>
</view>
<view class="uni-comment-content ziji" style="margin-right: 10px;text-align: right;padding-right: 15px;">{{item.chatContent}}</view>
<view class="uni-comment-date">{{item.chatTime}}</view>
</view>
<view class="uni-comment-face" v-if="item.messageType==1">
<image :src="$baseURL+user.headImage" mode="widthFix"></image>
</view>
<view class="uni-comment-face" v-if="item.messageType==2">
<image src="../../components/canvasShow/static/images/product/kefu.png" mode="widthFix"></image>
</view>
<view class="uni-comment-body" v-if="item.messageType==2">
<view class="uni-comment-top">
<view>{{item.shopName==''||item.shopName==null?'匿名':item.shopName}}</view>
</view>
<view class="uni-comment-content kehu" style="text-align: left;padding-left: 15px;">{{item.chatContent}}</view>
<view class="uni-comment-date">{{item.chatTime}}</view>
</view>
</view>
</view>
<view class="uni-comment" v-if="commentsList.length==0">
<view class="uni-comment-list">
<view class="uni-comment-face">
<image src="../../components/canvasShow/static/images/product/kefu.png" mode="widthFix"></image>
</view>
<view class="uni-comment-body">
<view class="uni-comment-top">
<view>商家</view>
</view>
<view class="uni-comment-content kehu" style="text-align: left;padding-left: 15px;">您好!请问有什么问题呢?</view>
<view class="uni-comment-date"></view>
</view>
</view>
</view>
</view>
</template>
<script>
const NET = require('../../utils/request')
const API = require('../../config/api')
export default {
data(){
return{
commentsList:[],
user:{},
index:'',
sumshop:{
chatContent:'',
shopId:''
},
timer: null // 定义定时器
}
},
mounted() {
this.timer = setInterval(() => {
this.getMsg()
}, 30000)
},
onLoad(option) {
console.log(option.shopId)
this.sumshop.shopId = option.shopId
NET.requestGet(API.keSeverList, option.shopId, 'GET').then(res => {
this.commentsList = res.data
NET.request(API.GetUser, {}, 'GET').then(iotem => {
this.user = iotem.data
})
})
},
beforeDestroy() {
// 组件销毁时清除定时器,避免内存泄漏
if (this.timer) {
clearInterval(this.timer)
}
},
methods:{
commitComments(){
if(this.sumshop.chatContent == ''){
return
}
NET.request(API.keSever, this.sumshop, 'POST').then(res => {
if(res.code=='200'){
this.sumshop.chatContent = ''
this.getMsg(1)
}
})
},
getMsg(val){
NET.requestGet(API.keSeverList, this.sumshop.shopId, 'GET').then(res => {
this.commentsList = res.data
if(val == 1){
this.scollBottom()
}
})
},
scollBottom(){
var oWords = document.getElementById('words')
setTimeout(() => {
this.$nextTick(() => {
oWords.scrollTop = oWords.scrollHeight+87.5
})
}, 100)
}
}
}
</script>
<style lang="scss" scoped>
.uni-padding-wrap{
height: calc(100vh - 100px);
position: relative;
}
.ziji {
width: 100%;
/* 假设消息框占据了屏幕宽度的80% */
padding: 16px;
/* 消息框内的内边距 */
background-color: #3F9B6A;
/* 蓝色背景 */
color: white;
/* 白色文字 */
position: relative;
/* 为了定位右上角的表情符号 */
font-size: 16px;
/* 字体大小 */
text-align: left;
/* 文字左对齐 */
/* 移除圆角 */
border-radius: 0;
/* 只给右上角添加圆角(如果需要的话,这里设置为0表示不添加) */
border-top-right-radius: 40px;
/* 可以根据需要调整或删除此行 */
border-bottom-right-radius: 0px;
/* 同上 */
/* 只保留左下角的直角(实际上不需要特别设置,因为默认就是直角) */
/* 但为了明确,我们可以设置其他三个角为0(如果之前设置了圆角的话) */
border-top-left-radius: 22px;
border-bottom-left-radius: 22px;
/* 左下角保持直角,这其实是默认值 */
}
.kehu {
width: 100%;
/* 假设消息框占据了屏幕宽度的80% */
padding: 16px;
/* 消息框内的内边距 */
background-color: #F7F5F6;
/* 蓝色背景 */
color: #000;
/* 白色文字 */
position: relative;
/* 为了定位右上角的表情符号 */
font-size: 16px;
/* 字体大小 */
text-align: left;
/* 文字左对齐 */
/* 移除圆角 */
border-radius: 0;
/* 只给右上角添加圆角(如果需要的话,这里设置为0表示不添加) */
border-top-right-radius: 22px;
/* 可以根据需要调整或删除此行 */
border-bottom-right-radius: 22px;
/* 同上 */
/* 只保留左下角的直角(实际上不需要特别设置,因为默认就是直角) */
/* 但为了明确,我们可以设置其他三个角为0(如果之前设置了圆角的话) */
border-top-left-radius: 40px;
border-bottom-left-radius: 0;
/* 左下角保持直角,这其实是默认值 */
}
view {
font-size: 28upx;
}
.uni-comment {
padding: 30upx;
display: flex;
flex-grow: 1;
flex-direction: column;
scrollbar-width: none;
overflow: hidden;
height: 95vh;
overflow-y: auto;
}
.uni-comment-list {
flex-wrap: nowrap;
padding: 10rpx 0;
margin: 10rpx 0;
width: 100%;
display: flex;
}
.uni-comment-listTWO{
flex-wrap: nowrap;
padding: 10rpx 0;
margin: 10rpx 0;
width: 100%;
display: flex;
justify-content: flex-end;
}
.uni-comment-face {
width: 70upx;
height: 70upx;
border-radius: 100%;
margin-right: 20upx;
flex-shrink: 0;
overflow: hidden;
}
.uni-comment-face image {
width: 100%;
border-radius: 100%;
}
.uni-comment-body {
margin-top: 10rpx;
width: 100%;
}
.uni-comment-top {
// display: flex;
// justify-content: flex-start;
line-height: 1.5em;
}
.uni-comment-top text {
color: #3F9B6A;
margin-right: 20rpx;
font-size: 24upx;
}
.uni-comment-top{
}
.uni-comment-date {
color: #666666;
font-size: 24upx;
}
.uni-comment-content {
line-height: 1.6em;
font-size: 28upx;
padding: 8rpx 10px;
margin:8rpx 0;
/* 移除固定高度和宽度 */
height: auto;
width: auto;
/* 使用 inline-block 或 flex 让盒子根据内容自动调整大小 */
display: inline-block;
max-width: 70%; /* 大致限制宽度为父元素的 70% */
word-wrap: break-word; /* 允许长单词换行 */
overflow-wrap: break-word; /* 同 word-wrap,更标准的写法 */
display: inline-block; /* 让盒子根据内容自适应宽度 */
}
.uni-comment-replay-btn {
background: #FFF;
font-size: 24upx;
line-height: 28upx;
padding: 5rpx 20upx;
border-radius: 30upx;
color: #333 !important;
margin: 0 10upx;
}
.commitButton{
height: 64rpx;
color: #fff;
width: 20%;
margin: 0rpx auto;
font-size: 27rpx;
border-radius: 10px;
line-height: 64rpx;
background-color: #3F9B6A;
}
.contentTextArea{
font-size: 30rpx;
background-color: #fff;
border:1rpx solid #e9e7ef;
border-right: 0px solid transparent;
width: 72%;
height: 40rpx;
margin: 0rpx auto;
padding: 10rpx 0 10rpx 20rpx;
border-radius: 10px;
}
</style>