refactor: 重构卫星选择器组件,优化布局和交互细节
All checks were successful
/ lint-build-and-check (push) Successful in 2m35s
/ depcheck (push) Successful in 2m39s
/ build-and-deploy-to-vercel (push) Successful in 3m10s
/ surge (push) Successful in 2m40s
/ playwright (push) Successful in 6m7s

This commit is contained in:
严浩
2025-03-12 14:34:20 +08:00
parent 4fba5091be
commit 38f35328b3

View File

@ -57,13 +57,6 @@ watchEffect(() => {
state.indeterminate = count > 0 && count < filteredCount; state.indeterminate = count > 0 && count < filteredCount;
state.checkAll = count === filteredCount && filteredCount > 0; state.checkAll = count === filteredCount && filteredCount > 0;
}); });
// 切换卫星选中状态
const toggleSatellite = (satellite: SatelliteItem) => {
satellite.selected = !satellite.selected;
updateSatelliteEntity(satellite);
};
// 更新卫星实体(添加或移除) // 更新卫星实体(添加或移除)
const updateSatelliteEntity = (satellite: SatelliteItem) => { const updateSatelliteEntity = (satellite: SatelliteItem) => {
if (!viewer) return; if (!viewer) return;
@ -87,6 +80,12 @@ const updateSatelliteEntity = (satellite: SatelliteItem) => {
} }
}; };
// 切换卫星选中状态
const toggleSatellite = (satellite: SatelliteItem) => {
satellite.selected = !satellite.selected;
updateSatelliteEntity(satellite);
};
// 全选/取消全选 // 全选/取消全选
const onCheckAllChange = (e: { target: { checked: boolean } }) => { const onCheckAllChange = (e: { target: { checked: boolean } }) => {
const checked = e.target.checked; const checked = e.target.checked;
@ -114,23 +113,22 @@ onBeforeUnmount(() => {
</script> </script>
<template> <template>
<div class="absolute top-0 left-0 p-4"> <div class="absolute left-0 top-0 p-4">
<APopover placement="bottomLeft" trigger="click" :overlayStyle="{ width: '320px' }"> <APopover :overlay-style="{ width: '320px' }" placement="bottomLeft" trigger="click">
<template #title> <template #title>
选择卫星 选择卫星
<span class="font-normal text-xs text-gray-500">{{ `(已选择: ${selectedCount}/${totalCount})` }}</span> <span class="text-xs font-normal text-gray-500">{{ `(已选择: ${selectedCount}/${totalCount})` }}</span>
</template> </template>
<template #content> <template #content>
<div class="satellite-selector">
<!-- 搜索框 --> <!-- 搜索框 -->
<AInput v-model:value="state.searchText" placeholder="搜索卫星" allowClear> <AInput v-model:value="state.searchText" allow-clear placeholder="搜索卫星">
<template #prefix><SearchOutlined /></template> <template #prefix><SearchOutlined /></template>
</AInput> </AInput>
<ADivider class="my-3" /> <ADivider class="my-3" />
<!-- 无结果提示 --> <!-- 无结果提示 -->
<div v-if="filteredSatellites.length === 0" class="text-center text-gray-500 py-4">没有找到匹配的卫星</div> <div v-if="filteredSatellites.length === 0" class="py-4 text-center text-gray-500">没有找到匹配的卫星</div>
<!-- 全选选项 --> <!-- 全选选项 -->
<ACheckbox <ACheckbox
@ -148,13 +146,12 @@ onBeforeUnmount(() => {
v-for="satellite in filteredSatellites" v-for="satellite in filteredSatellites"
:key="satellite.tle" :key="satellite.tle"
:checked="satellite.selected" :checked="satellite.selected"
class="my-2 flex w-full"
@change="() => toggleSatellite(satellite)" @change="() => toggleSatellite(satellite)"
class="flex my-2 w-full"
> >
{{ satellite.name }} {{ satellite.name }}
</ACheckbox> </ACheckbox>
</div> </div>
</div>
</template> </template>
<!-- 触发按钮 --> <!-- 触发按钮 -->
@ -165,22 +162,3 @@ onBeforeUnmount(() => {
</APopover> </APopover>
</div> </div>
</template> </template>
<style scoped>
.satellite-list {
scrollbar-width: thin;
}
.satellite-list::-webkit-scrollbar {
width: 4px;
}
.satellite-list::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
border-radius: 4px;
}
.satellite-selector {
max-height: 80vh;
}
</style>