refactor(数据大屏): 优化跑马灯的滚动速度计算方式,以px为单位同时兼顾缩放的效果

This commit is contained in:
wangjiahao 2024-06-12 16:02:15 +08:00
parent ee039c861b
commit a727d424c7
5 changed files with 37 additions and 13 deletions

View File

@ -508,6 +508,7 @@ const handleMouseDownOnShape = e => {
dashboardActive.value && dashboardActive.value &&
(isFirst || (!tabMoveInActiveId.value && !tabCollisionActiveId.value)) (isFirst || (!tabMoveInActiveId.value && !tabCollisionActiveId.value))
) { ) {
element.value['dragging'] = true
emit('onDragging', e) emit('onDragging', e)
} }
@ -543,6 +544,7 @@ const handleMouseDownOnShape = e => {
const up = () => { const up = () => {
dashboardActive.value && emit('onMouseUp') dashboardActive.value && emit('onMouseUp')
element.value['dragging'] = false
hasMove && snapshotStore.recordSnapshotCache('shape-handleMouseDownOnShape-up') hasMove && snapshotStore.recordSnapshotCache('shape-handleMouseDownOnShape-up')
// 线 // 线
eventBus.emit('unMove') eventBus.emit('unMove')
@ -699,6 +701,7 @@ const handleMouseDownOnPoint = (point, e) => {
dvMainStore.setShapeStyle(style, areaData.value.components, 'resize', baseGroupComponentsRadio) dvMainStore.setShapeStyle(style, areaData.value.components, 'resize', baseGroupComponentsRadio)
// //
dashboardActive.value && emit('onResizing', moveEvent) dashboardActive.value && emit('onResizing', moveEvent)
element.value['resizing'] = true
//Group //Group
element.value.component === 'Group' && groupSizeStyleAdaptor(element.value) element.value.component === 'Group' && groupSizeStyleAdaptor(element.value)
//Group resizegroupStyle //Group resizegroupStyle
@ -712,6 +715,7 @@ const handleMouseDownOnPoint = (point, e) => {
const up = () => { const up = () => {
dashboardActive.value && emit('onMouseUp') dashboardActive.value && emit('onMouseUp')
element.value['resizing'] = false
document.removeEventListener('mousemove', move) document.removeEventListener('mousemove', move)
document.removeEventListener('mouseup', up) document.removeEventListener('mouseup', up)
needSave && snapshotStore.recordSnapshotCache('shape-handleMouseDownOnPoint-up') needSave && snapshotStore.recordSnapshotCache('shape-handleMouseDownOnPoint-up')

View File

@ -316,16 +316,16 @@ const fontFamilyList = [
const scrollSpeedList = [ const scrollSpeedList = [
{ name: '停止', value: 0 }, { name: '停止', value: 0 },
{ name: '1', value: 80 }, { name: '10', value: 10 },
{ name: '2', value: 60 }, { name: '20', value: 20 },
{ name: '3', value: 40 }, { name: '30', value: 30 },
{ name: '4', value: 30 }, { name: '40', value: 40 },
{ name: '5', value: 20 }, { name: '50', value: 50 },
{ name: '6', value: 15 }, { name: '60', value: 60 },
{ name: '7', value: 10 }, { name: '70', value: 70 },
{ name: '8', value: 8 }, { name: '80', value: 80 },
{ name: '9', value: 6 }, { name: '90', value: 90 },
{ name: '10', value: 3 } { name: '100', value: 100 }
] ]
const opacitySizeList = [ const opacitySizeList = [

View File

@ -165,6 +165,9 @@ export const commonAttr = {
maintainRadio: false, // 布局时保持宽高比例 maintainRadio: false, // 布局时保持宽高比例
aspectRatio: 1, // 锁定时的宽高比例 aspectRatio: 1, // 锁定时的宽高比例
isShow: true, // 是否显示组件 isShow: true, // 是否显示组件
// 当前组件动作
dragging: false,
resizing: false,
collapseName: [ collapseName: [
'position', 'position',
'background', 'background',

View File

@ -32,7 +32,7 @@ const props = defineProps({
const { element } = toRefs(props) const { element } = toRefs(props)
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
const { editMode, curComponent } = storeToRefs(dvMainStore) const { editMode, curComponent, canvasStyleData } = storeToRefs(dvMainStore)
const onComponentClick = () => { const onComponentClick = () => {
if (curComponent.value.id !== element.value.id) { if (curComponent.value.id !== element.value.id) {
@ -94,6 +94,10 @@ const handleBlur = e => {
canEdit.value = false canEdit.value = false
} }
const marqueeTxt = computed(
() => !canEdit.value && !element.value['resizing'] && !element.value['dragging']
)
const setEdit = () => { const setEdit = () => {
if (element.value['isLock']) return if (element.value['isLock']) return
canEdit.value = true canEdit.value = true
@ -111,7 +115,18 @@ onBeforeUnmount(() => {
eventBus.off('componentClick', onComponentClick) eventBus.off('componentClick', onComponentClick)
}) })
const varStyle = computed(() => [{ '--scroll-speed': `${element.value.style.scrollSpeed}s` }]) // px
const varStyle = computed(() => [
{
'--scroll-speed': `${
element.value.style.scrollSpeed === 0 || !text.value
? 0
: (text.value.clientWidth * 100) /
canvasStyleData.value.scale /
element.value.style.scrollSpeed
}s`
}
])
const textStyle = computed(() => { const textStyle = computed(() => {
return { return {
@ -131,7 +146,7 @@ const textStyle = computed(() => {
<div <div
ref="text" ref="text"
:contenteditable="canEdit" :contenteditable="canEdit"
:class="{ 'can-edit': canEdit, 'marquee-txt': !canEdit }" :class="{ 'can-edit': canEdit, 'marquee-txt': marqueeTxt }"
tabindex="0" tabindex="0"
:style="textStyle" :style="textStyle"
@dblclick="setEdit" @dblclick="setEdit"

View File

@ -228,6 +228,8 @@ export const dvMainStore = defineStore('dataVisualization', {
setCurComponent({ component, index }) { setCurComponent({ component, index }) {
if (!component && this.curComponent) { if (!component && this.curComponent) {
this.curComponent['editing'] = false this.curComponent['editing'] = false
this.curComponent['resizing'] = false
this.curComponent['dragging'] = false
this.curComponent['canvasActive'] = false this.curComponent['canvasActive'] = false
// 如果当前组件不在主画布中 对应的分组的canvasActive 也要设置为false // 如果当前组件不在主画布中 对应的分组的canvasActive 也要设置为false
if (this.curComponent.canvasId !== 'canvas-main') { if (this.curComponent.canvasId !== 'canvas-main') {