更新新需求-采集
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<template>
|
||||
<div class="ai-choice-pills" :class="{ 'ai-choice-pills--wrap': wrap }">
|
||||
<button
|
||||
v-for="option in normalizedOptions"
|
||||
:key="option.value"
|
||||
type="button"
|
||||
class="ai-choice-pills__item"
|
||||
:class="{ 'ai-choice-pills__item--active': isActive(option.value) }"
|
||||
@click="toggle(option.value)"
|
||||
>
|
||||
{{ option.label }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
type Option = string | { label: string; value: string }
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: string | string[]
|
||||
options: Option[]
|
||||
multiple?: boolean
|
||||
wrap?: boolean
|
||||
}>(),
|
||||
{
|
||||
multiple: false,
|
||||
wrap: true,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(event: 'update:modelValue', value: string | string[]): void
|
||||
}>()
|
||||
|
||||
const normalizedOptions = computed(() =>
|
||||
props.options.map((option) =>
|
||||
typeof option === 'string' ? { label: option, value: option } : option,
|
||||
),
|
||||
)
|
||||
|
||||
function isActive(value: string) {
|
||||
return props.multiple
|
||||
? Array.isArray(props.modelValue) && props.modelValue.includes(value)
|
||||
: props.modelValue === value
|
||||
}
|
||||
|
||||
function toggle(value: string) {
|
||||
if (!props.multiple) {
|
||||
emit('update:modelValue', value)
|
||||
return
|
||||
}
|
||||
|
||||
const current = Array.isArray(props.modelValue) ? [...props.modelValue] : []
|
||||
const index = current.indexOf(value)
|
||||
if (index >= 0) {
|
||||
current.splice(index, 1)
|
||||
} else {
|
||||
current.push(value)
|
||||
}
|
||||
emit('update:modelValue', current)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ai-choice-pills {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.ai-choice-pills--wrap {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ai-choice-pills__item {
|
||||
min-height: 40px;
|
||||
padding: 0 18px;
|
||||
border: 1px solid #4b4b4b;
|
||||
border-radius: 999px;
|
||||
background: #1b1b1b;
|
||||
color: #dddddd;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
|
||||
}
|
||||
|
||||
.ai-choice-pills__item:hover {
|
||||
border-color: #8a8a8a;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.ai-choice-pills__item--active {
|
||||
border-color: #8c63ff;
|
||||
background: rgba(140, 99, 255, 0.16);
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user