|
@@ -1,10 +1,12 @@
|
|
|
<template>
|
|
|
- <view id='app'>
|
|
|
+ <view id='app' style="bottom: {{KeyBoardHeight}}px;">
|
|
|
<view class="placeholder"></view>
|
|
|
- <view class="head">
|
|
|
- <text>睿宝AI</text>
|
|
|
+ <view class="head" :style="{backgroundColor:styleData.color}">
|
|
|
+ <text :style="{color:styleData.fontColor}">睿宝AI</text>
|
|
|
+ <switch @change="styleChange(styleData)" />
|
|
|
</view>
|
|
|
- <view class="pageView">
|
|
|
+
|
|
|
+ <view class="pageView" :style="{backgroundColor:styleData.color}">
|
|
|
<view class="sidebar-left"></view>
|
|
|
<view class="body">
|
|
|
<view class="list-wrap">
|
|
@@ -15,7 +17,7 @@
|
|
|
<!-- user方-聊天内容 -->
|
|
|
<view class="item self" v-if="item.userContent != ''">
|
|
|
<image class="avtar" src="../../static/user-avatar.png" mode="aspectFit"></image>
|
|
|
- <view class="content right" disabled>{{ item.userContent }}</view>
|
|
|
+ <view class="content right" disabled :style="{backgroundColor:styleData.contentColor,color:styleData.fontColor}">{{ item.userContent }}</view>
|
|
|
</view>
|
|
|
<!-- ai方-聊天内容 -->
|
|
|
<view class="item other">
|
|
@@ -23,7 +25,7 @@
|
|
|
<view class="loadingPoint" v-if='msgList.isloading[index]'>
|
|
|
<loadingPointsVue></loadingPointsVue>
|
|
|
</view>
|
|
|
- <view class="content left" v-if='!msgList.isloading[index]'>
|
|
|
+ <view class="content left" v-if='!msgList.isloading[index]' :style="{backgroundColor:styleData.contentColor,color:styleData.fontColor}">
|
|
|
{{ msgList.otherChatList[index] }}
|
|
|
</view>
|
|
|
</view>
|
|
@@ -35,18 +37,23 @@
|
|
|
</view>
|
|
|
|
|
|
<view class="chat-bottom">
|
|
|
+ <view class="uni-label">
|
|
|
+ <label v-for="(item,index) in labelList" :key="index" @click="shortcuts(msgList,item)" :style="{backgroundColor:styleData.labelColor,color:styleData.fontColor}">{{item}}</label>
|
|
|
+ </view>
|
|
|
<view class="send-msg">
|
|
|
<view class="uni-textarea">
|
|
|
+ <!-- bindkeyboardheightchange='getKeyBoardHeight' - 添加键盘弹起触发属性 -->
|
|
|
<textarea id="input-textarea" type="text" v-model="msgList.chatMsg" placeholder="快来聊天吧"
|
|
|
- confirm-type="send" @confirm="handleSend" maxlength="300" />
|
|
|
+ confirm-type="send" @confirm="handleSend(msgList)" maxlength="300" />
|
|
|
</view>
|
|
|
<view class="uni-button">
|
|
|
- <button class="send-btn" @click="handleSend" type="primary">发送</button>
|
|
|
+ <button class="send-btn" @click="handleSend(msgList)" type="primary" :disabled="msgList.isClick" :style="{backgroundColor:styleData.btnColor}">发送</button>
|
|
|
</view>
|
|
|
</view>
|
|
|
- </view>
|
|
|
+ </view>s
|
|
|
</view>
|
|
|
<view class="sidebar-right">
|
|
|
+
|
|
|
<image src="../../static/logo.png" mode="aspectFit"></image>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -57,6 +64,7 @@
|
|
|
import {
|
|
|
nextTick,
|
|
|
reactive,
|
|
|
+ ref,
|
|
|
watch
|
|
|
} from 'vue';
|
|
|
|
|
@@ -66,6 +74,7 @@
|
|
|
|
|
|
import axios from 'axios';
|
|
|
import loadingPointsVue from '../../components/loadingPoints.vue';
|
|
|
+ import {styleChange,handleSend,scrollToBottom,shortcuts} from "../../until/fun.js"
|
|
|
|
|
|
const msgList = reactive({
|
|
|
// 输入框
|
|
@@ -81,98 +90,40 @@
|
|
|
otherChatList: [],
|
|
|
len: 0,
|
|
|
isloading: [],
|
|
|
- isClick: false
|
|
|
+ isClick: false,
|
|
|
+ // 键盘弹起高度
|
|
|
+ KeyBoardHeight:0
|
|
|
})
|
|
|
-
|
|
|
- // 发送消息
|
|
|
- const handleSend = async () => {
|
|
|
- msgList.isClick = !msgList.isClick
|
|
|
- const data = {
|
|
|
- AppId: '0c8ff06b-91d9-43f7-b61e-ca5da1db15d4',
|
|
|
- AId: 'TK1234',
|
|
|
- content: ''
|
|
|
- }
|
|
|
- if (msgList.chatMsg != '') {
|
|
|
- msgList.isloading[msgList.len] = true
|
|
|
- msgList.len++
|
|
|
- let obj = {
|
|
|
- otherContent: '',
|
|
|
- userContent: '',
|
|
|
- image: ""
|
|
|
- }
|
|
|
- data.content = msgList.chatMsg
|
|
|
- obj.userContent = msgList.chatMsg
|
|
|
- msgList.chatList.push(obj)
|
|
|
-
|
|
|
- obj.otherContent = await GetNewsList(data)
|
|
|
-
|
|
|
- // await sleep(16000);
|
|
|
- getChatContent(obj.otherContent, msgList.len)
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- msgList.otherContent = ''
|
|
|
- }
|
|
|
-
|
|
|
- // 滚动条回到最底部
|
|
|
- const scrollToBottom = (() => {
|
|
|
- nextTick(() => {
|
|
|
- const query = uni.createSelectorQuery();
|
|
|
- query.select("#content-box").boundingClientRect()
|
|
|
- query.select("#content-overflow").boundingClientRect()
|
|
|
- query.exec(res => {
|
|
|
- const scrollViewHeight = res[0].height
|
|
|
- const scrollContentHeight = res[1].height
|
|
|
- if (scrollViewHeight < scrollContentHeight) {
|
|
|
- const scrollTop = scrollContentHeight - scrollViewHeight
|
|
|
- msgList.scrollTop = scrollTop
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+
|
|
|
+ const styleData = reactive({
|
|
|
+ value:false,
|
|
|
+ color:'#f5f5f5',
|
|
|
+ fontColor:"black",
|
|
|
+ btnColor:"rgb(30,144,255)",
|
|
|
+ contentColor:"#fff",
|
|
|
+ labelColor:"#fff"
|
|
|
+
|
|
|
})
|
|
|
+
|
|
|
+ const labelList = ref([
|
|
|
+ "我要加油",
|
|
|
+ "92号",
|
|
|
+ "95号",
|
|
|
+ "98号",
|
|
|
+ "加油卡",
|
|
|
+ "易捷加油"
|
|
|
+ ])
|
|
|
|
|
|
//滚动至聊天底部
|
|
|
watch([msgList.otherChatList, msgList.chatList], (newVal) => {
|
|
|
- scrollToBottom()
|
|
|
+ scrollToBottom(msgList)
|
|
|
})
|
|
|
+
|
|
|
|
|
|
- // 调用数据接口
|
|
|
- const GetNewsList = async (data) => {
|
|
|
- msgList.chatMsg = ''
|
|
|
- var res = await getDataList(data)
|
|
|
- console.log(res)
|
|
|
- return res
|
|
|
- }
|
|
|
-
|
|
|
- // ------- 聊天逐字输出 -----------
|
|
|
- // 延时函数
|
|
|
- const sleep = ((delaytime = 10000) => {
|
|
|
- return new Promise(resolve => setTimeout(resolve, delaytime));
|
|
|
- })
|
|
|
-
|
|
|
- // 逐字显示内容
|
|
|
- const getChatContent = ((text, index) => {
|
|
|
- console.log(index)
|
|
|
- msgList.timer = setInterval(() => {
|
|
|
- msgList.textCount++;
|
|
|
- if (msgList.textCount == text.length + 1) {
|
|
|
- msgList.otherChatList[index - 1] = text;
|
|
|
- clearInterval(msgList.timer);
|
|
|
- } else {
|
|
|
- // 取字符串子串
|
|
|
- let nowStr = text.substring(0, msgList.textCount);
|
|
|
- msgList.otherChatList[index - 1] = nowStr;
|
|
|
- }
|
|
|
-
|
|
|
- }, 50);
|
|
|
- console.log(msgList.timer)
|
|
|
- msgList.textCount = 0
|
|
|
- msgList.isloading[index - 1] = false
|
|
|
- msgList.isClick = !msgList.isClick
|
|
|
- })
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style>
|
|
|
@import url("../../theme/chat32.css");
|
|
|
+ @import url("../../theme/public.css");
|
|
|
</style>
|