feat: 新增图表位置处理

This commit is contained in:
MTrun 2022-02-25 21:26:56 +08:00
parent d9a3b358e7
commit 0c2da460a3
11 changed files with 310 additions and 272 deletions

View File

@ -1,238 +1,233 @@
<template> <template>
<div class="go-global-setting"> <CollapseItem v-if="title" name="标题">
<CollapseItem v-if="title" name="标题"> <template #header>
<template #header> <n-switch v-show="inChart" v-model:value="title.show" size="small" />
<n-switch v-show="inChart" v-model:value="title.show" size="small" /> </template>
</template> <SettingItemBox name="标题">
<SettingItemBox name="标题"> <SettingItem name="颜色">
<SettingItem name="颜色"> <n-color-picker v-model:value="title.textStyle.color" size="small" />
<n-color-picker v-model:value="title.textStyle.color" size="small" /> </SettingItem>
</SettingItem> <SettingItem name="大小">
<SettingItem name="大小"> <n-input-number
<n-input-number v-model:value="title.textStyle.fontSize"
v-model:value="title.textStyle.fontSize" :min="1"
:min="1" size="small"
size="small" />
/> </SettingItem>
</SettingItem> </SettingItemBox>
</SettingItemBox> <SettingItemBox name="副标题">
<SettingItemBox name="副标题"> <SettingItem name="颜色">
<SettingItem name="颜色"> <n-color-picker size="small" v-model:value="title.subtextStyle.color" />
<n-color-picker </SettingItem>
size="small" <SettingItem name="大小">
v-model:value="title.subtextStyle.color" <n-input-number
/> v-model:value="title.subtextStyle.fontSize"
</SettingItem> :min="1"
<SettingItem name="大小"> size="small"
<n-input-number />
v-model:value="title.subtextStyle.fontSize" </SettingItem>
:min="1" </SettingItemBox>
size="small" </CollapseItem>
/>
</SettingItem>
</SettingItemBox>
</CollapseItem>
<CollapseItem v-if="xAxis" name="X轴"> <CollapseItem v-if="xAxis" name="X轴">
<template #header> <template #header>
<n-switch v-show="inChart" v-model:value="xAxis.show" size="small" /> <n-switch v-show="inChart" v-model:value="xAxis.show" size="small" />
</template> </template>
<SettingItemBox name="名称"> <SettingItemBox name="名称">
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker <n-color-picker
size="small" size="small"
v-model:value="xAxis.nameTextStyle.color" v-model:value="xAxis.nameTextStyle.color"
/> />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="标签"> <SettingItemBox name="标签">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="xAxis.axisLabel.show" size="small" /> <n-switch v-model:value="xAxis.axisLabel.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker size="small" v-model:value="xAxis.axisLabel.color" /> <n-color-picker size="small" v-model:value="xAxis.axisLabel.color" />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="轴线"> <SettingItemBox name="轴线">
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker <n-color-picker
v-model:value="xAxis.axisLine.lineStyle.color" v-model:value="xAxis.axisLine.lineStyle.color"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="粗细"> <SettingItem name="粗细">
<n-input-number <n-input-number
v-model:value="xAxis.axisLine.lineStyle.width" v-model:value="xAxis.axisLine.lineStyle.width"
:min="1" :min="1"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="对齐零"> <SettingItem name="对齐零">
<n-space> <n-space>
<n-switch v-model:value="xAxis.axisLine.onZero" size="small" /> <n-switch v-model:value="xAxis.axisLine.onZero" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="刻度"> <SettingItemBox name="刻度">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="xAxis.axisTick.show" size="small" /> <n-switch v-model:value="xAxis.axisTick.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="长度"> <SettingItem name="长度">
<n-input-number <n-input-number
v-model:value="xAxis.axisTick.length" v-model:value="xAxis.axisTick.length"
:min="1" :min="1"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="分割线"> <SettingItemBox name="分割线">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="xAxis.splitLine.show" size="small" /> <n-switch v-model:value="xAxis.splitLine.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker <n-color-picker
v-model:value="xAxis.splitLine.lineStyle.color" v-model:value="xAxis.splitLine.lineStyle.color"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="粗细"> <SettingItem name="粗细">
<n-input-number <n-input-number
v-model:value="xAxis.splitLine.lineStyle.width" v-model:value="xAxis.splitLine.lineStyle.width"
:min="1" :min="1"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="类型"> <SettingItem name="类型">
<n-select <n-select
v-model:value="xAxis.splitLine.lineStyle.type" v-model:value="xAxis.splitLine.lineStyle.type"
size="small" size="small"
:options="axisConf.splitLint.lineStyle.type" :options="axisConf.splitLint.lineStyle.type"
/> />
</SettingItem> </SettingItem>
<SettingItem name="位置"> <SettingItem name="位置">
<n-select <n-select
v-model:value="xAxis.position" v-model:value="xAxis.position"
size="small" size="small"
:options="axisConf.xposition" :options="axisConf.xposition"
/> />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
</CollapseItem> </CollapseItem>
<CollapseItem v-if="yAxis" name="Y轴"> <CollapseItem v-if="yAxis" name="Y轴">
<template #header> <template #header>
<n-switch v-show="inChart" v-model:value="yAxis.show" size="small" /> <n-switch v-show="inChart" v-model:value="yAxis.show" size="small" />
</template> </template>
<SettingItemBox name="名称"> <SettingItemBox name="名称">
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker <n-color-picker
size="small" size="small"
v-model:value="yAxis.nameTextStyle.color" v-model:value="yAxis.nameTextStyle.color"
/> />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="标签"> <SettingItemBox name="标签">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="yAxis.axisLabel.show" size="small" /> <n-switch v-model:value="yAxis.axisLabel.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker size="small" v-model:value="yAxis.axisLabel.color" /> <n-color-picker size="small" v-model:value="yAxis.axisLabel.color" />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="轴线"> <SettingItemBox name="轴线">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="yAxis.axisLine.show" size="small" /> <n-switch v-model:value="yAxis.axisLine.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker <n-color-picker
v-model:value="yAxis.axisLine.lineStyle.color" v-model:value="yAxis.axisLine.lineStyle.color"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="粗细"> <SettingItem name="粗细">
<n-input-number <n-input-number
v-model:value="yAxis.axisLine.lineStyle.width" v-model:value="yAxis.axisLine.lineStyle.width"
:min="1" :min="1"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="对齐零"> <SettingItem name="对齐零">
<n-space> <n-space>
<n-switch v-model:value="yAxis.axisLine.onZero" size="small" /> <n-switch v-model:value="yAxis.axisLine.onZero" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="刻度"> <SettingItemBox name="刻度">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="yAxis.axisTick.show" size="small" /> <n-switch v-model:value="yAxis.axisTick.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="长度"> <SettingItem name="长度">
<n-input-number <n-input-number
v-model:value="yAxis.axisTick.length" v-model:value="yAxis.axisTick.length"
:min="1" :min="1"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
<SettingItemBox name="分割线"> <SettingItemBox name="分割线">
<SettingItem v-show="inChart" name="展示"> <SettingItem v-show="inChart" name="展示">
<n-space> <n-space>
<n-switch v-model:value="yAxis.splitLine.show" size="small" /> <n-switch v-model:value="yAxis.splitLine.show" size="small" />
</n-space> </n-space>
</SettingItem> </SettingItem>
<SettingItem name="颜色"> <SettingItem name="颜色">
<n-color-picker <n-color-picker
v-model:value="yAxis.splitLine.lineStyle.color" v-model:value="yAxis.splitLine.lineStyle.color"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="粗细"> <SettingItem name="粗细">
<n-input-number <n-input-number
v-model:value="yAxis.splitLine.lineStyle.width" v-model:value="yAxis.splitLine.lineStyle.width"
:min="1" :min="1"
size="small" size="small"
/> />
</SettingItem> </SettingItem>
<SettingItem name="类型"> <SettingItem name="类型">
<n-select <n-select
v-model:value="yAxis.splitLine.lineStyle.type" v-model:value="yAxis.splitLine.lineStyle.type"
size="small" size="small"
:options="axisConf.splitLint.lineStyle.type" :options="axisConf.splitLint.lineStyle.type"
/> />
</SettingItem> </SettingItem>
<SettingItem name="位置"> <SettingItem name="位置">
<n-select <n-select
v-model:value="yAxis.position" v-model:value="yAxis.position"
size="small" size="small"
:options="axisConf.yposition" :options="axisConf.yposition"
/> />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
</CollapseItem> </CollapseItem>
<CollapseItem v-if="legend" name="图例"> <CollapseItem v-if="legend" name="图例">
<template #header> <template #header>
<n-switch v-show="inChart" v-model:value="legend.show" size="small" /> <n-switch v-show="inChart" v-model:value="legend.show" size="small" />
</template> </template>
<SettingItemBox name="图例文字"> <SettingItemBox name="图例文字">
<SettingItem> <SettingItem>
<n-color-picker size="small" v-model:value="legend.textStyle.color" /> <n-color-picker size="small" v-model:value="legend.textStyle.color" />
</SettingItem> </SettingItem>
</SettingItemBox> </SettingItemBox>
</CollapseItem> </CollapseItem>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -246,7 +241,7 @@ import {
} from '@/components/ChartItemSetting/index' } from '@/components/ChartItemSetting/index'
const props = defineProps({ const props = defineProps({
optiondata: { optionData: {
type: Object as PropType<GlobalThemeJsonType>, type: Object as PropType<GlobalThemeJsonType>,
required: true required: true
}, },
@ -258,23 +253,18 @@ const props = defineProps({
}) })
const title = computed(() => { const title = computed(() => {
return props.optiondata.title return props.optionData.title
}) })
const xAxis = computed(() => { const xAxis = computed(() => {
return props.optiondata.xAxis return props.optionData.xAxis
}) })
const yAxis = computed(() => { const yAxis = computed(() => {
return props.optiondata.yAxis return props.optionData.yAxis
}) })
const legend = computed(() => { const legend = computed(() => {
return props.optiondata.legend return props.optionData.legend
}) })
</script> </script>
<style lang="scss" scoped>
@include go(global-setting) {
}
</style>

View File

@ -0,0 +1,37 @@
<template>
<SettingItemBox name="边距">
<n-input-number
v-model:value="chartAttr.y"
:min="0"
size="small"
placeholder="px"
>
<template #prefix>
<n-text depth="3">上边</n-text>
</template>
</n-input-number>
<n-input-number
v-model:value="chartAttr.x"
:min="0"
size="small"
placeholder="px"
>
<template #prefix>
<n-text depth="3"></n-text>
</template>
</n-input-number>
</SettingItemBox>
</template>
<script setup lang="ts">
import { PropType } from 'vue'
import { PickCreateComponentType } from '@/packages/index.d'
import { SettingItemBox } from '@/components/ChartItemSetting/index'
const props = defineProps({
chartAttr: {
type: Object as PropType<Omit<PickCreateComponentType<'attr'>, 'node'>>,
required: true
}
})
</script>

View File

@ -21,7 +21,7 @@ $leftWidth: 60px;
@include go('config-item-box') { @include go('config-item-box') {
position: relative; position: relative;
display: flex; display: flex;
margin-top: 10px; margin: 20px 0;
.item-left { .item-left {
width: $leftWidth; width: $leftWidth;
text-align: left; text-align: left;

View File

@ -5,5 +5,7 @@ import CollapseItem from './CollapseItem.vue'
// 全局配置属性通用模板 // 全局配置属性通用模板
import GlobalSetting from './GlobalSetting.vue' import GlobalSetting from './GlobalSetting.vue'
// 方向通用模板
import PositionSetting from './PositionSetting.vue'
export { CollapseItem, SettingItemBox, SettingItem, GlobalSetting } export { CollapseItem, SettingItemBox, SettingItem, GlobalSetting, PositionSetting }

View File

@ -25,6 +25,9 @@ export interface CreateComponentType extends PublicConfigType {
option: GlobalThemeJsonType option: GlobalThemeJsonType
} }
// 获取组件实例类中某个key对应value类型的方法
export type PickCreateComponentType<T extends keyof CreateComponentType> = Pick<CreateComponentType, T>[T]
// 包分类枚举 // 包分类枚举
export enum PackagesCategoryEnum { export enum PackagesCategoryEnum {
CHARTS = 'Charts', CHARTS = 'Charts',

View File

@ -32,7 +32,6 @@ const packagesInstall = (app: App): void => {
* @param dropData * @param dropData
*/ */
const createComponent = async (dropData: ConfigType) => { const createComponent = async (dropData: ConfigType) => {
console.log(dropData)
const { category } = dropData const { category } = dropData
const key = dropData.key.substring(1) const key = dropData.key.substring(1)
const chart = await import(`./components/${dropData.package}/${category}/${key}/config.ts`) const chart = await import(`./components/${dropData.package}/${category}/${key}/config.ts`)

View File

@ -32,7 +32,7 @@
"length": 5 "length": 5
}, },
"splitLine": { "splitLine": {
"show": true, "show": false,
"lineStyle": { "lineStyle": {
"color": "#484753", "color": "#484753",
"width": 1, "width": 1,

View File

@ -130,6 +130,10 @@ export const useChartEditStoreStore = defineStore({
}, },
// * 找到目标 id 数据下标位置 // * 找到目标 id 数据下标位置
fetchTargetIndex(): number { fetchTargetIndex(): number {
if(!this.getTargetChart.selectId) {
loadingFinish()
return -1
}
const index = this.componentList.findIndex(e => e.id === this.getTargetChart.selectId) const index = this.componentList.findIndex(e => e.id === this.getTargetChart.selectId)
if (index === -1) { if (index === -1) {
loadingError() loadingError()
@ -183,7 +187,7 @@ export const useChartEditStoreStore = defineStore({
dom.style[key] = value dom.style[key] = value
} }
}, },
// * 移动组件列表位置到两端 // * 移动组件列表层级位置到两端
setBothEnds(isEnd = false, isHistory = true): void { setBothEnds(isEnd = false, isHistory = true): void {
try { try {
loadingStart() loadingStart()

View File

@ -1,17 +1,16 @@
<template> <template>
<div class="go-chart-content-details" v-if="targetData"> <div class="go-chart-content-details" v-if="targetData">
<div class="chart-config"> <SettingItemBox name="名称">
<SettingItemBox name="名称"> <n-input
<n-input type="text"
type="text" maxlength="6"
maxlength="6" show-count
show-count placeholder="请输入图表名称"
placeholder="请输入图表名称" size="small"
size="small" v-model:value="targetData.chartConfig.title"
v-model:value="targetData.chartConfig.title" />
/> </SettingItemBox>
</SettingItemBox> <PositionSetting :chartAttr="targetData.attr" />
</div>
<GlobalSetting :optionData="targetData.option" :in-chart="true" /> <GlobalSetting :optionData="targetData.option" :in-chart="true" />
</div> </div>
</template> </template>
@ -20,7 +19,7 @@
import { computed, Ref } from 'vue' import { computed, Ref } from 'vue'
import { loadAsyncComponent } from '@/utils' import { loadAsyncComponent } from '@/utils'
import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStoreStore } from '@/store/modules/chartEditStore/chartEditStore'
import { GlobalSetting } from '@/components/ChartItemSetting/index' import { GlobalSetting, PositionSetting } from '@/components/ChartItemSetting/index'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { SettingItemBox } from '@/components/ChartItemSetting/index' import { SettingItemBox } from '@/components/ChartItemSetting/index'
@ -38,8 +37,5 @@ const targetData: Ref<CreateComponentType> = computed(() => {
<style lang="scss" scoped> <style lang="scss" scoped>
@include go('chart-content-details') { @include go('chart-content-details') {
.chart-config {
padding: 20px 0;
}
} }
</style> </style>

View File

@ -19,7 +19,7 @@
:showTop="false" :showTop="false"
:depth="2" :depth="2"
> >
<!-- 画布 --> <!-- 页面配置 -->
<n-tabs <n-tabs
v-show="!selectTarget" v-show="!selectTarget"
class="tabs-box" class="tabs-box"
@ -91,9 +91,15 @@ const chartEditStoreStore = useChartEditStoreStore()
const { ConstructIcon, FlashIcon, DesktopOutlineIcon } = icon.ionicons5 const { ConstructIcon, FlashIcon, DesktopOutlineIcon } = icon.ionicons5
const ContentEdit = loadAsyncComponent(() => import('../ContentEdit/index.vue')) const ContentEdit = loadAsyncComponent(() => import('../ContentEdit/index.vue'))
const CanvasPage = loadAsyncComponent(() =>import('./components/CanvasPage/index.vue')) const CanvasPage = loadAsyncComponent(() =>
const ChartSetting = loadAsyncComponent(() =>import('./components/ChartSetting/index.vue')) import('./components/CanvasPage/index.vue')
const ChartData = loadAsyncComponent(() => import('./components/ChartData/index.vue')) )
const ChartSetting = loadAsyncComponent(() =>
import('./components/ChartSetting/index.vue')
)
const ChartData = loadAsyncComponent(() =>
import('./components/ChartData/index.vue')
)
const collapsed = ref<boolean>(getDetails.value) const collapsed = ref<boolean>(getDetails.value)
@ -151,10 +157,12 @@ const canvasTabList = [
<style lang="scss" scoped> <style lang="scss" scoped>
@include go(content-layers) { @include go(content-layers) {
padding: 10px;
overflow: hidden; overflow: hidden;
.icon-position { .tabs-box {
padding-top: 2px; padding: 10px;
.icon-position {
padding-top: 2px;
}
} }
} }
</style> </style>

View File

@ -1,7 +1,6 @@
import { PublicConfigType } from '@/packages/index.d' import { PickCreateComponentType } from '@/packages/index.d'
type PickPublicConfigType<T extends keyof PublicConfigType> = Pick<PublicConfigType, T>[T] type AttrType = PickCreateComponentType<'attr'>
type AttrType = PickPublicConfigType<'attr'>
export const useComponentStyle = (attr: AttrType, index: number) => { export const useComponentStyle = (attr: AttrType, index: number) => {
const componentStyle = { const componentStyle = {