Commit 1b9f6f1536e1fe1f376ab2a1bf19fa5f3794e63f
1 parent
1b53c9bc
perf(external/Composes): 信息下新增自定义标签器
Showing
6 changed files
with
280 additions
and
0 deletions
1 | +import cloneDeep from 'lodash/cloneDeep' | |
2 | +import { PublicConfigClass } from '@/packages/public' | |
3 | +import { CreateComponentType } from '@/packages/index.d' | |
4 | +import { chartInitConfig } from '@/settings/designSetting' | |
5 | +import { COMPONENT_INTERACT_EVENT_KET } from '@/enums/eventEnum' | |
6 | +import { interactActions, ComponentInteractEventEnum } from './interact' | |
7 | +import { OverrideInputsTabConfig } from './index' | |
8 | + | |
9 | +export const option = { | |
10 | + // 时间组件展示类型,必须和 interactActions 中定义的数据一致 | |
11 | + [COMPONENT_INTERACT_EVENT_KET]: ComponentInteractEventEnum.DATA, | |
12 | + // 默认值 | |
13 | + tabLabel: '选项1', | |
14 | + // 样式 | |
15 | + tabType: 'segment', | |
16 | + // 暴露配置内容给用户 | |
17 | + dataset: [ | |
18 | + { | |
19 | + label: '选项1', | |
20 | + value: '1' | |
21 | + }, | |
22 | + { | |
23 | + label: '选项2', | |
24 | + value: '2' | |
25 | + }, | |
26 | + { | |
27 | + label: '选项3', | |
28 | + value: '3' | |
29 | + } | |
30 | + ], | |
31 | + customTabCss: { | |
32 | + labelTextSize: '16', | |
33 | + labelDefaultColor: 'black', | |
34 | + labelActiveColor: 'green', | |
35 | + tabBottomBarColor: 'green', | |
36 | + segmentationBgColor: 'white', | |
37 | + segmentationActiveBgColor: '#C0C0C0' | |
38 | + } | |
39 | +} | |
40 | + | |
41 | +export default class Config extends PublicConfigClass implements CreateComponentType { | |
42 | + public key = OverrideInputsTabConfig.key | |
43 | + public attr = { ...chartInitConfig, w: 460, h: 32, zIndex: -1 } | |
44 | + public chartConfig = cloneDeep(OverrideInputsTabConfig) | |
45 | + public interactActions = interactActions | |
46 | + public option = cloneDeep(option) | |
47 | +} | ... | ... |
1 | +<template> | |
2 | + <collapse-item name="标签页配置" :expanded="true"> | |
3 | + <setting-item-box name="默认值" :alone="true"> | |
4 | + <n-select size="small" v-model:value="optionData.tabType" :options="tabTypeOptions" @change="onHandleSelect" /> | |
5 | + </setting-item-box> | |
6 | + <setting-item-box name="默认文字" :alone="true"> | |
7 | + <SettingItem name="大小"> | |
8 | + <n-input v-model:value="optionData.customTabCss.labelTextSize" /> | |
9 | + </SettingItem> | |
10 | + <SettingItem name="颜色"> | |
11 | + <n-color-picker | |
12 | + size="small" | |
13 | + :modes="['hex']" | |
14 | + v-model:value="optionData.customTabCss.labelDefaultColor" | |
15 | + ></n-color-picker> | |
16 | + </SettingItem> | |
17 | + <SettingItem> | |
18 | + <n-button size="small" @click="optionData.customTabCss.labelDefaultColor = 'black'"> 恢复默认 </n-button> | |
19 | + </SettingItem> | |
20 | + </setting-item-box> | |
21 | + <setting-item-box name="激活文字" :alone="true"> | |
22 | + <SettingItem name="颜色"> | |
23 | + <n-color-picker | |
24 | + size="small" | |
25 | + :modes="['hex']" | |
26 | + v-model:value="optionData.customTabCss.labelActiveColor" | |
27 | + ></n-color-picker> | |
28 | + </SettingItem> | |
29 | + <SettingItem> | |
30 | + <n-button size="small" @click="optionData.customTabCss.labelActiveColor = 'green'"> 恢复默认 </n-button> | |
31 | + </SettingItem> | |
32 | + </setting-item-box> | |
33 | + <setting-item-box name="底部条颜色" :alone="true"> | |
34 | + <SettingItem name="颜色"> | |
35 | + <n-color-picker | |
36 | + size="small" | |
37 | + :modes="['hex']" | |
38 | + v-model:value="optionData.customTabCss.tabBottomBarColor" | |
39 | + ></n-color-picker> | |
40 | + </SettingItem> | |
41 | + <SettingItem> | |
42 | + <n-button size="small" @click="optionData.customTabCss.tabBottomBarColor = 'green'"> 恢复默认 </n-button> | |
43 | + </SettingItem> | |
44 | + </setting-item-box> | |
45 | + <setting-item-box v-if="optionData.tabType === 'segment'" name="分段背景色" :alone="true"> | |
46 | + <SettingItem name="颜色"> | |
47 | + <n-color-picker | |
48 | + size="small" | |
49 | + :modes="['hex']" | |
50 | + v-model:value="optionData.customTabCss.segmentationBgColor" | |
51 | + ></n-color-picker> | |
52 | + </SettingItem> | |
53 | + <SettingItem> | |
54 | + <n-button size="small" @click="optionData.customTabCss.segmentationBgColor = 'white'"> 恢复默认 </n-button> | |
55 | + </SettingItem> | |
56 | + </setting-item-box> | |
57 | + <setting-item-box v-if="optionData.tabType === 'segment'" name="分段激活色" :alone="true"> | |
58 | + <SettingItem name="颜色"> | |
59 | + <n-color-picker | |
60 | + size="small" | |
61 | + :modes="['hex']" | |
62 | + v-model:value="optionData.customTabCss.segmentationActiveBgColor" | |
63 | + ></n-color-picker> | |
64 | + </SettingItem> | |
65 | + <SettingItem> | |
66 | + <n-button size="small" @click="optionData.customTabCss.segmentationActiveBgColor = '#C0C0C0'"> | |
67 | + 恢复默认 | |
68 | + </n-button> | |
69 | + </SettingItem> | |
70 | + </setting-item-box> | |
71 | + </collapse-item> | |
72 | +</template> | |
73 | + | |
74 | +<script lang="ts" setup> | |
75 | +import { PropType } from 'vue' | |
76 | +import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting' | |
77 | +import { option } from './config' | |
78 | + | |
79 | +const props = defineProps({ | |
80 | + optionData: { | |
81 | + type: Object as PropType<typeof option>, | |
82 | + required: true | |
83 | + } | |
84 | +}) | |
85 | + | |
86 | +const tabTypeOptions = [ | |
87 | + { | |
88 | + label: '线条', | |
89 | + value: 'bar' | |
90 | + }, | |
91 | + { | |
92 | + label: '分段', | |
93 | + value: 'segment' | |
94 | + } | |
95 | +] | |
96 | +const onHandleSelect = (value: string) => { | |
97 | + if (value === 'bar') { | |
98 | + props.optionData.customTabCss.segmentationBgColor = '' | |
99 | + props.optionData.customTabCss.segmentationActiveBgColor = '' | |
100 | + | |
101 | + } | |
102 | +} | |
103 | +</script> | ... | ... |
1 | + | |
2 | + | |
3 | +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d' | |
4 | +import { ChatCategoryEnum, ChatCategoryEnumName } from '@/packages/components/Informations/index.d' | |
5 | +import { useWidgetKey } from '@/packages/external/useWidgetKey' | |
6 | + | |
7 | +const { key, conKey, chartKey } = useWidgetKey('OverrideInputsTab', true) | |
8 | + | |
9 | +export const OverrideInputsTabConfig: ConfigType = { | |
10 | + key, | |
11 | + chartKey, | |
12 | + conKey, | |
13 | + title: '自定义标签选择器', | |
14 | + category: ChatCategoryEnum.MORE, | |
15 | + categoryName: ChatCategoryEnumName.MORE, | |
16 | + package: PackagesCategoryEnum.INFORMATIONS, | |
17 | + chartFrame: ChartFrameEnum.COMMON, | |
18 | + image: 'inputs_tab.png' | |
19 | +} | ... | ... |
1 | +<template> | |
2 | + <n-tabs class="override-n-tabs" :type="option.value.tabType" @update:value="onChange"> | |
3 | + <n-tab v-for="(item, index) in option.value.dataset" :name="item.label" :key="index"> {{ item.label }} </n-tab> | |
4 | + </n-tabs> | |
5 | +</template> | |
6 | + | |
7 | +<script setup lang="ts"> | |
8 | +import { PropType, toRefs, shallowReactive, watch } from 'vue' | |
9 | +import cloneDeep from 'lodash/cloneDeep' | |
10 | +import { CreateComponentType } from '@/packages/index.d' | |
11 | +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | |
12 | +import { useChartInteract } from '@/hooks' | |
13 | +import { InteractEventOn } from '@/enums/eventEnum' | |
14 | +import { ComponentInteractParamsEnum } from './interact' | |
15 | + | |
16 | +const props = defineProps({ | |
17 | + chartConfig: { | |
18 | + type: Object as PropType<CreateComponentType>, | |
19 | + required: true | |
20 | + } | |
21 | +}) | |
22 | + | |
23 | +const { w, h } = toRefs(props.chartConfig.attr) | |
24 | + | |
25 | +const { | |
26 | + labelTextSize, | |
27 | + labelDefaultColor, | |
28 | + labelActiveColor, | |
29 | + tabBottomBarColor, | |
30 | + segmentationBgColor, | |
31 | + segmentationActiveBgColor | |
32 | +} = toRefs(props.chartConfig.option.customTabCss) | |
33 | + | |
34 | +const option = shallowReactive({ | |
35 | + value: cloneDeep(props.chartConfig.option) | |
36 | +}) | |
37 | + | |
38 | +// 监听事件改变 | |
39 | +const onChange = (v: string) => { | |
40 | + if (v === undefined) return | |
41 | + const selectItem = option.value.dataset.find((item: { label: string; value: any }) => item.label === v) | |
42 | + // 存储到联动数据 | |
43 | + useChartInteract( | |
44 | + props.chartConfig, | |
45 | + useChartEditStore, | |
46 | + { [ComponentInteractParamsEnum.DATA]: selectItem.value }, | |
47 | + InteractEventOn.CHANGE | |
48 | + ) | |
49 | +} | |
50 | + | |
51 | +// 手动更新 | |
52 | +watch( | |
53 | + () => props.chartConfig.option, | |
54 | + (newData: any) => { | |
55 | + option.value = newData | |
56 | + onChange(newData.tabValue) | |
57 | + }, | |
58 | + { | |
59 | + immediate: true, | |
60 | + deep: true | |
61 | + } | |
62 | +) | |
63 | +</script> | |
64 | + | |
65 | +<style lang="scss" scoped> | |
66 | +@include deep() { | |
67 | + .n-tabs-tab { | |
68 | + font-size: v-bind('labelTextSize+"px"') !important; | |
69 | + color: v-bind('labelDefaultColor') !important; | |
70 | + } | |
71 | + .n-tabs-tab--active { | |
72 | + color: v-bind('labelActiveColor') !important; | |
73 | + background-color: v-bind('segmentationActiveBgColor') !important; | |
74 | + } | |
75 | + .n-tabs-bar { | |
76 | + background-color: v-bind('tabBottomBarColor') !important; | |
77 | + } | |
78 | + .n-tabs-rail { | |
79 | + background-color: v-bind('segmentationBgColor') !important; | |
80 | + } | |
81 | +} | |
82 | +</style> | ... | ... |
1 | +import { InteractEventOn, InteractActionsType } from '@/enums/eventEnum' | |
2 | + | |
3 | +// 时间组件类型 | |
4 | +export enum ComponentInteractEventEnum { | |
5 | + DATA = 'data' | |
6 | +} | |
7 | + | |
8 | +// 联动参数 | |
9 | +export enum ComponentInteractParamsEnum { | |
10 | + DATA = 'data' | |
11 | +} | |
12 | + | |
13 | +// 定义组件触发回调事件 | |
14 | +export const interactActions: InteractActionsType[] = [ | |
15 | + { | |
16 | + interactType: InteractEventOn.CHANGE, | |
17 | + interactName: '选择完成', | |
18 | + componentEmitEvents: { | |
19 | + [ComponentInteractEventEnum.DATA]: [ | |
20 | + { | |
21 | + value: ComponentInteractParamsEnum.DATA, | |
22 | + label: '选择项' | |
23 | + } | |
24 | + ] | |
25 | + } | |
26 | + } | |
27 | +] | ... | ... |
... | ... | @@ -7,6 +7,7 @@ import { OverrideImageConfig } from '@/packages/components/external/Informations |
7 | 7 | import { OverrideCarouselConfig } from '@/packages/components/external/Informations/Mores/OverrideCarousel' |
8 | 8 | import { OverrideSelectConfig } from '@/packages/components/external/Informations/Mores/OverrideSelect' |
9 | 9 | import { OverrideInputsDateConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsDate' |
10 | +import { OverrideInputsTabConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsTab' | |
10 | 11 | |
11 | 12 | export function useInjectLib(packagesList: EPackagesType) { |
12 | 13 | |
... | ... | @@ -18,6 +19,7 @@ export function useInjectLib(packagesList: EPackagesType) { |
18 | 19 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideCarouselConfig) |
19 | 20 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideSelectConfig) |
20 | 21 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsDateConfig) |
22 | + addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsTabConfig) | |
21 | 23 | } |
22 | 24 | |
23 | 25 | /** | ... | ... |