20260325稳定版
This commit is contained in:
+61
-19
@@ -3,6 +3,7 @@
|
||||
<HeaderItem title="AI律师咨询"/>
|
||||
<view style="line-height: 35rpx"
|
||||
class="flex flex-col justify-start items-start text-25 p-30">
|
||||
<view class="text-25 text-gray text-center my-15 w-100p">该内容由人工智能生成</view>
|
||||
<view v-for="(item, index) in list" :key="index" class="mb-25 w-100p">
|
||||
<view v-if="!item.isMine" class="flex justify-start items-start">
|
||||
<u-icon name="/static/robot.png" size="60rpx"/>
|
||||
@@ -46,6 +47,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<Login ref="Login" @done="onLoginDone"/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -57,17 +59,20 @@ import {sendChatReq, stopChatReq} from "@/api/lawOrg";
|
||||
import {getUserInfo} from "@/util/user";
|
||||
import {MAIN} from "@/config/color";
|
||||
import {dictDataReq} from "@/api/common";
|
||||
import Login from "@/components/Login.vue";
|
||||
|
||||
export default {
|
||||
name: "index",
|
||||
components: {HeaderItem, CustomTabbar},
|
||||
components: {Login, HeaderItem, CustomTabbar},
|
||||
data() {
|
||||
return {
|
||||
list: [],
|
||||
questionList: [],
|
||||
content: '',
|
||||
taskId: null,
|
||||
answering: false
|
||||
answering: false,
|
||||
socket: null,
|
||||
timer: null,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -118,39 +123,76 @@ export default {
|
||||
}, 100)
|
||||
},
|
||||
async stopAI() {
|
||||
console.log('stoping')
|
||||
await stopChatReq({
|
||||
taskId: this.taskId
|
||||
})
|
||||
this.answering = false
|
||||
uni.closeSocket()
|
||||
this.list[this.list.length - 1].done = true
|
||||
},
|
||||
onLoginDone(){
|
||||
uni.hideLoading()
|
||||
this.list.push({
|
||||
content: '您好!我是法律机器人,请问您想咨询什么问题呢?',
|
||||
isMine: false,
|
||||
loading: false,
|
||||
done: true,
|
||||
})
|
||||
const _this = this
|
||||
this.socket = uni.connectSocket({
|
||||
url: `${WS_API}/${getUserInfo().uid}`,
|
||||
success: () => {
|
||||
_this.ping()
|
||||
},
|
||||
})
|
||||
uni.onSocketMessage(res => {
|
||||
if (res.data === '连接成功') return
|
||||
const aiData = JSON.parse(res.data)
|
||||
this.list[this.list.length - 1].loading = false
|
||||
if (aiData.answer !== '__END__') this.list[this.list.length - 1].content += aiData.answer
|
||||
this.taskId = aiData.taskId
|
||||
this.scrollToBottom()
|
||||
})
|
||||
},
|
||||
ping() {
|
||||
this.timer = setInterval(() => {
|
||||
if (this.socket) {
|
||||
this.socket.send({
|
||||
data: 'ping'
|
||||
})
|
||||
}
|
||||
}, 10000)
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.list.push({
|
||||
content: '您好!我是法律机器人,请问您想咨询什么问题呢?',
|
||||
isMine: false,
|
||||
loading: false,
|
||||
done: true,
|
||||
})
|
||||
uni.connectSocket({
|
||||
url: `${WS_API}/${getUserInfo().uid}`
|
||||
})
|
||||
uni.onSocketMessage(res => {
|
||||
if (res.data === '连接成功') return
|
||||
const aiData = JSON.parse(res.data)
|
||||
this.list[this.list.length - 1].loading = false
|
||||
if (aiData.answer !== '__END__') this.list[this.list.length - 1].content += aiData.answer
|
||||
this.taskId = aiData.taskId
|
||||
this.scrollToBottom()
|
||||
uni.showLoading({
|
||||
title: '加载中...',
|
||||
})
|
||||
this.$refs.Login.doLogin()
|
||||
this.getQuestionsList()
|
||||
},
|
||||
onUnload() {
|
||||
if (this.timer) clearInterval(this.timer)
|
||||
uni.closeSocket()
|
||||
this.stopAI()
|
||||
},
|
||||
onHide() {
|
||||
if (this.timer) clearInterval(this.timer)
|
||||
uni.closeSocket()
|
||||
this.stopAI()
|
||||
},
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: "贵港公共法律服务",
|
||||
path: `/pages/ai/index`
|
||||
}
|
||||
},
|
||||
onShareTimeline() {
|
||||
return {
|
||||
title: "贵港公共法律服务",
|
||||
path: `/pages/ai/index`
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user