|
@@ -147,7 +147,6 @@
|
|
|
<div class=" text-gray-400">{{ item.sceneDescription }}</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
-
|
|
|
</div>
|
|
|
<el-empty v-else description="暂无场景"></el-empty>
|
|
|
<div class="flex justify-center mt-10">
|
|
@@ -260,7 +259,7 @@
|
|
|
/>
|
|
|
</div>
|
|
|
<div class="messageRight">
|
|
|
- <div class="message mt-4 ml-4 p-4 rounded-r-md rounded-bl-md text-xs relative" >
|
|
|
+ <div v-show="!item.edit" :ref="`message${index}`" class="message mt-4 ml-4 p-4 rounded-r-md rounded-bl-md text-xs relative" >
|
|
|
<div v-if="item.voiceFilePosition" class="yyPlayBg mb-2 w-16 p-1 cursor-pointer" >
|
|
|
<img v-if="audioPlayIndex == index" class="yyPlay" src="@/assets/images/播放/yyPlay1.png" alt="" >
|
|
|
<img v-else class="yyPlay" src="@/assets/images/播放/yyPlay.png" alt="" @click="playAudio(item.voiceFilePosition, index)">
|
|
@@ -275,7 +274,7 @@
|
|
|
{{ item.chatGuidance }}
|
|
|
</div>
|
|
|
</div>
|
|
|
- <el-dropdown v-if="index != 0" class="messageDropdown" @command="handleCommand" placement="top-end">
|
|
|
+ <el-dropdown v-if="index != 0" class="messageDropdown" @command="handleCommand4($event, item, index)" placement="top-end">
|
|
|
<el-button class="messageButton" icon="el-icon-more" circle></el-button>
|
|
|
<el-dropdown-menu slot="dropdown">
|
|
|
<el-dropdown-item command="1">编辑</el-dropdown-item>
|
|
@@ -284,6 +283,19 @@
|
|
|
</el-dropdown-menu>
|
|
|
</el-dropdown>
|
|
|
</div>
|
|
|
+ <div :ref="`messageEdit${index}`" v-show="item.edit" class="message messageEdit mt-4 ml-4 p-4 rounded-r-md rounded-bl-md text-xs relative" >
|
|
|
+ <el-input
|
|
|
+ class="eidtTextarea"
|
|
|
+ :ref="`messageEditInput${index}`"
|
|
|
+ type="textarea"
|
|
|
+ resize="none"
|
|
|
+ v-model="item.editContent">
|
|
|
+ </el-input>
|
|
|
+ <div class="flex justify-end mt-2">
|
|
|
+ <el-button @click="editCancel(item, index)">取消</el-button>
|
|
|
+ <el-button @click="editSave(item, index)">保存</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<!-- 用户发送的信息 -->
|
|
@@ -295,8 +307,28 @@
|
|
|
/>
|
|
|
</div>
|
|
|
<div class="messageRight">
|
|
|
- <div class="messageUser mr-4 mt-4 p-2 rounded-l-md rounded-br-md text-xs">
|
|
|
+ <div :ref="`message${index}`" v-show="!item.edit" class="messageUser mr-4 mt-4 p-4 rounded-l-md rounded-br-md text-xs relative">
|
|
|
{{ item.content }}
|
|
|
+ <el-dropdown v-if="index != 0" class="messageDropdown" @command="handleCommand4($event, item, index)" placement="top-end">
|
|
|
+ <el-button class="messageButton" icon="el-icon-more" circle></el-button>
|
|
|
+ <el-dropdown-menu slot="dropdown">
|
|
|
+ <el-dropdown-item command="1">编辑</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="2">删除</el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </el-dropdown>
|
|
|
+ </div>
|
|
|
+ <div :ref="`messageEdit${index}`" v-show="item.edit" class="messageUser messageEdit mt-4 ml-4 p-4 rounded-r-md rounded-bl-md text-xs relative" >
|
|
|
+ <el-input
|
|
|
+ class="eidtTextarea"
|
|
|
+ :ref="`messageEditInput${index}`"
|
|
|
+ type="textarea"
|
|
|
+ resize="none"
|
|
|
+ v-model="item.editContent">
|
|
|
+ </el-input>
|
|
|
+ <div class="flex justify-end mt-2">
|
|
|
+ <el-button @click="editCancel(item, index)">取消</el-button>
|
|
|
+ <el-button @click="editSave(item, index)">保存</el-button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -320,7 +352,7 @@
|
|
|
<!-- <i class="el-icon-picture-outline text-2xl cursor-pointer"></i> -->
|
|
|
<!-- <i class="el-icon-s-opportunity text-2xl cursor-pointer"></i> -->
|
|
|
</div>
|
|
|
- <el-button type="text" :loading="chatLoading" @click.prevent="getStreamChatWithWeb" class="px-4 rounded-r-lg text-sm text-gray-400" :class="content && 'planeColor'">
|
|
|
+ <el-button type="text" :disabled="!content" :loading="chatLoading" @click.prevent="getStreamChatWithWeb" class="px-4 rounded-r-lg text-sm text-gray-400" :class="content && 'planeColor'">
|
|
|
<v-icon v-show="!chatLoading" name="paper-plane" scale="1.5"/>
|
|
|
</el-button>
|
|
|
</div>
|
|
@@ -387,7 +419,9 @@ import {
|
|
|
getChatRecordApi,
|
|
|
updateTitleApi,
|
|
|
clearRecordApi,
|
|
|
- getVoiceFileApi
|
|
|
+ getVoiceFileApi,
|
|
|
+ updateRecordApi,
|
|
|
+ deleteRecordApi
|
|
|
} from "@/api/chat.js"
|
|
|
import { detailApi } from "@/api/detail.js"
|
|
|
import { Message, MessageBox, Notification, Loading } from 'element-ui'
|
|
@@ -628,10 +662,86 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
+ // 聊天记录操作相关↓
|
|
|
+ handleCommand4(value1, value2, value3) {
|
|
|
+ console.log(value1, 'value1');
|
|
|
+ console.log(value2, 'value2');
|
|
|
+ if (value1 == 1) {
|
|
|
+ // 编辑
|
|
|
+ let height = this.$refs[`message${value3}`][0].offsetHeight
|
|
|
+ let width = this.$refs[`message${value3}`][0].offsetWidth
|
|
|
+
|
|
|
+ value2.edit = true
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs[`messageEditInput${value3}`][0].$el.children[0].style.height = height + 'px'
|
|
|
+ this.$refs[`messageEdit${value3}`][0].style.width = width + 'px'
|
|
|
+ })
|
|
|
+ } else if (value1 == 2) {
|
|
|
+ // 删除
|
|
|
+ this.$confirm('此操作将永久删除该聊天记录, 是否继续?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ this.deleteRecord(value2, value3)
|
|
|
+ })
|
|
|
+ } else if (value1 == 3) {
|
|
|
+ // 重新生成最后一句对话
|
|
|
+ this.resetChat(value2, value3)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 重新生成最后一条聊天记录
|
|
|
+ resetChat(value, index) {
|
|
|
+ let params = {
|
|
|
+ recordId: value.id,
|
|
|
+ role: value.role,
|
|
|
+ }
|
|
|
+ deleteRecordApi(params).then(res => {
|
|
|
+ this.returnMessage.splice(index, 1)
|
|
|
+ this.getStreamChatWithWeb()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 编辑单条聊天记录-取消
|
|
|
+ editCancel(value, index) {
|
|
|
+ value.edit = false
|
|
|
+ value.editContent = value.content
|
|
|
+ },
|
|
|
+ // 编辑单条聊天记录-保存
|
|
|
+ editSave(value, index) {
|
|
|
+ console.log(value, 'value');
|
|
|
+ let params = {
|
|
|
+ content: value.editContent,
|
|
|
+ recordId: value.id,
|
|
|
+ role: value.role,
|
|
|
+ }
|
|
|
+ updateRecordApi(params).then(res => {
|
|
|
+ console.log(res, 'ressss');
|
|
|
+ value.edit = false
|
|
|
+ this.getChatRecord(this.recordId)
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ // 删除单条聊天记录
|
|
|
+ deleteRecord(value, index) {
|
|
|
+ let params = {
|
|
|
+ recordId: value.id,
|
|
|
+ role: value.role,
|
|
|
+ }
|
|
|
+ deleteRecordApi(params).then(res => {
|
|
|
+ this.$message({
|
|
|
+ message: '删除成功',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+ this.getChatRecord(this.recordId)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
// 聊天记录新增对话
|
|
|
async newStart_juese(value) {
|
|
|
console.log(value, 'value');
|
|
|
this.audioUrl = ""
|
|
|
+ this.sceneId = null
|
|
|
+ this.sceneInfo = {}
|
|
|
this.messageOptions = []
|
|
|
this.returnMessage = []
|
|
|
// 点击聊天记录切换聊天
|
|
@@ -697,17 +807,28 @@ export default {
|
|
|
let array = res.data
|
|
|
// this.returnMessage
|
|
|
this.historyRes = res.data
|
|
|
+ if (this.returnMessage.length > 1) {
|
|
|
+ this.returnMessage = this.returnMessage.splice(0, 1)
|
|
|
+ }
|
|
|
for (let i = 0; i < array.length; i++) {
|
|
|
const element = array[i];
|
|
|
let history = JSON.parse(element.history)
|
|
|
history.map(item => {
|
|
|
+ item.id = element.id
|
|
|
+ item.edit = false
|
|
|
+ item.editContent = item.content
|
|
|
if (item.role == 'assistant') {
|
|
|
item.voiceFilePosition = element.voiceFilePosition
|
|
|
}
|
|
|
})
|
|
|
this.returnMessage = [...this.returnMessage, ...history]
|
|
|
}
|
|
|
- this.configForm.radio2 = res.data[res.data.length - 1].modelId
|
|
|
+ this.configForm.radio2 = this.modelList[0].id
|
|
|
+ this.modelList.map(item => {
|
|
|
+ if (item.id == array[array.length - 1].modelId) {
|
|
|
+ this.configForm.radio2 = item.id
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
searchHistory(characterId) {
|
|
@@ -815,10 +936,13 @@ export default {
|
|
|
// localStorage.setItem(`[userId:${123},aiId:${this.info.id}]`, JSON.stringify(this.returnMessage));
|
|
|
// }
|
|
|
if (this.sceneId) {
|
|
|
+ console.log(this.sceneId);
|
|
|
let sceneList = this.info.sceneList
|
|
|
for (let i = 0; i < sceneList.length; i++) {
|
|
|
const element = sceneList[i];
|
|
|
if (element.sceneId == this.sceneId) {
|
|
|
+ this.sceneInfo = element
|
|
|
+ this.configForm.radio2 = element.modelId
|
|
|
this.returnMessage.push({
|
|
|
role: 'assistant',
|
|
|
content: element.sceneWelcome
|
|
@@ -878,6 +1002,9 @@ export default {
|
|
|
if (this.chatLoading) {
|
|
|
return
|
|
|
}
|
|
|
+ if (!this.content) {
|
|
|
+ return
|
|
|
+ }
|
|
|
this.getStreamChatWithWeb()
|
|
|
}
|
|
|
},
|
|
@@ -953,9 +1080,7 @@ export default {
|
|
|
}, 50)
|
|
|
},
|
|
|
async getStreamChatWithWeb() {
|
|
|
- if (!this.content) {
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
this.textCache = ''
|
|
|
this.resError = false
|
|
|
this.messageLoading = true
|
|
@@ -972,13 +1097,16 @@ export default {
|
|
|
if (!this.recordId) {
|
|
|
this.recordId = await this.addChat()
|
|
|
}
|
|
|
- this.returnMessage.push({
|
|
|
- role: 'user',
|
|
|
- content: this.content
|
|
|
- })
|
|
|
+ if (this.content) {
|
|
|
+ this.returnMessage.push({
|
|
|
+ role: 'user',
|
|
|
+ content: this.content
|
|
|
+ })
|
|
|
+ }
|
|
|
let HistoryMessage = JSON.parse(JSON.stringify(this.returnMessage))
|
|
|
- HistoryMessage = HistoryMessage.slice(0, -1)
|
|
|
- console.log(HistoryMessage, 'HistoryMessage');
|
|
|
+ console.log(HistoryMessage, 'HistoryMessage1');
|
|
|
+ HistoryMessage = HistoryMessage.splice(1, HistoryMessage.length)
|
|
|
+ console.log(HistoryMessage, 'HistoryMessage2');
|
|
|
// 历史记录取最新的20条传给后端
|
|
|
if (HistoryMessage && HistoryMessage.length > 20) {
|
|
|
HistoryMessage = HistoryMessage.slice(HistoryMessage.length - 1, 20)
|
|
@@ -1037,7 +1165,7 @@ export default {
|
|
|
// 如果开启自动播放,则查询并播放语音
|
|
|
this.audioUrl = ""
|
|
|
if (!this.resError) {
|
|
|
- let index = this.historyRes.length * 2
|
|
|
+ let index = this.returnMessage.length - 1
|
|
|
this.initAudio(index)
|
|
|
}
|
|
|
console.log('结束');
|
|
@@ -1062,23 +1190,32 @@ export default {
|
|
|
// console.log(value, 'value');
|
|
|
for (let i = 0; i < value.length; i++) {
|
|
|
const element = value[i];
|
|
|
+
|
|
|
if (this.isJSON(element)) {
|
|
|
- if(JSON.parse(element).code == 401) {
|
|
|
+ let value = JSON.parse(element)
|
|
|
+ if(value.code == 401) {
|
|
|
this.returnMessage.splice(this.returnMessage.length - 1, 1)
|
|
|
this.noLogin(element)
|
|
|
this.chatLoading = false
|
|
|
break;
|
|
|
}
|
|
|
- if(JSON.parse(element).code == 500) {
|
|
|
- console.log(JSON.parse(element), 'JSON.parse(element)');
|
|
|
+ if(value.code == 500) {
|
|
|
+ console.log(value, 'JSON.parse(element)');
|
|
|
this.returnMessage.splice(this.returnMessage.length - 2, 2)
|
|
|
- this.$message.error(JSON.parse(element).content || '系统错误请联系管理员')
|
|
|
+ this.$message.error(value.content || '系统错误请联系管理员')
|
|
|
this.resError = true
|
|
|
this.chatLoading = false
|
|
|
break;
|
|
|
}
|
|
|
- let txt = JSON.parse(element).content
|
|
|
- this.returnMessage[this.returnMessage.length - 1].content += txt
|
|
|
+ if (!value.done) {
|
|
|
+ let txt = value.content
|
|
|
+ this.returnMessage[this.returnMessage.length - 1].content += txt
|
|
|
+ } else {
|
|
|
+ // 对话流结束
|
|
|
+ // 临时插入的ai对话记录和用户记录插入聊天id
|
|
|
+ this.returnMessage[this.returnMessage.length - 1].id = value.content
|
|
|
+ this.returnMessage[this.returnMessage.length - 2].id = value.content
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -1123,8 +1260,15 @@ export default {
|
|
|
// 播放聊天语音
|
|
|
initAudio(index) {
|
|
|
// 从聊天记录获取id
|
|
|
- let history = this.historyRes[ index / 2 - 1]
|
|
|
+ console.log(this.returnMessage[index], 'swssssssss');
|
|
|
+ let id = this.returnMessage[index].id
|
|
|
+ let history = this.historyRes.map((item) => {
|
|
|
+ if (item.id == id) {
|
|
|
+ return item
|
|
|
+ }
|
|
|
+ })
|
|
|
console.log(history, 'history');
|
|
|
+ return
|
|
|
|
|
|
this.loopGetVoice(history.id, index)
|
|
|
},
|
|
@@ -1291,9 +1435,10 @@ export default {
|
|
|
position: absolute;
|
|
|
right: 0;
|
|
|
background-repeat: no-repeat;
|
|
|
- background-attachment: fixed;
|
|
|
+ // background-attachment: fixed;
|
|
|
background-size: cover;
|
|
|
background-color: #fff;
|
|
|
+ background-position: center center;
|
|
|
display: flex;
|
|
|
height: 100%;
|
|
|
justify-content: center;
|
|
@@ -1461,7 +1606,8 @@ export default {
|
|
|
-webkit-box-shadow: -1px 0 0 0 var(--bg-color1);
|
|
|
box-shadow: -1px 0 0 0 var(--bg-color1);
|
|
|
}
|
|
|
- .message:hover >>> .messageButton {
|
|
|
+ .message:hover >>> .messageButton,
|
|
|
+ .messageUser:hover >>> .messageButton {
|
|
|
display: block;
|
|
|
}
|
|
|
.messageButton {
|
|
@@ -1476,4 +1622,17 @@ export default {
|
|
|
bottom: -12px;
|
|
|
right: 10px;
|
|
|
}
|
|
|
+
|
|
|
+ .eidtTextarea >>> .el-textarea__inner {
|
|
|
+ padding: 0;
|
|
|
+ background: none;
|
|
|
+ border: 0;
|
|
|
+ color: #fff;
|
|
|
+ }
|
|
|
+ .messageUser >>> .el-textarea__inner {
|
|
|
+ color: #000;
|
|
|
+ }
|
|
|
+ .messageEdit {
|
|
|
+ min-width: 400px;
|
|
|
+ }
|
|
|
</style>
|