@@ -23,6 +23,7 @@ const pickerParent = ref<string | null>(null)
2323const pickerItems = ref <string []>([]) // 绝对路径
2424const pickerDrives = ref <DriveEntry []>([])
2525const pickerQuickDirs = ref <QuickDir []>([])
26+ const pickerError = ref (' ' )
2627const pickerCreating = ref (false )
2728const pickerNewName = ref (' ' )
2829const newNameInput = ref <InstanceType <typeof SInput > | null >(null )
@@ -50,6 +51,10 @@ function resetCreate() {
5051 pickerNewName .value = ' '
5152}
5253
54+ function getErrorMessage(e : unknown ): string {
55+ return e instanceof Error ? e .message : String (e )
56+ }
57+
5358function enterDriveMode() {
5459 resetCreate ()
5560 pickerPath .value = ' '
@@ -66,9 +71,11 @@ async function navigate(absPath: string): Promise<boolean> {
6671 pickerPath .value = res .path
6772 pickerParent .value = res .parent
6873 pickerItems .value = res .items
74+ pickerError .value = ' '
6975 return true
7076 } catch (e : any ) {
71- emit (' error' , e ?.message ?? String (e ))
77+ pickerError .value = getErrorMessage (e )
78+ emit (' error' , pickerError .value )
7279 return false
7380 } finally {
7481 pickerLoading .value = false
@@ -108,17 +115,29 @@ async function open(initialPath = '') {
108115 enterDriveMode ()
109116 pickerDrives .value = []
110117 pickerQuickDirs .value = []
118+ pickerError .value = ' '
119+ pickerLoading .value = true
111120 pickerOpen .value = true
112121
113- const [drives, quicks ] = await Promise .all ([
114- props .transport .listDrives (). catch (() => [] as DriveEntry []) ,
115- props .transport .quickDirs (). catch (() => [] as QuickDir []) ,
122+ const [drivesResult, quicksResult ] = await Promise .allSettled ([
123+ props .transport .listDrives (),
124+ props .transport .quickDirs (),
116125 ])
117- pickerDrives .value = drives
118- pickerQuickDirs .value = quicks
126+
127+ if (drivesResult .status === ' fulfilled' ) pickerDrives .value = drivesResult .value
128+ if (quicksResult .status === ' fulfilled' ) pickerQuickDirs .value = quicksResult .value
129+
130+ const errors: string [] = []
131+ if (drivesResult .status === ' rejected' ) errors .push (` 磁盘列表:${getErrorMessage (drivesResult .reason )} ` )
132+ if (quicksResult .status === ' rejected' ) errors .push (` 常用目录:${getErrorMessage (quicksResult .reason )} ` )
133+ if (errors .length ) {
134+ pickerError .value = ` 请求目录失败:${errors .join (' ;' )} `
135+ emit (' error' , pickerError .value )
136+ }
137+ pickerLoading .value = false
119138
120139 if (initialPath && await navigate (initialPath )) return
121- if (drives . length === 1 ) await navigate (drives [0 ].path )
140+ if (pickerDrives . value . length === 1 ) await navigate (pickerDrives . value [0 ].path )
122141 // 多盘符:保持 driveMode 让用户选
123142}
124143
@@ -156,11 +175,12 @@ defineExpose({ open })
156175 @click =" navigate (d .path )"
157176 >{{ d.label }}</SChip >
158177 </div >
178+ <div v-if =" pickerError" class =" chatui-picker-error" >{{ pickerError }}</div >
159179
160180 <div class =" chatui-picker-list" >
161181 <div v-if =" pickerLoading" class =" chatui-picker-empty" >{{ L.loading }}</div >
162182 <template v-else-if =" pickerDriveMode " >
163- <div v-if =" pickerDrives.length === 0" class =" chatui-picker-empty" >{{ L.noSubdirs }}</div >
183+ <div v-if =" pickerDrives.length === 0 && !pickerError " class =" chatui-picker-empty" >{{ L.noSubdirs }}</div >
164184 <div
165185 v-for =" d in pickerDrives" :key =" d.path"
166186 class =" chatui-picker-item"
@@ -187,7 +207,7 @@ defineExpose({ open })
187207 <SButton type="outline" size="sm" @click =" confirmCreate " >✓</SButton >
188208 <SButton type="outline" size="sm" @click =" cancelCreate " >✕</SButton >
189209 </div >
190- <div v-if =" pickerItems.length === 0 && !pickerCreating" class =" chatui-picker-empty" >{{ L.noSubdirs }}</div >
210+ <div v-if =" pickerItems.length === 0 && !pickerCreating && !pickerError " class =" chatui-picker-empty" >{{ L.noSubdirs }}</div >
191211 <div v-for =" item in pickerItems" :key =" item" class =" chatui-picker-item" @click =" navigate(item)" >
192212 <span class =" chatui-picker-icon" >▶</span >{{ itemLabel(item) }}
193213 </div >
@@ -227,6 +247,15 @@ defineExpose({ open })
227247 background : var (--chatui-bg-hover );
228248}
229249.chatui-picker-qd-active { background : var (--chatui-bg-active ) !important ; }
250+ .chatui-picker-error {
251+ padding : 8px 12px ;
252+ border-bottom : 1px solid var (--chatui-border );
253+ color : var (--chatui-btn-danger , #d14343 );
254+ background : var (--chatui-bg-surface );
255+ font-size : 12px ;
256+ line-height : 1.4 ;
257+ word-break : break-word ;
258+ }
230259.chatui-picker-create-row {
231260 display : flex ; align-items : center ; gap : 6px ; padding : 5px 14px ;
232261 border-bottom : 1px solid var (--chatui-border );
0 commit comments