2424 </div >
2525 <p v-else-if =" loading" shadow =" always" style =" margin : 0.5rem 0 " >
2626 <el-icon class =" is-loading color-primary mr-4" ><Loading /></el-icon >
27- {{ $t('chat.tip.answerLoading ') }}
27+ {{ $t('views.application.generateDialog.loading ') }}
2828 <span class =" dotting" ></span >
2929 </p >
3030 <p v-else class =" flex align-center" >
3333 </p >
3434 </el-scrollbar >
3535 <div v-if =" answer && !loading && !isStreaming && !showContinueButton" >
36- <el-button type =" primary" @click =" () => emit('replace', answer)" > {{ $t('views.application.generateDialog.replace') }} </el-button >
36+ <el-button type =" primary" @click =" () => emit('replace', answer)" >
37+ {{ $t('views.application.generateDialog.replace') }}
38+ </el-button >
3739 <el-button @click =" reAnswerClick" :disabled =" !answer || loading" :loading =" loading" >
3840 {{ $t('views.application.generateDialog.remake') }}
3941 </el-button >
4042 </div >
43+ <div class =" mt-8" v-else >
44+ <el-button type =" primary" v-if =" showContinueButton" @click =" continueStreaming" link >
45+ {{ $t('views.application.generateDialog.continue') }}
46+ </el-button >
47+ </div >
4148 </div >
4249
4350 <!-- 文本输入框 -->
4956 {{ $t('views.application.generateDialog.stop') }}
5057 </el-button >
5158 </div >
52- <div v-if =" showContinueButton" class =" text-center mb-8" >
53- <el-button class =" border-primary video-stop-button" @click =" continueStreaming" >
54- <app-icon iconName =" app-video-stop" class =" mr-8" ></app-icon >
55- {{ $t('views.application.generateDialog.continue') }}
56- </el-button >
57- </div >
59+
5860 <div class =" operate-textarea" >
5961 <el-input
6062 ref =" quickInputRef"
7577 :disabled =" !inputValue.trim() || loading || isStreaming"
7678 @click =" handleSubmit"
7779 >
78- <img v-show =" !inputValue.trim() || loading || isStreaming" src =" @/assets/icon_send.svg" alt =" " />
80+ <img
81+ v-show =" !inputValue.trim() || loading || isStreaming"
82+ src =" @/assets/icon_send.svg"
83+ alt =" "
84+ />
7985 <SendIcon v-show =" inputValue.trim() && !loading && !isStreaming" />
8086 </el-button >
8187 </div >
8894</template >
8995
9096<script setup lang="ts">
91- import { computed , onUnmounted ,reactive , ref , nextTick , watch } from ' vue'
97+ import { computed , onUnmounted , reactive , ref , nextTick , watch } from ' vue'
9298import { useRoute } from ' vue-router'
9399import { MsgConfirm } from ' @/utils/message'
94100import { t } from ' @/locales'
@@ -161,7 +167,6 @@ const currentDisplayIndex = ref<number>(0) // 当前显示到的字符位置
161167let streamTimer: number | null = null // 定时器引用
162168const isOutputComplete = ref <boolean >(false )
163169
164-
165170// 模拟流式输出的定时器函数
166171const startStreamingOutput = () => {
167172 if (streamTimer ) {
@@ -182,9 +187,9 @@ const startStreamingOutput = () => {
182187 if (currentAnswer && currentAnswer .role === ' ai' ) {
183188 currentAnswer .content = fullContent .value .substring (0 , currentDisplayIndex .value )
184189 }
185- } else if (loading .value === false && currentDisplayIndex .value >= fullContent .value .length ) {
186- stopStreaming ()
187- }
190+ } else if (loading .value === false && currentDisplayIndex .value >= fullContent .value .length ) {
191+ stopStreaming ()
192+ }
188193 }, 50 ) // 每50ms输出一次
189194}
190195
@@ -195,7 +200,7 @@ const stopStreaming = () => {
195200 streamTimer = null
196201 }
197202 isStreaming .value = false
198- isPaused .value = false
203+ isPaused .value = false
199204 loading .value = false
200205 isOutputComplete .value = true
201206}
@@ -204,7 +209,6 @@ const showStopButton = computed(() => {
204209 return isStreaming .value
205210})
206211
207-
208212// 暂停流式输出
209213const pauseStreaming = () => {
210214 isPaused .value = true
@@ -218,7 +222,6 @@ const continueStreaming = () => {
218222 }
219223}
220224
221-
222225/**
223226 * 获取一个递归函数,处理流式数据
224227 * @param chat 每一条对话记录
@@ -227,8 +230,8 @@ const continueStreaming = () => {
227230 */
228231const getWrite = (reader : any ) => {
229232 let tempResult = ' '
230- const middleAnswer = reactive ({ content: ' ' , role: ' ai' })
231- chatMessages .value .push (middleAnswer )
233+ const middleAnswer = reactive ({ content: ' ' , role: ' ai' })
234+ chatMessages .value .push (middleAnswer )
232235
233236 // 初始化状态并
234237 fullContent .value = ' '
@@ -245,7 +248,7 @@ const getWrite = (reader: any) => {
245248 const write_stream = ({ done , value }: { done: boolean ; value: any }) => {
246249 try {
247250 if (done ) {
248- // 流数据接收完成,但定时器继续运行直到显示完所有内容
251+ // 流数据接收完成,但定时器继续运行直到显示完所有内容
249252 loading .value = false
250253 return
251254 }
@@ -302,10 +305,11 @@ const answer = computed(() => {
302305
303306// 按钮状态计算
304307const showContinueButton = computed (() => {
305- return ! isStreaming .value && isPaused .value && currentDisplayIndex .value < fullContent .value .length
308+ return (
309+ ! isStreaming .value && isPaused .value && currentDisplayIndex .value < fullContent .value .length
310+ )
306311})
307312
308-
309313function generatePrompt(inputValue : any ) {
310314 loading .value = true
311315 const workspaceId = user .getWorkspaceId () || ' default'
@@ -360,12 +364,10 @@ const handleSubmit = (event?: any) => {
360364 if (! originalUserInput .value ) {
361365 originalUserInput .value = inputValue .value
362366 }
363- if (inputValue .value ) {
367+ if (inputValue .value ) {
364368 generatePrompt (inputValue .value )
365- inputValue .value = ' '
369+ inputValue .value = ' '
366370 }
367-
368-
369371 } else {
370372 // 如果同时按下ctrl/shift/cmd/opt +enter,则会换行
371373 insertNewlineAtCursor (event )
@@ -415,17 +417,12 @@ const handleScroll = () => {
415417}
416418
417419const handleDialogClose = (done : () => void ) => {
418-
419420 // 弹出 消息
420- MsgConfirm (
421- t (' common.tip' ),
422- t (' views.application.generateDialog.exit' ),
423- {
424- confirmButtonText: t (' common.confirm' ),
425- cancelButtonText: t (' common.cancel' ),
426- distinguishCancelAndClose: true ,
427- }
428- )
421+ MsgConfirm (t (' common.tip' ), t (' views.application.generateDialog.exit' ), {
422+ confirmButtonText: t (' common.confirm' ),
423+ cancelButtonText: t (' common.cancel' ),
424+ distinguishCancelAndClose: true ,
425+ })
429426 .then (() => {
430427 // 点击确认,清除状态
431428 stopStreaming ()
@@ -437,8 +434,7 @@ const handleDialogClose = (done: () => void) => {
437434 })
438435 .catch (() => {
439436 // 点击取消
440- }
441- )
437+ })
442438}
443439
444440// 组件卸载时清理定时器
0 commit comments