Files
gsfdc/portal/app/components/OptionSelect.vue
T
wuzilongandCursor 9c7c80e194 feat: 把估价智能体和部署配置提交到主分支
门户估价对话、会员与智能体账号,以及生产 Docker 部署一直停在工作区,远端主分支还没有这些改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-23 09:42:44 +08:00

115 lines
2.7 KiB
Vue

<template>
<div ref="root" class="option-select">
<button
type="button"
class="trigger"
:aria-expanded="open"
aria-haspopup="listbox"
@click="open = !open"
>
<span>{{ current }}</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true">
<path d="m6 9 6 6 6-6" />
</svg>
</button>
<ul v-if="open" class="menu" role="listbox">
<li v-for="item in options" :key="item.value">
<button
type="button"
role="option"
:aria-selected="item.value === modelValue"
:class="{ on: item.value === modelValue }"
@click="choose(item.value)"
>
{{ item.label }}
</button>
</li>
</ul>
</div>
</template>
<script setup lang="ts">
type Option = { value: number; label: string }
const props = defineProps<{
modelValue: number | null
options: Option[]
}>()
const emit = defineEmits<{ "update:modelValue": [value: number] }>()
const open = ref(false)
const root = ref<HTMLElement | null>(null)
const current = computed(() => props.options.find((item) => item.value === props.modelValue)?.label || "请选择")
function choose(value: number) {
emit("update:modelValue", value)
open.value = false
}
function onPointerDown(event: PointerEvent) {
if (!root.value?.contains(event.target as Node)) open.value = false
}
onMounted(() => document.addEventListener("pointerdown", onPointerDown))
onBeforeUnmount(() => document.removeEventListener("pointerdown", onPointerDown))
</script>
<style scoped>
.option-select { position: relative; }
.trigger {
width: 100%;
height: 40px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 0 12px;
border: 1px solid #d6e4ff;
border-radius: 10px;
background: #fff;
color: #1e3a5f;
font: inherit;
font-size: 14px;
cursor: pointer;
text-align: left;
}
.trigger span {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.trigger svg { width: 16px; height: 16px; flex: none; color: #6b86a8; }
.menu {
position: absolute;
z-index: 2;
top: calc(100% + 4px);
left: 0;
right: 0;
margin: 0;
padding: 6px;
list-style: none;
max-height: 220px;
overflow: auto;
border: 1px solid #d7e3f4;
border-radius: 10px;
background: #fff;
box-shadow: 0 10px 28px rgba(30, 58, 95, 0.14);
}
.menu button {
width: 100%;
border: 0;
border-radius: 8px;
background: transparent;
color: #1e3a5f;
font: inherit;
font-size: 14px;
text-align: left;
padding: 8px 10px;
cursor: pointer;
}
.menu button:hover,
.menu button.on { background: #e8f1ff; color: #1d4ed8; }
</style>