feat: 新增预览拖拽

This commit is contained in:
奔跑的面条 2023-07-09 15:54:01 +08:00
parent e979149cfb
commit 7076c4deb7
7 changed files with 197 additions and 101 deletions

View File

@ -1,78 +1,84 @@
@import './config.scss'; @import './config.scss';
@import './function.scss'; @import './function.scss';
@import '../theme.scss'; @import '../theme.scss';
@mixin go($block) { @mixin go($block) {
$B: $namespace + '-' + $block; $B: $namespace + '-' + $block;
.#{$B} { .#{$B} {
@content; @content;
} }
} }
@mixin goId($block) { @mixin dark {
$B: $namespace + '-' + $block; [data-theme='dark'] {
##{$B} { @content;
@content; }
} }
}
@mixin goId($block) {
@mixin deep() { $B: $namespace + '-' + $block;
:deep() { ##{$B} {
@content; @content;
} }
} }
@mixin when($state) { @mixin deep() {
@at-root { :deep() {
&.#{$state-prefix + $state} { @content;
@content; }
} }
}
} @mixin when($state) {
@at-root {
@mixin themeify { &.#{$state-prefix + $state} {
@each $theme-name, $theme-map in $themes { @content;
$theme-map: $theme-map !global; }
[data-theme='#{$theme-name}'] & { }
@content; }
}
} @mixin themeify {
} @each $theme-name, $theme-map in $themes {
$theme-map: $theme-map !global;
@mixin fetch-theme($param) { [data-theme='#{$theme-name}'] & {
@include themeify { @content;
#{$param}: themed($param); }
} }
} }
@mixin fetch-theme-custom ($key, $value) { @mixin fetch-theme($param) {
@include themeify { @include themeify {
#{$key}: themed($value); #{$param}: themed($param);
} }
} }
//获取背景颜色 @mixin fetch-theme-custom ($key, $value) {
@mixin fetch-bg-color($target) { @include themeify {
@include themeify { #{$key}: themed($value);
background-color: themed($target); }
} }
}
//获取背景颜色
//获取背景渐变颜色 @mixin fetch-bg-color($target) {
@mixin background-image($target) { @include themeify {
@include themeify { background-color: themed($target);
background-image: themed($target); }
} }
}
//获取背景渐变颜色
//设置边框颜色 @mixin background-image($target) {
@mixin fetch-border-color($target) { @include themeify {
@include themeify { background-image: themed($target);
border-color: themed($target); }
} }
}
@mixin hover-border-color($target) { //设置边框颜色
@include themeify { @mixin fetch-border-color($target) {
border: 1px solid themed($target); @include themeify {
} border-color: themed($target);
} }
}
@mixin hover-border-color($target) {
@include themeify {
border: 1px solid themed($target);
}
}

View File

@ -1,9 +1,15 @@
// 页面全局样式 // 页面全局样式
// 去除高德地图 logo // 去除高德地图 logo
.amap-logo { .amap-logo {
display: none !important; display: none !important;
opacity: 0 !important; opacity: 0 !important;
} }
.amap-copyright { .amap-copyright {
opacity: 0 !important; opacity: 0 !important;
} }
[data-theme='dark'] {
body {
background-color: #18181c;
}
}

View File

@ -23,16 +23,27 @@ export const useScale = (localStorageInfo: ChartEditStorageType) => {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
removeEvent() removeEvent()
const fitDom = document.querySelector(".go-preview.fit") as HTMLElement const transform = previewRef.value?.style.transform
if (fitDom) fitDom.style.overflow = 'auto'
const transform = previewRef.value.style.transform
// 使用正则解析 scale(1, 1) 中的两个数值
const regRes = transform.match(/scale\((\d+\.?\d*)*/) as RegExpMatchArray const regRes = transform.match(/scale\((\d+\.?\d*)*/) as RegExpMatchArray
const width = regRes[1] const width = regRes[1]
const previewBoxDom = document.querySelector('.go-preview') as HTMLElement
const entityDom = document.querySelector('.go-preview-entity') as HTMLElement
if (previewBoxDom) {
previewBoxDom.style.overflow = 'unset'
previewBoxDom.style.position = 'absolute'
previewBoxDom.style.top = '10px'
previewBoxDom.style.left = '20px'
}
if (entityDom) {
entityDom.style.overflow = 'unset'
}
if (e.wheelDelta > 0) { if (e.wheelDelta > 0) {
previewRef.value.style.transform = `scale(${parseFloat(Number(width).toFixed(2)) + 0.1})` const resNum = parseFloat(Number(width).toFixed(2))
previewRef.value.style.transform = `scale(${resNum > 5 ? 5 : resNum + 0.1})`
} else { } else {
previewRef.value.style.transform = `scale(${parseFloat(Number(width).toFixed(2)) - 0.1})` const resNum = parseFloat(Number(width).toFixed(2))
previewRef.value.style.transform = `scale(${resNum < 0.2 ? 0.2 : resNum - 0.1})`
} }
} }
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<div :class="`go-preview ${chartEditStore.editCanvasConfig.previewScaleType}`"> <div :class="`go-preview ${chartEditStore.editCanvasConfig.previewScaleType}`" @mousedown="dragCanvas">
<template v-if="showEntity"> <template v-if="showEntity">
<!-- 实体区域 --> <!-- 实体区域 -->
<div ref="entityRef" class="go-preview-entity"> <div ref="entityRef" class="go-preview-entity">
@ -30,7 +30,7 @@
import { computed } from 'vue' import { computed } from 'vue'
import { PreviewRenderList } from './components/PreviewRenderList' import { PreviewRenderList } from './components/PreviewRenderList'
import { getFilterStyle, setTitle } from '@/utils' import { getFilterStyle, setTitle } from '@/utils'
import { getEditCanvasConfigStyle, getSessionStorageInfo, keyRecordHandle } from './utils' import { getEditCanvasConfigStyle, getSessionStorageInfo, keyRecordHandle, dragCanvas } from './utils'
import { useComInstall } from './hooks/useComInstall.hook' import { useComInstall } from './hooks/useComInstall.hook'
import { useScale } from './hooks/useScale.hook' import { useScale } from './hooks/useScale.hook'
import { useStore } from './hooks/useStore.hook' import { useStore } from './hooks/useStore.hook'

View File

@ -0,0 +1,55 @@
import { listen } from 'dom-helpers'
import throttle from 'lodash/throttle'
let prevMoveXValue = [0, 0]
let prevMoveYValue = [0, 0]
// 拖拽处理
export const dragCanvas = (e: MouseEvent) => {
const previewBoxDom = document.querySelector('.go-preview') as HTMLElement
if (!previewBoxDom || previewBoxDom.style.position !== 'absolute') return
if (!window.$KeyboardActive?.space) return
e.preventDefault()
e.stopPropagation()
// @ts-ignore
document.activeElement?.blur()
const startX = e.screenX
const startY = e.screenY
const listenMousemove = listen(
window,
'mousemove',
throttle((moveEvent: MouseEvent) => {
const nx = moveEvent.screenX - startX
const ny = moveEvent.screenY - startY
const [prevMoveX1, prevMoveX2] = prevMoveXValue
const [prevMoveY1, prevMoveY2] = prevMoveYValue
prevMoveXValue = [prevMoveX2, nx]
prevMoveYValue = [prevMoveY2, ny]
// 去除小数部分
if (previewBoxDom) {
const oldLeft = previewBoxDom.style.left ? Number(previewBoxDom.style.left.split('px')[0]) : 0
const oldTop = previewBoxDom.style.top ? Number(previewBoxDom.style.top.split('px')[0]) : 0
previewBoxDom.style.left =
oldLeft +
(prevMoveX2 > prevMoveX1 ? Math.abs(prevMoveX2 - prevMoveX1) : -Math.abs(prevMoveX2 - prevMoveX1)) +
'px'
previewBoxDom.style.top =
oldTop +
(prevMoveY2 > prevMoveY1 ? Math.abs(prevMoveY2 - prevMoveY1) : -Math.abs(prevMoveY2 - prevMoveY1)) +
'px'
}
}, 20)
)
const listenMouseup = listen(window, 'mouseup', () => {
prevMoveXValue = [0, 0]
prevMoveYValue = [0, 0]
listenMousemove()
listenMouseup()
})
}

View File

@ -1,3 +1,4 @@
export * from './style' export * from './style'
export * from './storage' export * from './storage'
export * from './keyboard' export * from './keyboard'
export * from './drag'

View File

@ -12,8 +12,16 @@ export const keyRecordHandle = () => {
if ([17, 32].includes(keyCode) && window.$KeyboardActive) { if ([17, 32].includes(keyCode) && window.$KeyboardActive) {
switch (keyCode) { switch (keyCode) {
case 17: window.$KeyboardActive.ctrl = true; break case 17:
case 32: window.$KeyboardActive.space = true; break window.$KeyboardActive.ctrl = true
break
case 32:
window.$KeyboardActive.space = true
const previewBoxDom = document.querySelector('.go-preview') as HTMLElement
if (previewBoxDom && previewBoxDom.style.position === 'absolute') {
previewBoxDom.style.cursor = 'move'
}
break
} }
} }
} }
@ -24,9 +32,18 @@ export const keyRecordHandle = () => {
if ([17, 32].includes(keyCode) && window.$KeyboardActive) { if ([17, 32].includes(keyCode) && window.$KeyboardActive) {
switch (keyCode) { switch (keyCode) {
case 17: window.$KeyboardActive.ctrl = false; break case 17:
case 32: window.$KeyboardActive.space = false; break window.$KeyboardActive.ctrl = false
break
case 32:
window.$KeyboardActive.space = false
break
} }
} }
const previewBoxDom = document.querySelector('.go-preview') as HTMLElement
if (previewBoxDom) {
previewBoxDom.style.cursor = 'default'
}
} }
} }