Files
xl-mobile/src/components/XDropdownList.vue

74 lines
1.8 KiB
Vue
Raw Normal View History

2025-03-27 15:38:21 +08:00
<script setup>
import {ref} from "vue";
2025-05-12 19:45:27 +08:00
import XDropdownItem from "./XDropdownItem.vue";
2025-03-27 15:38:21 +08:00
const show = ref(false);
2025-05-12 19:45:27 +08:00
const modelValue = defineModel();
const emits = defineEmits(['change']);
const {option} = defineProps({
option: {
type: Array,
default: [],
}
});
const change = (id) => {
modelValue.value = id;
emits('change');
2025-05-27 19:01:45 +08:00
show.value = false;
2025-05-12 19:45:27 +08:00
}
2025-03-27 15:38:21 +08:00
</script>
<template>
2025-05-12 19:45:27 +08:00
<view class="relative z-[9990]">
2025-03-27 15:38:21 +08:00
<view @click="show=!show">
2025-05-12 19:45:27 +08:00
<view class="bg-[#fff] !py-[14rpx] !px-[24rpx] rounded-[8rpx]">
{{ option.find(v => v.id === modelValue)?.name }}
</view>
2025-03-27 15:38:21 +08:00
<tui-icon
:style="{
transform: !show ? 'rotate(0deg)' : 'rotate(180deg)'
}"
class="absolute top-1/2 -translate-y-1/2 right-[20rpx] duration-300"
name="arrowdown"
:size="20">
</tui-icon>
</view>
<transition name="fade">
2025-05-12 19:45:27 +08:00
<view v-if="show"
class="absolute top-[calc(100%+10rpx)] min-w-full bg-[#fff] rounded-[8rpx] x-dropdown-card">
<x-dropdown-item v-for="v in option" @click="change(v.id)" :active="modelValue===v.id">
{{ v.name }}
</x-dropdown-item>
2025-03-27 15:38:21 +08:00
</view>
</transition>
</view>
<view
v-if="show"
id="mask"
@click="show=false"
class="!w-screen !h-screen !fixed left-0 top-0 z-[999]">
</view>
</template>
<style lang="scss" scoped>
2025-03-27 16:35:46 +08:00
.x-dropdown-card {
box-shadow: 0px 2px 20px 5px rgba(0, 0, 0, 0.2);
}
2025-03-27 15:38:21 +08:00
.fade-enter-active,
.fade-leave-active {
transition: opacity 300ms;
position: absolute;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
position: absolute;
}
</style>