Commit 4cf3299f by 李伟康

修复BUG

1 parent 6e7f81dd
......@@ -15,6 +15,7 @@
"autoprefixer": "^8.0.0",
"core-js": "^3.6.4",
"dayjs": "^1.10.5",
"emoji-regex": "^10.2.1",
"glsx-common": "^2.1.0",
"lib-flexible": "^0.3.2",
"postcss-loader": "^6.2.0",
......
.sprite-icon { background-image: url(../images/sprite.png);background-size: 133px 94px;}
.icon-close { width: 20px; height: 20px; background-position: -84px -30px;}
.icon-ai { width: 20px; height: 20px; background-position: -84px -30px;}
.icon-close { width: 20px; height: 20px; background-position: 0px -74px;}
.icon-down { width: 12px; height: 12px; background-position: -115px -54px;}
.icon-eye { width: 13px; height: 8px; background-position: -115px -76px;}
.icon-gift-del { width: 18px; height: 18px; background-position: -115px 0px;}
......@@ -7,9 +8,8 @@
.icon-link { width: 32px; height: 32px; background-position: -42px 0px;}
.icon-menu-active { width: 22px; height: 20px; background-position: 0px -44px;}
.icon-menu { width: 22px; height: 20px; background-position: -32px -44px;}
.icon-more { width: 20px; height: 20px; background-position: 0px -74px;}
.icon-more { width: 20px; height: 20px; background-position: -30px -74px;}
.icon-pdf { width: 32px; height: 34px; background-position: 0px 0px;}
.icon-profile { width: 20px; height: 20px; background-position: -30px -74px;}
.icon-profile { width: 20px; height: 20px; background-position: -60px -74px;}
.icon-PYQ { width: 21px; height: 20px; background-position: -84px 0px;}
.icon-send { width: 10px; height: 10px; background-position: -64px -44px;}
.icon-ai { width: 20px; height: 20px; background-position: -60px -74px;}
\ No newline at end of file
.icon-send { width: 10px; height: 10px; background-position: -64px -44px;}
\ No newline at end of file

15.9 KB | W: | H:

16 KB | W: | H:

src/assets/images/sprite.png
src/assets/images/sprite.png
src/assets/images/sprite.png
src/assets/images/sprite.png
  • 2-up
  • Swipe
  • Onion skin
<template>
<div class="chat-gpt-box">
<div
class="chat-gpt-box"
v-show="show"
>
<div
:class="['view',{'show-tips':showTips&& issuesList.length}]"
ref="contentView"
......@@ -60,7 +63,7 @@
</div>
</div>
</template>
<div class="input-box flex isFullSucreen">
<div :class="['input-box flex isFullSucreen']">
<van-field
v-model="issue"
:border="false"
......@@ -68,6 +71,7 @@
enterKeyhint="send"
@keydown="onkeydown"
ref="input"
maxlength="1000"
></van-field>
<van-button @click="send()">发送</van-button>
</div>
......@@ -77,8 +81,12 @@
<script type='text/ecmascript-6'>
import { chatgptApi } from '@/api'
import * as dayjs from 'dayjs'
import emojiRegex from 'emoji-regex'
export default {
name: 'ChatGpt',
props: {
show: Boolean
},
data () {
return {
contentList: [],
......@@ -87,7 +95,9 @@ export default {
issue: '',
scriptLibraryAIId: '',
todayQuestionLeft: 0,
questionCountTotal: 20
questionCountTotal: 20,
lastQuestionTime: '',
padding: false
}
},
watch: {
......@@ -100,9 +110,8 @@ export default {
},
methods: {
filterText (text) {
const emojiRegex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
whitespaceRegex = /^\s+$/g
return text.replace(emojiRegex, '').replace(whitespaceRegex, '')
const whitespaceRegex = /^\s+$/g
return text.replace(emojiRegex(), '').replace(whitespaceRegex, '')
},
async getAiId () {
this.showLoading()
......@@ -134,24 +143,32 @@ export default {
}
},
send (val) {
const { issue, todayQuestionLeft, questionCountTotal } = this,
const { issue, todayQuestionLeft, questionCountTotal, padding } = this,
content = val || issue
if (todayQuestionLeft == 0) {
return this.showToast(`每天每个用户最多发送提问${questionCountTotal}个问题`)
try {
if (!content) throw false
if (padding) throw '请等待回复后再试'
if (todayQuestionLeft < 1) throw `每天每个用户最多发送提问${questionCountTotal}个问题`
} catch (error) {
if (error) this.showToast(error)
return
}
if (!content) return
const chatTime = Date.now()
const id = Date.now()
this.contentList.push({
contentType: 0,
content,
chatTime: dayjs(chatTime).format('YYYY-MM-DD HH:mm:ss')
chatTime: dayjs(id).format('YYYY-MM-DD HH:mm:ss'),
id
})
this.padding = true
this.lastQuestionTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
if (!val) {
this.issue = ''
this.$refs.input.blur()
}
this.toBottom()
this.$nextTick(() => {
this.addRecord(id)
this.toQuestionChatGPT(content)
})
},
......@@ -167,38 +184,39 @@ export default {
content: '',
id
})
const { response } = await chatgptApi.issueChatGpt({
question,
history: ''
})
let questionEffectiveCount = 0
if (response.indexOf('很抱歉') == -1) questionEffectiveCount = 1
this.contentList.find(i => i.id == id).chatTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
let index = 0, speed = 10
const typeWriter = () => {
if (index < response.length) {
this.contentList.find(i => i.id == id).content += response.charAt(index)
index++
setTimeout(typeWriter, speed)
this.toBottom()
} else this.addRecord(id, questionEffectiveCount)
try {
const { response } = await chatgptApi.issueChatGpt({
question,
history: ''
})
this.padding = false
this.contentList.find(i => i.id == id).chatTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
let index = 0, speed = 10
const typeWriter = () => {
if (index < response.length) {
this.contentList.find(i => i.id == id).content += response.charAt(index)
index++
setTimeout(typeWriter, speed)
this.toBottom()
} else this.addRecord(id)
}
typeWriter()
} catch (error) {
this.padding = false
}
typeWriter()
},
addRecord (id, questionEffectiveCount) {
const { contentList, scriptLibraryAIId } = this,
index = this.contentList.findIndex(i => i.id == id),
questionItem = contentList[index - 1],
answerItem = contentList[index],
lastQuestionTime = dayjs(questionItem.chatTime).format('YYYY-MM-DD HH:mm:ss')
delete answerItem.id
chatgptApi.updatedAiRecord({
scriptLibraryAIId,
addRecord (id) {
const { contentList, scriptLibraryAIId, lastQuestionTime } = this,
item = contentList.find(i => i.id == id)
delete item.id
let params = {
lastQuestionTime,
aiRecordList: [questionItem, answerItem],
questionCount: 1,
questionEffectiveCount
}).then(res => {
aiRecordList: [item],
scriptLibraryAIId
}
if (item.contentType == 1 && item.content.indexOf('很抱歉') == -1) params.questionEffectiveCount = 1
else params.questionCount = 1
chatgptApi.updatedAiRecord(params).then(res => {
this.getAiId()
})
}
......@@ -334,5 +352,11 @@ export default {
padding: 0;
}
}
.fixedKeyboard {
// position: fixed;
// width: 100%;
// box-sizing: border-box;
// bottom: 0;
}
}
</style>
\ No newline at end of file
......@@ -4,7 +4,7 @@
v-model="tabIndex"
color="#3975C6"
title-inactive-color="#BBB"
title-active-color="#2c2c2c"
title-active-color="#3975C6"
@click="click"
:key="updata"
v-bind="$attrs"
......
......@@ -13,10 +13,8 @@
:showDropdown="false"
></search-box>
</div>
<template v-if="tabIndex == 0">
<chat-gpt></chat-gpt>
</template>
<template v-else>
<chat-gpt :show="tabIndex == 0"></chat-gpt>
<template v-if="tabIndex == 1">
<template v-if="flag">
<template v-if="list.length">
<scroll-view
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!