@@ -143,23 +143,28 @@ export async function DynamicWeiXinChannel(data: SyncData) {
143143 async function uploadImages ( images : FileData [ ] ) : Promise < void > {
144144 const fileInput = ( await waitForElement ( 'input[type="file"][accept="image/*"]' ) ) as HTMLInputElement ;
145145
146- const dataTransfer = new DataTransfer ( ) ;
147-
148- // 使用Promise.all等待所有图片加载完成
149- await Promise . all (
146+ // 1. 并行下载所有图片,保持数组顺序
147+ const files = await Promise . all (
150148 images . map ( async ( image ) => {
151149 const response = await fetch ( image . url ) ;
152150 const blob = await response . blob ( ) ;
153151 const file = new File ( [ blob ] , image . name , { type : image . type } ) ;
154- console . log ( `图片文件 : ${ file . name } ${ file . type } ${ file . size } ` ) ;
155- dataTransfer . items . add ( file ) ;
152+ console . log ( `图片文件准备就绪 : ${ file . name } ${ file . type } ${ file . size } ` ) ;
153+ return file ;
156154 } ) ,
157155 ) ;
158156
157+ // 2. 将所有文件添加到同一个DataTransfer对象中
158+ const dataTransfer = new DataTransfer ( ) ;
159+ for ( const file of files ) {
160+ dataTransfer . items . add ( file ) ;
161+ }
162+
159163 // 先聚焦到文件输入框
160164 fileInput . focus ( ) ;
161165 await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
162166
167+ // 一次性赋值所有文件
163168 fileInput . files = dataTransfer . files ;
164169
165170 // 触发更完整的事件序列来模拟真实用户行为
@@ -175,7 +180,7 @@ export async function DynamicWeiXinChannel(data: SyncData) {
175180 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
176181 }
177182
178- console . log ( '图片上传事件已触发 ' ) ;
183+ console . log ( '所有图片上传事件已触发 ' ) ;
179184 }
180185
181186 try {
0 commit comments