Commit 0794e0b7533ec8c54874b5dbc5af89820cf228e1

Authored by fengwotao
1 parent 13f81554

perf(src/packages): 优化自定义按钮点击切换

@@ -16,7 +16,6 @@ export const useChartInteract = ( @@ -16,7 +16,6 @@ export const useChartInteract = (
16 const chartEditStore = useChartEditStore() 16 const chartEditStore = useChartEditStore()
17 const { interactEvents } = chartConfig.events 17 const { interactEvents } = chartConfig.events
18 const { selectTargetItems } = chartConfig.option 18 const { selectTargetItems } = chartConfig.option
19 - const { data } = param  
20 const fnOnEvent = interactEvents.filter(item => { 19 const fnOnEvent = interactEvents.filter(item => {
21 return item.interactOn === interactEventOn 20 return item.interactOn === interactEventOn
22 }) 21 })
@@ -33,21 +32,32 @@ export const useChartInteract = ( @@ -33,21 +32,32 @@ export const useChartInteract = (
33 Header.value[key] = param[item.interactFn[key]] 32 Header.value[key] = param[item.interactFn[key]]
34 } 33 }
35 }) 34 })
36 - setJump(selectTargetItems) 35 + setTabJump(selectTargetItems)
37 }) 36 })
38 - function setJump(selectTargetItems: string[]) {  
39 - console.log('当前选择的关联项', selectTargetItems) 37 + function setTabJump(selectTargetItems: string[]) {
  38 + /**
  39 + * 逻辑
  40 + * 排除按钮组件
  41 + * 先遍历图表数组,只要是目标项,则认为是联动绑定,新增一个属性是否是联动组件设置为true
  42 + * 在遍历图表数组,只要是目标项并且是联动组件则显示,否则隐藏
  43 + */
40 try { 44 try {
41 - console.log('当前页面所有的组件列表', chartEditStore.componentList) 45 + chartEditStore.componentList.forEach((item: any) => {
  46 + if (item.key !== 'Button') {
  47 + if (selectTargetItems.includes(item.id)) {
  48 + item.isInteractComponent = true
  49 + }
  50 + }
  51 + })
42 //优化循环性能 52 //优化循环性能
43 for (let i = 0, len = chartEditStore.componentList.length; i < len; i++) { 53 for (let i = 0, len = chartEditStore.componentList.length; i < len; i++) {
44 const compId = chartEditStore.componentList[i].id 54 const compId = chartEditStore.componentList[i].id
45 - const compItem = chartEditStore.componentList[i] 55 + const compItem = chartEditStore.componentList[i] as any
46 if (status) { 56 if (status) {
47 if (compItem.key !== 'Button') { 57 if (compItem.key !== 'Button') {
48 - if (selectTargetItems.includes(compId)) { 58 + if (selectTargetItems.includes(compId) && compItem.isInteractComponent) {
49 compItem.status.hide = false 59 compItem.status.hide = false
50 - } else { 60 + } else if (!selectTargetItems.includes(compId) && compItem.isInteractComponent) {
51 compItem.status.hide = true 61 compItem.status.hide = true
52 } 62 }
53 } 63 }
@@ -29,31 +29,29 @@ @@ -29,31 +29,29 @@
29 </setting-item> 29 </setting-item>
30 </setting-item-box> 30 </setting-item-box>
31 <setting-item-box :alone="true"> 31 <setting-item-box :alone="true">
  32 + <setting-item name="按钮文字" :alone="true">
  33 + <n-input v-model:value="optionData.dataset" size="small" placeholder="按钮文字"></n-input>
  34 + </setting-item>
  35 + </setting-item-box>
  36 + <setting-item-box :alone="true">
32 <template #name> 37 <template #name>
33 - <n-text>跳转</n-text> 38 + <n-text>目标</n-text>
34 <n-tooltip trigger="hover"> 39 <n-tooltip trigger="hover">
35 <template #trigger> 40 <template #trigger>
36 <n-icon size="21" :depth="3"> 41 <n-icon size="21" :depth="3">
37 <help-outline-icon></help-outline-icon> 42 <help-outline-icon></help-outline-icon>
38 </n-icon> 43 </n-icon>
39 </template> 44 </template>
40 - <span class="help-span">{{ threeFileHelpMessgae }}</span> 45 + <span class="help-span">{{ targetHelpMessgae }}</span>
41 </n-tooltip> 46 </n-tooltip>
42 </template> 47 </template>
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.selectTargetItems"  
54 - :options="selectTargetItemOptions"  
55 - />  
56 - </setting-item> 48 + <n-select
  49 + style="width: 13.5vw"
  50 + placeholder="请选择目标项"
  51 + multiple
  52 + v-model:value="optionData.selectTargetItems"
  53 + :options="selectTargetItemOptions"
  54 + />
57 </setting-item-box> 55 </setting-item-box>
58 </collapse-item> 56 </collapse-item>
59 </template> 57 </template>
@@ -76,7 +74,7 @@ const chartEditStore = useChartEditStore() @@ -76,7 +74,7 @@ const chartEditStore = useChartEditStore()
76 74
77 const { HelpOutlineIcon } = icon.ionicons5 75 const { HelpOutlineIcon } = icon.ionicons5
78 76
79 -const threeFileHelpMessgae = ref(`勾选当前项和跳转的目标项`) 77 +const targetHelpMessgae = ref(`勾选目标项,支持多个`)
80 78
81 const buttonTypeOptions = [ 79 const buttonTypeOptions = [
82 { 80 {
@@ -28,9 +28,11 @@ const props = defineProps({ @@ -28,9 +28,11 @@ const props = defineProps({
28 }) 28 })
29 29
30 const { w, h } = toRefs(props.chartConfig.attr) 30 const { w, h } = toRefs(props.chartConfig.attr)
  31 +
31 const { buttonType, buttonDashed, buttonGhost, buttonColor, buttonTextColor, buttonTextSize, dataset } = toRefs( 32 const { buttonType, buttonDashed, buttonGhost, buttonColor, buttonTextColor, buttonTextSize, dataset } = toRefs(
32 props.chartConfig.option 33 props.chartConfig.option
33 ) 34 )
  35 +
34 const option = shallowReactive({ 36 const option = shallowReactive({
35 value: cloneDeep(props.chartConfig.option) 37 value: cloneDeep(props.chartConfig.option)
36 }) 38 })