wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
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
<script lang="ts" setup>
import icon_drag_outlined from '@/assets/svg/icon_drag_outlined.svg'
import draggable from 'vuedraggable'
import { getFieldData, getDrillFieldData } from '@/api/chart'
import { reactive, watch, ref } from 'vue'
import { useCache } from '@/hooks/web/useCache'
 
const { wsCache } = useCache()
const loading = ref(false)
 
const state = reactive({
  sortList: []
})
 
const props = defineProps({
  chart: {
    type: Object,
    required: true
  },
  field: {
    type: Object,
    required: true
  },
  fieldType: {
    type: String,
    required: true
  },
  originSortList: {
    type: Array,
    default: () => [],
    required: false
  }
})
 
const emit = defineEmits(['onSortChange'])
 
watch(
  () => props.chart,
  () => {
    init()
  },
  { deep: true }
)
 
const init = () => {
  loading.value = true
  const chart = props.chart
  if (!chart.chartExtRequest) {
    chart.chartExtRequest = {
      user: wsCache.get('user.uid')
    }
  }
  const param = {
    fieldId: props.field.id,
    fieldType: props.fieldType,
    data: chart
  }
  let reqMethod = props.fieldType === 'drillFields' ? getDrillFieldData : getFieldData
  reqMethod(param)
    .then(response => {
      const strArr = response.data
      if (props.originSortList?.length) {
        const tmp = []
        props.originSortList.forEach(ele => {
          const index = strArr.findIndex(item => item === ele)
          if (index !== -1) {
            tmp.push(strArr[index])
            strArr.splice(index, 1)
          }
        })
        strArr.unshift(...tmp)
      }
      state.sortList = strArr
        .filter(ele => ele?.trim())
        .map(ele => {
          return transStr2Obj(ele)
        })
      onUpdate()
      loading.value = false
    })
    .catch(() => {
      loading.value = false
    })
}
const onUpdate = () => {
  const strArr = state.sortList.map(ele => {
    return transObj2Str(ele)
  })
  emit('onSortChange', strArr)
}
 
const transStr2Obj = str => {
  return { name: 'name', value: str }
}
 
const transObj2Str = obj => {
  return obj.value
}
 
init()
</script>
 
<template>
  <el-scrollbar height="100%" max-height="599px">
    <draggable
      v-loading="loading"
      :list="state.sortList"
      animation="300"
      class="drag-list"
      item-key="name"
      @update="onUpdate"
    >
      <template #item="{ element }">
        <span :key="element.value" class="item-dimension" :title="element.value">
          <el-icon class="item-icon">
            <Icon name="icon_drag_outlined"><icon_drag_outlined class="svg-icon" /></Icon>
          </el-icon>
          <span class="item-span">
            {{ element.value }}
          </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>