Files
aurora-admin/frameworks/Dropdown.vue2.vue
T

69 lines
2.5 KiB
Vue

<template>
<div class="aa-dropdown" ref="root">
<div class="aa-dropdown-trigger" @click="open = !open">
<slot>操作</slot>
</div>
<div v-show="open" class="aa-dropdown-panel">
<template v-for="(item, i) in items">
<div v-if="item.divider" :key="'d' + i" class="aa-dropdown-divider"></div>
<div
v-else
:key="item.key || i"
class="aa-dropdown-item"
:class="{ 'is-danger': item.danger, 'is-disabled': item.disabled }"
@click="onClick(item)"
>
<span v-if="item.icon" class="ico">{{ item.icon }}</span>
{{ item.label }}
</div>
</template>
</div>
</div>
</template>
<script>
export default {
name: 'AaDropdown',
props: {
items: { type: Array, default: () => [] }, // [{ key, label, danger, disabled, divider, icon }]
triggerText: { type: String, default: '操作' }
},
data() { return { open: false }; },
methods: {
onClick(item) {
if (item.disabled || item.divider) return;
this.$emit('select', item.key != null ? item.key : item.label);
this.open = false;
},
onDocClick(e) {
if (this.$refs.root && !this.$refs.root.contains(e.target)) this.open = false;
}
},
mounted() { document.addEventListener('click', this.onDocClick); },
beforeDestroy() { document.removeEventListener('click', this.onDocClick); }
};
</script>
<!-- 样式对齐 组件2.txt Dropdown 规范 -->
<style>
.aa-dropdown { position: relative; display: inline-block; }
.aa-dropdown-trigger {
border: 1px solid #E8ECF1; background: #fff; border-radius: 4px; height: 32px; padding: 0 12px;
cursor: pointer; font-size: 14px; color: #262626; display: inline-flex; align-items: center; gap: 4px;
}
.aa-dropdown-trigger:hover { border-color: #2F54EB; }
.aa-dropdown-panel {
position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 120px;
background: #fff; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); padding: 4px 0;
}
.aa-dropdown-item {
display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; cursor: pointer;
font-size: 14px; color: #262626; white-space: nowrap;
}
.aa-dropdown-item:hover { background: #F5F7FA; }
.aa-dropdown-item.is-danger { color: #F5222D; }
.aa-dropdown-item.is-disabled { color: #BFBFBF; cursor: not-allowed; }
.aa-dropdown-item.is-disabled:hover { background: transparent; }
.aa-dropdown-divider { height: 1px; background: #F0F0F0; margin: 4px 0; }
</style>