Commit 3731f6aa908c977f0d18bd03c8149a709ea06b30
1 parent
46b6cdbf
feat(packages/external): 优化自定义按钮跳转
Showing
4 changed files
with
68 additions
and
49 deletions
1 | -import { toRefs, ref } from 'vue' | |
1 | +import { toRefs } from 'vue' | |
2 | 2 | import { CreateComponentType } from '@/packages/index.d' |
3 | 3 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
4 | 4 | |
... | ... | @@ -14,6 +14,8 @@ export const useChartInteract = ( |
14 | 14 | ) => { |
15 | 15 | const chartEditStore = useChartEditStore() |
16 | 16 | const { interactEvents } = chartConfig.events |
17 | + const { selectCurrentItems } = chartConfig.option | |
18 | + const { selectTargetItems } = chartConfig.option | |
17 | 19 | const fnOnEvent = interactEvents.filter(item => { |
18 | 20 | return item.interactOn === interactEventOn |
19 | 21 | }) |
... | ... | @@ -30,26 +32,21 @@ export const useChartInteract = ( |
30 | 32 | Header.value[key] = param[item.interactFn[key]] |
31 | 33 | } |
32 | 34 | }) |
33 | - setJump(chartConfig) | |
35 | + setJump(selectCurrentItems, selectTargetItems) | |
34 | 36 | }) |
35 | - function setJump(chart: CreateComponentType) { | |
36 | - /** | |
37 | - * 通过页面显示隐藏来模拟页面跳转 | |
38 | - * 当前点击对象和绑定的联动组件(分组或单个)内容隐藏,目标对象和绑定的联动组件(分组或单个)内容显示 | |
39 | - */ | |
37 | + function setJump(selectCurrentItems: string[], selectTargetItems: string[]) { | |
40 | 38 | try { |
41 | - const targetId = chart.option.dataset[0].target | |
42 | - const currentId = chart.option.dataset[0].current | |
43 | - const targetButtonId = chart.option.dataset[0].targetButton | |
44 | - const currentButtonId = chart.option.dataset[0].currentButton | |
45 | - const targetIndex = chartEditStore.fetchTargetIndex(targetId) | |
46 | - const currentIndex = chartEditStore.fetchTargetIndex(currentId) | |
47 | - const targetButtonIndex = chartEditStore.fetchTargetIndex(targetButtonId) | |
48 | - const currentButtonIndex = chartEditStore.fetchTargetIndex(currentButtonId) | |
49 | - chartEditStore.componentList[targetIndex].status.hide = false | |
50 | - chartEditStore.componentList[currentIndex].status.hide = true | |
51 | - chartEditStore.componentList[targetButtonIndex].status.hide = false | |
52 | - chartEditStore.componentList[currentButtonIndex].status.hide = true | |
39 | + //优化循环性能 | |
40 | + for (let i = 0, len = chartEditStore.componentList.length; i < len; i++) { | |
41 | + const compId = chartEditStore.componentList[i].id | |
42 | + const compItem = chartEditStore.componentList[i] | |
43 | + if (selectCurrentItems.includes(compId)) { | |
44 | + compItem.status.hide = true | |
45 | + } | |
46 | + if (selectTargetItems.includes(compId)) { | |
47 | + compItem.status.hide = false | |
48 | + } | |
49 | + } | |
53 | 50 | } finally { |
54 | 51 | console.log() |
55 | 52 | } | ... | ... |
... | ... | @@ -6,25 +6,20 @@ import { COMPONENT_INTERACT_EVENT_KET } from '@/enums/eventEnum' |
6 | 6 | import { interactActions, ComponentInteractEventEnum } from './interact' |
7 | 7 | import { ButtonConfig } from './index' |
8 | 8 | |
9 | + | |
9 | 10 | export const option = { |
10 | 11 | // 时间组件展示类型,必须和 interactActions 中定义的数据一致 |
11 | 12 | [COMPONENT_INTERACT_EVENT_KET]: ComponentInteractEventEnum.DATA, |
12 | 13 | // 暴露配置内容给用户 |
13 | - dataset: [ | |
14 | - { | |
15 | - label: '', | |
16 | - current: '', | |
17 | - target: '', | |
18 | - currentButton: '', | |
19 | - targetButton: '' | |
20 | - } | |
21 | - ], | |
14 | + dataset: '第1页', | |
22 | 15 | buttonType: 'primary', |
23 | 16 | buttonGhost: false, |
24 | 17 | buttonDashed: false, |
25 | 18 | buttonColor: '', |
26 | 19 | buttonTextColor: 'white', |
27 | 20 | buttonTextSize: '16', |
21 | + selectCurrentItems: [], | |
22 | + selectTargetItems: [] | |
28 | 23 | } |
29 | 24 | |
30 | 25 | export default class Config extends PublicConfigClass implements CreateComponentType { | ... | ... |
... | ... | @@ -40,27 +40,41 @@ |
40 | 40 | <span class="help-span">{{ threeFileHelpMessgae }}</span> |
41 | 41 | </n-tooltip> |
42 | 42 | </template> |
43 | - <setting-item v-for="(item, index) in optionData.dataset" :key="index"> | |
44 | - <n-input v-model:value="item.label" size="small" placeholder="按钮文字"></n-input> | |
45 | - <div style="height: 5px"></div> | |
46 | - <n-input v-model:value="item.currentButton" size="small" placeholder="填写当前按钮id(事件里面)"></n-input> | |
47 | - <div style="height: 5px"></div> | |
48 | - <n-input v-model:value="item.targetButton" size="small" placeholder="填写目标按钮id(事件里面)"></n-input> | |
49 | - <div style="height: 5px"></div> | |
50 | - <n-input v-model:value="item.current" size="small" placeholder="填写当前页面id(事件里面)"></n-input> | |
51 | - <div style="height: 5px"></div> | |
52 | - <n-input v-model:value="item.target" size="small" placeholder="填写目标页面id(事件里面)"></n-input> | |
53 | - <div style="height: 5px"></div> | |
43 | + <setting-item name="按钮文字" :alone="true"> | |
44 | + <n-input v-model:value="optionData.dataset" size="small" placeholder="按钮文字"></n-input> | |
45 | + </setting-item> | |
46 | + </setting-item-box> | |
47 | + <setting-item-box name="当前项"> | |
48 | + <setting-item name="当前项" :alone="true"> | |
49 | + <n-select | |
50 | + placeholder="请选择当前项" | |
51 | + multiple | |
52 | + size="small" | |
53 | + v-model:value="optionData.selectCurrentItems" | |
54 | + :options="selectCurrentItemOptions" | |
55 | + /> | |
56 | + </setting-item> | |
57 | + </setting-item-box> | |
58 | + <setting-item-box name="目标项"> | |
59 | + <setting-item name="目标项" :alone="true"> | |
60 | + <n-select | |
61 | + placeholder="请选择目标项" | |
62 | + multiple | |
63 | + size="small" | |
64 | + v-model:value="optionData.selectTargetItems" | |
65 | + :options="selectTargetItemOptions" | |
66 | + /> | |
54 | 67 | </setting-item> |
55 | 68 | </setting-item-box> |
56 | 69 | </collapse-item> |
57 | 70 | </template> |
58 | 71 | |
59 | 72 | <script lang="ts" setup> |
60 | -import { PropType, ref } from 'vue' | |
73 | +import { PropType, ref, onMounted } from 'vue' | |
61 | 74 | import { CollapseItem, SettingItemBox } from '@/components/Pages/ChartItemSetting' |
62 | 75 | import { option } from './config' |
63 | 76 | import { icon } from '@/plugins' |
77 | +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | |
64 | 78 | |
65 | 79 | defineProps({ |
66 | 80 | optionData: { |
... | ... | @@ -69,11 +83,11 @@ defineProps({ |
69 | 83 | } |
70 | 84 | }) |
71 | 85 | |
86 | +const chartEditStore = useChartEditStore() | |
87 | + | |
72 | 88 | const { HelpOutlineIcon } = icon.ionicons5 |
73 | 89 | |
74 | -const threeFileHelpMessgae = ref(` | |
75 | -在事件里面复制对应组件id,填写你要跳转的目标,相当于一个按钮就绑定了一个页面(分组),然后跳转到另一个页面,其实就是点击当前页隐藏,目标页显示 | |
76 | -`) | |
90 | +const threeFileHelpMessgae = ref(`勾选当前项和跳转的目标项`) | |
77 | 91 | |
78 | 92 | const buttonTypeOptions = [ |
79 | 93 | { |
... | ... | @@ -105,6 +119,19 @@ const buttonTypeOptions = [ |
105 | 119 | value: 'error' |
106 | 120 | } |
107 | 121 | ] |
122 | + | |
123 | +const selectCurrentItemOptions = ref<{ label: string; value: string }[]>([]) | |
124 | + | |
125 | +const selectTargetItemOptions = ref<{ label: string; value: string }[]>([]) | |
126 | + | |
127 | +onMounted(() => { | |
128 | + const componentList = chartEditStore.componentList.map(item => ({ | |
129 | + label: item.chartConfig?.title, | |
130 | + value: item.id | |
131 | + })) | |
132 | + selectCurrentItemOptions.value = componentList | |
133 | + selectTargetItemOptions.value = componentList | |
134 | +}) | |
108 | 135 | </script> |
109 | 136 | <style lang="scss" scoped> |
110 | 137 | .help-span { | ... | ... |
... | ... | @@ -5,9 +5,9 @@ |
5 | 5 | :dashed="buttonDashed" |
6 | 6 | :ghost="buttonGhost" |
7 | 7 | :color="buttonColor" |
8 | - @click="onClick(option.value.dataset[0])" | |
8 | + @click="onClick(option.value.dataset)" | |
9 | 9 | > |
10 | - <span class="button-text-color">{{ option.value.dataset[0].label }}</span> | |
10 | + <span class="button-text-color">{{ dataset }}</span> | |
11 | 11 | </n-button> |
12 | 12 | </template> |
13 | 13 | |
... | ... | @@ -28,7 +28,7 @@ const props = defineProps({ |
28 | 28 | }) |
29 | 29 | |
30 | 30 | const { w, h } = toRefs(props.chartConfig.attr) |
31 | -const { buttonType, buttonDashed, buttonGhost, buttonColor, buttonTextColor, buttonTextSize } = toRefs( | |
31 | +const { buttonType, buttonDashed, buttonGhost, buttonColor, buttonTextColor, buttonTextSize, dataset } = toRefs( | |
32 | 32 | props.chartConfig.option |
33 | 33 | ) |
34 | 34 | const option = shallowReactive({ |
... | ... | @@ -39,13 +39,13 @@ const onClick = (v: any) => { |
39 | 39 | useChartInteract( |
40 | 40 | props.chartConfig, |
41 | 41 | useChartEditStore, |
42 | - { [ComponentInteractParamsEnum.DATA]: v?.current }, | |
43 | - InteractEventOn.CHANGE, | |
42 | + { [ComponentInteractParamsEnum.DATA]: v }, | |
43 | + InteractEventOn.CHANGE | |
44 | 44 | ) |
45 | 45 | } |
46 | 46 | |
47 | 47 | onMounted(() => { |
48 | - onClick(option.value.dataset[0]) | |
48 | + onClick(option.value.dataset) | |
49 | 49 | }) |
50 | 50 | |
51 | 51 | // 手动更新 | ... | ... |