Showing
7 changed files
with
161 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 { ButtonConfig } from './index' | |
8 | + | |
9 | +export const option = { | |
10 | + // 时间组件展示类型,必须和 interactActions 中定义的数据一致 | |
11 | + [COMPONENT_INTERACT_EVENT_KET]: ComponentInteractEventEnum.DATA, | |
12 | + // 暴露配置内容给用户 | |
13 | + dataset: [ | |
14 | + { | |
15 | + label: '', | |
16 | + current: '', | |
17 | + target: '', | |
18 | + currentButton: '', | |
19 | + targetButton: '' | |
20 | + } | |
21 | + ] | |
22 | +} | |
23 | + | |
24 | +export default class Config extends PublicConfigClass implements CreateComponentType { | |
25 | + public key = ButtonConfig.key | |
26 | + public attr = { ...chartInitConfig, w: 460, h: 32, zIndex: -1 } | |
27 | + public chartConfig = cloneDeep(ButtonConfig) | |
28 | + public interactActions = interactActions | |
29 | + public option = cloneDeep(option) | |
30 | +} | ... | ... |
1 | +<template> | |
2 | + <collapse-item name="按钮配置" :expanded="true"> | |
3 | + <setting-item-box name="配置项" :alone="true"> | |
4 | + <setting-item v-for="(item, index) in optionData.dataset" :key="index"> | |
5 | + <n-input v-model:value="item.label" size="small" placeholder="按钮文字"></n-input> | |
6 | + <div style="height: 5px"></div> | |
7 | + <n-input v-model:value="item.currentButton" size="small" placeholder="当前按钮"></n-input> | |
8 | + <div style="height: 5px"></div> | |
9 | + <n-input v-model:value="item.targetButton" size="small" placeholder="目标按钮"></n-input> | |
10 | + <div style="height: 5px"></div> | |
11 | + <n-input v-model:value="item.current" size="small" placeholder="当前页面"></n-input> | |
12 | + <div style="height: 5px"></div> | |
13 | + <n-input v-model:value="item.target" size="small" placeholder="目标页面"></n-input> | |
14 | + <div style="height: 5px"></div> | |
15 | + </setting-item> | |
16 | + </setting-item-box> | |
17 | + </collapse-item> | |
18 | +</template> | |
19 | + | |
20 | +<script lang="ts" setup> | |
21 | +import { PropType } from 'vue' | |
22 | +import { CollapseItem, SettingItemBox } from '@/components/Pages/ChartItemSetting' | |
23 | +import { option } from './config' | |
24 | + | |
25 | +defineProps({ | |
26 | + optionData: { | |
27 | + type: Object as PropType<typeof option>, | |
28 | + required: true | |
29 | + } | |
30 | +}) | |
31 | +</script> | ... | ... |
1 | +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d' | |
2 | +import { ChatCategoryEnum, ChatCategoryEnumName } from '@/packages/components/Informations/index.d' | |
3 | +import { useWidgetKey } from '@/packages/external/useWidgetKey' | |
4 | + | |
5 | +const { key, conKey, chartKey } = useWidgetKey('Button', true) | |
6 | + | |
7 | +export const ButtonConfig: ConfigType = { | |
8 | + key, | |
9 | + chartKey, | |
10 | + conKey, | |
11 | + title: '自定义按钮', | |
12 | + category: ChatCategoryEnum.MORE, | |
13 | + categoryName: ChatCategoryEnumName.MORE, | |
14 | + package: PackagesCategoryEnum.INFORMATIONS, | |
15 | + chartFrame: ChartFrameEnum.STATIC, | |
16 | + image: 'inputs_tab.png' | |
17 | +} | ... | ... |
1 | +<template> | |
2 | + <n-button :style="{ width: `${w}px`, height: `${h}px` }" type="primary" @click="onClick(option.value.dataset[0])">{{ | |
3 | + option.value.dataset[0].label | |
4 | + }}</n-button> | |
5 | +</template> | |
6 | + | |
7 | +<script setup lang="ts"> | |
8 | +import { PropType, toRefs, shallowReactive, watch, onMounted } 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 | +const option = shallowReactive({ | |
25 | + value: cloneDeep(props.chartConfig.option) | |
26 | +}) | |
27 | + | |
28 | +const onClick = (v: any) => { | |
29 | + useChartInteract( | |
30 | + props.chartConfig, | |
31 | + useChartEditStore, | |
32 | + { [ComponentInteractParamsEnum.DATA]: v?.current }, | |
33 | + InteractEventOn.CHANGE | |
34 | + ) | |
35 | +} | |
36 | + | |
37 | +onMounted(() => { | |
38 | + // onClick(option.value.dataset[0], false) | |
39 | +}) | |
40 | + | |
41 | +// 手动更新 | |
42 | +watch( | |
43 | + () => props.chartConfig.option, | |
44 | + (newData: any) => { | |
45 | + option.value = newData | |
46 | + // onClick(newData.tabValue, true) | |
47 | + }, | |
48 | + { | |
49 | + immediate: true, | |
50 | + deep: true | |
51 | + } | |
52 | +) | |
53 | +</script> | ... | ... |
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 | +] | ... | ... |
... | ... | @@ -9,6 +9,7 @@ import { OverrideSelectConfig } from '@/packages/components/external/Information |
9 | 9 | import { OverrideInputsDateConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsDate' |
10 | 10 | import { OverrideInputsTabConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsTab' |
11 | 11 | import { OverrideTextCommonConfig } from '@/packages/components/external/Informations/Mores/OverrideTextCommon' |
12 | +import { ButtonConfig } from '@/packages/components/external/Informations/Mores/Button' | |
12 | 13 | import { OverrideBarCommonConfig } from '@/packages/components/external/Charts/Bars/OverrideBarCommon' |
13 | 14 | import { OverrideLineCommonConfig } from '@/packages/components/external/Charts/Lines/OverrideLineCommon' |
14 | 15 | import { OverrideLineGradientsConfig } from '@/packages/components/external/Charts/Lines/OverrideLineGradients' |
... | ... | @@ -25,6 +26,7 @@ export function useInjectLib(packagesList: EPackagesType) { |
25 | 26 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsDateConfig) |
26 | 27 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsTabConfig) |
27 | 28 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideTextCommonConfig) |
29 | + addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, ButtonConfig) | |
28 | 30 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideBarCommonConfig) |
29 | 31 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideLineCommonConfig) |
30 | 32 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideLineGradientsConfig) | ... | ... |