Commit 4cf3299f by 李伟康

修复BUG

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