Skip to content

Commit 48cf976

Browse files
committed
style: format code for consistency and readability in index.vue
1 parent 244f110 commit 48cf976

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

ui/src/components/ai-chat/index.vue

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<el-checkbox-group v-model="multipleSelectionChat" @change="handleCheckedChatChange">
4141
<template v-for="(item, index) in chatList" :key="index">
4242
<div class="flex-between w-full">
43-
<el-checkbox :value="item.record_id" v-if="selection" />
43+
<el-checkbox :value="item.record_id" v-if="selection"/>
4444
<div
4545
class="w-full border-r-8"
4646
:class="selection ? 'is-selected p-12 mt-8 mb-8 cursor' : 'mt-24'"
@@ -59,7 +59,7 @@
5959
</div>
6060
</div>
6161
<div class="flex align-center w-full">
62-
<el-checkbox :value="item.record_id" v-if="selection" />
62+
<el-checkbox :value="item.record_id" v-if="selection"/>
6363
<div
6464
class="w-full border-r-8"
6565
:class="selection ? 'is-selected p-12 cursor' : ''"
@@ -97,12 +97,15 @@
9797
<div style="position: relative">
9898
<!-- 置底按钮 -->
9999
<el-button v-if="isBottom" circle class="back-bottom-button" @click="setScrollBottom">
100-
<el-icon><ArrowDownBold /></el-icon>
100+
<el-icon>
101+
<ArrowDownBold/>
102+
</el-icon>
101103
</el-button>
102104
<div class="mul-operation border-t w-full" v-if="selection === true">
103105
<div class="flex-between chat-width">
104106
<el-checkbox v-model="checkAll" @change="handleCheckAllChange">
105-
{{ $t('common.allCheck') }}</el-checkbox
107+
{{ $t('common.allCheck') }}
108+
</el-checkbox
106109
>
107110
<div>
108111
<el-button @click="cancelCheckHandle">
@@ -163,39 +166,40 @@ import {
163166
provide,
164167
onBeforeMount,
165168
} from 'vue'
166-
import { useRoute } from 'vue-router'
169+
import {useRoute} from 'vue-router'
167170
import applicationApi from '@/api/application/application'
168171
import chatAPI from '@/api/chat/chat'
169172
import SystemResourceManagementApplicationAPI from '@/api/system-resource-management/application.ts'
170173
import syetrmResourceManagementChatLogApi from '@/api/system-resource-management/chat-log'
171174
import chatLogApi from '@/api/application/chat-log'
172-
import { ChatManagement, type chatType } from '@/api/type/application'
173-
import { randomId } from '@/utils/common'
175+
import {ChatManagement, type chatType} from '@/api/type/application'
176+
import {randomId} from '@/utils/common'
174177
import useStore from '@/stores'
175-
import { debounce } from 'lodash'
178+
import {debounce} from 'lodash'
176179
import AnswerContent from '@/components/ai-chat/component/answer-content/index.vue'
177180
import QuestionContent from '@/components/ai-chat/component/question-content/index.vue'
178181
import TransitionContent from '@/components/ai-chat/component/transition-content/index.vue'
179182
import ChatInputOperate from '@/components/ai-chat/component/chat-input-operate/index.vue'
180183
import PrologueContent from '@/components/ai-chat/component/prologue-content/index.vue'
181184
import UserForm from '@/components/ai-chat/component/user-form/index.vue'
182185
import Control from '@/components/ai-chat/component/control/index.vue'
183-
import type { CheckboxValueType } from 'element-plus'
184-
import { t } from '@/locales'
186+
import type {CheckboxValueType} from 'element-plus'
187+
import {t} from '@/locales'
185188
import bus from '@/bus'
186-
import { throttle } from 'lodash-es'
187-
import { copyClick } from '@/utils/clipboard'
189+
import {throttle} from 'lodash-es'
190+
import {copyClick} from '@/utils/clipboard'
191+
188192
provide('upload', (file: any, loading?: Ref<boolean>) => {
189193
return props.type === 'debug-ai-chat'
190194
? applicationApi.postUploadFile(file, 'TEMPORARY_120_MINUTE', 'TEMPORARY_120_MINUTE', loading)
191195
: chatAPI.postUploadFile(file, chartOpenId.value, 'CHAT', loading)
192196
})
193197
const transcribing = ref<boolean>(false)
194-
defineOptions({ name: 'AiChat' })
198+
defineOptions({name: 'AiChat'})
195199
const route = useRoute()
196200
const {
197-
params: { accessToken, id },
198-
query: { mode },
201+
params: {accessToken, id},
202+
query: {mode},
199203
} = route as any
200204
const props = withDefaults(
201205
defineProps<{
@@ -223,7 +227,7 @@ const emit = defineEmits([
223227
'openParagraphDocument',
224228
'update:selection',
225229
])
226-
const { application, common, chatUser } = useStore()
230+
const {application, common, chatUser} = useStore()
227231
const isMobile = computed(() => {
228232
return common.isMobile() || mode === 'embed' || mode === 'mobile'
229233
})
@@ -283,15 +287,15 @@ watch(
283287
}
284288
}
285289
},
286-
{ deep: true, immediate: true },
290+
{deep: true, immediate: true},
287291
)
288292
289293
watch(
290294
() => props.applicationDetails,
291295
() => {
292296
chartOpenId.value = ''
293297
},
294-
{ deep: true },
298+
{deep: true},
295299
)
296300
297301
watch(
@@ -359,6 +363,7 @@ function toggleSelect(id: number) {
359363
multipleSelectionChat.value.splice(index, 1)
360364
}
361365
}
366+
362367
function cancelCheckHandle() {
363368
checkAll.value = false
364369
multipleSelectionChat.value = []
@@ -378,6 +383,7 @@ function UserFormConfirm() {
378383
firsUserInput.value = false
379384
showUserInput.value = false
380385
}
386+
381387
function UserFormCancel() {
382388
// 恢复初始数据
383389
form_data.value = JSON.parse(JSON.stringify(initialFormData.value))
@@ -503,6 +509,7 @@ const getChatRecordDetailsAPI = (row: any) => {
503509
}
504510
return Promise.reject('404')
505511
}
512+
506513
/**
507514
* 获取对话详情
508515
* @param row
@@ -517,6 +524,7 @@ function getSourceDetail(row: any) {
517524
})
518525
})
519526
}
527+
520528
/**
521529
* 对话
522530
*/
@@ -538,15 +546,15 @@ const getWrite = (chat: any, reader: any, stream: boolean) => {
538546
const write_stream = async () => {
539547
try {
540548
while (true) {
541-
const { done, value } = await reader.read()
549+
const {done, value} = await reader.read()
542550
543551
if (done) {
544552
ChatManagement.close(chat.id)
545553
return
546554
}
547555
548556
const decoder = new TextDecoder('utf-8')
549-
let str = decoder.decode(value, { stream: true })
557+
let str = decoder.decode(value, {stream: true})
550558
551559
tempResult += str
552560
const split = tempResult.match(/data:.*?}\n\n/g)
@@ -579,7 +587,7 @@ const getWrite = (chat: any, reader: any, stream: boolean) => {
579587
const write_json = async () => {
580588
try {
581589
while (true) {
582-
const { done, value } = await reader.read()
590+
const {done, value} = await reader.read()
583591
584592
if (done) {
585593
const result_block = JSON.parse(tempResult)
@@ -613,6 +621,7 @@ const errorWrite = (chat: any, message?: string) => {
613621
ChatManagement.updateStatus(chat.id, 500)
614622
ChatManagement.close(chat.id)
615623
}
624+
616625
// 保存上传文件列表
617626
618627
function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_params_data?: any) {
@@ -750,7 +759,7 @@ const handleScrollTop = ($event: any) => {
750759
}
751760
isBottom.value =
752761
scrollTop.value + scrollDiv.value.wrapRef.offsetHeight < dialogScrollbar.value!.scrollHeight
753-
emit('scroll', { ...$event, dialogScrollbar: dialogScrollbar.value, scrollDiv: scrollDiv.value })
762+
emit('scroll', {...$event, dialogScrollbar: dialogScrollbar.value, scrollDiv: scrollDiv.value})
754763
}
755764
/**
756765
* 处理跟随滚动条
@@ -759,8 +768,13 @@ const handleScroll = () => {
759768
if (props.type !== 'log' && scrollDiv.value) {
760769
// 内部高度小于外部高度 就需要出滚动条
761770
if (scrollDiv.value.wrapRef.offsetHeight < dialogScrollbar.value.scrollHeight) {
762-
// 滚动到底部
763-
scrollDiv.value.setScrollTop(dialogScrollbar.value.scrollHeight)
771+
// 只有在用户已经在底部附近时才自动滚动到底部
772+
const isNearBottom =
773+
dialogScrollbar.value.scrollHeight - (scrollTop.value + scrollDiv.value.wrapRef.offsetHeight) <= 40
774+
if (scorll.value || isNearBottom) {
775+
// 滚动到底部
776+
scrollDiv.value.setScrollTop(dialogScrollbar.value.scrollHeight)
777+
}
764778
}
765779
}
766780
}
@@ -776,7 +790,7 @@ onBeforeMount(() => {
776790
})
777791
778792
function parseTransform(transformStr: string) {
779-
const result = { scale: 1, translateX: 0, translateY: 0, translateZ: 0 }
793+
const result = {scale: 1, translateX: 0, translateY: 0, translateZ: 0}
780794
781795
if (!transformStr || transformStr === 'none') return result
782796
@@ -797,6 +811,7 @@ function parseTransform(transformStr: string) {
797811
798812
return result
799813
}
814+
800815
onMounted(() => {
801816
if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) {
802817
const userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
@@ -810,7 +825,7 @@ onMounted(() => {
810825
// 2. 解析当前变换状态
811826
const currentTransform = target.style.transform
812827
const transformValues = parseTransform(currentTransform)
813-
const { scale, translateX, translateY } = transformValues
828+
const {scale, translateX, translateY} = transformValues
814829
// 确保scale是数值类型
815830
const currentScale = Array.isArray(scale) ? scale[0] : scale
816831
@@ -844,7 +859,7 @@ onMounted(() => {
844859
}
845860
}
846861
},
847-
{ passive: false },
862+
{passive: false},
848863
)
849864
850865
window.sendMessage = sendMessage
@@ -879,7 +894,7 @@ watch(
879894
handleScroll() // 确保 DOM 更新后再滚动
880895
})
881896
},
882-
{ deep: true, immediate: true },
897+
{deep: true, immediate: true},
883898
)
884899
885900
defineExpose({

0 commit comments

Comments
 (0)