Merge pull request #10627 from dataease/pr@dev-v2@refactor_scroll-text

refactor(数据大屏): 跑马灯优化初始化位置等问题
This commit is contained in:
王嘉豪 2024-06-30 16:31:30 +08:00 committed by GitHub
commit 0107d1e609
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { keycodes } from '@/utils/DeShortcutKey.js' import { keycodes } from '@/utils/DeShortcutKey.js'
import eventBus from '@/utils/eventBus' import eventBus from '@/utils/eventBus'
import { computed, nextTick, onBeforeUnmount, ref } from 'vue' import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
import { toRefs } from 'vue' import { toRefs } from 'vue'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain' import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
@ -12,6 +12,9 @@ const isCtrlDown = ref(false)
const emit = defineEmits(['input']) const emit = defineEmits(['input'])
const text = ref(null) const text = ref(null)
const textOut = ref(null)
const scrollScale = ref('100%')
let timeId = null
const props = defineProps({ const props = defineProps({
propValue: { propValue: {
@ -113,6 +116,10 @@ const selectText = element => {
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
eventBus.off('componentClick', onComponentClick) eventBus.off('componentClick', onComponentClick)
if (timeId) {
clearInterval(timeId)
timeId = null
}
}) })
// px // px
@ -124,15 +131,33 @@ const varStyle = computed(() => [
: (text.value.clientWidth * 100) / : (text.value.clientWidth * 100) /
canvasStyleData.value.scale / canvasStyleData.value.scale /
element.value.style.scrollSpeed element.value.style.scrollSpeed
}s` }s`,
'--scroll-scale': `${scrollScale.value}`
} }
]) ])
const init = () => {
timeId = setInterval(() => {
if (textOut.value && text.value) {
const result =
(element.value.style.width * canvasStyleData.value.scale) / text.value.clientWidth + '%'
console.log('===result=' + result)
scrollScale.value = result
} else {
scrollScale.value = '100%'
}
}, 1000)
}
const textStyle = computed(() => { const textStyle = computed(() => {
return { return {
verticalAlign: element.value['style'].verticalAlign verticalAlign: element.value['style'].verticalAlign
} }
}) })
onMounted(() => {
init()
})
</script> </script>
<template> <template>
@ -140,6 +165,7 @@ const textStyle = computed(() => {
v-if="editMode == 'edit'" v-if="editMode == 'edit'"
:style="varStyle" :style="varStyle"
class="v-text" class="v-text"
ref="textOut"
@keydown="handleKeydown" @keydown="handleKeydown"
@keyup="handleKeyup" @keyup="handleKeyup"
> >
@ -197,15 +223,14 @@ const textStyle = computed(() => {
} }
.marquee-txt { .marquee-txt {
display: inline-block; display: inline-block;
padding-left: 100%; /* 从右至左开始滚动 */
animation: marqueeAnimation var(--scroll-speed) linear infinite; animation: marqueeAnimation var(--scroll-speed) linear infinite;
} }
@keyframes marqueeAnimation { @keyframes marqueeAnimation {
0% { 0% {
transform: translate(100%, 0); transform: translate(var(--scroll-scale), 0);
} }
100% { 100% {
transform: translate(-50%, 0); transform: translate(-100%, 0);
} }
} }
</style> </style>