@@ -67,21 +67,21 @@ export const handleImgError = (url: string, e?: HTMLImageElement) => {
6767
6868/** 需要加载的图片 */
6969const needLoadImgList = createRootMemo ( ( ) => {
70- const list = new Set < number > ( ) ;
71- for ( const [ index , img ] of imgList ( ) . entries ( ) )
72- if ( img . loadType !== 'loaded' && img . src ) list . add ( index ) ;
70+ const list = new Set < string > ( ) ;
71+ for ( const img of imgList ( ) )
72+ if ( img . loadType !== 'loaded' && img . src ) list . add ( img . src ) ;
7373 return list ;
7474} ) ;
7575
76- /** 当前需要加载的图片 */
77- const loadImgList = new Set < number > ( ) ;
76+ /** 当前加载的图片 */
77+ const loadImgList = new Set < string > ( ) ;
7878
7979/** 加载指定图片。返回是否已加载完成 */
80- const loadImg = ( index : number ) => {
81- if ( index === - 1 || ! needLoadImgList ( ) . has ( index ) ) return true ;
82- const img = getImg ( index ) ;
80+ const loadImg = ( url : string ) => {
81+ const img = store . imgMap [ url ] ;
82+ if ( ! needLoadImgList ( ) . has ( img . src ) ) return true ;
8383 if ( img . loadType === 'error' ) return true ;
84- loadImgList . add ( index ) ;
84+ loadImgList . add ( url ) ;
8585 return false ;
8686} ;
8787
@@ -123,7 +123,7 @@ const loadRangeImg = (target = 0, loadNum = 2) => {
123123 const step = start <= end ? 1 : - 1 ;
124124
125125 while ( condition ( ) ) {
126- if ( ! loadImg ( index ) ) hasUnloadedImg = true ;
126+ if ( ! loadImg ( getImg ( index ) . src ) ) hasUnloadedImg = true ;
127127 if ( loadImgList . size >= loadNum ) return index !== end || hasUnloadedImg ;
128128 index += step ;
129129 }
@@ -170,9 +170,9 @@ export const updateImgLoadType = singleThreaded(() => {
170170 }
171171
172172 setState ( ( state ) => {
173- for ( const index of needLoadImgList ( ) ) {
174- const img = getImg ( index , state ) ;
175- if ( loadImgList . has ( index ) ) {
173+ for ( const url of needLoadImgList ( ) ) {
174+ const img = state . imgMap [ url ] ;
175+ if ( loadImgList . has ( url ) ) {
176176 if ( img . loadType !== 'loading' ) {
177177 img . loadType = 'loading' ;
178178 if ( ! store . option . imgRecognition . enabled && img . width === undefined )
0 commit comments