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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<script lang="ts" setup>
import tabTitle from '@/assets/svg/tab-title.svg'
import dvExpandDown from '@/assets/svg/dv-expand-down.svg'
import dvExpandRight from '@/assets/svg/dv-expand-right.svg'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { snapshotStoreWithOut } from '@/store/modules/data-visualization/snapshot'
import { storeToRefs } from 'pinia'
import { ElIcon, ElMessage, ElRow } from 'element-plus-secondary'
import Icon from '../icon-custom/src/Icon.vue'
import { nextTick, ref, toRefs } from 'vue'
import draggable from 'vuedraggable'
import { composeStoreWithOut } from '@/store/modules/data-visualization/compose'
import RealTimeGroup from '@/components/data-visualization/RealTimeGroup.vue'
import eventBus from '@/utils/eventBus'
import { syncViewTitle } from '@/utils/canvasUtils'
import { useI18n } from '@/hooks/web/useI18n'
 
const dvMainStore = dvMainStoreWithOut()
const snapshotStore = snapshotStoreWithOut()
const composeStore = composeStoreWithOut()
const { t } = useI18n()
const { areaData } = storeToRefs(composeStore)
 
const { curTabName } = storeToRefs(dvMainStore)
 
const props = defineProps({
  tabPosition: {
    type: String,
    required: false,
    default: 'main'
  },
  componentData: [],
  tabElement: {}
})
 
const { componentData, tabElement } = toRefs(props)
 
const getComponent = index => {
  return componentData.value[index]
}
const onClick = item => {
  if (item) {
    dvMainStore.setCurTabName(item.name)
  } else {
    dvMainStore.setCurTabName(null)
  }
  //其他情况点击清理选择区域
  areaData.value.components.splice(0, areaData.value.components.length)
}
 
let nameEdit = ref(false)
let editComponentId = ref('')
let inputName = ref('')
let nameInput = ref(null)
let curEditComponent = null
const editComponentName = item => {
  curEditComponent = item
  editComponentId.value = `#component-label-${item.name}`
  nameEdit.value = true
  inputName.value = item.title
  nextTick(() => {
    nameInput.value.focus()
  })
}
const closeEditComponentName = () => {
  nameEdit.value = false
  if (!inputName.value || !inputName.value.trim()) {
    return
  }
  if (inputName.value.trim() === curEditComponent.title) {
    return
  }
  if (inputName.value.length < 1 || inputName.value.length > 64) {
    ElMessage.warning(t('components.length_1_64_characters'))
    return
  }
  curEditComponent.title = inputName.value
  syncViewTitle(curEditComponent)
  inputName.value = ''
  curEditComponent = null
}
 
const dragOnEnd = ({ newIndex }) => {
  const source = componentData.value[newIndex]
  dvMainStore.setCurTabName(source.title)
  eventBus.emit('onTabSortChange-' + tabElement.value?.id)
  snapshotStore.recordSnapshotCache('dragOnEnd')
}
 
const handleContextMenu = e => {
  e.preventDefault()
  // 获取鼠标点击位置
  const x = e.clientX
  const y = e.clientY
  const customContextMenu = document.createElement('div')
  customContextMenu.style.position = 'fixed'
  customContextMenu.style.left = x + 'px'
  customContextMenu.style.top = y + 'px'
 
  // 将自定义菜单添加到页面
  document.body.appendChild(customContextMenu)
 
  // 为自定义菜单添加事件监听器,例如,点击菜单项后执行的操作
  customContextMenu.addEventListener('click', () => {
    // 在这里执行菜单项点击后的操作
    // 例如,关闭菜单
    document.body.removeChild(customContextMenu)
  })
}
 
const expandClick = component => {
  component['expand'] = !component['expand']
}
</script>
 
<template>
  <!--为了保持图层视觉上的一致性 这里进行数组的倒序排列 相应的展示和移动按照倒序处理-->
  <div class="real-time-component-list">
    <button hidden="true" id="close-button"></button>
    <el-row class="list-wrap">
      <div class="list-container" @contextmenu="handleContextMenu">
        <draggable
          @end="dragOnEnd"
          :list="componentData"
          animation="100"
          class="drag-list"
          item-key="id"
        >
          <template #item="{ index }">
            <div>
              <div
                :title="getComponent(index)?.title"
                class="component-item"
                :class="{
                  activated: curTabName === getComponent(index)?.name,
                  'component-item-group': props.tabPosition === 'groupTab'
                }"
                @click="onClick(getComponent(index))"
              >
                <div style="width: 22px">
                  <el-icon
                    class="component-expand expand-icon"
                    @click="expandClick(getComponent(index))"
                  >
                    <Icon v-if="getComponent(index)?.expand" name="dv-expand-down"
                      ><dvExpandDown class="svg-icon expand-icon"
                    /></Icon>
                    <Icon v-if="!getComponent(index)?.expand" name="dv-expand-right"
                      ><dvExpandRight class="svg-icon expand-icon"
                    /></Icon>
                  </el-icon>
                </div>
                <el-icon class="component-icon">
                  <Icon><component :is="tabTitle"></component></Icon>
                </el-icon>
                <span
                  :id="`component-label-${getComponent(index)?.name}`"
                  class="component-label"
                  @dblclick="editComponentName(getComponent(index))"
                >
                  {{ getComponent(index)?.title }}
                </span>
              </div>
              <div v-if="getComponent(index)?.expand">
                <real-time-group
                  :tab-position="tabPosition"
                  :component-data="getComponent(index).componentData"
                ></real-time-group>
              </div>
            </div>
          </template>
        </draggable>
      </div>
    </el-row>
    <Teleport v-if="editComponentId && nameEdit" :to="editComponentId">
      <input
        class="custom-teleport"
        @keydown.stop
        @keyup.stop
        ref="nameInput"
        v-model="inputName"
        @blur="closeEditComponentName"
      />
    </Teleport>
  </div>
</template>
 
<style lang="less" scoped>
.component-item-group {
  padding: 0 2px 0 40px !important;
}
.real-time-component-list {
  white-space: nowrap;
  .list-wrap {
    max-height: calc(100% - @component-toolbar-height);
    overflow-y: auto;
    width: 100%;
    .list-container {
      width: 100%;
      .component-item {
        position: relative;
        height: 30px;
        width: 100%;
        cursor: grab;
        color: @dv-canvas-main-font-color;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        font-size: 12px;
        padding: 0 2px 0 15px;
        user-select: none;
 
        .component-icon {
          color: #a6a6a6;
          font-size: 14px;
        }
        .component-label {
          color: #ebebeb;
        }
 
        > span.component-label {
          font-size: 12px;
          margin-left: 10px;
          position: relative;
          min-width: 43px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          input {
            position: absolute;
            left: 0;
            width: 100%;
            background-color: white;
            outline: none;
            border: none;
            border-radius: 2px;
            padding: 0 4px;
            height: 100%;
          }
        }
 
        &:active {
          cursor: grabbing;
        }
 
        &:hover {
          background-color: rgba(235, 235, 235, 0.1);
 
          .icon-container {
            .component-base {
              opacity: 1;
            }
            width: 22px !important;
          }
        }
 
        .icon-container {
          .component-base {
            opacity: 0;
          }
          width: 0px;
          display: flex;
          justify-content: flex-end;
          align-items: center;
          flex-grow: 1;
          cursor: none;
          i {
            font-size: 16px;
            cursor: pointer;
          }
        }
      }
      .activated {
        background-color: var(--ed-color-primary-1a, rgba(51, 112, 255, 0.05)) !important;
        :deep(.component-icon) {
          color: var(--ed-color-primary);
        }
        :deep(.component-label) {
          color: var(--ed-color-primary);
        }
      }
    }
  }
}
 
.real-time-component-list :deep(.ed-popper) {
  background: #303133 !important;
}
 
.component-base {
  cursor: pointer;
  height: 22px !important;
  width: 22px !important;
  border-radius: 4px;
  padding: 0 4px;
 
  .opt-icon {
    font-size: 14px;
  }
 
  &:hover {
    background: rgba(235, 235, 235, 0.1);
  }
 
  &:active {
    background: rgba(235, 235, 235, 0.1);
  }
}
 
.component-icon-display {
  opacity: 1 !important;
}
 
.icon-container-show {
  width: 70px !important;
}
 
.icon-container-lock {
  width: 45px !important;
}
 
.container-item-not-show {
  color: #5f5f5f !important;
  :deep(.component-icon) {
    color: #5f5f5f !important;
  }
  :deep(.component-label) {
    color: #5f5f5f !important;
  }
}
 
.component-expand {
  cursor: pointer;
  height: 16px !important;
  width: 16px !important;
  border-radius: 2px;
  padding: 0 2px;
 
  .expand-icon {
    font-size: 10px;
  }
 
  &:hover {
    background: rgba(235, 235, 235, 0.1);
  }
 
  &:active {
    background: rgba(235, 235, 235, 0.1);
  }
}
.custom-teleport {
  background: #1a1a1a !important;
}
</style>
 
<style lang="less">
.compose-dropdown {
  position: initial !important;
}
</style>