11<script setup lang="ts">
2- import { ref , onMounted , computed } from ' vue'
2+ import { ref , onMounted , computed , onBeforeUnmount } from ' vue'
33import { marked } from ' marked'
44
5+ const deviceDropdownRef = ref <HTMLElement | null >(null )
6+ const sourceDropdownRef = ref <HTMLElement | null >(null )
7+
58interface DeviceType {
69 id: string
710 name: string
@@ -150,7 +153,20 @@ function getFileIcon(fileName: string): string {
150153 return ' 📄'
151154}
152155
156+ function handleClickOutside(event : MouseEvent ) {
157+ const target = event .target as HTMLElement
158+ if (deviceDropdownRef .value && ! deviceDropdownRef .value .contains (target )) {
159+ isDeviceDropdownOpen .value = false
160+ }
161+ if (sourceDropdownRef .value && ! sourceDropdownRef .value .contains (target )) {
162+ isSourceDropdownOpen .value = false
163+ }
164+ }
165+
153166onMounted (async () => {
167+ // 添加全局点击事件监听
168+ document .addEventListener (' click' , handleClickOutside )
169+
154170 // 自动获取SecRandom发布信息
155171 isLoading .value = true
156172 hasError .value = false
@@ -235,8 +251,12 @@ onMounted(async () => {
235251})
236252 </script >
237253
254+ onBeforeUnmount(() => {
255+ document.removeEventListener('click', handleClickOutside)
256+ })
257+
238258<template >
239- <div class =" download-container" >
259+ <div class =" download-container" @click.stop >
240260 <div class =" download-header" >
241261 <h1 >下载 SecRandom</h1 >
242262 <p class =" subtitle" >选择适合您需求的版本(仅支持Windows)</p >
@@ -246,7 +266,7 @@ onMounted(async () => {
246266 <div class =" filter-section" >
247267 <div class =" filter-group" >
248268 <label >版本类型:</label >
249- <div class =" dropdown" :class =" { open: isDeviceDropdownOpen }" >
269+ <div class =" dropdown" :class =" { open: isDeviceDropdownOpen }" ref = " deviceDropdownRef " >
250270 <button @click =" isDeviceDropdownOpen = !isDeviceDropdownOpen" class =" dropdown-button" >
251271 {{ dynamicDeviceTypes.find(t => t.id === selectedDeviceType)?.name }}
252272 <span class =" arrow" >▼</span >
@@ -270,7 +290,7 @@ onMounted(async () => {
270290
271291 <div class =" filter-group" >
272292 <label >下载源:</label >
273- <div class =" dropdown" :class =" { open: isSourceDropdownOpen }" >
293+ <div class =" dropdown" :class =" { open: isSourceDropdownOpen }" ref = " sourceDropdownRef " >
274294 <button @click =" isSourceDropdownOpen = !isSourceDropdownOpen" class =" dropdown-button" >
275295 {{ downloadSources.find(s => s.id === selectedDownloadSource)?.name }}
276296 <span class =" arrow" >▼</span >
@@ -378,9 +398,6 @@ onMounted(async () => {
378398
379399<style scoped>
380400.download-container {
381- width : 100% ;
382- max-width : none ;
383- margin : 0 ;
384401 padding : 2rem 0rem ;
385402}
386403
@@ -415,7 +432,7 @@ onMounted(async () => {
415432.filter-group label {
416433 display : block ;
417434 margin-bottom : 0.5rem ;
418- font-weight : 500 ;
435+ font-weight : bold ;
419436}
420437
421438.dropdown {
@@ -426,7 +443,7 @@ onMounted(async () => {
426443 width : 100% ;
427444 padding : 0.75rem 1rem ;
428445 border : 1px solid var (--vp-c-border );
429- border-radius : 0.5 rem ;
446+ border-radius : 0.7 rem ;
430447 background : var (--vp-c-bg );
431448 color : var (--vp-c-text-1 );
432449 cursor : pointer ;
@@ -571,8 +588,8 @@ onMounted(async () => {
571588
572589.file-list {
573590 background : var (--vp-c-bg-soft );
574- border-radius : 0.75 rem ;
575- padding : 1.5 rem 1 rem ;
591+ border-radius : 0.7 rem ;
592+ padding : 2.0 rem 2.0 rem ;
576593 width : 100% ;
577594 box-sizing : border-box ;
578595}
@@ -620,7 +637,7 @@ onMounted(async () => {
620637 padding : 1rem ;
621638 background : var (--vp-c-bg );
622639 border : 1px solid var (--vp-c-border );
623- border-radius : 0.5 rem ;
640+ border-radius : 0.7 rem ;
624641 transition : all 0.2s ;
625642}
626643
@@ -659,7 +676,7 @@ onMounted(async () => {
659676 background : var (--vp-c-brand-1 );
660677 color : white ;
661678 text-decoration : none ;
662- border-radius : 0.25 rem ;
679+ border-radius : 0.7 rem ;
663680 transition : background 0.2s ;
664681}
665682
0 commit comments