Commit 5821d52622a12dd6567aa6f2397780e029c75ed1

Authored by fengwotao
1 parent a1b1e8a7

perf: 优化按钮点击切换

... ... @@ -10,12 +10,13 @@ export const useChartInteract = (
10 10 chartConfig: CreateComponentType,
11 11 useChartEditStore: ChartEditStoreType,
12 12 param: { [T: string]: any },
13   - interactEventOn: string
  13 + interactEventOn: string,
  14 + status: boolean
14 15 ) => {
15 16 const chartEditStore = useChartEditStore()
16 17 const { interactEvents } = chartConfig.events
17   - const { selectCurrentItems } = chartConfig.option
18 18 const { selectTargetItems } = chartConfig.option
  19 + const { data } = param
19 20 const fnOnEvent = interactEvents.filter(item => {
20 21 return item.interactOn === interactEventOn
21 22 })
... ... @@ -32,19 +33,24 @@ export const useChartInteract = (
32 33 Header.value[key] = param[item.interactFn[key]]
33 34 }
34 35 })
35   - setJump(selectCurrentItems, selectTargetItems)
  36 + setJump(selectTargetItems)
36 37 })
37   - function setJump(selectCurrentItems: string[], selectTargetItems: string[]) {
  38 + function setJump(selectTargetItems: string[]) {
  39 + console.log('当前选择的关联项', selectTargetItems)
38 40 try {
  41 + console.log('当前页面所有的组件列表', chartEditStore.componentList)
39 42 //优化循环性能
40 43 for (let i = 0, len = chartEditStore.componentList.length; i < len; i++) {
41 44 const compId = chartEditStore.componentList[i].id
42 45 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
  46 + if (status) {
  47 + if (compItem.key !== 'Button') {
  48 + if (selectTargetItems.includes(compId)) {
  49 + compItem.status.hide = false
  50 + } else {
  51 + compItem.status.hide = true
  52 + }
  53 + }
48 54 }
49 55 }
50 56 } finally {
... ...
... ... @@ -18,7 +18,6 @@ export const option = {
18 18 buttonColor: '',
19 19 buttonTextColor: 'white',
20 20 buttonTextSize: '16',
21   - selectCurrentItems: [],
22 21 selectTargetItems: []
23 22 }
24 23
... ...
... ... @@ -44,17 +44,6 @@
44 44 <n-input v-model:value="optionData.dataset" size="small" placeholder="按钮文字"></n-input>
45 45 </setting-item>
46 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 47 <setting-item-box name="目标项">
59 48 <setting-item name="目标项" :alone="true">
60 49 <n-select
... ... @@ -120,8 +109,6 @@ const buttonTypeOptions = [
120 109 }
121 110 ]
122 111
123   -const selectCurrentItemOptions = ref<{ label: string; value: string }[]>([])
124   -
125 112 const selectTargetItemOptions = ref<{ label: string; value: string }[]>([])
126 113
127 114 onMounted(() => {
... ... @@ -129,7 +116,6 @@ onMounted(() => {
129 116 label: item.chartConfig?.title,
130 117 value: item.id
131 118 }))
132   - selectCurrentItemOptions.value = componentList
133 119 selectTargetItemOptions.value = componentList
134 120 })
135 121 </script>
... ...
... ... @@ -5,7 +5,7 @@
5 5 :dashed="buttonDashed"
6 6 :ghost="buttonGhost"
7 7 :color="buttonColor"
8   - @click="onClick(option.value.dataset)"
  8 + @click="onClick(option.value.selectTargetItems, true)"
9 9 >
10 10 <span class="button-text-color">{{ dataset }}</span>
11 11 </n-button>
... ... @@ -35,17 +35,18 @@ const option = shallowReactive({
35 35 value: cloneDeep(props.chartConfig.option)
36 36 })
37 37
38   -const onClick = (v: any) => {
  38 +const onClick = (v: any, status: boolean) => {
39 39 useChartInteract(
40 40 props.chartConfig,
41 41 useChartEditStore,
42 42 { [ComponentInteractParamsEnum.DATA]: v },
43   - InteractEventOn.CHANGE
  43 + InteractEventOn.CHANGE,
  44 + status
44 45 )
45 46 }
46 47
47 48 onMounted(() => {
48   - onClick(option.value.dataset)
  49 + onClick(option.value.selectTargetItems, false)
49 50 })
50 51
51 52 // 手动更新
... ...