wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<script lang="ts" setup>
import icon_drag_outlined from '@/assets/svg/icon_drag_outlined.svg'
import draggable from 'vuedraggable'
import { reactive, watch, ref } from 'vue'
import chartViewManager from '../../../js/panel'
 
const loading = ref(false)
 
const state = reactive({
  sortList: []
})
 
const props = defineProps({
  chart: {
    type: Object,
    required: true
  }
})
 
const emit = defineEmits(['onPriorityChange'])
 
watch(
  () => props.chart,
  () => {
    init()
  },
  { deep: true }
)
 
const init = () => {
  const chart = props.chart
  if (!chart.sortPriority?.length) {
    state.sortList.splice(0, state.sortList.length)
  } else {
    state.sortList.splice(0, state.sortList.length, ...chart.sortPriority)
  }
  const chartInstance = chartViewManager.getChartView(chart.render, chart.type)
  if (chartInstance) {
    const axis = chartInstance.axis
    const axisMap = axis?.reduce((p, n) => {
      let axisArr
      switch (n) {
        case 'xAxis':
          axisArr = chart.xAxis
          break
        case 'yAxis':
          axisArr = chart.yAxis
          break
        case 'xAxisExt':
          axisArr = chart.xAxisExt
          break
        case 'yAxisExt':
          axisArr = chart.yAxisExt
          break
        case 'extBubble':
          axisArr = chart.extBubble
          break
        case 'flowMapEndName':
          axisArr = chart.flowMapEndName
          break
        case 'flowMapStartName':
          axisArr = chart.flowMapStartName
          break
        case 'extColor':
          axisArr = chart.extColor
          break
        case 'extStack':
          axisArr = chart.extStack
          break
        case 'drill':
          axisArr = chart.drillFields
          break
        default:
          break
      }
      axisArr?.forEach(ele => {
        if (!p[ele.id]) {
          p[ele.id] = ele.chartShowName ?? ele.name
        }
      })
      return p
    }, {})
    state.sortList = state.sortList.reduce((p, n) => {
      if (axisMap[n.id]) {
        n.name = axisMap[n.id]
        p.push(n)
      }
      return p
    }, [])
    Object.entries(axisMap).forEach(([key, value]) => {
      if (!state.sortList.find(item => item.id === key)) {
        state.sortList.push({ id: key, name: value })
      }
    })
  }
}
const onUpdate = () => {
  emit('onPriorityChange', state.sortList)
}
 
init()
</script>
 
<template>
  <el-scrollbar height="100%" max-height="599px">
    <draggable
      v-loading="loading"
      :list="state.sortList"
      animation="300"
      class="drag-list"
      item-key="id"
      @update="onUpdate"
    >
      <template #item="{ element }">
        <span :key="element.id" class="item-dimension" :title="element.name">
          <el-icon class="item-icon">
            <Icon name="icon_drag_outlined"><icon_drag_outlined class="svg-icon" /></Icon>
          </el-icon>
          <span class="item-span">
            {{ element.name }}
          </span>
        </span>
      </template>
    </draggable>
  </el-scrollbar>
</template>
 
<style lang="less" scoped>
.drag-list {
  height: 50vh;
}
 
.item-dimension {
  padding: 2px;
  margin: 2px;
  border: 1px solid #dee0e3;
  border-radius: 4px;
  text-align: left;
  color: #606266;
  background-color: white;
  display: flex;
  align-items: center;
  cursor: move;
}
 
.item-icon {
  font-size: 16px;
  margin: 0 4px;
  color: #646a73;
}
 
.item-span {
  display: inline-block;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
 
  color: #1f2329;
 
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: 22px;
}
 
.blackTheme .item-dimension {
  border: solid 1px;
  border-color: var(--TableBorderColor);
  color: var(--TextPrimary);
  background-color: var(--MainBG);
}
 
.item-dimension + .item-dimension {
  margin-top: 6px;
}
 
.item-dimension:hover {
  box-shadow: 0px 4px 8px 0px rgba(31, 35, 41, 0.1);
}
 
.blackTheme .item-dimension:hover {
  color: var(--Main);
  background: var(--ContentBG);
}
</style>