140140 :title =" $t (` iconCollectionPage.collectionPicker.title ` )"
141141 :cancel-text =" $t (` iconCollectionPage.collectionPicker.cancel ` )"
142142 :ok-text =" $t (` iconCollectionPage.collectionPicker.confirm ` )"
143+ :z-index =" ICON_COLLECTION_PICKER_Z_INDEX "
144+ :teleport-disable =" true "
143145 @confirm =" handleConfirm "
144146 @cancel =" handleCancel "
145147 ></DesktopPicker >
@@ -173,6 +175,10 @@ const { customIconCollections, defaultIconCollections, defaultIconCollection } =
173175 storeToRefs (globalStore );
174176const { githubProxy, githubProxyRegex } = storeToRefs (settingsStore );
175177
178+ const ICON_COLLECTION_PICKER_Z_INDEX = 11001 ;
179+ const ICON_COLLECTION_FETCH_RETRY_COUNT = 1 ;
180+ const ICON_COLLECTION_FETCH_RETRY_DELAY = 600 ;
181+
176182const form = reactive ({
177183 iconName: " " ,
178184 iconCollectionName: " " ,
@@ -247,14 +253,61 @@ const setCustomIconCollections = (collection: any[]) => {
247253 globalStore .setCustomIconCollections (collection );
248254};
249255
256+ const getFallbackIconCollectionUrl = () => {
257+ return defaultIconCollections .value [0 ]?.value || " " ;
258+ };
259+
260+ const isKnownIconCollectionUrl = (url : string ) => {
261+ return iconCollectionColumns .value .some ((item ) => item .value === url );
262+ };
263+
264+ const setCurrentIconCollectionUrl = (url : string ) => {
265+ form .iconCollectionUrl = url ;
266+ defaultIconCollectionValue .value [0 ] = url ;
267+ };
268+
269+ let iconFetchRequestId = 0 ;
270+
271+ const wait = (ms : number ) => new Promise ((resolve ) => setTimeout (resolve , ms ));
272+
273+ const fetchIconCollection = async (url : string ) => {
274+ let lastError;
275+
276+ for (let attempt = 0 ; attempt <= ICON_COLLECTION_FETCH_RETRY_COUNT ; attempt ++ ) {
277+ try {
278+ const { data } = await axios .get (url );
279+ return data ;
280+ } catch (error ) {
281+ lastError = error ;
282+
283+ if (attempt < ICON_COLLECTION_FETCH_RETRY_COUNT ) {
284+ await wait (ICON_COLLECTION_FETCH_RETRY_DELAY );
285+ }
286+ }
287+ }
288+
289+ throw lastError ;
290+ };
291+
250292const fetchIcons = async () => {
293+ const requestId = iconFetchRequestId + 1 ;
294+ iconFetchRequestId = requestId ;
295+ const iconCollectionUrl = form .iconCollectionUrl ;
296+
251297 try {
252298 Toast .loading (t (` globalNotify.refresh.loading ` ), {
253299 cover: true ,
254300 id: " icon-collection" ,
255301 });
256302 fetchStatus .value = " loading" ;
257- const { data } = await axios .get (rewriteGithubUrl (form .iconCollectionUrl ));
303+ const rewrittenIconCollectionUrl = rewriteGithubUrl (iconCollectionUrl );
304+ if (! rewrittenIconCollectionUrl ) {
305+ throw new Error (" Missing icon collection URL" );
306+ }
307+ const data = await fetchIconCollection (rewrittenIconCollectionUrl );
308+ if (requestId !== iconFetchRequestId ) {
309+ return ;
310+ }
258311 const collectionKey = form .iconListKey || " icons" ;
259312 const iconUrlKey = form .iconItemUrlKey || " url" ;
260313 iconList .value = data [collectionKey ];
@@ -271,23 +324,23 @@ const fetchIcons = async () => {
271324 });
272325 // 添加自定义图标仓库,
273326 const hasCollection = iconCollectionColumns .value .some (
274- (item ) => item .value === form . iconCollectionUrl ,
327+ (item ) => item .value === iconCollectionUrl ,
275328 );
276329 console .log (" hasCollection" , hasCollection );
277330 if (! hasCollection ) {
278331 const list = [
279332 {
280333 text: name ,
281- value: form . iconCollectionUrl ,
334+ value: iconCollectionUrl ,
282335 },
283336 ... customIconCollections .value ,
284337 ];
285338 setCustomIconCollections (list );
286- setDefaultIconCollection (form . iconCollectionUrl );
287- defaultIconCollectionValue .value [0 ] = form . iconCollectionUrl ;
339+ setDefaultIconCollection (iconCollectionUrl );
340+ defaultIconCollectionValue .value [0 ] = iconCollectionUrl ;
288341 } else {
289- setDefaultIconCollection (form . iconCollectionUrl );
290- defaultIconCollectionValue .value [0 ] = form . iconCollectionUrl ;
342+ setDefaultIconCollection (iconCollectionUrl );
343+ defaultIconCollectionValue .value [0 ] = iconCollectionUrl ;
291344 }
292345 } else {
293346 iconList .value = [];
@@ -297,6 +350,9 @@ const fetchIcons = async () => {
297350 fetchStatus .value = " success" ;
298351 Toast .hide (" icon-collection" );
299352 } catch (error ) {
353+ if (requestId !== iconFetchRequestId ) {
354+ return ;
355+ }
300356 Toast .hide (" icon-collection" );
301357 iconList .value = [];
302358 searchResult .value = [];
@@ -338,13 +394,22 @@ const handleCancel = () => {
338394};
339395
340396const syncIconCollectionState = () => {
341- if (defaultIconCollection .value ) {
342- form .iconCollectionUrl = defaultIconCollection .value ;
343- defaultIconCollectionValue .value [0 ] = defaultIconCollection .value ;
344- } else {
345- form .iconCollectionUrl = defaultIconCollections .value [0 ].value ;
346- defaultIconCollectionValue .value [0 ] = defaultIconCollections .value [0 ].value ;
397+ const savedIconCollectionUrl = defaultIconCollection .value ;
398+ const fallbackIconCollectionUrl = getFallbackIconCollectionUrl ();
399+ const iconCollectionUrl =
400+ savedIconCollectionUrl && isKnownIconCollectionUrl (savedIconCollectionUrl )
401+ ? savedIconCollectionUrl
402+ : fallbackIconCollectionUrl ;
403+
404+ if (! iconCollectionUrl ) {
405+ return ;
406+ }
407+
408+ if (savedIconCollectionUrl && savedIconCollectionUrl !== iconCollectionUrl ) {
409+ setDefaultIconCollection (iconCollectionUrl );
347410 }
411+
412+ setCurrentIconCollectionUrl (iconCollectionUrl );
348413};
349414
350415const clearIconName = () => {
@@ -460,6 +525,7 @@ defineExpose({ show, hide, close });
460525 padding-left : 60px ;
461526 flex-shrink : 0 ;
462527 .action-btn {
528+ cursor : pointer ;
463529 display : flex ;
464530 align-items : center ;
465531 justify-content : flex-end ;
0 commit comments