fix: 新增图层

This commit is contained in:
MTrun 2022-01-29 11:44:51 +08:00
parent a2a3a31df5
commit 3acf2fe732
14 changed files with 108 additions and 28 deletions

View File

@ -9,8 +9,12 @@ build:
lint: lint:
npm run lint npm run lint
new:
npm run new
help: help:
@echo " make dev 开发模式" @echo " make dev 开发模式"
@echo " make build 编译模式" @echo " make build 编译模式"
@echo " make new 通过自动化流程创建代码"
@echo " make lint 格式校验" @echo " make lint 格式校验"

View File

@ -1,15 +1,15 @@
import { getUUID } from '@/utils' import { getUUID } from '@/utils'
import { BarCommonConfig } from './index' import { BarCommonConfig } from './index'
import { ConfigType } from '@/packages/index.d'
export const chartSize = { import omit from 'lodash/omit'
w: 500,
h: 300
}
export default class Config { export default class Config {
private id: string = getUUID() private id: string = getUUID()
private key: string = BarCommonConfig.key private key: string = BarCommonConfig.key
public attr = { x: 0, y: 0, ...chartSize }
chartData: Exclude<ConfigType, ['node']> = omit(BarCommonConfig, ['node'])
public attr = { x: 0, y: 0, w: 500, h: 300 }
// 图表配置项 // 图表配置项
public config = { public config = {

View File

@ -2,7 +2,6 @@ import BarCommon from './index.vue'
import image from '@/assets/images/chart/charts/bar_x.png' import image from '@/assets/images/chart/charts/bar_x.png'
import { ConfigType, PackagesCategoryEnum } from '@/packages/index.d' import { ConfigType, PackagesCategoryEnum } from '@/packages/index.d'
import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d' import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
import { chartSize } from './config'
export const BarCommonConfig: ConfigType = { export const BarCommonConfig: ConfigType = {
key: 'VBarCommon', key: 'VBarCommon',
@ -12,5 +11,4 @@ export const BarCommonConfig: ConfigType = {
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: BarCommon, node: BarCommon,
image: image, image: image,
chartData: { chartSize }
} }

View File

@ -7,12 +7,6 @@ export type ConfigType = {
category: string category: string
categoryName: string categoryName: string
package: string package: string
chartData: {
chartSize: {
w: number
h: number
}
}
node: Component node: Component
image: string | (() => Promise<typeof import('*.png')>) image: string | (() => Promise<typeof import('*.png')>)
[T: string]: unknown [T: string]: unknown

View File

@ -42,15 +42,22 @@ export type MousePositionType = {
[EditCanvasTypeEnum.Y]: number [EditCanvasTypeEnum.Y]: number
} }
// 操作目标
export type TargetChartType = {
index: number
}
// Store 类型 // Store 类型
export enum chartEditStoreEnum { export enum chartEditStoreEnum {
EDITCANVAS = 'editCanvas', EDITCANVAS = 'editCanvas',
MOUSEPOSITION = 'mousePosition', MOUSEPOSITION = 'mousePosition',
COMPONENT_LIST = 'componentList' COMPONENT_LIST = 'componentList',
TARGET_CHART = 'targetChart'
} }
export interface chartEditStoreType { export interface chartEditStoreType {
[chartEditStoreEnum.EDITCANVAS]: EditCanvasType [chartEditStoreEnum.EDITCANVAS]: EditCanvasType
[chartEditStoreEnum.MOUSEPOSITION]: MousePositionType [chartEditStoreEnum.MOUSEPOSITION]: MousePositionType
[chartEditStoreEnum.TARGET_CHART]: TargetChartType
[chartEditStoreEnum.COMPONENT_LIST]: any[] [chartEditStoreEnum.COMPONENT_LIST]: any[]
} }

View File

@ -34,6 +34,9 @@ export const useChartEditStoreStore = defineStore({
x: 0, x: 0,
y: 0 y: 0
}, },
targetChart: {
index: 0
},
componentList: [] componentList: []
}), }),
getters: { getters: {

View File

@ -0,0 +1,10 @@
export interface HistoryStackType {
}
export interface chartHistoryStoreType {
// 后退栈
backStack: [],
// 前进栈
forwardStack: []
}

View File

@ -0,0 +1,11 @@
import { defineStore } from 'pinia'
import { chartHistoryStoreType } from './chartHistoryStore.d'
import { setLocalStorage, getLocalStorage } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum'
export const useChartHistoryStoreStore = defineStore({
id: 'useChartHistoryStore',
state: (): chartHistoryStoreType => ({}),
getters: {},
actions: {}
})

View File

@ -24,7 +24,7 @@ $dark: (
linear-gradient(90deg, transparent 14px, $--color-text-2 0) linear-gradient(90deg, transparent 14px, $--color-text-2 0)
), ),
// hover 边框颜色 // hover 边框颜色
hover-border-color: #55606e, hover-border-color: $--color-dark-bg-5,
// 阴影 // 阴影
box-shadow: 0 8px 20px #5252521f box-shadow: 0 8px 20px #5252521f

View File

@ -26,7 +26,7 @@ $light: (
linear-gradient(90deg, transparent 14px, $--color-dark-bg-5 0) linear-gradient(90deg, transparent 14px, $--color-dark-bg-5 0)
), ),
// hover 边框颜色 // hover 边框颜色
hover-border-color: $--color-light-bg-1, hover-border-color: $--color-light-bg-4,
// 阴影 // 阴影
box-shadow: 0 8px 20px #0000001a box-shadow: 0 8px 20px #0000001a
); );

View File

@ -7,6 +7,10 @@
transition: all 0.4s; transition: all 0.4s;
} }
.go-transition-quick {
transition: all 0.2s;
}
.go-flex-center { .go-flex-center {
display: flex; display: flex;
justify-content: center; justify-content: center;

View File

@ -23,8 +23,7 @@ export const handleDrop = async (e: DragEvent) => {
// 创建新图表组件 // 创建新图表组件
let newComponent = await createComponent(dropData) let newComponent = await createComponent(dropData)
const { w, h } = dropData.chartData.chartSize newComponent.setPosition(e.offsetX - newComponent.attr.w / 2, e.offsetY - newComponent.attr.h / 2)
newComponent.setPosition(e.offsetX - w / 2, e.offsetY - h / 2)
chartEditStore.addComponentList(newComponent) chartEditStore.addComponentList(newComponent)
loadingFinish() loadingFinish()

View File

@ -1,17 +1,63 @@
<template> <template>
<div class="go-content-layers-list-item"> <div class="go-content-layers-list-item go-flex-center">
<n-space> <n-image
<div>图片</div> class="list-img"
<b-text> object-fit="contain"
文字 preview-disabled
:src="image"
:fallback-src="requireFallbackImg()"
/>
<n-ellipsis>
<b-text class="list-text">
{{ title }}
</b-text> </b-text>
</n-space> </n-ellipsis>
</div> </div>
</template> </template>
<script setup lang="ts"></script> <script setup lang="ts">
import { ref, toRefs } from 'vue'
import { requireFallbackImg } from '@/utils'
import { useDesignStore } from '@/store/modules/designStore/designStore'
//
const designStore = useDesignStore()
const themeColor = ref(designStore.getAppTheme)
const props = defineProps({
componentData: {
type: Object,
required: true
}
})
const { image, title } = toRefs(props.componentData.chartData)
</script>
<style lang="scss" scoped> <style lang="scss" scoped>
@include go(content-layers-list-items) { $centerHeight: 40px;
$textSize: 10px;
@include go(content-layers-list-item) {
justify-content: start !important;
padding: 6px 10px;
cursor: pointer;
margin-bottom: 5px;
@extend .go-transition-quick;
&:hover {
@include filter-bg-color('background-color4');
color: v-bind('themeColor');
}
.list-img {
flex-shrink: 0;
height: $centerHeight;
border-radius: 5px;
overflow: hidden;
border: 1px solid;
padding: 2px;
@include hover-border-color('hover-border-color')
}
.list-text {
padding-left: 10px;
font-size: $textSize;
}
} }
</style> </style>

View File

@ -13,7 +13,11 @@
</template> </template>
<!-- 图层内容 --> <!-- 图层内容 -->
<ListItem v-for="item in chartEditStore.getComponentList" :key="item.id"/> <ListItem
v-for="item in chartEditStore.getComponentList"
:key="item.id"
:componentData="item"
/>
</ContentBox> </ContentBox>
</template> </template>