mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 08:12:49 +08:00
feat: 新增滚动条控制
This commit is contained in:
parent
ceb8cd5158
commit
c57a4850b6
@ -6,6 +6,7 @@ export enum EditCanvasTypeEnum {
|
|||||||
HEIGHT = 'height',
|
HEIGHT = 'height',
|
||||||
OFFSET = 'offset',
|
OFFSET = 'offset',
|
||||||
SCALE = 'scale',
|
SCALE = 'scale',
|
||||||
|
USERSCALE = 'userScale',
|
||||||
LOCKSCALE = 'lockScale',
|
LOCKSCALE = 'lockScale',
|
||||||
BACKGROUND = 'background'
|
BACKGROUND = 'background'
|
||||||
}
|
}
|
||||||
@ -21,6 +22,8 @@ export type EditCanvasType = {
|
|||||||
[EditCanvasTypeEnum.OFFSET]: number
|
[EditCanvasTypeEnum.OFFSET]: number
|
||||||
// 缩放
|
// 缩放
|
||||||
[EditCanvasTypeEnum.SCALE]: number
|
[EditCanvasTypeEnum.SCALE]: number
|
||||||
|
// 缩放
|
||||||
|
[EditCanvasTypeEnum.USERSCALE]: number
|
||||||
// 锁定缩放
|
// 锁定缩放
|
||||||
[EditCanvasTypeEnum.LOCKSCALE]: boolean
|
[EditCanvasTypeEnum.LOCKSCALE]: boolean
|
||||||
// 背景色
|
// 背景色
|
||||||
|
@ -20,8 +20,10 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
height: 1080,
|
height: 1080,
|
||||||
// 偏移量
|
// 偏移量
|
||||||
offset: 20,
|
offset: 20,
|
||||||
// 默认缩放
|
// 系统控制缩放
|
||||||
scale: 1,
|
scale: 1,
|
||||||
|
// 用户控制的缩放
|
||||||
|
userScale: 1,
|
||||||
// 锁定缩放
|
// 锁定缩放
|
||||||
lockScale: false,
|
lockScale: false,
|
||||||
// 默认背景色
|
// 默认背景色
|
||||||
@ -50,7 +52,8 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
key: T,
|
key: T,
|
||||||
value: any
|
value: any
|
||||||
): void {
|
): void {
|
||||||
const dom = this.editCanvas.editContentDom
|
const dom = this.getEditCanvas.editContentDom
|
||||||
|
console.log(dom);
|
||||||
if (dom) {
|
if (dom) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
dom.style[key] = value
|
dom.style[key] = value
|
||||||
@ -58,8 +61,8 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
},
|
},
|
||||||
// * 设置页面大小
|
// * 设置页面大小
|
||||||
setPageSize(): void {
|
setPageSize(): void {
|
||||||
this.setPageAttribute('height', `${this.editCanvas.height}px`)
|
this.setPageAttribute('height', `${this.getEditCanvas.height}px`)
|
||||||
this.setPageAttribute('width', `${this.editCanvas.width}px`)
|
this.setPageAttribute('width', `${this.getEditCanvas.width}px`)
|
||||||
},
|
},
|
||||||
// * 设置鼠标位置
|
// * 设置鼠标位置
|
||||||
setMousePosition(x: number, y: number): void {
|
setMousePosition(x: number, y: number): void {
|
||||||
@ -68,28 +71,35 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
},
|
},
|
||||||
// * 计算缩放
|
// * 计算缩放
|
||||||
computedScale() {
|
computedScale() {
|
||||||
if (this.editCanvas.editLayoutDom) {
|
if (this.getEditCanvas.editLayoutDom) {
|
||||||
|
|
||||||
// 现有展示区域
|
// 现有展示区域
|
||||||
const width = this.editCanvas.editLayoutDom.clientWidth - this.editCanvas.offset * 2
|
const width =
|
||||||
const height = this.editCanvas.editLayoutDom.clientHeight - this.editCanvas.offset * 4
|
this.getEditCanvas.editLayoutDom.clientWidth - this.getEditCanvas.offset * 2 - 5
|
||||||
|
const height =
|
||||||
|
this.getEditCanvas.editLayoutDom.clientHeight - this.getEditCanvas.offset * 4
|
||||||
|
|
||||||
// 用户设定大小
|
// 用户设定大小
|
||||||
const editCanvasWidth = this.editCanvas.width
|
const editCanvasWidth = this.getEditCanvas.width
|
||||||
const editCanvasHeight = this.editCanvas.height
|
const editCanvasHeight = this.getEditCanvas.height
|
||||||
|
|
||||||
// 需保持的比例
|
// 需保持的比例
|
||||||
const baseProportion = parseFloat((editCanvasWidth / editCanvasHeight).toFixed(5))
|
const baseProportion = parseFloat(
|
||||||
const currentRate = parseFloat((width / height).toFixed(5))
|
(editCanvasWidth / editCanvasHeight).toFixed(5)
|
||||||
|
)
|
||||||
|
const currentRate = parseFloat((width / height).toFixed(5))
|
||||||
|
|
||||||
if (currentRate > baseProportion) {
|
if (currentRate > baseProportion) {
|
||||||
// 表示更宽
|
// 表示更宽
|
||||||
const scaleWidth = parseFloat(((height * baseProportion) / editCanvasWidth).toFixed(5))
|
const scaleWidth = parseFloat(
|
||||||
this.setScale(parseFloat((scaleWidth).toFixed(5)))
|
((height * baseProportion) / editCanvasWidth).toFixed(5)
|
||||||
|
)
|
||||||
|
this.setScale(parseFloat(scaleWidth.toFixed(5)))
|
||||||
} else {
|
} else {
|
||||||
// 表示更高
|
// 表示更高
|
||||||
const scaleHeight = parseFloat(((width / baseProportion) / editCanvasHeight).toFixed(5))
|
const scaleHeight = parseFloat(
|
||||||
this.setScale(parseFloat((scaleHeight).toFixed(5)))
|
(width / baseProportion / editCanvasHeight).toFixed(5)
|
||||||
|
)
|
||||||
|
this.setScale(parseFloat(scaleHeight.toFixed(5)))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window['$message'].warning('找不到元素')
|
window['$message'].warning('找不到元素')
|
||||||
@ -109,10 +119,13 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
return remove
|
return remove
|
||||||
},
|
},
|
||||||
// * 设置缩放
|
// * 设置缩放
|
||||||
setScale(scale: number): void {
|
setScale(scale: number, sys = true): void {
|
||||||
this.getEditCanvas.scale = scale
|
console.log(scale);
|
||||||
// 设置页面元素
|
|
||||||
this.setPageAttribute('transform', `scale(${scale})`)
|
this.setPageAttribute('transform', `scale(${scale})`)
|
||||||
|
this.getEditCanvas.userScale = scale
|
||||||
|
if (sys) {
|
||||||
|
this.getEditCanvas.scale = scale
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
// 背景斑点需配合 @mixin background-image 使用
|
// 背景斑点需配合 @mixin background-image 使用
|
||||||
.go-point-bg {
|
.go-point-bg {
|
||||||
@include fetch-theme('background-color');
|
@include fetch-theme-custom('background-color', 'background-color1');
|
||||||
background-size: 15px 15px, 15px 15px;
|
background-size: 15px 15px, 15px 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,15 @@
|
|||||||
</n-icon>
|
</n-icon>
|
||||||
</n-space>
|
</n-space>
|
||||||
</div>
|
</div>
|
||||||
<aside class="content">
|
|
||||||
|
<aside class="content" :class="{ hideScroll: hideScrollbar }">
|
||||||
<n-scrollbar x-scrollable>
|
<n-scrollbar x-scrollable>
|
||||||
<n-scrollbar>
|
<n-scrollbar>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</n-scrollbar>
|
</n-scrollbar>
|
||||||
</n-scrollbar>
|
</n-scrollbar>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<div v-if="showBottom" class="bottom go-mt-0">
|
<div v-if="showBottom" class="bottom go-mt-0">
|
||||||
<slot name="bottom"></slot>
|
<slot name="bottom"></slot>
|
||||||
</div>
|
</div>
|
||||||
@ -36,8 +38,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
const { ChevronBackOutlineIcon } = icon.ionicons5
|
const { ChevronBackOutlineIcon } = icon.ionicons5
|
||||||
|
|
||||||
|
const chartEditStore = useChartEditStoreStore()
|
||||||
const emit = defineEmits(['back'])
|
const emit = defineEmits(['back'])
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
@ -66,6 +72,12 @@ defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const hideScrollbar = computed(() => {
|
||||||
|
return (
|
||||||
|
chartEditStore.getEditCanvas.userScale <= chartEditStore.getEditCanvas.scale
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const backHandle = () => {
|
const backHandle = () => {
|
||||||
emit('back')
|
emit('back')
|
||||||
}
|
}
|
||||||
@ -128,5 +140,17 @@ $topHeight: 36px;
|
|||||||
height: calc(100vh - #{$--header-height} - #{$topHeight});
|
height: calc(100vh - #{$--header-height} - #{$topHeight});
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
@include deep() {
|
||||||
|
.content {
|
||||||
|
&.hideScroll {
|
||||||
|
.n-scrollbar-container {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.n-scrollbar-rail {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user