perf: 优化标尺的展示方式

This commit is contained in:
奔跑的面条 2022-08-21 14:42:31 +08:00
parent 1b01fd81a8
commit a7edef16f4
4 changed files with 56 additions and 28 deletions

View File

@ -3,8 +3,6 @@
<slot></slot> <slot></slot>
<!-- 水印 --> <!-- 水印 -->
<edit-watermark></edit-watermark> <edit-watermark></edit-watermark>
<!-- 标尺 -->
<edit-rule></edit-rule>
<!-- 拖拽时的辅助线 --> <!-- 拖拽时的辅助线 -->
<edit-align-line></edit-align-line> <edit-align-line></edit-align-line>
<!-- 框选时的样式框 --> <!-- 框选时的样式框 -->
@ -22,7 +20,6 @@ import { mousedownBoxSelect } from '../../hooks/useDrag.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { EditAlignLine } from '../EditAlignLine' import { EditAlignLine } from '../EditAlignLine'
import { EditWatermark } from '../EditWatermark' import { EditWatermark } from '../EditWatermark'
import { EditRule } from '../EditRule'
import { EditSelect } from '../EditSelect' import { EditSelect } from '../EditSelect'
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()

View File

@ -1,9 +1,10 @@
<template> <template>
<sketch-rule <sketch-rule
v-if="configShow"
:thick="thick" :thick="thick"
:scale="scale" :scale="scale"
:width="width" :width="canvasBox().width"
:height="height" :height="canvasBox().height"
:startX="startX" :startX="startX"
:startY="startY" :startY="startY"
:lines="lines" :lines="lines"
@ -11,7 +12,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { toRefs, computed } from 'vue' import { ref, toRefs, computed, watch } from 'vue'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useDesignStore } from '@/store/modules/designStore/designStore' import { useDesignStore } from '@/store/modules/designStore/designStore'
@ -20,12 +21,12 @@ const designStore = useDesignStore()
const { width, height } = toRefs(chartEditStore.getEditCanvasConfig) const { width, height } = toRefs(chartEditStore.getEditCanvasConfig)
// const configShow = ref(true)
const scale = 1
// x // x
const startX = 20 const startX = -10
// y // y
const startY = 20 const startY = -10
// //
const thick = 20 const thick = 20
// 线 // 线
@ -34,15 +35,42 @@ const lines = {
v: [] v: []
} }
const canvasBox = () => {
const layoutDom = document.getElementById('go-chart-edit-layout')
if (layoutDom) {
return {
height: layoutDom.clientHeight - 40,
width: layoutDom.clientWidth
}
}
return {
width: width.value,
height: height.value
}
}
const scale = computed(() => {
return chartEditStore.getEditCanvas.scale
})
// //
const themeColor = computed(() => { const themeColor = computed(() => {
return designStore.getAppTheme return designStore.getAppTheme
}) })
//
watch(
() => scale.value,
() => {
configShow.value = false
setTimeout(() => {
configShow.value = true
})
}
)
</script> </script>
<style> <style>
/* 使 SCSS 使 CSS /* 使 SCSS 使 CSS
此库有计划 Vue3 版本但是开发的时候还没发布 */ 此库有计划 Vue3 版本但是开发的时候还没发布 */
@ -50,13 +78,15 @@ const themeColor = computed(() => {
top: 0; top: 0;
left: 0; left: 0;
} }
/* 适配底部的工具栏不遮盖 */
#mb-ruler .v-container {
height: calc(100% - 65px) !important;
}
/* 横线 */ /* 横线 */
#mb-ruler .v-container .lines .line { #mb-ruler .v-container .lines .line {
/* 最大缩放 200% */ /* 最大缩放 200% */
width: 200vw !important; width: 200vw !important;
border-top: 1px dashed v-bind('themeColor') !important; border-top: 1px dashed v-bind('themeColor') !important;
} }
#mb-ruler .v-container .indicator { #mb-ruler .v-container .indicator {
border-bottom: 1px dashed v-bind('themeColor') !important; border-bottom: 1px dashed v-bind('themeColor') !important;

View File

@ -17,19 +17,16 @@ export const exportHandle = () => {
) )
// 导出图片 // 导出图片
const ruler = document.getElementById('mb-ruler')
const range = document.querySelector('.go-edit-range') as HTMLElement const range = document.querySelector('.go-edit-range') as HTMLElement
const watermark = document.getElementById('go-edit-watermark') const watermark = document.getElementById('go-edit-watermark')
// 隐藏边距线 // 隐藏边距线
if (!ruler || !range || !watermark) { if (!range || !watermark) {
window['$message'].error('导出失败!') window['$message'].error('导出失败!')
return return
} }
// 记录缩放比例 // 记录缩放比例
const scaleTemp = chartEditStore.getEditCanvas.scale const scaleTemp = chartEditStore.getEditCanvas.scale
// 去除标尺Dom
ruler.style.display = 'none'
// 百分百展示页面 // 百分百展示页面
chartEditStore.setScale(1, true) chartEditStore.setScale(1, true)
// 展示水印 // 展示水印
@ -39,8 +36,6 @@ export const exportHandle = () => {
canvasCut(range, () => { canvasCut(range, () => {
// 隐藏水印 // 隐藏水印
if (watermark) watermark.style.display = 'none' if (watermark) watermark.style.display = 'none'
// 放开边距线
if (ruler) ruler.style.display = 'block'
// 还原页面大小 // 还原页面大小
chartEditStore.setScale(scaleTemp, true) chartEditStore.setScale(scaleTemp, true)
}) })

View File

@ -1,4 +1,5 @@
<template> <template>
<edit-rule></edit-rule>
<content-box <content-box
id="go-chart-edit-layout" id="go-chart-edit-layout"
:flex="true" :flex="true"
@ -24,7 +25,11 @@
<!-- 图表 --> <!-- 图表 -->
<div v-for="(item, index) in chartEditStore.getComponentList" :key="item.id"> <div v-for="(item, index) in chartEditStore.getComponentList" :key="item.id">
<!-- 分组 --> <!-- 分组 -->
<edit-group v-if="item.isGroup" :groupData="(item as CreateComponentGroupType)" :groupIndex="index"></edit-group> <edit-group
v-if="item.isGroup"
:groupData="(item as CreateComponentGroupType)"
:groupIndex="index"
></edit-group>
<!-- 单组件 --> <!-- 单组件 -->
<edit-shape-box <edit-shape-box
@ -88,6 +93,7 @@ import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
import { ContentBox } from '../ContentBox/index' import { ContentBox } from '../ContentBox/index'
import { EditGroup } from './components/EditGroup' import { EditGroup } from './components/EditGroup'
import { EditRange } from './components/EditRange' import { EditRange } from './components/EditRange'
import { EditRule } from './components/EditRule'
import { EditBottom } from './components/EditBottom' import { EditBottom } from './components/EditBottom'
import { EditShapeBox } from './components/EditShapeBox' import { EditShapeBox } from './components/EditShapeBox'
import { EditTools } from './components/EditTools' import { EditTools } from './components/EditTools'
@ -174,7 +180,7 @@ onMounted(() => {
@include background-image('background-point'); @include background-image('background-point');
@include goId('chart-edit-content') { @include goId('chart-edit-content') {
border-radius: 10px; border-radius: 10px;
margin: 15px; margin: 25px;
overflow: hidden; overflow: hidden;
@extend .go-transition; @extend .go-transition;
@include fetch-theme('box-shadow'); @include fetch-theme('box-shadow');