chat.vue 30.4 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1
<template>
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
2 3 4 5
	<view class="container">
		<!-- #ifdef H5 -->
		<view v-if="isWidescreen" class="header">uni-ai-chat</view>
		<!-- #endif -->
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
6
		<text class="noData" v-if="msgList.length === 0">没有对话记录</text>
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
7
		<scroll-view :scroll-into-view="scrollIntoView" scroll-y="true" class="msg-list" :enable-flex="true">
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
8
			<uni-ai-msg ref="msg" v-for="(msg,index) in msgList" :key="index" :msg="msg" @changeAnswer="changeAnswer"
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
9 10 11
				:show-cursor="index == msgList.length - 1 && msgList.length%2 === 0 && sseIndex"
				:isLastMsg="index == msgList.length - 1" @removeMsg="removeMsg(index)"></uni-ai-msg>
			<template v-if="msgList.length%2 !== 0">
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
12
				<view v-if="requestState == -100" class="retries-box">
DCloud_JSON's avatar
1.1.5  
DCloud_JSON 已提交
13
					<text>消息发送失败</text>
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
14
					<uni-icons @click="send" color="#d22" type="refresh-filled" class="retries-icon"></uni-icons>
DCloud_JSON's avatar
1.1.5  
DCloud_JSON 已提交
15
				</view>
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
16
				<view class="tip-ai-ing" v-else-if="msgList.length">
DCloud_JSON's avatar
1.1.5  
DCloud_JSON 已提交
17 18 19 20 21 22 23
					<text>uni-ai正在思考中...</text>
					<view v-if="NODE_ENV == 'development' && !enableStream">
						如需提速,请开通<uni-link class="uni-link" href="https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html"
							text="[流式响应]"></uni-link>
					</view>
				</view>
			</template>
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
24
			<view v-if="adpid" class="open-ad-btn-box">
DCloud_JSON's avatar
1.2.3  
DCloud_JSON 已提交
25
				<text style="color: red;">
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
26 27
					默认不启用广告组件(被注释),如需使用,请"去掉注释"(“重新运行”后生效)
					位置:/pages/chat/chat.vue 第30行,或全局搜索 uni-ad-rewarded-video
DCloud_JSON's avatar
1.2.3  
DCloud_JSON 已提交
28 29
				</text>
				<!-- <uni-ad-rewarded-video v-show="insufficientScore" :adpid="adpid" @onAdClose="onAdClose"></uni-ad-rewarded-video> -->
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
30 31
			</view>
			<view @click="closeSseChannel" class="stop-responding" v-if="sseIndex"> ▣ 停止响应</view>
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
			<view id="last-msg-item" style="height: 1px;"></view>
		</scroll-view>

		<view class="foot-box" :style="{'padding-bottom':footBoxPaddingBottom}">
			<!-- #ifdef H5 -->
			<view class="pc-menu" v-if="isWidescreen">
				<view class="pc-trash pc-menu-item" @click="clearAllMsg" title="删除">
					<image src="@/static/remove.png" mode="heightFix"></image>
				</view>
				<view class="settings pc-menu-item" @click="setLLMmodel" title="设置">
					<uni-icons color="#555" size="20px" type="settings"></uni-icons>
				</view>
			</view>
DCloud_JSON's avatar
1.0.22  
DCloud_JSON 已提交
45
			<!-- #endif -->
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
46 47 48 49 50 51 52 53
			<view class="foot-box-content">
				<view v-if="!isWidescreen" class="menu">
					<uni-icons class="menu-item" @click="clearAllMsg" type="trash" size="24" color="#888"></uni-icons>
					<uni-icons class="menu-item" @click="setLLMmodel" color="#555" size="20px"
						type="settings"></uni-icons>
				</view>
				<view class="textarea-box">
					<textarea v-model="content" :cursor-spacing="15" class="textarea" :auto-height="!isWidescreen"
DCloud_JSON's avatar
1.2.6  
DCloud_JSON 已提交
54
						placeholder="请输入要发给uni-ai的内容" :maxlength="-1" :adjust-position="false"
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
55 56
						:disable-default-padding="false" placeholder-class="input-placeholder"></textarea>
				</view>
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
57
				<view class="send-btn-box" :title="(msgList.length && msgList.length%2 !== 0) ? 'ai正在回复中不能发送':''">
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
58 59 60
					<!-- #ifdef H5 -->
					<text v-if="isWidescreen" class="send-btn-tip">↵ 发送 / shift + ↵ 换行</text>
					<!-- #endif -->
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
61
					<button @click="beforeSend" :disabled="inputBoxDisabled || !content" class="send"
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
62
						type="primary">发送</button>
DCloud_JSON's avatar
DCloud_JSON 已提交
63 64
				</view>
			</view>
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
65 66
		</view>
		<llm-config ref="llm-config"></llm-config>
DCloud_JSON's avatar
DCloud_JSON 已提交
67 68 69 70 71
	</view>
</template>

<script>
	// 引入配置文件
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
72
	import config from '@/config.js';
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
73

DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
74
	// 导入uniCloud云对象task模块
DCloud_JSON's avatar
1.2.4  
DCloud_JSON 已提交
75 76 77
	import uniCoTask from '@/common/unicloud-co-task.js';
	// 导入 将多个字消息文本,分割成单个字 分批插入到最末尾的消息中 的类
	import SliceMsgToLastMsg from './SliceMsgToLastMsg.js';
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
78 79 80 81 82 83 84 85 86
	// 收集所有执行云对象的任务列表
	let uniCoTaskList = []
	// 定义终止并清空 云对象的任务列表中所有 任务的方法
	uniCoTaskList.clear = function() {
		// 执行数组内的所有任务
		uniCoTaskList.forEach(task => task.abort())
		// 清空数组
		uniCoTaskList.slice(0, uniCoTaskList.length)
	}
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
87

DCloud_JSON's avatar
DCloud_JSON 已提交
88 89 90 91 92 93 94
	// 获取广告id
	const {
		adpid
	} = config
	// 初始化sse通道
	let sseChannel = false;

DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
95
	// 键盘的shift键是否被按下
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
96 97
	let shiftKeyPressed = false
	
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
98
	export default {
DCloud_JSON's avatar
DCloud_JSON 已提交
99 100 101 102 103
		data() {
			return {
				// 使聊天窗口滚动到指定元素id的值
				scrollIntoView: "",
				// 消息列表数据
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
104 105 106 107 108
				msgList: [],
				// 通讯请求状态
				requestState:0,//0发送中 100发送成功 -100发送失败
				// 本地对话是否因积分不足而终止
				insufficientScore:false,
DCloud_JSON's avatar
DCloud_JSON 已提交
109 110 111 112 113 114 115 116 117
				// 输入框的消息内容
				content: "",
				// 记录流式响应次数
				sseIndex: 0,
				// 是否启用流式响应模式
				enableStream: true,
				// 当前屏幕是否为宽屏
				isWidescreen: false,
				// 广告位id
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
118 119
				adpid,
				llmModel: false,
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
120
				keyboardHeight: 0
DCloud_JSON's avatar
DCloud_JSON 已提交
121
			}
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
122
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
123 124 125 126 127 128 129 130
		computed: {
			// 输入框是否禁用
			inputBoxDisabled() {
				// 如果正在等待流式响应,则禁用输入框
				if (this.sseIndex !== 0) {
					return true
				}
				// 如果消息列表长度为奇数,则禁用输入框
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
131 132
				return !!(this.msgList.length && this.msgList.length % 2 !== 0)
			},
DCloud_JSON's avatar
DCloud_JSON 已提交
133 134 135
			// 获取当前环境
			NODE_ENV() {
				return process.env.NODE_ENV
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
136 137 138
			},
			footBoxPaddingBottom() {
				return (this.keyboardHeight || 10) + 'px'
DCloud_JSON's avatar
DCloud_JSON 已提交
139 140 141
			}
		},
		// 监听msgList变化,将其存储到本地缓存中
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
142
		watch: {
DCloud_JSON's avatar
DCloud_JSON 已提交
143
			msgList: {
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
144
				handler(msgList) {
DCloud_JSON's avatar
DCloud_JSON 已提交
145
					// 将msgList存储到本地缓存中
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
146 147 148 149
					uni.setStorage({
						"key": "uni-ai-msg",
						"data": msgList
					})
DCloud_JSON's avatar
DCloud_JSON 已提交
150 151 152
				},
				// 深度监听msgList变化
				deep: true
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
153 154 155 156 157 158
			},
			insufficientScore(insufficientScore){
				uni.setStorage({
					"key": "uni-ai-chat-insufficientScore",
					"data": insufficientScore
				})
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
			},
			llmModel(llmModel) {
				let title = 'uni-ai-chat'
				if (llmModel) {
					title += ` (${llmModel})`
				}
				// uni.setNavigationBarTitle({title})
				// #ifdef H5
				if (this.isWidescreen) {
					document.querySelector('.header').innerText = title
				}
				// #endif
				uni.setStorage({
					key: 'uni-ai-chat-llmModel',
					data: llmModel
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
175
			}
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
176 177 178 179 180 181 182 183 184 185
		},
		beforeMount() {
			// #ifdef H5
			// 监听屏幕宽度变化,判断是否为宽屏 并设置isWidescreen的值
			uni.createMediaQueryObserver(this).observe({
				minWidth: 650,
			}, matches => {
				this.isWidescreen = matches;
			})
			// #endif
DCloud_JSON's avatar
DCloud_JSON 已提交
186
		},
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
187
		async mounted() {
DCloud_JSON's avatar
DCloud_JSON 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
			// 如果存在广告位id且用户token未过期
			if (this.adpid && uniCloud.getCurrentUserInfo().tokenExpired > Date.now()) {
				// 查询当前用户的积分
				// 获取数据库对象
				let db = uniCloud.databaseForJQL();
				// 获取uni-id-users集合
				let res = await db.collection("uni-id-users")
					// 查询条件
					.where({
						// 当前用户id
						"_id": uniCloud.getCurrentUserInfo().uid
					})
					// 返回score字段
					.field('score')
					// 执行查询
					.get()
				// 输出当前用户积分
				console.log('当前用户有多少积分:', res.data[0] && res.data[0].score);
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
206
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
207 208 209 210 211 212 213

			// for (let i = 0; i < 15; i++) {
			// 	this.msgList.push({
			// 		isAi: i % 2 == true,
			// 		content: "1-" + i
			// 	})
			// }
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
214

DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
215
			// 获得历史对话记录
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
216
			this.msgList = uni.getStorageSync('uni-ai-msg') || [];
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
217 218

			// 获得之前设置的llmModel
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
219 220 221 222
			this.llmModel = uni.getStorageSync('uni-ai-chat-llmModel')
			
			// 获得之前设置的uni-ai-chat-insufficientScore
			this.insufficientScore = uni.getStorageSync('uni-ai-chat-insufficientScore') || false
DCloud_JSON's avatar
DCloud_JSON 已提交
223 224 225 226 227 228

			// 如果上一次对话中 最后一条消息ai未回复。则一启动就自动重发。
			let length = this.msgList.length
			if (length) {
				let lastMsg = this.msgList[length - 1]
				if (!lastMsg.isAi) {
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
229
					this.send()
DCloud_JSON's avatar
DCloud_JSON 已提交
230 231 232 233 234 235 236 237 238 239 240
				}
			}

			// this.msgList.pop()
			// console.log('this.msgList', this.msgList);

			// 在dom渲染完毕后 使聊天窗口滚动到最后一条消息
			this.$nextTick(() => {
				this.showLastMsg()
			})

DCloud_JSON's avatar
1.0.18  
DCloud_JSON 已提交
241
			// #ifdef H5
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
242 243 244 245 246 247 248 249 250 251 252 253
			//获得消息输入框对象
			let adjunctKeydown = false
			const textareaDom = document.querySelector('.textarea-box textarea');
			if (textareaDom) {
				//键盘按下时
				textareaDom.onkeydown = e => {
					// console.log('onkeydown', e.keyCode)
					if ([16, 17, 18, 93].includes(e.keyCode)) {
						//按下了shift ctrl alt windows键
						adjunctKeydown = true;
					}
					if (e.keyCode == 13 && !adjunctKeydown) {
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
254 255 256
						e.preventDefault()
						// 执行发送
						setTimeout(() => {
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
257
							this.beforeSend();
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
258
						}, 300)
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
259 260 261 262 263 264 265 266
					}
				};
				textareaDom.onkeyup = e => {
					//松开adjunct键
					if ([16, 17, 18, 93].includes(e.keyCode)) {
						adjunctKeydown = false;
					}
				};
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
				
				// 可视窗口高
				let initialInnerHeight = window.innerHeight;
				if (uni.getSystemInfoSync().platform == "ios") {
					textareaDom.addEventListener('focus', () => {
						let interval = setInterval(function() {
							if (window.innerHeight !== initialInnerHeight) {
								clearInterval(interval)
								// 触发相应的回调函数
								document.querySelector('.container').style.height = window.innerHeight + 'px'
								window.scrollTo(0, 0);
								this.showLastMsg()
							}
						}, 1);
					})
					textareaDom.addEventListener('blur', () => {
						document.querySelector('.container').style.height = initialInnerHeight + 'px'
					})
				}else{
					window.addEventListener('resize',(e)=>{
						this.showLastMsg()
					})
				}
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
290 291
			}
			// #endif
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
292 293 294 295 296 297 298 299 300 301

			// #ifndef H5
			uni.onKeyboardHeightChange(e => {
				this.keyboardHeight = e.height
				// 在dom渲染完毕后 使聊天窗口滚动到最后一条消息
				this.$nextTick(() => {
					this.showLastMsg()
				})
			})
			// #endif
DCloud_JSON's avatar
DCloud_JSON 已提交
302
		},
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
303 304 305 306 307 308
		methods: {
			setLLMmodel() {
				this.$refs['llm-config'].open(model => {
					console.log('model', model);
					this.llmModel = model
				})
DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
309
			},
DCloud_JSON's avatar
DCloud_JSON 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322
			// 此(惰性)函数,检查是否开通uni-push;决定是否启用enableStream
			async checkIsOpenPush() {
				try {
					// 获取推送客户端id
					await uni.getPushClientId()
					// 如果获取成功,则将checkIsOpenPush函数重写为一个空函数
					this.checkIsOpenPush = () => {}
				} catch (err) {
					// 如果获取失败,则将enableStream设置为false
					this.enableStream = false
				}
			},
			// 更新最后一条消息
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
			updateLastMsg(param) {
				let length = this.msgList.length
				if (length === 0) {
					return
				}
				let lastMsg = this.msgList[length - 1]
			
				// 如果param是函数,则将最后一条消息作为参数传入该函数
				if (typeof param == 'function') {
					let callback = param;
					callback(lastMsg)
				} else {
					// 否则,将参数解构为data和cover两个变量
					const [data, cover = false] = arguments
					if (cover) {
						lastMsg = data
					} else {
						lastMsg = Object.assign(lastMsg, data)
					}
				}
				this.msgList.splice(length - 1, 1, lastMsg)
			},
DCloud_JSON's avatar
DCloud_JSON 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
			// 广告关闭事件
			onAdClose(e) {
				console.log('onAdClose e.detail.isEnded', e.detail.isEnded);
				if (e.detail.isEnded) {
					//5次轮训查结果
					let i = 0;
					uni.showLoading({
						mask: true
					})
					let myIntive = setInterval(async e => {
						i++;
						// 获取云数据库实例
						const db = uniCloud.database();
						// 获取uni-id-users集合
						let res = await db.collection("uni-id-users")
							// 查询条件为_id等于当前用户id
							.where('"_id" == $cloudEnv_uid')
							// 只返回score字段
							.field('score')
							// 执行查询
							.get()
						// 解构出score字段的值,如果没有则默认为undefined
						let {
							score
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
369 370
						} = res.result.data[0] || {}
						console.log('score',score);
DCloud_JSON's avatar
DCloud_JSON 已提交
371 372 373 374 375
						if (score > 0 || i > 5) {
							// 清除轮询定时器
							clearInterval(myIntive)
							// 隐藏加载提示
							uni.hideLoading()
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
376 377
							if (score > 0) {
								this.insufficientScore = false
DCloud_JSON's avatar
DCloud_JSON 已提交
378 379 380 381
								// 移除最后一条消息
								this.msgList.pop()
								this.$nextTick(() => {
									// 重发消息
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
382
									this.send()
DCloud_JSON's avatar
DCloud_JSON 已提交
383 384 385 386 387 388 389 390 391 392
									uni.showToast({
										title: '积分余额:' + score,
										icon: 'none'
									});
								})
							}
						}
					}, 2000);
				}
			},
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
393 394 395 396 397 398 399 400
			// 换一个答案
			async changeAnswer() {
				// 如果问题还在回答中需要先关闭
				if (this.sseIndex) {
					this.closeSseChannel()
				}
				//删除旧的回答
				this.msgList.pop()
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
401 402
				this.updateLastMsg({
					// 防止 偶发答案涉及敏感,重复回答时。提问内容 被卡掉无法重新问
DCloud_JSON's avatar
1.2.8  
DCloud_JSON 已提交
403
					illegal: false
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
404 405 406
				})
				// 多设备登录时其他设备看广告后点击重新回答,insufficientScore应当设置为 false
				this.insufficientScore = false
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
407
				this.send()
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
408
			},
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
409
			removeMsg(index) {
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
410
				// 成对删除,如果点中的是 ai 回答的内容,index -= 1
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
411 412 413
				if (this.msgList[index].isAi) {
					index -= 1
				}
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
414 415 416 417 418 419
				
				// 如果删除的就是正在问的,且问题还在回答中需要先关闭
				if (this.sseIndex && index == this.msgList.length - 2) {
					this.closeSseChannel()
				}
				
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
420
				this.msgList.splice(index,2)
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
421
			},
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
422
			async beforeSend() {
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
423 424 425 426 427
				if (this.inputBoxDisabled) {
					return uni.showToast({
						title: 'ai正在回复中不能发送',
						icon: 'none'
					});
DCloud_JSON's avatar
1.0.19  
DCloud_JSON 已提交
428
				}
DCloud_JSON's avatar
DCloud_JSON 已提交
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
				// 如果开启了广告位需要登录
				if (this.adpid) {
					// 获取本地缓存的token
					let token = uni.getStorageSync('uni_id_token')
					// 如果token不存在
					if (!token) {
						// 弹出提示框
						return uni.showModal({
							// 提示内容
							content: '启用激励视频,客户端需登录并启用安全网络',
							// 不显示取消按钮
							showCancel: false,
							// 确认按钮文本
							confirmText: "查看详情",
							// 弹框关闭后执行的回调函数
							complete() {
								// 文档链接
								let url = "https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#ad"
								// #ifndef H5
								// 将文档链接复制到剪贴板
								uni.setClipboardData({
									// 复制的内容
									data: url,
									// 不显示提示框
									showToast: false,
									// 复制成功后的回调函数
									success() {
										// 弹出提示框
										uni.showToast({
											// 提示内容
											title: '已复制文档链接,请到浏览器粘贴浏览',
											// 不显示图标
											icon: 'none',
											// 提示框持续时间
											duration: 5000
										});
									}
								})
								// #endif

								// #ifdef H5
								// 在新窗口打开文档链接
								window.open(url)
								// #endif
							}
						});
					}
				}

				// 如果内容为空
				if (!this.content) {
					// 弹出提示框
					return uni.showToast({
						// 提示内容
						title: '内容不能为空',
						// 不显示图标
						icon: 'none'
					});
				}

				// 将用户输入的消息添加到消息列表中
				this.msgList.push({
					// 标记为非人工智能机器人,即:为用户发送的消息
					isAi: false,
					// 消息内容
					content: this.content,
					// 消息创建时间
					create_time: Date.now()
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
497 498
				})

DCloud_JSON's avatar
DCloud_JSON 已提交
499 500
				// 展示最后一条消息
				this.showLastMsg()
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
501
				// dom加载完成后 清空文本内容
DCloud_JSON's avatar
DCloud_JSON 已提交
502
				this.$nextTick(() => {
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
503
					this.content = ''
DCloud_JSON's avatar
DCloud_JSON 已提交
504 505
				})
				this.send() // 发送消息
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
506
			},
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
507
			async send() {
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
508 509 510 511 512 513 514
				// 请求状态归零
				this.requestState = 0
				// 防止重复发起,关闭之前的
				uniCoTaskList.clear()
				// 清除旧的afterChatCompletion(如果存在)
				if(this.afterChatCompletion && this.afterChatCompletion.clear) this.afterChatCompletion.clear()
				
DCloud_JSON's avatar
DCloud_JSON 已提交
515 516
				let messages = []
				// 复制一份,消息列表数据
517 518 519
				let msgs = JSON.parse(JSON.stringify(this.msgList))
				
				// - 获取上下文的代码【start】-
DCloud_JSON's avatar
DCloud_JSON 已提交
520 521 522 523 524 525 526 527
				// 带总结的消息 index
				let findIndex = [...msgs].reverse().findIndex(item => item.summarize)
				// console.log('findIndex', findIndex)
				if (findIndex != -1) {
					let aiSummaryIndex = msgs.length - findIndex - 1
					// console.log('aiSummaryIndex', aiSummaryIndex)
					// 将带总结的消息的 内容 更换成 总结
					msgs[aiSummaryIndex].content = msgs[aiSummaryIndex].summarize
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
528 529
					// 拿最后一条带直接的消息作为与ai对话的msg body
					msgs = msgs.splice(aiSummaryIndex)
DCloud_JSON's avatar
DCloud_JSON 已提交
530 531 532 533 534
				} else {
					// 如果未总结过就直接从末尾拿10条
					msgs = msgs.splice(-10)
				}
				// 过滤涉敏问题
535 536 537 538
				msgs = msgs.filter(msg => !msg.illegal)
				// - 获取上下文的代码【end】-
				
				// 如果:不希望带上上下文;请注释掉 上方:获取上下文的代码【start】-【end】。并添加,代码: msgs = [msgs.pop()]
DCloud_JSON's avatar
DCloud_JSON 已提交
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
				// 根据数据内容设置角色
				messages = msgs.map(item => {
					// 角色默认为用户
					let role = "user"
					// 如果是ai再根据 是否有总结 来设置角色为 system 还是 assistant
					if (item.isAi) {
						role = item.summarize ? 'system' : 'assistant'
					}
					return {
						content: item.content,
						role
					}
				})

				// 在控制台输出 向ai机器人发送的完整消息内容
				console.log('send to ai messages:', messages);
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
555 556 557

				// 检查是否开通uni-push;决定是否启用enableStream
				await this.checkIsOpenPush()
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
558
				// console.log('this.enableStream',this.enableStream);
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
559

DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
560 561
				// 流式响应和云对象的请求结束回调函数
				let sseEnd,requestEnd;
DCloud_JSON's avatar
DCloud_JSON 已提交
562
				// 判断是否开启了流式响应模式
DCloud_JSON's avatar
1.2.4  
DCloud_JSON 已提交
563
				if (this.enableStream) {
DCloud_JSON's avatar
DCloud_JSON 已提交
564 565
					// 创建消息通道
					sseChannel = new uniCloud.SSEChannel()
DCloud_JSON's avatar
1.2.4  
DCloud_JSON 已提交
566 567 568
					// console.log('sseChannel',sseChannel);
					
					// 将多个字的文本,分割成单个字 分批插入到最末尾的消息中
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
569
					this.sliceMsgToLastMsg = new SliceMsgToLastMsg(this)
DCloud_JSON's avatar
DCloud_JSON 已提交
570
					// 监听message事件
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
571
					sseChannel.on('message', (message) => {
DCloud_JSON's avatar
DCloud_JSON 已提交
572 573 574 575 576 577 578 579
						// console.log('on message', message);
						// 将从云端接收到的消息添加到消息列表中

						// 如果之前未添加过就添加,否则就执行更新最后一条消息
						if (this.sseIndex === 0) {
							this.msgList.push({
								isAi: true,
								content: message,
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
580
								create_time: Date.now()
DCloud_JSON's avatar
DCloud_JSON 已提交
581
							})
DCloud_JSON's avatar
1.2.4  
DCloud_JSON 已提交
582
						} else {
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
583
							this.sliceMsgToLastMsg.addMsg(message)
DCloud_JSON's avatar
1.2.4  
DCloud_JSON 已提交
584 585 586
							// this.updateLastMsg(lastMsg => {
							// 	lastMsg.content += message
							// })
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
587 588
						}
						this.showLastMsg()
DCloud_JSON's avatar
DCloud_JSON 已提交
589 590
						// 让流式响应计数值递增
						this.sseIndex++
DCloud_JSON's avatar
1.2.4  
DCloud_JSON 已提交
591 592
					})

DCloud_JSON's avatar
DCloud_JSON 已提交
593 594
					// 监听end事件,如果云端执行end时传了message,会在客户端end事件内收到传递的消息
					sseChannel.on('end', (e) => {
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
595
						console.log('sse 结束',e)
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
596 597
						// 更改“按字分割追加到最后一条消息“的时间间隔为0,即:一次性加载完(不再分割加载)
						this.sliceMsgToLastMsg.t = 0
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
						if(e && typeof e == 'object' && e.errCode){
							let setLastAiMsgContent = (content)=>{
								// console.log(content);
								// 如果最后一项不是ai的就添加,否则就执行更新最后一条消息
								if (this.sseIndex === 0) {
									this.msgList.push({
										isAi: true,
										content,
										create_time: Date.now()
									})
								} else {
									this.updateLastMsg(lastMsg => {
										lastMsg.content += content
									})
								}
								this.showLastMsg()
							}
							if(e.errCode == 60004){
								//服务商检测到AI输出了敏感内容
								let length = this.msgList.length
								//如果最后一项不是ai,就创建一项
								if(length % 2){
									this.msgList.push({
										isAi: true,
										content:"内容涉及敏感",
										illegal:true,
										create_time: Date.now()
									})
									length += 1
								}
								// 更新倒数第2项 用户提的问题
								this.msgList[length - 2].illegal = true
								// 更新倒数第1项 ai 回答的内容
								this.msgList[length - 1].illegal = true
								this.msgList[length - 1].content = "内容涉及敏感"
								
							}else{
								setLastAiMsgContent(e.errMsg)
							}
						}
						sseEnd()
					})
					await sseChannel.open(); // 等待通道开启
					
					// 等待对话完成(云函数请求完成,sse 执行了 end)之后
					(function fnSelf(that){
						fnSelf.clear = ()=>{
							// console.log('do fnSelf.clear');
							if(fnSelf.clear.sse){
								// console.log('fnSelf.clear.sse();')
								fnSelf.clear.sse();
							}
							if(fnSelf.clear.request){
								// console.log('fnSelf.clear.request();')
								fnSelf.clear.request();
							}
						}
						Promise.all([
							new Promise((resolve,reject)=>{
								sseEnd = resolve;
								fnSelf.clear.sse = reject;
							}),
							new Promise((resolve,reject)=>{
								requestEnd = resolve;
								fnSelf.clear.request = reject;
							})
						]).then((e)=>{
							// console.log('sseEnd && requestEnd');
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
666 667 668
							//当两个都结束时
							sseChannel.close()
							// 结束流式响应 将流式响应计数值 设置为 0
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
669 670 671 672 673 674 675 676
							that.sseIndex = 0
						}).catch((err)=>{
							// console.log('afterChatCompletion is close',err);
						})
						that.afterChatCompletion = fnSelf
					})(this)
				}
				
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
677 678 679 680 681
				// 导入uni-ai-chat模块,并设置customUI为true
				let task = uniCoTask({
					coName: "uni-ai-chat",
					funName: "send",
					param: [{
DCloud_JSON's avatar
DCloud_JSON 已提交
682
						messages, // 消息列表
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
683 684 685 686 687 688
						sseChannel, // 消息通道
						llmModel: this.llmModel
					}],
					config: {
						customUI: true
					},
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
689 690 691 692 693
					success: res => {
						// 更新 通讯状态为100(发送成功)
						this.requestState = 100
						// console.log("success",res);
						if (!res.data) return
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
694 695
						
						let {
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
696
							reply,
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
697 698 699 700 701 702
							summarize,
							insufficientScore,
							illegal
						} = res.data
						
						// 特殊处理 - start
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
703 704
						if(this.enableStream == false && !reply){
							//服务商检测到AI输出了敏感内容
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
705
							illegal = true
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
706
							reply = "内容涉及敏感"
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
707 708
						}
						// 特殊处理 - end
DCloud_JSON's avatar
1.2.9  
DCloud_JSON 已提交
709 710 711 712 713 714 715 716 717
            
            // 非流式模式 && 内容涉及敏感
            if (this.enableStream == false && illegal) {
            	console.error('内容涉及敏感');
            	this.updateLastMsg({
            		// 添加消息涉敏标记
            		illegal: true
            	})
            }
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
718

DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
719
						// 非流式模式 或者流式模式,但列表还没有数据且已经进入异常的情况下
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
720
						if (this.enableStream == false || this.sseIndex == 0 && (illegal||insufficientScore)) {
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
721 722 723 724 725 726 727
							// 将从云端接收到的消息添加到消息列表中
							this.msgList.push({
								// 消息创建时间
								create_time: Date.now(),
								// 标记消息为来自AI机器人
								isAi: true,
								// 消息内容
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
728
								content:reply,
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
729
								// 消息是否涉敏标记
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
730
								illegal
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
731
							})
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
732 733 734 735 736
						}
						
						if(insufficientScore){
							// 积分不足
							this.insufficientScore = true
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
737 738 739 740
						}
						// 如果回调包含总结的内容,就设置总结
						if(summarize){
							console.log(' 拿到总结',summarize);
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
741 742
							// 总结的内容是上一轮对话的
							// console.log('setSummarize');
DCloud_JSON's avatar
1.2.7  
DCloud_JSON 已提交
743 744 745
							let index = this.msgList.length - 1;
							// 如果最后一项是ai就往前退2项,否则退1项(流式响应的时候,回答可能晚于总结)
							if(index%2){
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
746 747 748 749 750
								index -= 2
							}else{
								index -= 1
							}
							// 假如第一次提问就需要总结
DCloud_JSON's avatar
1.2.7  
DCloud_JSON 已提交
751 752
							if (index < 1) {
								index = 1
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
753 754 755 756
							}
							let msg = this.msgList[index]
							msg.summarize = summarize
							this.msgList.splice(index, 1, msg)
DCloud_JSON's avatar
1.2.7  
DCloud_JSON 已提交
757
							// console.log('setSummarize this.msgList',this.msgList,this.msgList.length-1,index);
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
758
						}
DCloud_JSON's avatar
1.2.9  
DCloud_JSON 已提交
759
						
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
760 761
					},
					complete:e=>{
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
762 763
						if (this.enableStream) {
							requestEnd()
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
764
						}
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
765
						// console.log('complete:',e);
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
766 767 768 769
						// 滚动窗口以显示最新的一条消息
						this.$nextTick(() => {
							this.showLastMsg()
						})
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
770 771
					},
					fail: e => {
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
772
						console.error(e);
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
773 774
						// 更新 通讯状态为-100(发送失败)
						this.requestState = -100
DCloud_JSON's avatar
DCloud_JSON 已提交
775 776 777 778
						// 弹框提示用户错误原因
						uni.showModal({
							content: JSON.stringify(e.message),
							showCancel: false
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
779 780 781 782 783
						});
						// 如果启用流式,云函数出错了,sse 也应当被终止
						if (this.enableStream) {
							sseEnd()
						}
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
784 785 786 787 788 789 790
					}
				})
				uniCoTaskList.push(task)
			},
			closeSseChannel() {
				// 如果存在消息通道,就关闭消息通道
				if (sseChannel) {
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
791 792
					sseChannel.close()
					// 设置为 false 防止重复调用closeSseChannel时出错
DCloud_JSON's avatar
1.2.5  
DCloud_JSON 已提交
793 794
					sseChannel = false
					this.sliceMsgToLastMsg.end()
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
795 796 797 798 799 800
				}
				// 清空历史网络请求(调用云对象)任务
				uniCoTaskList.clear()
				// 将流式响应计数值归零
				this.sseIndex = 0
			},
DCloud_JSON's avatar
DCloud_JSON 已提交
801 802
			// 滚动窗口以显示最新的一条消息
			showLastMsg() {
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
803 804 805 806 807 808 809 810
				// 等待DOM更新
				this.$nextTick(() => {
					// 将scrollIntoView属性设置为"last-msg-item",以便滚动窗口到最后一条消息
					this.scrollIntoView = "last-msg-item"
					// 等待DOM更新,即:滚动完成
					this.$nextTick(() => {
						// 将scrollIntoView属性设置为空,以便下次设置滚动条位置可被监听
						this.scrollIntoView = ""
DCloud_JSON's avatar
DCloud_JSON 已提交
811 812 813 814
					})
				})
			},
			// 清空消息列表
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
815
			clearAllMsg(e) {
DCloud_JSON's avatar
DCloud_JSON 已提交
816 817 818 819 820 821
				// 弹出确认清空聊天记录的提示框
				uni.showModal({
					title: "确认要清空聊天记录?",
					content: '本操作不可撤销',
					complete: (e) => {
						// 如果用户确认清空聊天记录
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
822
						if (e.confirm) {
DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
823 824
							// 关闭ssh请求
							this.closeSseChannel()
DCloud_JSON's avatar
DCloud_JSON 已提交
825
							// 将消息列表清空 
DCloud_JSON's avatar
1.2.0  
DCloud_JSON 已提交
826
							this.msgList.splice(0, this.msgList.length);
DCloud_JSON's avatar
DCloud_JSON 已提交
827 828 829 830 831 832 833 834 835 836 837 838 839
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	/* #ifdef VUE3 && APP-PLUS */
	@import "@/components/uni-ai-msg/uni-ai-msg.scss";
	/* #endif */

DCloud_JSON's avatar
1.1.1  
DCloud_JSON 已提交
840 841
	/* #ifndef APP-NVUE */
	page,
842 843 844
	/* #ifdef H5 */
	.container *,
	/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
845 846
	view,
	textarea,
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
847
	button {
DCloud_JSON's avatar
DCloud_JSON 已提交
848 849 850
		display: flex;
		box-sizing: border-box;
	}
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
851

DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
852 853 854 855
	page {
		height: 100%;
		width: 100%;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
856

DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
857
	/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
858

DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
859 860 861 862 863 864 865 866 867 868 869 870
	.stop-responding {
		font-size: 14px;
		border-radius: 3px;
		margin-bottom: 15px;
		background-color: #f0b00a;
		color: #FFF;
		width: 90px;
		height: 30px;
		line-height: 30px;
		margin: 0 auto;
		justify-content: center;
		margin-bottom: 15px;
DCloud_JSON's avatar
DCloud_JSON 已提交
871
		/* #ifdef H5 */
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
872
		cursor: pointer;
DCloud_JSON's avatar
DCloud_JSON 已提交
873
		/* #endif */
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
874
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
875

DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
876 877
	.stop-responding:hover {
		box-shadow: 0 0 10px #aaa;
DCloud_JSON's avatar
DCloud_JSON 已提交
878 879 880
	}

	.container {
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
881
		height: 100%;
DCloud_JSON's avatar
DCloud_JSON 已提交
882
		background-color: #FAFAFA;
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
883 884 885 886
		flex-direction: column;
		align-items: center;
		justify-content: center;
		// border: 1px solid blue;
DCloud_JSON's avatar
DCloud_JSON 已提交
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
	}

	.foot-box {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		padding: 10px 0px;
		background-color: #FFF;
	}

	.foot-box-content {
		justify-content: space-around;
	}

	.textarea-box {
		padding: 8px 10px;
		background-color: #f9f9f9;
		border-radius: 5px;
	}

	.textarea-box .textarea {
DCloud_JSON's avatar
1.0.23  
DCloud_JSON 已提交
908
		max-height: 120px;
DCloud_JSON's avatar
DCloud_JSON 已提交
909 910 911 912
		font-size: 14px;
		/* #ifndef APP-NVUE */
		overflow: auto;
		/* #endif */
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
913
		width: 450rpx;
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
914
		font-size: 14px;
DCloud_JSON's avatar
DCloud_JSON 已提交
915 916 917 918 919 920 921
	}

	/* #ifdef H5 */
	/*隐藏滚动条*/
	.textarea-box .textarea::-webkit-scrollbar {
		width: 0;
	}
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
922

DCloud_JSON's avatar
DCloud_JSON 已提交
923 924 925
	/* #endif */

	.input-placeholder {
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
926
		color: #bbb;
DCloud_JSON's avatar
1.0.11  
DCloud_JSON 已提交
927
		line-height: 18px;
DCloud_JSON's avatar
DCloud_JSON 已提交
928 929 930 931 932 933 934 935 936 937 938 939 940 941
	}

	.trash,
	.send {
		width: 50px;
		height: 30px;
		justify-content: center;
		align-items: center;
		flex-shrink: 0;
	}

	.trash {
		width: 30rpx;
		margin-left: 10rpx;
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
942 943 944 945 946 947 948 949 950 951 952
	}

	.menu {
		justify-content: center;
		align-items: center;
		flex-shrink: 0;
	}

	.menu-item {
		width: 30rpx;
		margin: 0 10rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
	}

	.send {
		color: #FFF;
		border-radius: 4px;
		display: flex;
		margin: 0;
		padding: 0;
		font-size: 14px;
		margin-right: 20rpx;
	}

	/* #ifndef APP-NVUE */
	.send::after {
		display: none;
	}
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
969

DCloud_JSON's avatar
DCloud_JSON 已提交
970 971 972 973
	/* #endif */


	.msg-list {
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
974
		height: 0; //不可省略,先设置为0 再由flex: 1;撑开才是一个滚动容器
DCloud_JSON's avatar
DCloud_JSON 已提交
975 976
		flex: 1;
		width: 750rpx;
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
977
		// border: 1px solid red;
DCloud_JSON's avatar
DCloud_JSON 已提交
978
	}
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
979

DCloud_JSON's avatar
DCloud_JSON 已提交
980 981 982 983 984 985 986
	.noData {
		margin-top: 15px;
		text-align: center;
		width: 750rpx;
		color: #aaa;
		font-size: 12px;
		justify-content: center;
DCloud_JSON's avatar
1.2.2  
DCloud_JSON 已提交
987 988 989 990 991
	}
	
	.open-ad-btn-box{
		justify-content: center;
		margin: 10px 0;
DCloud_JSON's avatar
DCloud_JSON 已提交
992
	}
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
993

DCloud_JSON's avatar
DCloud_JSON 已提交
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
	.tip-ai-ing {
		align-items: center;
		flex-direction: column;
		font-size: 14px;
		color: #919396;
		padding: 15px 0;
	}

	.uni-link {
		margin-left: 5px;
		line-height: 20px;
	}

	/* #ifdef H5 */
	@media screen and (min-width:650px) {
		.foot-box {
			border-top: solid 1px #dde0e2;
		}

DCloud_JSON's avatar
1.1.1  
DCloud_JSON 已提交
1013
		.container,.container * {
DCloud_JSON's avatar
DCloud_JSON 已提交
1014 1015 1016
			max-width: 950px;
		}

DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
1017
		.container {
DCloud_JSON's avatar
1.1.1  
DCloud_JSON 已提交
1018 1019 1020
			box-shadow: 0 0 5px #e0e1e7;
			height: calc(100vh - 44px);
			margin: 22px auto;
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1021
			border-radius: 10px;
DCloud_JSON's avatar
1.1.1  
DCloud_JSON 已提交
1022 1023 1024 1025 1026 1027
			overflow: hidden;
			background-color: #FAFAFA;
		}
		
		page {
			background-color: #efefef;
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1028
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1029

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1030 1031 1032 1033 1034 1035 1036 1037
		.container .header {
			height: 44px;
			line-height: 44px;
			border-bottom: 1px solid #F0F0F0;
			width: 100vw;
			justify-content: center;
			font-weight: 500;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1038

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1039 1040 1041 1042 1043
		.content {
			background-color: #f9f9f9;
			position: relative;
			max-width: 90%;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1044

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
		// .copy {
		// 	color: #888888;
		// 	position: absolute;
		// 	right: 8px;
		// 	top: 8px;
		// 	font-size: 12px;
		// 	cursor:pointer;
		// }
		// .copy :hover{
		// 	color: #4b9e5f;
		// }

		.foot-box,
		.foot-box-content,
		.msg-list,
		.msg-item,
		// .create_time,
		.noData,
		.textarea-box,
		.textarea,
		textarea-box {
			width: 100% !important;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1068

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1069 1070 1071 1072 1073 1074
		.textarea-box,
		.textarea,
		textarea,
		textarea-box {
			height: 120px;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1075

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1076 1077 1078 1079
		.foot-box,
		.textarea-box {
			background-color: #FFF;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1080

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1081 1082 1083 1084 1085 1086
		.foot-box-content {
			flex-direction: column;
			justify-content: center;
			align-items: flex-end;
			padding-bottom: 0;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1087

DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
1088
		.pc-menu {
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1089 1090
			padding: 0 10px;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1091

DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
1092
		.pc-menu-item {
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1093 1094 1095 1096 1097 1098 1099 1100
			height: 20px;
			justify-content: center;
			align-items: center;
			align-content: center;
			display: flex;
			margin-right: 10px;
			cursor: pointer;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1101

DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
1102
		.pc-trash {
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1103 1104
			opacity: 0.8;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1105

DCloud_JSON's avatar
1.0.21  
DCloud_JSON 已提交
1106
		.pc-trash image {
DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1107 1108
			height: 15px;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1109 1110


DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1111 1112 1113 1114
		.textarea-box,
		.textarea-box * {
			// border: 1px solid #000;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1115

DCloud_JSON's avatar
1.0.16  
DCloud_JSON 已提交
1116 1117 1118 1119 1120 1121
		.send-btn-box .send-btn-tip {
			color: #919396;
			margin-right: 8px;
			font-size: 12px;
			line-height: 28px;
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
1122
	}
DCloud_JSON's avatar
1.1.0  
DCloud_JSON 已提交
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
	/* #endif */
	.retries-box{
		justify-content: center;
		align-items: center;
		font-size: 12px;
		color: #d2071b;
	}
	.retries-icon{
		margin-top: 1px;
		margin-left: 5px;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
1134
</style>