featr: 新增图层选中的样式

This commit is contained in:
MTrun 2022-01-29 21:44:22 +08:00
parent b3d723d323
commit ab8c84e1b9
7 changed files with 137 additions and 45 deletions

View File

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

View File

@ -1,6 +1,6 @@
import { Component } from '@/router/types' import { Component } from '@/router/types'
// import { ConfigType } from '@/packages/index.d' // 组件配置
export type ConfigType = { export type ConfigType = {
key: string key: string
title: string title: string
@ -12,6 +12,16 @@ export type ConfigType = {
[T: string]: unknown [T: string]: unknown
} }
// 组件实例类
export interface CreateComponentType {
id: string
key: string
chartData: ConfigType
config: object
setPosition: Function
}
// 包分类枚举
export enum PackagesCategoryEnum { export enum PackagesCategoryEnum {
CHARTS = 'Charts', CHARTS = 'Charts',
TABLES = 'Tables', TABLES = 'Tables',
@ -19,6 +29,7 @@ export enum PackagesCategoryEnum {
DECORATES = 'Decorates' DECORATES = 'Decorates'
} }
// 包分类名称
export enum PackagesCategoryName { export enum PackagesCategoryName {
CHARTS = '图表', CHARTS = '图表',
TABLES = '表格', TABLES = '表格',
@ -26,6 +37,7 @@ export enum PackagesCategoryName {
DECORATES = '小组件' DECORATES = '小组件'
} }
// 图表包类型
export type PackagesType = { export type PackagesType = {
[PackagesCategoryEnum.CHARTS]: ConfigType[] [PackagesCategoryEnum.CHARTS]: ConfigType[]
[PackagesCategoryEnum.INFORMATION]: ConfigType[] [PackagesCategoryEnum.INFORMATION]: ConfigType[]

View File

@ -44,11 +44,12 @@ export type MousePositionType = {
// 操作目标 // 操作目标
export type TargetChartType = { export type TargetChartType = {
index: number hoverIndex?: string
selectIndex?: string
} }
// Store 类型 // Store 类型
export enum chartEditStoreEnum { export enum ChartEditStoreEnum {
EDITCANVAS = 'editCanvas', EDITCANVAS = 'editCanvas',
MOUSEPOSITION = 'mousePosition', MOUSEPOSITION = 'mousePosition',
COMPONENT_LIST = 'componentList', COMPONENT_LIST = 'componentList',
@ -56,8 +57,8 @@ export enum chartEditStoreEnum {
} }
export interface chartEditStoreType { export interface chartEditStoreType {
[chartEditStoreEnum.EDITCANVAS]: EditCanvasType [ChartEditStoreEnum.EDITCANVAS]: EditCanvasType
[chartEditStoreEnum.MOUSEPOSITION]: MousePositionType [ChartEditStoreEnum.MOUSEPOSITION]: MousePositionType
[chartEditStoreEnum.TARGET_CHART]: TargetChartType [ChartEditStoreEnum.TARGET_CHART]: TargetChartType
[chartEditStoreEnum.COMPONENT_LIST]: any[] [ChartEditStoreEnum.COMPONENT_LIST]: any[]
} }

View File

@ -4,7 +4,8 @@ import { loadingStart, loadingFinish, loadingError } from '@/utils'
import { import {
chartEditStoreType, chartEditStoreType,
EditCanvasType, EditCanvasType,
MousePositionType MousePositionType,
TargetChartType
} from './chartEditStore.d' } from './chartEditStore.d'
// 编辑区域内容 // 编辑区域内容
@ -35,7 +36,8 @@ export const useChartEditStoreStore = defineStore({
y: 0 y: 0
}, },
targetChart: { targetChart: {
index: 0 hoverIndex: undefined,
selectIndex: undefined
}, },
componentList: [] componentList: []
}), }),
@ -46,11 +48,25 @@ export const useChartEditStoreStore = defineStore({
getEditCanvas(): EditCanvasType { getEditCanvas(): EditCanvasType {
return this.editCanvas return this.editCanvas
}, },
getTargetChart():TargetChartType {
return this.targetChart
},
getComponentList(): any[] { getComponentList(): any[] {
return this.componentList return this.componentList
} }
}, },
actions: { actions: {
// * 设置 editCanvas 数据项
setEditCanvasItem< T extends keyof EditCanvasType, K extends EditCanvasType[T] >(key: T, value: K) {
this.editCanvas[key] = value
},
// * 设置目标数据
setTargetHoverChart(hoverIndex?:TargetChartType["hoverIndex"]) {
this.targetChart.hoverIndex = hoverIndex
},
setTargetSelectChart(selectIndex?:TargetChartType["selectIndex"]) {
this.targetChart.selectIndex = selectIndex
},
// * 新增组件列表 // * 新增组件列表
addComponentList<T>(chartData: T): void { addComponentList<T>(chartData: T): void {
this.componentList.push(chartData) this.componentList.push(chartData)
@ -75,13 +91,6 @@ export const useChartEditStoreStore = defineStore({
loadingError() loadingError()
} }
}, },
// * 设置数据项
setEditCanvasItem<
T extends keyof EditCanvasType,
K extends EditCanvasType[T]
>(key: T, value: K) {
this.editCanvas[key] = value
},
// * 设置页面样式属性 // * 设置页面样式属性
setPageStyle<T extends keyof CSSStyleDeclaration>( setPageStyle<T extends keyof CSSStyleDeclaration>(
key: T, key: T,

View File

@ -75,7 +75,7 @@ const designStore = useDesignStore()
const themeColor = ref(designStore.getAppTheme) const themeColor = ref(designStore.getAppTheme)
const chartEditStore = getChartEditStore() const chartEditStore = getChartEditStore()
const chartEditStoreEnum = getChartEditStoreEnum() const ChartEditStoreEnum = getChartEditStoreEnum()
const { lockScale, scale } = toRefs(chartEditStore.getEditCanvas) const { lockScale, scale } = toRefs(chartEditStore.getEditCanvas)
// //
@ -117,7 +117,7 @@ const selectHandle = (v: number) => {
// //
const lockHandle = () => { const lockHandle = () => {
chartEditStore.setEditCanvasItem( chartEditStore.setEditCanvasItem(
chartEditStoreEnum.LOCK_SCALE, ChartEditStoreEnum.LOCK_SCALE,
!lockScale.value !lockScale.value
) )
} }

View File

@ -1,5 +1,9 @@
<template> <template>
<div class="go-content-layers-list-item go-flex-center"> <div
class="go-content-layers-list-item"
:class="{ hover: hover, select: select }"
>
<div class="go-flex-center item-content">
<n-image <n-image
class="list-img" class="list-img"
object-fit="contain" object-fit="contain"
@ -13,15 +17,20 @@
</b-text> </b-text>
</n-ellipsis> </n-ellipsis>
</div> </div>
<div :class="{ 'select-modal': select }" />
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, toRefs } from 'vue' import { ref, toRefs, computed } from 'vue'
import { requireFallbackImg } from '@/utils' import { requireFallbackImg } from '@/utils'
import { useDesignStore } from '@/store/modules/designStore/designStore' import { useDesignStore } from '@/store/modules/designStore/designStore'
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
// //
const designStore = useDesignStore() const designStore = useDesignStore()
const themeColor = ref(designStore.getAppTheme) const themeColor = ref(designStore.getAppTheme)
const chartEditStore = useChartEditStoreStore()
const props = defineProps({ const props = defineProps({
componentData: { componentData: {
@ -29,22 +38,61 @@ const props = defineProps({
required: true required: true
} }
}) })
const { image, title } = toRefs(props.componentData.chartData) const { image, title } = toRefs(props.componentData.chartData)
//
const select = computed(() => {
return props.componentData.id === chartEditStore.getTargetChart.selectIndex
})
const hover = computed(() => {
return props.componentData.id === chartEditStore.getTargetChart.hoverIndex
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
$centerHeight: 40px; $centerHeight: 52px;
$textSize: 10px; $textSize: 10px;
@include go(content-layers-list-item) { @include go(content-layers-list-item) {
justify-content: start !important; position: relative;
padding: 6px 10px; height: $centerHeight;
cursor: pointer; width: 90%;
margin: 10px 5%;
margin-bottom: 5px; margin-bottom: 5px;
border-radius: 5px;
cursor: pointer;
border: 1px solid rgba(0, 0, 0, 0);
@extend .go-transition-quick; @extend .go-transition-quick;
&.hover,
&:hover { &:hover {
@include filter-bg-color('background-color4'); @include filter-bg-color('background-color4');
color: v-bind('themeColor'); }
/* 选中 */
&.select {
border: 1px solid v-bind('themeColor');
/* 需要设置最高级,覆盖 hover 的颜色 */
background-color: rgba(0, 0, 0, 0) !important;
}
.select-modal,
.item-content {
position: absolute;
top: 0;
left: 0;
}
.item-content {
z-index: 1;
padding: 6px 5px;
justify-content: start !important;
width: calc(100% - 10px);
height: calc(100% - 10px);
}
.select-modal {
background-color: v-bind('themeColor');
opacity: 0.3;
width: 100%;
height: 100%;
} }
.list-img { .list-img {
flex-shrink: 0; flex-shrink: 0;
@ -53,7 +101,7 @@ $textSize: 10px;
overflow: hidden; overflow: hidden;
border: 1px solid; border: 1px solid;
padding: 2px; padding: 2px;
@include hover-border-color('hover-border-color') @include hover-border-color('hover-border-color');
} }
.list-text { .list-text {
padding-left: 10px; padding-left: 10px;

View File

@ -17,30 +17,52 @@
v-for="item in chartEditStore.getComponentList" v-for="item in chartEditStore.getComponentList"
:key="item.id" :key="item.id"
:componentData="item" :componentData="item"
@mousedown="mousedownHandle(item)"
@mouseenter="mouseenterHandle(item)"
@mouseleave="mouseleaveHandle(item)"
/> />
</ContentBox> </ContentBox>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ContentBox } from '../ContentBox/index' import { ContentBox } from '../ContentBox/index'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore' import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d' import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
import { ChartEditStoreEnum, TargetChartType } from '@/store/modules/chartEditStore/chartEditStore.d'
import { CreateComponentType } from '@/packages/index.d'
import { ListItem } from './components/ListItem/index' import { ListItem } from './components/ListItem/index'
import { icon } from '@/plugins' import { icon } from '@/plugins'
const { LayersIcon } = icon.ionicons5 const { LayersIcon } = icon.ionicons5
const chartLayoutStore = useChartLayoutStore() const chartLayoutStore = useChartLayoutStore()
const chartEditStore = useChartEditStoreStore() const chartEditStore = useChartEditStoreStore()
const backHandle = () => { const backHandle = () => {
chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false) chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false)
} }
//
const mousedownHandle = (item: CreateComponentType) => {
chartEditStore.setTargetSelectChart(item.id)
}
//
const mouseenterHandle = (item: CreateComponentType) => {
chartEditStore.setTargetHoverChart(item.id)
}
//
const mouseleaveHandle = (item: CreateComponentType) => {
chartEditStore.setTargetHoverChart(undefined)
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
$wight: 150px; $wight: 170px;
@include go(content-layers) { @include go(content-layers) {
width: $wight; width: $wight;
flex-shrink: 0; flex-shrink: 0;