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
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
<script lang="ts" setup>
import custom_sort from '@/assets/svg/custom_sort.svg'
import dvRename from '@/assets/svg/dv-rename.svg'
import icon_calendar_outlined from '@/assets/svg/icon_calendar_outlined.svg'
import icon_copy_outlined from '@/assets/svg/icon_copy_outlined.svg'
import icon_deleteTrash_outlined from '@/assets/svg/icon_delete-trash_outlined.svg'
import icon_edit_outlined from '@/assets/svg/icon_edit_outlined.svg'
import icon_local_outlined from '@/assets/svg/icon_local_outlined.svg'
import icon_number_outlined from '@/assets/svg/icon_number_outlined.svg'
import icon_url_outlined from '@/assets/svg/icon_url_outlined.svg'
import icon_switch_outlined from '@/assets/svg/icon_switch_outlined.svg'
import icon_text_outlined from '@/assets/svg/icon_text_outlined.svg'
import more_v from '@/assets/svg/more_v.svg'
import { ref, computed, nextTick } from 'vue'
import { ElCascaderPanel } from 'element-plus-secondary'
import { timeTypes } from './util'
import { fieldType } from '@/utils/attr'
import { useI18n } from '@/hooks/web/useI18n'
 
export interface Menu {
  svgName: string
  label?: string
  command: string
  divided?: boolean
}
const { t } = useI18n()
 
const props = defineProps({
  extField: {
    type: Number,
    default: 0
  },
  showTime: {
    type: Boolean,
    default: false
  },
  transType: {
    type: String,
    default: ''
  }
})
const timeTypesChildren = timeTypes.map(ele => {
  return {
    label: ele === 'custom' ? t('data_set.customize') : ele,
    value: ele
  }
})
 
const options = computed(() => {
  const optionArr = [
    {
      label: props.transType,
      value: 'translate',
      icon: icon_switch_outlined
    },
    {
      label: t('data_set.change_field_type'),
      value: 'translateType',
      icon: custom_sort,
      children: [
        {
          label: t('data_set.text'),
          icon: icon_text_outlined,
          value: 'text'
        },
        {
          label: t('data_set.time'),
          icon: icon_calendar_outlined,
          value: 'time',
          children: props.showTime ? timeTypesChildren : []
        },
        {
          label: t('data_set.geographical_location'),
          icon: icon_local_outlined,
          value: 'location'
        },
        {
          label: t('data_set.numerical_value'),
          icon: icon_number_outlined,
          value: 'value'
        },
        {
          label: t('data_set.numeric_value_decimal'),
          icon: icon_number_outlined,
          value: 'float'
        },
        {
          label: 'URL',
          icon: icon_url_outlined,
          value: 'url'
        }
      ]
    },
    {
      label: t('data_set.edit'),
      value: 'editor',
      icon: icon_edit_outlined
    },
    {
      label: t('data_set.rename'),
      value: 'rename',
      icon: dvRename
    },
    {
      label: t('data_set.copy'),
      value: 'copy',
      icon: icon_copy_outlined
    },
    {
      label: t('data_set.delete'),
      value: 'delete',
      icon: icon_deleteTrash_outlined
    }
  ]
  if (![2, 3].includes(props.extField)) {
    optionArr.splice(2, 1)
  }
 
  if ([3].includes(props.extField)) {
    optionArr.splice(0, 1)
    optionArr.splice(0, 1)
  }
  return optionArr
})
const deTypeArr = ref([])
const popover = ref()
const level = ref(1)
const cascaderPanel = ref()
const handleExpand = val => {
  level.value = val.left + 1
}
const emit = defineEmits(['handleCommand'])
const handleCommand = () => {
  const [translate, fieldType, timeType] = deTypeArr.value
  popover.value.hide()
  emit('handleCommand', timeType || fieldType || translate)
  nextTick(() => {
    deTypeArr.value = []
  })
}
const handleChange = () => {
  handleCommand()
}
</script>
 
<template>
  <el-popover
    :popper-class="
      options.length === 6
        ? 'menu-more_popper_one menu-more_popper_six'
        : extField === 3
        ? 'menu-more_popper_one menu-more_popper_three'
        : 'menu-more_popper_one'
    "
    :persistent="false"
    ref="popover"
    placement="right"
    :width="level * 175"
    trigger="click"
  >
    <template #reference>
      <el-icon class="menu-more">
        <Icon name="more_v"><more_v class="svg-icon" /></Icon>
      </el-icon>
    </template>
    <ElCascaderPanel
      v-model="deTypeArr"
      @expand-change="handleExpand"
      ref="cascaderPanel"
      :border="false"
      :options="options"
      @change="handleChange"
    >
      <template #default="{ data }">
        <div class="flex-align-center icon">
          <el-icon v-if="data.icon">
            <Icon
              ><component
                class="svg-icon"
                :class="
                  ['text', 'location', 'value', 'float', 'time', 'url'].includes(data.value) &&
                  `field-icon-${fieldType[['float', 'value'].includes(data.value) ? 2 : 0]}`
                "
                :is="data.icon"
              ></component
            ></Icon>
          </el-icon>
          <span>
            {{ data.label }}
          </span>
        </div>
      </template>
    </ElCascaderPanel>
  </el-popover>
</template>
<style lang="less" scoped>
.menu-more {
  cursor: pointer;
  height: 24px;
  width: 24px;
  border-radius: 4px;
  font-size: 16px;
  &:hover {
    background: rgba(31, 35, 41, 0.1);
  }
}
</style>
 
<style lang="less">
.menu-more_popper_six > :first-child > :first-child > :first-child {
  height: 210px;
}
 
.menu-more_popper_three > :first-child > :first-child > :first-child {
  height: 145px;
}
.menu-more_popper_one {
  padding: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
 
  .ed-cascader-node.in-active-path {
    color: #1f2329;
    font-weight: 400;
  }
  .ed-cascader-panel {
    .ed-cascader-menu {
      border-radius: 4px;
      border: 1px solid #dee0e3;
      background: #fff;
      box-shadow: 0px 4px 8px 0px rgba(31, 35, 41, 0.1);
      border-right: none;
      &:nth-child(2) {
        > div {
          height: 210px;
        }
      }
      &:nth-child(3) {
        margin-top: 64px;
      }
      .arrow-right {
        position: absolute;
        top: 50%;
        right: 11px;
        transform: translateY(-50%);
      }
    }
  }
}
</style>