配置示例：

[图片附件未整合: ../../../../_assets/193078745643352064/001-93bda211d3.png]

网格列表配置：

[图片附件未整合: ../../../../_assets/193078745643352064/002-2563c0dff0.png]

代码示例：

1、行上、行末

```javascript
//行上按钮、行末下拉按钮获取dataId
const dataId = this.data['id'];
//传入附件字段id
batchDownload('841587339898257472',dataId);

function batchDownload(_fieldid,_dataId) {
  const Log = (text, visible = false, type = 'info', delay = 1000) => {
    console.log(text);
    if (visible) {
      return window.weappUi.Dialog.message({ type, content: text, delay });
    }
  };
  // 通过sdk获取数据项，得到附件字段的值
  const getDataId = () => {
    const fieldId = _fieldid;
		const targetData = window.ebdfListSdk.getListData().find((row)=>{
    	const target = row.some((data)=>{
        	return data.id === _dataId
    	})
    	return target;
		})
  	const ids = targetData?.length ? targetData[0]?.[fieldId] : '';
    console.log(ids)
    return ids || '';
  };
  const beginPack = async (dataIds) => {
    if (!dataIds) return '';
    const res = await window.weappUtils.request({
      url: '/api/file/batchDownloadByFileIds', params: { module: 'ebuilderform', fileIds: dataIds },
    });
    if (res?.data?.success) {
      Log('成功获取到file-uuid');
      return res;
    }
    Log('获取file-uuid请求失败');
    return res;
  };

  const getPackStatus = async (uuid) => {
    if (!uuid) {
      Log('提供的UUID无效，无法检查打包状态。');
      return;
    }

    const MAX_ATTEMPTS = 5 * 60 * 1000; // 5分钟转换为毫秒
    const ATTEMPT_DELAY = 1000; // 1000毫秒的延迟
    let attempts = 0;
    let lastPercent = 0;

    const checkStatus = async () => {
      Log(`正在检查UUID: ${uuid}的打包状态，第${attempts + 1}次尝试...`);
      const res = await window.weappUtils.request({
        url: '/api/file/batchDownloadPercent', params: { uuid },
      });

      if (res?.data) {
        const percent = parseInt(`${res.data.percent}`, 10);

        if (`${percent}` === '100') {
          // 如果下载完成，返回fileId
          const { fileId } = res.data;
          Log('云端下载已完成,正在下载到本地...', true);
          return fileId;
        }
        if (`${percent}` === '-1') {
          Log('正在从云端下载，请稍后…');
        } else if (percent > lastPercent) {
          Log(`打包进度: ${percent}%`, true);
          // 如果进度有更新，更新lastPercent并记录尝试次数
          lastPercent = percent;
          attempts++;
          Log(`UUID: ${uuid}的进度已更新至${percent}%。`);
        } else {
          attempts++;
        }
      } else {
        Log(`未能获取到UUID: ${uuid}的打包状态。`);
        // 如果请求失败，重置尝试次数
        attempts = 0;
      }

      // 如果尝试次数未超过最大尝试次数且未超过5分钟，继续重试
      if (attempts < MAX_ATTEMPTS) {
        return new Promise((resolve) => setTimeout(() => resolve(checkStatus()), ATTEMPT_DELAY));
      }
      // 超过最大尝试次数，放弃重试
      Log(`UUID: ${uuid}的下载在5分钟后超时。`);
      return '下载超时';
    };

    return checkStatus();
  };
  const downloadFile = async (fileid) => {
    if (!fileid) return;
    window.location.href = `/api/file/remotedownload/${fileid}/upload/true`;
    Log(`fileid: ${fileid}下载完成。`, true, 'success');
  };

  const main = async () => {
    const dataIds = getDataId();
    if (!dataIds) return;
    const ref = Log('正在下载，请不要关闭当前页面...', true, 'info', 0);
    const res = await beginPack(dataIds);
    const uuid = res?.data?.data;
    if (!uuid) {
      if (res?.msg) {
        ref.destroy();
        Log(res?.msg, true, 'info', 2000);
      } else {
        ref.destroy();
      }
      return;
    }
    const fileId = await getPackStatus(uuid);
    ref.destroy();
    downloadFile(fileId);
  };
  main();
}
```

  
2、多id下载demo，如果必须放在右上角的话：

```javascript
/**
 * 批量下载附件
 * @param {String} _fieldid 附件字段ID
 * @param {String|String[]} _dataId 数据ID（支持单个或多个）
 */
function batchDownload(_fieldid, _dataId) {
  const Log = (text, visible = false, type = 'info', delay = 1000) => {
    console.log(text);
    if (visible && window.weappUi?.Dialog?.message) {
      return window.weappUi.Dialog.message({ type, content: text, delay });
    }
  };

  /**
   * 获取附件 fileIds（支持多 dataId）
   */
  const getDataId = () => {
    const fieldId = _fieldid;
    const dataIdList = Array.isArray(_dataId) ? _dataId : [_dataId];
    const fileIdSet = new Set();

    const listData = window.ebdfListSdk?.getListData?.() || [];

    listData.forEach(row => {
      row.forEach(item => {
        if (dataIdList.includes(item.id)) {
          const val = item[fieldId];
          if (!val) return;

          if (Array.isArray(val)) {
            val.forEach(v => v && fileIdSet.add(String(v)));
          } else {
            String(val)
              .split(',')
              .forEach(v => v && fileIdSet.add(v.trim()));
          }
        }
      });
    });

    return Array.from(fileIdSet).join(',');
  };

  /**
   * 发起打包请求
   */
  const beginPack = async (fileIds) => {
    if (!fileIds) return null;

    const res = await window.weappUtils.request({
      url: '/api/file/batchDownloadByFileIds',
      params: {
        module: 'ebuilderform',
        fileIds,
      },
    });

    if (res?.data?.success) {
      Log('成功获取打包任务');
      return res.data.data; // uuid
    }

    Log('打包请求失败');
    return null;
  };

  /**
   * 轮询打包进度
   */
  const getPackStatus = async (uuid) => {
    if (!uuid) return null;

    const MAX_TIME = 5 * 60 * 1000;
    const START_TIME = Date.now();

    const checkStatus = async () => {
      if (Date.now() - START_TIME > MAX_TIME) {
        Log('打包超时（5分钟）', true, 'warning');
        return null;
      }

      const res = await window.weappUtils.request({
        url: '/api/file/batchDownloadPercent',
        params: { uuid },
      });

      const percent = Number(res?.data?.percent);

      if (percent === 100) {
        Log('打包完成，开始下载', true, 'success');
        return res.data.fileId;
      }

      if (percent === -1) {
        Log('正在从云端下载，请稍候...', true);
      } else if (percent > 0) {
        Log(`打包进度：${percent}%`, true);
      }

      await new Promise(r => setTimeout(r, 1000));
      return checkStatus();
    };

    return checkStatus();
  };

  /**
   * 下载最终文件
   */
  const downloadFile = (fileId) => {
    if (!fileId) {
      Log('未获取到下载文件', true, 'warning');
      return;
    }
    window.location.href = `/api/file/remotedownload/${fileId}/upload/true`;
  };

  /**
   * 主流程
   */
  const main = async () => {
    const fileIds = getDataId();
    if (!fileIds) {
      Log('未找到附件数据', true, 'warning');
      return;
    }

    const loading = Log(
      '正在准备下载，请稍候...',
      true,
      'info',
      0
    );

    const uuid = await beginPack(fileIds);
    if (!uuid) {
      loading?.destroy?.();
      return;
    }

    const fileId = await getPackStatus(uuid);
    loading?.destroy?.();
    downloadFile(fileId);
  };

  main();
}
```

### check_mark_button 单行下载（不变）

```
batchDownload('841587339898257472', '123');
```

### check_mark_button 多行下载（新增 check_mark_button）

```
batchDownload('841587339898257472', ['123','456','789']);
```

### check_mark_button 勾选行（示例）

```
const ids = ebdfListSdk.getCheckedID();  //获取选中的数据id
batchDownload('841587339898257472', ids);
```
