

## 一、表格视图

### 1.1批量编辑列表接口

```javascript
window.axios.interceptors.request.use(config => {
  const targetUrls = [
    '/api/ebuilder/form/list/getListDatas',
    '/api/ebuilder/form/list/getListDataCount'
  ];
  
  if (targetUrls.some(url => config.url.includes(url)) && config.data?.batchEditValue === '1') {
    config.data.searchParamData = {
      ...config.data.searchParamData,
      searchType: '2',
      type: 'and',
      commonSearchFields: {
        ...config.data.searchParamData?.commonSearchFields,
        field_5: [{
          field_5_condition_type: 'like',
          field_5: '1248636925461774338,1245151117068730370'
        }]
      }
    };
  }
  return config;
});
```

[图片附件未整合: ../../../../_assets/474021899974737920/001-e074646958.png]

## 二、数据列表

### 2.1批量编辑列表数据获取接口

```javascript
// 配置区 - 用户可根据需要修改以下配置
const INTERCEPTOR_CONFIG = {
  // 目标接口路径（支持字符串、正则表达式或数组）
  targetApi: ["/api/ebuilder/coms/nlist/getData"],
  
  // 目标组件ID（支持字符串或数组）
  targetCompId: "f16488ac53e34c23ba540223a67582ee", // 数据列表的组件compId
  
  // 要添加的基础过滤器参数（示例，可以配置个数据ID字段，自行触发搜索，看接口中的实际的filter参数内容）
  baseFilter: [{
    "customSelect": null,
    "conditionComId": "f50bafda52fc403a8137a770f8d4f39c_filter_EXCLUDECACHE",
    "conditionType": "and",
    "dataType": "field",
    "id": "ee5bcf8bbe6748ee95a85eb12acf615f",
    "value": "1248589599161556993 1245151117068730370",
    "filterFields": [{
      "compId": "f50bafda52fc403a8137a770f8d4f39c",
      "compType": "Text",
      "dataset": {
        "isPhysical": true,
        "ebuilderDataConfig": {
          "dataSetup": {},
          "type": "FORM"
        },
        "detailTable": false,
        "groupId": "weaver-ebuilder-form-service",
        "usage": "all",
        "appId": "1170209714353602563",
        "id": "1170209723078869030",
        "text": "软件过程管理表单",
        "type": "LOGIC",
        "objType": "physical"
      },
      "fieldName": "id",
      "id": "5",
      "objId": "1170209723078869030",
      "type": "String",
      "text": "数据ID"
    }],
    "funcType": "like"
  }]
};

// 请求拦截器实现
axios.interceptors.request.use(function (config) {
  // 统一处理为数组格式
  const targetApis = Array.isArray(INTERCEPTOR_CONFIG.targetApi) 
    ? INTERCEPTOR_CONFIG.targetApi 
    : [INTERCEPTOR_CONFIG.targetApi];
  
  // 检查是否为目标接口
  const isTargetApi = targetApis.some(api => {
    if (typeof api === 'string') {
      return config.url.indexOf(api) > -1;
    } else if (api instanceof RegExp) {
      return api.test(config.url);
    }
    return false;
  });
  
  if (!isTargetApi) {
    return config;
  }
  
  // 只处理POST请求和FormData数据
  if (config.method !== 'post' || !(config.data instanceof FormData)) {
    return config;
  }
  
  // 获取相关参数
  const formData = config.data;
  const batchEditValue = formData.get('batchEditValue');
  const compId = formData.get('compId');
  
  // 检查条件：batchEditValue为1且compId匹配目标
  if (batchEditValue !== '1') {
    return config;
  }
  
  const isCompIdMatched = Array.isArray(INTERCEPTOR_CONFIG.targetCompId)
    ? INTERCEPTOR_CONFIG.targetCompId.includes(compId)
    : compId === INTERCEPTOR_CONFIG.targetCompId;
  
  if (!isCompIdMatched) {
    return config;
  }
  
  // 处理filter参数
  try {
    const filter = formData.get('filter');
    let filterArray = [];
    
    if (filter && filter !== 'undefined' && filter !== 'null') {
      filterArray = JSON.parse(filter);
    }
    
    // 合并过滤器参数
    if (Array.isArray(INTERCEPTOR_CONFIG.baseFilter)) {
      const mergedFilter = [...filterArray, ...INTERCEPTOR_CONFIG.baseFilter];
      formData.set('filter', JSON.stringify(mergedFilter));
    }
  } catch (error) {
    // 静默处理JSON解析错误
  }
  
  return config;
}, function (error) {
  return Promise.reject(error);
});
```

baseFilter的结构可以设置搜索 - 数据ID，然后在前台查看getData接口的filter参数，来进行模拟：  
[图片附件未整合: ../../../../_assets/474021899974737920/002-b2a7eeab23.png]

[图片附件未整合: ../../../../_assets/474021899974737920/003-d9f9acc147.png]

### 示例2

```javascript
// 动态获取ids的函数
const getIds = () => {
  const _ebSdk = window.ebuilderSDK; // 全局SDK
  const _pageSdk = _ebSdk.getPageSDK(); // 当前页面SDK
  var compInstance = _pageSdk.getCompInstance('fe991c8c4cd94fe69d0eb919c7413206');
  var ids = compInstance.getCheckedIds();
  return ids.join(',');
}

// 配置区 - 用户可根据需要修改以下配置
const INTERCEPTOR_CONFIG = {
  // 目标接口路径（支持字符串、正则表达式或数组）
  targetApi: ["/api/ebuilder/coms/nlist/getData"],
  
  // 目标组件ID（支持字符串或数组）
  targetCompId: "fe991c8c4cd94fe69d0eb919c7413206", // 数据列表的组件compId
  
  // 要添加的基础过滤器参数（已改为动态获取）
  getBaseFilter: () => {  // 改为函数形式动态获取
    const ids = getIds();  // 动态获取当前选中的ids
    
    return [{
      "conditionComId": "fe991c8c4cd94fe69d0eb919c7413206_filter_EXCLUDECACHE",
      "conditionType": "and",
      "dataType": "field",
      "id": "f41d8416100f4765997fc371ce636daa",
      "value": ids,  // 动态设置当前选中的ids
      "filterFields": [{
        "compId": "fe991c8c4cd94fe69d0eb919c7413206",
        "compType": "RelateBrowser",
        "dataset": {
          "isPhysical": true,
          "hasChangeExtConfig": false,
          "ebuilderDataConfig": {
            "dataSetup": {
              "dataType": "ALL",
              "dataSource": "ALL",
              "dataPermission": "HAVE_PERMISSION_DATA"
            },
            "type": "FORM"
          },
          "groupId": "weaver-ebuilder-form-service",
          "usage": "all",
          "module": "ebuilder",
          "hasChangeGroupFilter": false,
          "type": "LOGIC",
          "hasChangePermissions": false,
          "detailTable": false,
          "appId": "1194005430984065024",
          "isFormModuleSelected": true,
          "id": "1194005473841463298",
          "text": "电站表单",
          "objType": "physical"
        },
        "fieldName": "field_1258954364674048005",
        "id": "1258954364674048005",
        "objId": "1194005473841463298",
        "type": "RelateBrowser",
        "text": "电站信息"
      }],
      "funcType": "inC"
    }];
  }
};

// 请求拦截器实现
axios.interceptors.request.use(function (config) {
  // 统一处理为数组格式
  const targetApis = Array.isArray(INTERCEPTOR_CONFIG.targetApi) 
    ? INTERCEPTOR_CONFIG.targetApi 
    : [INTERCEPTOR_CONFIG.targetApi];
  
  // 检查是否为目标接口
  const isTargetApi = targetApis.some(api => {
    if (typeof api === 'string') {
      return config.url.indexOf(api) > -1;
    } else if (api instanceof RegExp) {
      return api.test(config.url);
    }
    return false;
  });
  
  if (!isTargetApi) {
    return config;
  }
  
  // 只处理POST请求和FormData数据
  if (config.method !== 'post' || !(config.data instanceof FormData)) {
    return config;
  }
  
  // 获取相关参数
  const formData = config.data;
  const batchEditValue = formData.get('batchEditValue');
  const compId = formData.get('compId');
  
  // 检查条件：batchEditValue为1且compId匹配目标
  if (batchEditValue !== '1') {
    return config;
  }
  
  const isCompIdMatched = Array.isArray(INTERCEPTOR_CONFIG.targetCompId)
    ? INTERCEPTOR_CONFIG.targetCompId.includes(compId)
    : compId === INTERCEPTOR_CONFIG.targetCompId;
  
  if (!isCompIdMatched) {
    return config;
  }
  
  // 处理filter参数
  try {
    const filter = formData.get('filter');
    let filterArray = [];
    
    if (filter && filter !== 'undefined' && filter !== 'null') {
      filterArray = JSON.parse(filter);
    }
    
    // 动态获取过滤器参数
    let baseFilter = [];
    if (typeof INTERCEPTOR_CONFIG.getBaseFilter === 'function') {
      baseFilter = INTERCEPTOR_CONFIG.getBaseFilter();
    } else {
      baseFilter = INTERCEPTOR_CONFIG.baseFilter || [];
    }
    
    // 合并过滤器参数
    if (Array.isArray(baseFilter)) {
      const mergedFilter = [...filterArray, ...baseFilter];
      formData.set('filter', JSON.stringify(mergedFilter));
    }
  } catch (error) {
    // 静默处理JSON解析错误
  }
  
  return config;
}, function (error) {
  return Promise.reject(error);
});
```
