mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 00:02:51 +08:00
fix: 编写拖拽信息
This commit is contained in:
parent
08a24b9e3c
commit
bb7aa78738
4
src/enums/editPageEnum.ts
Normal file
4
src/enums/editPageEnum.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// 页面拖拽键名
|
||||||
|
export enum DragKeyEnum {
|
||||||
|
DROG_KEY = 'ChartData'
|
||||||
|
}
|
11
src/packages/components/Chart/Bars/BarCommon/config.ts
Normal file
11
src/packages/components/Chart/Bars/BarCommon/config.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { getUUID } from '@/utils'
|
||||||
|
|
||||||
|
export class Config {
|
||||||
|
name: string = 'BarCommon'
|
||||||
|
id: string = getUUID()
|
||||||
|
attr = { w: 500, h: 300 }
|
||||||
|
// 图表的
|
||||||
|
public config = {
|
||||||
|
global: {}
|
||||||
|
}
|
||||||
|
}
|
7
src/packages/components/Chart/Bars/BarCommon/config.vue
Normal file
7
src/packages/components/Chart/Bars/BarCommon/config.vue
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<div>配置项目</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
</script>
|
@ -1,13 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
柱状图组件渲染
|
这里是柱状图组件渲染
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
const props = defineProps({
|
||||||
|
chart: {
|
||||||
|
type: Object,
|
||||||
|
require: true
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
@ -8,6 +8,7 @@ import { ChartList } from '@/packages/components/Chart/index'
|
|||||||
import { DecorateList } from '@/packages/components/Decorate/index'
|
import { DecorateList } from '@/packages/components/Decorate/index'
|
||||||
import { InformationList } from '@/packages/components/Information/index'
|
import { InformationList } from '@/packages/components/Information/index'
|
||||||
import { TableList } from '@/packages/components/Table/index'
|
import { TableList } from '@/packages/components/Table/index'
|
||||||
|
import {} from './useCreate'
|
||||||
|
|
||||||
// 所有图表
|
// 所有图表
|
||||||
let packagesList: PackagesType = {
|
let packagesList: PackagesType = {
|
||||||
|
9
src/packages/useCreate.ts
Normal file
9
src/packages/useCreate.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { ConfigType } from '@/packages/index.d'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 获取目标拖拽组件信息
|
||||||
|
* @param drayData
|
||||||
|
*/
|
||||||
|
export const createComponent = (drayData: Exclude<ConfigType, 'node'>) => {
|
||||||
|
|
||||||
|
}
|
@ -5,7 +5,7 @@ import { PageEnum } from '@/enums/pageEnum'
|
|||||||
export function createRouterGuards(router: Router) {
|
export function createRouterGuards(router: Router) {
|
||||||
// 前置
|
// 前置
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
const Loading = window['$loading'] || null;
|
const Loading = window['$loading'];
|
||||||
Loading && Loading.start();
|
Loading && Loading.start();
|
||||||
const isErrorPage = router.getRoutes().findIndex((item) => item.name === to.name);
|
const isErrorPage = router.getRoutes().findIndex((item) => item.name === to.name);
|
||||||
if (isErrorPage === -1) {
|
if (isErrorPage === -1) {
|
||||||
@ -15,7 +15,7 @@ export function createRouterGuards(router: Router) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.afterEach((to, _, failure) => {
|
router.afterEach((to, _, failure) => {
|
||||||
const Loading = window['$loading'] || null;
|
const Loading = window['$loading'];
|
||||||
document.title = (to?.meta?.title as string) || document.title;
|
document.title = (to?.meta?.title as string) || document.title;
|
||||||
Loading && Loading.finish();
|
Loading && Loading.finish();
|
||||||
})
|
})
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
// 编辑区域大小
|
// 编辑区域大小
|
||||||
export enum EditCanvasTypeEnum {
|
export enum EditCanvasTypeEnum {
|
||||||
EDITLAYOUTDOM = 'editLayoutDom',
|
EDIT_LAYOUT_DOM = 'editLayoutDom',
|
||||||
EDITCONTENTDON = 'editContentDom',
|
EDIT_CONTENT_DOM = 'editContentDom',
|
||||||
WIDTH = 'width',
|
WIDTH = 'width',
|
||||||
HEIGHT = 'height',
|
HEIGHT = 'height',
|
||||||
OFFSET = 'offset',
|
OFFSET = 'offset',
|
||||||
SCALE = 'scale',
|
SCALE = 'scale',
|
||||||
USERSCALE = 'userScale',
|
USER_SCALE = 'userScale',
|
||||||
LOCKSCALE = 'lockScale',
|
LOCK_SCALE = 'lockScale',
|
||||||
BACKGROUND = 'background'
|
BACKGROUND = 'background',
|
||||||
}
|
}
|
||||||
export type EditCanvasType = {
|
export type EditCanvasType = {
|
||||||
// 编辑区域 DOM
|
// 编辑区域 DOM
|
||||||
[EditCanvasTypeEnum.EDITLAYOUTDOM]: HTMLElement | null
|
[EditCanvasTypeEnum.EDIT_LAYOUT_DOM]: HTMLElement | null
|
||||||
[EditCanvasTypeEnum.EDITCONTENTDON]: HTMLElement | null
|
[EditCanvasTypeEnum.EDIT_CONTENT_DOM]: HTMLElement | null
|
||||||
// 大屏宽度
|
// 大屏宽度
|
||||||
[EditCanvasTypeEnum.WIDTH]: number
|
[EditCanvasTypeEnum.WIDTH]: number
|
||||||
// 大屏高度
|
// 大屏高度
|
||||||
@ -23,9 +23,9 @@ export type EditCanvasType = {
|
|||||||
// 缩放
|
// 缩放
|
||||||
[EditCanvasTypeEnum.SCALE]: number
|
[EditCanvasTypeEnum.SCALE]: number
|
||||||
// 缩放
|
// 缩放
|
||||||
[EditCanvasTypeEnum.USERSCALE]: number
|
[EditCanvasTypeEnum.USER_SCALE]: number
|
||||||
// 锁定缩放
|
// 锁定缩放
|
||||||
[EditCanvasTypeEnum.LOCKSCALE]: boolean
|
[EditCanvasTypeEnum.LOCK_SCALE]: boolean
|
||||||
// 背景色
|
// 背景色
|
||||||
[EditCanvasTypeEnum.BACKGROUND]?: string
|
[EditCanvasTypeEnum.BACKGROUND]?: string
|
||||||
}
|
}
|
||||||
@ -45,9 +45,12 @@ export type MousePositionType = {
|
|||||||
// Store 类型
|
// Store 类型
|
||||||
export enum chartEditStoreEnum {
|
export enum chartEditStoreEnum {
|
||||||
EDITCANVAS = 'editCanvas',
|
EDITCANVAS = 'editCanvas',
|
||||||
MOUSEPOSITION = 'mousePosition'
|
MOUSEPOSITION = 'mousePosition',
|
||||||
|
COMPONENT_LIST = 'componentList'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface chartEditStoreType {
|
export interface chartEditStoreType {
|
||||||
[chartEditStoreEnum.EDITCANVAS]: EditCanvasType
|
[chartEditStoreEnum.EDITCANVAS]: EditCanvasType
|
||||||
[chartEditStoreEnum.MOUSEPOSITION]: MousePositionType
|
[chartEditStoreEnum.MOUSEPOSITION]: MousePositionType
|
||||||
|
[chartEditStoreEnum.COMPONENT_LIST]: any[]
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
mousePosition: {
|
mousePosition: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
}
|
},
|
||||||
|
componentList: []
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getMousePosition(): MousePositionType {
|
getMousePosition(): MousePositionType {
|
||||||
@ -41,8 +42,15 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
getEditCanvas(): EditCanvasType {
|
getEditCanvas(): EditCanvasType {
|
||||||
return this.editCanvas
|
return this.editCanvas
|
||||||
},
|
},
|
||||||
|
getComponentList(): any[] {
|
||||||
|
return this.componentList
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
// * 新增组件列表
|
||||||
|
addComponentList<T>(chartData:T):void {
|
||||||
|
this.componentList.push(chartData)
|
||||||
|
},
|
||||||
// * 设置数据项
|
// * 设置数据项
|
||||||
setEditCanvasItem<T extends keyof EditCanvasType, K extends EditCanvasType[T]>(key: T, value: K) {
|
setEditCanvasItem<T extends keyof EditCanvasType, K extends EditCanvasType[T]>(key: T, value: K) {
|
||||||
this.editCanvas[key] = value
|
this.editCanvas[key] = value
|
||||||
|
@ -7,7 +7,7 @@ import debounce from 'lodash/debounce'
|
|||||||
* * 生成一个不重复的ID
|
* * 生成一个不重复的ID
|
||||||
* @param { Number } randomLength
|
* @param { Number } randomLength
|
||||||
*/
|
*/
|
||||||
export function getUUID(randomLength: number) {
|
export function getUUID(randomLength: number = 10) {
|
||||||
return Number(
|
return Number(
|
||||||
Math.random().toString().substr(2, randomLength) + Date.now()
|
Math.random().toString().substr(2, randomLength) + Date.now()
|
||||||
).toString(36)
|
).toString(36)
|
||||||
|
@ -28,6 +28,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { AppleControlBtn } from '@/components/AppleControlBtn/index'
|
import { AppleControlBtn } from '@/components/AppleControlBtn/index'
|
||||||
import { requireFallbackImg } from '@/utils'
|
import { requireFallbackImg } from '@/utils'
|
||||||
|
import { DragKeyEnum } from '@/enums/editPageEnum'
|
||||||
|
import { ConfigType } from '@/packages/index.d'
|
||||||
|
import omit from 'lodash/omit'
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
menuOptions: {
|
menuOptions: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@ -36,11 +40,9 @@ defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 拖拽处理
|
// 拖拽处理
|
||||||
const handleDragStart = (e: DragEvent, item: any) => {
|
const handleDragStart = (e: DragEvent, item: ConfigType) => {
|
||||||
if (e.dataTransfer instanceof Object && e.target instanceof Object) {
|
// 将配置项绑定到拖拽属性上
|
||||||
e.dataTransfer.setData('chartName', item.key)
|
e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['node', 'image'])))
|
||||||
e.dataTransfer.setData('chartNode', item.node)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ const selectHandle = (v: number) => {
|
|||||||
// 点击锁处理
|
// 点击锁处理
|
||||||
const lockHandle = () => {
|
const lockHandle = () => {
|
||||||
chartEditStore.setEditCanvasItem(
|
chartEditStore.setEditCanvasItem(
|
||||||
chartEditStoreEnum.LOCKSCALE,
|
chartEditStoreEnum.LOCK_SCALE,
|
||||||
!lockScale.value
|
!lockScale.value
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
35
src/views/chart/components/ContentEdit/hooks/useDrop.hook.ts
Normal file
35
src/views/chart/components/ContentEdit/hooks/useDrop.hook.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { toRefs } from 'vue'
|
||||||
|
import { useThrottleFn } from '@vueuse/core'
|
||||||
|
import { getChartEditStore } from './useStore.hook'
|
||||||
|
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
|
import { DragKeyEnum } from '@/enums/editPageEnum'
|
||||||
|
|
||||||
|
const chartEditStore = getChartEditStore()
|
||||||
|
const { scale } = toRefs(chartEditStore.getEditCanvas)
|
||||||
|
|
||||||
|
// * 拖拽中
|
||||||
|
export const handleDrop = (e: DragEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
const Loading = window['$loading']
|
||||||
|
try {
|
||||||
|
Loading.start()
|
||||||
|
|
||||||
|
const chartName = e!.dataTransfer!.getData(DragKeyEnum.DROG_KEY)
|
||||||
|
console.log(chartName)
|
||||||
|
chartEditStore.setMousePosition(e.offsetX, e.offsetY)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
Loading.finish()
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
Loading.error()
|
||||||
|
window['$message'].success(`添加图表失败,请保存数据后刷新重试`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// * 拖拽结束
|
||||||
|
export const handleDragOver = (e: DragEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy'
|
||||||
|
}
|
@ -6,13 +6,13 @@ const chartEditStore = getChartEditStore()
|
|||||||
|
|
||||||
export const useLayout = () => {
|
export const useLayout = () => {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 设置 Dom 值(ref 不生效先用document)
|
// 设置 Dom 值(ref 不生效先用 document)
|
||||||
chartEditStore.setEditCanvasItem(
|
chartEditStore.setEditCanvasItem(
|
||||||
EditCanvasTypeEnum.EDITLAYOUTDOM,
|
EditCanvasTypeEnum.EDIT_LAYOUT_DOM,
|
||||||
document.getElementById('go-chart-edit-layout')
|
document.getElementById('go-chart-edit-layout')
|
||||||
)
|
)
|
||||||
chartEditStore.setEditCanvasItem(
|
chartEditStore.setEditCanvasItem(
|
||||||
EditCanvasTypeEnum.EDITCONTENTDON,
|
EditCanvasTypeEnum.EDIT_CONTENT_DOM,
|
||||||
document.getElementById('go-chart-edit-content')
|
document.getElementById('go-chart-edit-content')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
:showTop="false"
|
:showTop="false"
|
||||||
:showBottom="true"
|
:showBottom="true"
|
||||||
:depth="1"
|
:depth="1"
|
||||||
|
@drop="handleDrop"
|
||||||
|
@dragover="handleDragOver"
|
||||||
>
|
>
|
||||||
<div id="go-chart-edit-content">
|
<div id="go-chart-edit-content">
|
||||||
<!-- 中间区域 -->
|
<!-- 中间区域 -->
|
||||||
@ -19,15 +21,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onUnmounted, onMounted } from 'vue'
|
import { onUnmounted, onMounted,toRefs } from 'vue'
|
||||||
import { ContentBox } from '../ContentBox/index'
|
import { ContentBox } from '../ContentBox/index'
|
||||||
import { EditRange } from './components/EditRange'
|
import { EditRange } from './components/EditRange'
|
||||||
import { EditBottom } from './components/EditBottom'
|
import { EditBottom } from './components/EditBottom'
|
||||||
import { useLayout } from './hooks/useLayout.hook'
|
import { useLayout } from './hooks/useLayout.hook'
|
||||||
|
import { handleDrop, handleDragOver } from './hooks/useDrop.hook'
|
||||||
|
|
||||||
// 布局处理
|
// 布局处理
|
||||||
useLayout()
|
useLayout()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@ -35,7 +37,7 @@ useLayout()
|
|||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@include background-image("background-point");
|
@include background-image('background-point');
|
||||||
@extend .go-point-bg;
|
@extend .go-point-bg;
|
||||||
@include goId(chart-edit-content) {
|
@include goId(chart-edit-content) {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -47,7 +49,7 @@ useLayout()
|
|||||||
@extend .go-transition;
|
@extend .go-transition;
|
||||||
&.content-resize {
|
&.content-resize {
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
@include hover-border-color("hover-border-color");
|
@include hover-border-color('hover-border-color');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user