Skip to content

Commit a3d4d20

Browse files
committed
fix(Embedded Systems): The top and bottom spacing is inconsistent between floating mode and full-screen mode; optimization is recommended.
1 parent 273171b commit a3d4d20

3 files changed

Lines changed: 51 additions & 29 deletions

File tree

‎frontend/src/main.ts‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,12 @@ import App from './App.vue'
99
import router from './router'
1010
import { i18n } from './i18n'
1111
import VueDOMPurifyHTML from 'vue-dompurify-html'
12+
import { isSupportFlexGap } from './utils/utils'
1213

1314
// import 'element-plus/dist/index.css'
1415
cssHasPseudo(document)
1516

16-
function supportsFlexGap() {
17-
const flex = document.createElement('div')
18-
19-
flex.style.display = 'flex'
20-
flex.style.flexDirection = 'column'
21-
flex.style.rowGap = '1px'
22-
23-
const child1 = document.createElement('div')
24-
const child2 = document.createElement('div')
25-
26-
child1.style.height = '1px'
27-
child2.style.height = '1px'
28-
29-
flex.appendChild(child1)
30-
flex.appendChild(child2)
31-
32-
document.body.appendChild(flex)
33-
34-
const isSupported = flex.scrollHeight === 3
35-
36-
document.body.removeChild(flex)
37-
38-
return isSupported
39-
}
40-
41-
document.documentElement.setAttribute('data-no-flex-gap', String(!supportsFlexGap()))
17+
isSupportFlexGap()
4218

4319
const app = createApp(App)
4420
const pinia = createPinia()

‎frontend/src/utils/utils.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,32 @@ export const formatArg = (text: string) => {
315315
return text
316316
}
317317
}
318+
319+
function supportsFlexGap() {
320+
const flex = document.createElement('div')
321+
322+
flex.style.display = 'flex'
323+
flex.style.flexDirection = 'column'
324+
flex.style.rowGap = '1px'
325+
326+
const child1 = document.createElement('div')
327+
const child2 = document.createElement('div')
328+
329+
child1.style.height = '1px'
330+
child2.style.height = '1px'
331+
332+
flex.appendChild(child1)
333+
flex.appendChild(child2)
334+
335+
document.body.appendChild(flex)
336+
337+
const isSupported = flex.scrollHeight === 3
338+
339+
document.body.removeChild(flex)
340+
341+
return isSupported
342+
}
343+
344+
export const isSupportFlexGap = () => {
345+
document.documentElement.setAttribute('data-no-flex-gap', String(!supportsFlexGap()))
346+
}

‎frontend/src/views/chat/index.vue‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@
452452
</template>
453453

454454
<script setup lang="ts">
455-
import { computed, nextTick, onMounted, ref } from 'vue'
455+
import { computed, nextTick, onMounted, onBeforeUnmount, ref } from 'vue'
456456
import { Chat, chatApi, ChatInfo, type ChatMessage, ChatRecord } from '@/api/chat'
457457
import ChatRow from './ChatRow.vue'
458458
import ChartAnswer from './answer/ChartAnswer.vue'
@@ -483,7 +483,7 @@ import { onClickOutside } from '@vueuse/core'
483483
import { useAppearanceStoreWithOut } from '@/stores/appearance'
484484
import { useUserStore } from '@/stores/user'
485485
import { debounce } from 'lodash-es'
486-
import { isMobile } from '@/utils/utils'
486+
import { isMobile, isSupportFlexGap } from '@/utils/utils'
487487
import router from '@/router'
488488
import QuickQuestion from '@/views/chat/QuickQuestion.vue'
489489
import { useChatConfigStore } from '@/stores/chatConfig.ts'
@@ -1130,8 +1130,19 @@ function jumpCreatChat() {
11301130
history.replaceState({}, '', newUrl)
11311131
}
11321132
}
1133-
1133+
function checkAfterVisible() {
1134+
if (document.visibilityState === 'visible') {
1135+
clearInterval(time)
1136+
requestAnimationFrame(() => {
1137+
isSupportFlexGap()
1138+
})
1139+
}
1140+
}
1141+
let time: number
11341142
onMounted(() => {
1143+
time = setInterval(() => {
1144+
checkAfterVisible()
1145+
}, 1000)
11351146
chatConfig.fetchGlobalConfig()
11361147
if (isPhone.value) {
11371148
chatListSideBarShow.value = false
@@ -1142,6 +1153,12 @@ onMounted(() => {
11421153
getChatList(jumpCreatChat)
11431154
assistantPrepareInit()
11441155
})
1156+
1157+
onBeforeUnmount(() => {
1158+
clearInterval(time)
1159+
clearInterval(scrollTime)
1160+
clearTimeout(scrollingTime)
1161+
})
11451162
</script>
11461163

11471164
<style lang="less" scoped>

0 commit comments

Comments
 (0)