mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-24 02:16:10 +08:00
fix: 新增组件拖拽
This commit is contained in:
parent
bbeba4a8d8
commit
7a3af81d7a
@ -12,10 +12,8 @@
|
|||||||
"animate.css": "^4.1.1",
|
"animate.css": "^4.1.1",
|
||||||
"axios": "^0.23.0",
|
"axios": "^0.23.0",
|
||||||
"crypto-ts": "^1.0.2",
|
"crypto-ts": "^1.0.2",
|
||||||
"mockjs": "^1.1.0",
|
|
||||||
"naive-ui": "^2.24.1",
|
"naive-ui": "^2.24.1",
|
||||||
"pinia": "^2.0.6",
|
"pinia": "^2.0.6",
|
||||||
"plop": "^3.0.5",
|
|
||||||
"screenfull": "^6.0.0",
|
"screenfull": "^6.0.0",
|
||||||
"vue": "^3.2.16",
|
"vue": "^3.2.16",
|
||||||
"vue-i18n": "^9.2.0-beta.23",
|
"vue-i18n": "^9.2.0-beta.23",
|
||||||
@ -31,12 +29,15 @@
|
|||||||
"@vue/compiler-sfc": "^3.2.20",
|
"@vue/compiler-sfc": "^3.2.20",
|
||||||
"@vueuse/core": "^7.3.0",
|
"@vueuse/core": "^7.3.0",
|
||||||
"default-passive-events": "^2.0.0",
|
"default-passive-events": "^2.0.0",
|
||||||
|
"echarts": "^5.2.2",
|
||||||
"eslint": "^8.4.1",
|
"eslint": "^8.4.1",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"eslint-plugin-vue": "^8.2.0",
|
"eslint-plugin-vue": "^8.2.0",
|
||||||
"lodash": "~4.17.21",
|
"lodash": "~4.17.21",
|
||||||
|
"mockjs": "^1.1.0",
|
||||||
|
"plop": "^3.0.5",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
"sass": "^1.43.2",
|
"sass": "^1.43.2",
|
||||||
"sass-loader": "^12.2.0",
|
"sass-loader": "^12.2.0",
|
||||||
@ -45,6 +46,7 @@
|
|||||||
"vite-plugin-importer": "^0.2.5",
|
"vite-plugin-importer": "^0.2.5",
|
||||||
"vite-plugin-mock": "^2.9.6",
|
"vite-plugin-mock": "^2.9.6",
|
||||||
"vite-plugin-style-import": "^1.2.1",
|
"vite-plugin-style-import": "^1.2.1",
|
||||||
|
"vue-echarts": "^6.0.2",
|
||||||
"vue-tsc": "^0.28.7"
|
"vue-tsc": "^0.28.7"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
|
449
pnpm-lock.yaml
generated
449
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,19 @@
|
|||||||
import { getUUID } from '@/utils'
|
import { getUUID } from '@/utils'
|
||||||
|
import { BarCommonConfig } from './index'
|
||||||
|
|
||||||
export default class Config {
|
export default class Config {
|
||||||
name: string = 'BarCommon'
|
|
||||||
id: string = getUUID()
|
id: string = getUUID()
|
||||||
attr = { w: 500, h: 300 }
|
key: string = BarCommonConfig.key
|
||||||
// 图表的
|
attr = { x: 0, y: 0, w: 500, h: 300 }
|
||||||
|
|
||||||
|
// 图表配置项
|
||||||
public config = {
|
public config = {
|
||||||
global: {}
|
global: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置坐标
|
||||||
|
setPosition(x: number, y: number) {
|
||||||
|
this.attr.x = x
|
||||||
|
this.attr.y = y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,8 @@ import { ChartList } from '@/packages/components/Charts/index'
|
|||||||
import { DecorateList } from '@/packages/components/Decorates/index'
|
import { DecorateList } from '@/packages/components/Decorates/index'
|
||||||
import { InformationList } from '@/packages/components/Informations/index'
|
import { InformationList } from '@/packages/components/Informations/index'
|
||||||
import { TableList } from '@/packages/components/Tables/index'
|
import { TableList } from '@/packages/components/Tables/index'
|
||||||
import {} from './useCreate'
|
|
||||||
|
|
||||||
// 所有图表
|
// * 所有图表
|
||||||
let packagesList: PackagesType = {
|
let packagesList: PackagesType = {
|
||||||
[PackagesCategoryEnum.CHARTS]: ChartList,
|
[PackagesCategoryEnum.CHARTS]: ChartList,
|
||||||
[PackagesCategoryEnum.INFORMATION]: InformationList,
|
[PackagesCategoryEnum.INFORMATION]: InformationList,
|
||||||
@ -18,7 +17,7 @@ let packagesList: PackagesType = {
|
|||||||
[PackagesCategoryEnum.DECORATES]: DecorateList
|
[PackagesCategoryEnum.DECORATES]: DecorateList
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册
|
// * 注册
|
||||||
const packagesInstall = (app: App): void => {
|
const packagesInstall = (app: App): void => {
|
||||||
for (const item in packagesList) {
|
for (const item in packagesList) {
|
||||||
const chartList: ConfigType[] = (packagesList as any)[item]
|
const chartList: ConfigType[] = (packagesList as any)[item]
|
||||||
@ -28,4 +27,15 @@ const packagesInstall = (app: App): void => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { packagesList, packagesInstall }
|
/**
|
||||||
|
* * 获取目标拖拽组件信息
|
||||||
|
* @param dropData
|
||||||
|
*/
|
||||||
|
const createComponent = async (dropData: ConfigType) => {
|
||||||
|
const { category } = dropData
|
||||||
|
const key = dropData.key.substring(1)
|
||||||
|
const chart = await import(`./components/${dropData.package}/${category}/${key}/config.ts`)
|
||||||
|
return new chart.default()
|
||||||
|
}
|
||||||
|
|
||||||
|
export { packagesList, packagesInstall, createComponent }
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { ConfigType, PackagesCategoryEnum } from '@/packages/index.d'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * 获取目标拖拽组件信息
|
|
||||||
* @param drayData
|
|
||||||
*/
|
|
||||||
export const createComponent = async (drayData: Exclude<ConfigType, 'node'>) => {
|
|
||||||
const chart = await import(`./${drayData.categoryName}`)
|
|
||||||
return new chart()
|
|
||||||
}
|
|
@ -44,15 +44,27 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
},
|
},
|
||||||
getComponentList(): any[] {
|
getComponentList(): any[] {
|
||||||
return this.componentList
|
return this.componentList
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
// * 新增组件列表
|
// * 新增组件列表
|
||||||
addComponentList<T>(chartData:T):void {
|
addComponentList<T>(chartData: T): void {
|
||||||
this.componentList.push(chartData)
|
this.componentList.push(chartData)
|
||||||
},
|
},
|
||||||
|
// * 删除组件列表
|
||||||
|
removeComponentList<T extends { key: string }>(chartData: T): void {
|
||||||
|
const i = this.componentList.findIndex(e => e.key === chartData.key)
|
||||||
|
if (i !== -1) {
|
||||||
|
this.componentList.splice(i, 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
window['$message'].success(`图表删除失败,无法找到此元素`)
|
||||||
|
},
|
||||||
// * 设置数据项
|
// * 设置数据项
|
||||||
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
|
||||||
},
|
},
|
||||||
// * 设置页面样式属性
|
// * 设置页面样式属性
|
||||||
@ -72,7 +84,7 @@ export const useChartEditStoreStore = defineStore({
|
|||||||
dom.classList.add('content-resize')
|
dom.classList.add('content-resize')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
dom.classList.remove('content-resize')
|
dom.classList.remove('content-resize')
|
||||||
}, 600);
|
}, 600)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// * 设置页面大小
|
// * 设置页面大小
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="go-edit-bottom">
|
<div class="go-edit-bottom">
|
||||||
<n-popselect :options="shortcutKeyOptions" size="medium">
|
<n-space>
|
||||||
<n-button class="scale-btn" secondary size="mini">
|
<n-text>
|
||||||
<n-icon class="lock-icon" size="18" :depth="2">
|
滤镜设置
|
||||||
<DicomOverlayIcon />
|
</n-text>
|
||||||
</n-icon>
|
<!-- 快捷键提示 -->
|
||||||
</n-button>
|
<n-popselect :options="shortcutKeyOptions" size="medium">
|
||||||
</n-popselect>
|
<n-button class="scale-btn" secondary size="mini">
|
||||||
|
<n-icon class="lock-icon" size="18" :depth="3">
|
||||||
|
<DicomOverlayIcon />
|
||||||
|
</n-icon>
|
||||||
|
</n-button>
|
||||||
|
</n-popselect>
|
||||||
|
</n-space>
|
||||||
<n-space class="bottom-ri">
|
<n-space class="bottom-ri">
|
||||||
<!-- 缩放比例 -->
|
<!-- 缩放比例 -->
|
||||||
<n-select
|
<n-select
|
||||||
@ -55,11 +60,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, toRefs, shallowReactive, watchEffect } from 'vue'
|
import { reactive, ref, toRefs, watchEffect } from 'vue'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
const { LockClosedOutlineIcon, LockOpenOutlineIcon } = icon.ionicons5
|
const { LockClosedOutlineIcon, LockOpenOutlineIcon } = icon.ionicons5
|
||||||
const { DicomOverlayIcon } = icon.carbon
|
const { DicomOverlayIcon } = icon.carbon
|
||||||
import { getChartEditStore, getChartEditStoreEnum } from '../../hooks/useStore.hook'
|
import {
|
||||||
|
getChartEditStore,
|
||||||
|
getChartEditStoreEnum
|
||||||
|
} from '../../hooks/useStore.hook'
|
||||||
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
||||||
|
|
||||||
// 全局颜色
|
// 全局颜色
|
||||||
@ -71,7 +79,7 @@ const chartEditStoreEnum = getChartEditStoreEnum()
|
|||||||
const { lockScale, scale } = toRefs(chartEditStore.getEditCanvas)
|
const { lockScale, scale } = toRefs(chartEditStore.getEditCanvas)
|
||||||
|
|
||||||
// 缩放选项
|
// 缩放选项
|
||||||
let filterOptions = reactive([
|
let filterOptions = [
|
||||||
{
|
{
|
||||||
label: '自适应',
|
label: '自适应',
|
||||||
value: 0
|
value: 0
|
||||||
@ -92,7 +100,7 @@ let filterOptions = reactive([
|
|||||||
label: '200%',
|
label: '200%',
|
||||||
value: 200
|
value: 200
|
||||||
}
|
}
|
||||||
])
|
]
|
||||||
|
|
||||||
// 选择值
|
// 选择值
|
||||||
const filterValue = ref('')
|
const filterValue = ref('')
|
||||||
@ -127,7 +135,7 @@ const sliderMaks = reactive({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 快捷键
|
// 快捷键
|
||||||
const shortcutKeyOptions = shallowReactive([
|
const shortcutKeyOptions = [
|
||||||
{
|
{
|
||||||
label: '键盘快捷键列表',
|
label: '键盘快捷键列表',
|
||||||
value: '1'
|
value: '1'
|
||||||
@ -136,7 +144,7 @@ const shortcutKeyOptions = shallowReactive([
|
|||||||
label: 'Ctrl + C 复制',
|
label: 'Ctrl + C 复制',
|
||||||
value: '2'
|
value: '2'
|
||||||
}
|
}
|
||||||
])
|
]
|
||||||
|
|
||||||
// 监听 scale 变化
|
// 监听 scale 变化
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
|
@ -3,27 +3,36 @@ import { useThrottleFn } from '@vueuse/core'
|
|||||||
import { getChartEditStore } from './useStore.hook'
|
import { getChartEditStore } from './useStore.hook'
|
||||||
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { DragKeyEnum } from '@/enums/editPageEnum'
|
import { DragKeyEnum } from '@/enums/editPageEnum'
|
||||||
|
import { createComponent } from '@/packages'
|
||||||
|
import { ConfigType } from '@/packages/index.d'
|
||||||
|
|
||||||
const chartEditStore = getChartEditStore()
|
const chartEditStore = getChartEditStore()
|
||||||
const { scale } = toRefs(chartEditStore.getEditCanvas)
|
const { scale } = toRefs(chartEditStore.getEditCanvas)
|
||||||
|
|
||||||
// * 拖拽中
|
// * 拖拽中
|
||||||
export const handleDrop = (e: DragEvent) => {
|
export const handleDrop = async (e: DragEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const Loading = window['$loading']
|
const Loading = window['$loading']
|
||||||
try {
|
try {
|
||||||
Loading.start()
|
Loading.start()
|
||||||
|
|
||||||
const chartName = e!.dataTransfer!.getData(DragKeyEnum.DROG_KEY)
|
const drayDataString = e!.dataTransfer!.getData(DragKeyEnum.DROG_KEY)
|
||||||
console.log(chartName)
|
|
||||||
chartEditStore.setMousePosition(e.offsetX, e.offsetY)
|
const dropData: Exclude<ConfigType, ['node', 'image']> = JSON.parse(
|
||||||
|
drayDataString
|
||||||
|
)
|
||||||
|
|
||||||
|
let newComponent= await createComponent(dropData)
|
||||||
|
newComponent.setPosition(e.offsetX, e.offsetY)
|
||||||
|
|
||||||
|
chartEditStore.addComponentList(newComponent)
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Loading.finish()
|
Loading.finish()
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Loading.error()
|
Loading.error()
|
||||||
window['$message'].success(`添加图表失败,请保存数据后刷新重试`)
|
window['$message'].success(`图表正在研发中, 敬请期待...`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,12 @@
|
|||||||
>
|
>
|
||||||
<div id="go-chart-edit-content">
|
<div id="go-chart-edit-content">
|
||||||
<!-- 中间区域 -->
|
<!-- 中间区域 -->
|
||||||
<EditRange></EditRange>
|
<EditRange>
|
||||||
|
<!-- 组件名称会重复,必须使用 id -->
|
||||||
|
<div v-for="item in chartEditStore.getComponentList" :key="item.id">
|
||||||
|
<component :is="item.key" />
|
||||||
|
</div>
|
||||||
|
</EditRange>
|
||||||
</div>
|
</div>
|
||||||
<!-- 底部控制 -->
|
<!-- 底部控制 -->
|
||||||
<template #bottom>
|
<template #bottom>
|
||||||
@ -21,12 +26,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onUnmounted, onMounted,toRefs } 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'
|
import { handleDrop, handleDragOver } from './hooks/useDrop.hook'
|
||||||
|
import { getChartEditStore } from './hooks/useStore.hook'
|
||||||
|
|
||||||
|
const chartEditStore = getChartEditStore()
|
||||||
|
|
||||||
// 布局处理
|
// 布局处理
|
||||||
useLayout()
|
useLayout()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user