feat: 文本组件添加接口

This commit is contained in:
huanghao1412 2024-01-26 18:43:59 +08:00
parent d6964ac52b
commit e3c89c555b
13 changed files with 143 additions and 45 deletions

View File

@ -40,24 +40,28 @@ const isProject = computed(() => {
<style lang="scss" scoped> <style lang="scss" scoped>
$min-width: 520px; $min-width: 520px;
@include go(header) { @include go(header) {
width: 100vw;
&-box { &-box {
display: grid; display: grid;
grid-template-columns: repeat(3, 33%); grid-template-columns: $min-width 1fr $min-width;
&.is-project { &.is-project {
grid-template-columns: none; grid-template-columns: none;
} }
.header-item { .header-item {
display: flex; display: flex;
align-items: center; align-items: center;
min-width: $min-width; //min-width: $min-width;
&.left { &.left {
justify-content: start; justify-content: start;
min-width: $min-width;
} }
&.center { &.center {
justify-content: center; justify-content: center;
flex: 1;
} }
&.right { &.right {
justify-content: end; justify-content: end;
min-width: $min-width;
} }
} }
height: $--header-height; height: $--header-height;

View File

@ -9,13 +9,13 @@ import { SankeyConfig } from './Sankey/index'
import { GraphConfig } from './Graph/index' import { GraphConfig } from './Graph/index'
export default [ export default [
ProcessConfig, // ProcessConfig,
RadarConfig, // RadarConfig,
FunnelConfig, // FunnelConfig,
HeatmapConfig, // HeatmapConfig,
WaterPoloConfig, WaterPoloConfig,
TreeMapConfig, // TreeMapConfig,
GraphConfig, // GraphConfig,
SankeyConfig, // SankeyConfig,
DialConfig // DialConfig
] ]

View File

@ -111,16 +111,16 @@ watch(() => props.chartConfig.option.titleContrl, (v) => {
deep: true, deep: true,
}) })
// // //
useChartDataFetch(props.chartConfig, useChartEditStore, (resData: number) => { // useChartDataFetch(props.chartConfig, useChartEditStore, (resData: number) => {
let d = parseFloat(`${resData}`) * 100 // let d = parseFloat(`${resData}`) * 100
// @ts-ignore // // @ts-ignore
option.value.title.text = `${+d.toFixed(2)}%` // option.value.title.text = `${+d.toFixed(2)}%`
// @ts-ignore // // @ts-ignore
option.value.series[0].data[0].value[0] = d // option.value.series[0].data[0].value[0] = d
// @ts-ignore // // @ts-ignore
option.value.series[0].data[1].value[0] = 100 - d // option.value.series[0].data[1].value[0] = 100 - d
}) // })
const { vChartRef } = useChartCommonData(props.chartConfig, useChartEditStore) const { vChartRef } = useChartCommonData(props.chartConfig, useChartEditStore)
</script> </script>

View File

@ -2,8 +2,8 @@ import Bars from './Bars'
import Pies from './Pies' import Pies from './Pies'
import Lines from './Lines' import Lines from './Lines'
// import Scatters from './Scatters' // import Scatters from './Scatters'
// import Mores from './Mores' import Mores from './Mores'
// import Maps from './Maps' // import Maps from './Maps'
// export const ChartList = [...Bars, ...Lines, ...Pies, ...Scatters, ...Maps, ...Mores] // export const ChartList = [...Bars, ...Lines, ...Pies, ...Scatters, ...Maps, ...Mores]
export const ChartList = [...Bars, ...Lines, ...Pies] export const ChartList = [...Bars, ...Lines, ...Pies, ...Mores]

View File

@ -17,6 +17,7 @@ export const FontWeightObject = {
export const option = { export const option = {
dataset: '让数字化看得见', dataset: '让数字化看得见',
showUnit: false,
fontSize: 32, fontSize: 32,
fontColor: '#ffffff', fontColor: '#ffffff',
fontWeight: 'normal', fontWeight: 'normal',

View File

@ -4,6 +4,15 @@
<setting-item> <setting-item>
<n-input v-model:value="optionData.dataset" type="textarea" size="small"></n-input> <n-input v-model:value="optionData.dataset" type="textarea" size="small"></n-input>
</setting-item> </setting-item>
<SettingItem>
<n-text :depth="3">开启数据时将会覆盖此文本</n-text>
</SettingItem>
<SettingItem>
<n-space>
<n-switch v-model:value="optionData.showUnit" size="small" />
<n-text>展示单位</n-text>
</n-space>
</SettingItem>
</setting-item-box> </setting-item-box>
</collapse-item> </collapse-item>

View File

@ -9,6 +9,6 @@ export const TextBarrageConfig: ConfigType = {
category: ChatCategoryEnum.TEXT, category: ChatCategoryEnum.TEXT,
categoryName: ChatCategoryEnumName.TEXT, categoryName: ChatCategoryEnumName.TEXT,
package: PackagesCategoryEnum.INFORMATIONS, package: PackagesCategoryEnum.INFORMATIONS,
chartFrame: ChartFrameEnum.STATIC, chartFrame: ChartFrameEnum.ECHARTS,
image: 'text_barrage.png' image: 'text_barrage.png'
} }

View File

@ -2,7 +2,12 @@
<div class="go-text-box"> <div class="go-text-box">
<div class="content"> <div class="content">
<span> <span>
{{ option.dataset }} <template v-if="!dataEnable">
{{ option.dataset }}
</template>
<template v-else>
{{ dataValue }}{{ option.showUnit ? dataUnit : '' }}
</template>
</span> </span>
</div> </div>
</div> </div>
@ -11,10 +16,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { PropType, toRefs, shallowReactive, watch, computed, ref } from 'vue' import { PropType, toRefs, shallowReactive, watch, computed, ref } from 'vue'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { useChartDataFetch } from '@/hooks' import { useChartCommonData } from '@/hooks'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { option as configOption } from './config' import { option as configOption } from './config'
import { values } from 'lodash' import { values } from 'lodash'
import { resultType } from '@/store/modules/chartEditStore/chartEditStore.d'
const props = defineProps({ const props = defineProps({
chartConfig: { chartConfig: {
@ -30,14 +36,16 @@ const { fontColor, fontSize, letterSpacing, fontWeight, animationTime, animation
) )
const option = shallowReactive({ const option = shallowReactive({
dataset: configOption.dataset dataset: configOption.dataset,
showUnit: configOption.showUnit
}) })
// //
watch( watch(
() => props.chartConfig.option.dataset, [() => props.chartConfig.option.dataset, () => props.chartConfig.option.showUnit],
(newData: any) => { ([newData, newShowUnit]: [any, boolean]) => {
option.dataset = newData option.dataset = newData
option.showUnit = newShowUnit
}, },
{ {
immediate: true, immediate: true,
@ -64,20 +72,44 @@ watch(
} }
) )
const dataEnable = ref()
const dataValue = ref()
const dataUnit = ref()
watch(
() => props.chartConfig.commonData,
newData => {
try {
const data = newData[newData.currentSource] as Object & { enable: boolean, result: resultType }
dataEnable.value = data.enable
dataValue.value = data.result.value
dataUnit.value = data.result.unit
} catch (error) {
console.log(error)
}
},
{
immediate: true,
deep: true
}
)
const transitionDuration = computed(() => { const transitionDuration = computed(() => {
return Math.floor((w.value as any) / (animationSpeed.value as any)) return Math.floor((w.value as any) / (animationSpeed.value as any))
}) })
// // //
useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => { // useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => {
option.dataset = newData // option.dataset = newData
}) // })
useChartCommonData(props.chartConfig, useChartEditStore)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@include go('text-box') { @include go('text-box') {
display: flex; display: flex;
align-items: center; align-items: center;
overflow: hidden;
.content { .content {
width: 100%; width: 100%;
color: v-bind('fontColor'); color: v-bind('fontColor');

View File

@ -28,6 +28,7 @@ export const option = {
link: '', link: '',
linkHead: 'http://', linkHead: 'http://',
dataset: '我是文本', dataset: '我是文本',
showUnit: false,
fontSize: 20, fontSize: 20,
fontColor: '#ffffff', fontColor: '#ffffff',
paddingX: 10, paddingX: 10,

View File

@ -4,6 +4,15 @@
<setting-item> <setting-item>
<n-input v-model:value="optionData.dataset" type="textarea" size="small"></n-input> <n-input v-model:value="optionData.dataset" type="textarea" size="small"></n-input>
</setting-item> </setting-item>
<SettingItem>
<n-text :depth="3">开启数据时将会覆盖此文本</n-text>
</SettingItem>
<SettingItem>
<n-space>
<n-switch v-model:value="optionData.showUnit" size="small" />
<n-text>展示单位</n-text>
</n-space>
</SettingItem>
</setting-item-box> </setting-item-box>
<setting-item-box name="链接" :alone="true"> <setting-item-box name="链接" :alone="true">
<setting-item> <setting-item>

View File

@ -9,6 +9,6 @@ export const TextCommonConfig: ConfigType = {
category: ChatCategoryEnum.TEXT, category: ChatCategoryEnum.TEXT,
categoryName: ChatCategoryEnumName.TEXT, categoryName: ChatCategoryEnumName.TEXT,
package: PackagesCategoryEnum.INFORMATIONS, package: PackagesCategoryEnum.INFORMATIONS,
chartFrame: ChartFrameEnum.STATIC, chartFrame: ChartFrameEnum.ECHARTS,
image: 'text_static.png' image: 'text_static.png'
} }

View File

@ -1,18 +1,30 @@
<template> <template>
<div class="go-text-box"> <div class="go-text-box">
<div class="content"> <div class="content">
<span style="cursor: pointer; white-space: pre-wrap" v-if="link" @click="click">{{ option.dataset }}</span> <span
<span style="white-space: pre-wrap" v-else>{{ option.dataset }}</span> :style="{cursor: link ? 'pointer' : 'unset'}"
style="cursor: pointer; white-space: pre-wrap"
@click="link ? click : () => {}"
>
<template v-if="!dataEnable">
{{ option.dataset }}
</template>
<template v-else>
{{ dataValue }}{{ option.showUnit ? dataUnit : '' }}
</template>
</span>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { PropType, toRefs, shallowReactive, watch } from 'vue' import { PropType, toRefs, shallowReactive, watch, ref } from 'vue'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { useChartDataFetch } from '@/hooks' import { useChartDataFetch } from '@/hooks'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { option as configOption } from './config' import { option as configOption } from './config'
import { useChartCommonData } from '@/hooks'
import { resultType } from '@/store/modules/chartEditStore/chartEditStore.d'
const props = defineProps({ const props = defineProps({
chartConfig: { chartConfig: {
@ -39,14 +51,16 @@ const {
} = toRefs(props.chartConfig.option) } = toRefs(props.chartConfig.option)
const option = shallowReactive({ const option = shallowReactive({
dataset: configOption.dataset dataset: configOption.dataset,
showUnit: configOption.showUnit
}) })
// //
watch( watch(
() => props.chartConfig.option.dataset, [() => props.chartConfig.option.dataset, () => props.chartConfig.option.showUnit],
(newData: any) => { ([newData, newShowUnit]: [any, boolean]) => {
option.dataset = newData option.dataset = newData
option.showUnit = newShowUnit
}, },
{ {
immediate: true, immediate: true,
@ -54,10 +68,33 @@ watch(
} }
) )
// const dataEnable = ref()
useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => { const dataValue = ref()
option.dataset = newData const dataUnit = ref()
}) watch(
() => props.chartConfig.commonData,
newData => {
try {
const data = newData[newData.currentSource] as Object & { enable: boolean, result: resultType }
dataEnable.value = data.enable
dataValue.value = data.result.value
dataUnit.value = data.result.unit
} catch (error) {
console.log(error)
}
},
{
immediate: true,
deep: true
}
)
// //
// useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => {
// option.dataset = newData
// })
useChartCommonData(props.chartConfig, useChartEditStore)
// //
const click = () => { const click = () => {

View File

@ -1,9 +1,9 @@
<template> <template>
<n-space> <n-space :wrap="false">
<n-icon size="20" :depth="3"> <n-icon size="20" :depth="3">
<fish-icon></fish-icon> <fish-icon></fish-icon>
</n-icon> </n-icon>
<n-text @click="handleFocus"> <n-text class="text" @click="handleFocus">
工作空间 - 工作空间 -
<n-button v-show="!focus" secondary size="tiny"> <n-button v-show="!focus" secondary size="tiny">
<span class="title"> <span class="title">
@ -81,6 +81,11 @@ const handleBlur = async () => {
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.text{
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.title { .title {
padding-left: 5px; padding-left: 5px;
padding-right: 5px; padding-right: 5px;