填报自动代出JS效率很低,如何优化

// 获取当前控件的位置信息,例如 "C3"

const location = this.options.location;

// 从 "C3" 解析出列号和行号 {col: 2, row: 2} (索引从0开始)

// 注意:这里不需要像示例代码那样 +1,直接获取行号索引即可

const currentRow = FR.cellStr2ColumnRow(location).row;

// 获取当前控件(公司名称)的值

const companyName = this.getValue();

// --- 健壮性判断:如果清空了公司名称,则也清空关联字段 ---

if (!companyName) {

// 清空 B 列(统一社会信用码),列索引为 1

_g().setCellValue(FR.columnRow2CellStr({col: 1, row: currentRow}), null, "");

// 清空 D 列(所属产业),列索引为 3

_g().setCellValue(FR.columnRow2CellStr({col: 3, row: currentRow}), null, "");

// 清空 I 列(国家/地区),列索引为 8

_g().setCellValue(FR.columnRow2CellStr({col: 8, row: currentRow}), null, "");

// 清空 J 列(省),列索引为 9

_g().setCellValue(FR.columnRow2CellStr({col: 9, row: currentRow}), null, "");

// 清空 K 列(市),列索引为 10

_g().setCellValue(FR.columnRow2CellStr({col: 10, row: currentRow}), null, "");

// 清空 L 列(区),列索引为 11

_g().setCellValue(FR.columnRow2CellStr({col: 11, row: currentRow}), null, "");

return; // 结束执行

}

// --- 使用 remoteEvaluate 远程求值来获取数据 ---

// 1. 根据公司名称,查询对应的“统一社会信用码”

// FR.remoteEvaluate('sql("数据连接名", "SQL查询语句", 第几列, 第几行)')

const creditCode = FR.remoteEvaluate('sql("DBFine", "SELECT fd_credit_no FROM ods_t_oa_en_company_main WHERE doc_subject = \'' + companyName + '\' GROUP BY fd_credit_no", 1, 1)');

// 2. 根据公司名称,查询对应的“所属产业”

const industry = FR.remoteEvaluate('sql("DBFine", "SELECT fd_industry FROM ods_t_oa_en_company_main WHERE doc_subject = \'' + companyName + '\' GROUP BY fd_industry", 1, 1)');

// 3. 根据公司名称,查询对应的“公司ID”

const companyId = FR.remoteEvaluate('sql("DBFine", "SELECT fd_id FROM ods_t_oa_en_company_main WHERE doc_subject = \'' + companyName + '\' GROUP BY fd_id", 1, 1)');

// 构造一次性查询地址信息的SQL语句,提高效率

const areaSql = "SELECT fd_country, fd_province, fd_city, fd_district FROM ods_t_api_base_company_area WHERE fd_company_id = '" + companyId + "'";

// 从一条SQL结果中,按列序号分别获取 国家、省、市、区

const country = FR.remoteEvaluate('sql("DBFine", "' + areaSql + '", 1, 1)');

const province = FR.remoteEvaluate('sql("DBFine", "' + areaSql + '", 2, 1)');

const city = FR.remoteEvaluate('sql("DBFine", "' + areaSql + '", 3, 1)');

const district = FR.remoteEvaluate('sql("DBFine", "' + areaSql + '", 4, 1)');

// --- 使用 setTimeout 异步给单元格赋值 ---

// (参考您的示例代码写法,这有助于避免某些渲染冲突)

setTimeout(function() {

// 目标单元格是 B 列(统一社会信用码),其列号索引是 1

const targetCellB = FR.columnRow2CellStr({col: 1, row: currentRow}); // 动态拼接出目标单元格地址,如 "B3"

_g().setCellValue(targetCellB, null, creditCode); // 给 B 列单元格赋值

// 目标单元格是 D 列(所属产业),其列号索引是 3

const targetCellD = FR.columnRow2CellStr({col: 3, row: currentRow}); // 动态拼接出目标单元格地址,如 "D3"

_g().setCellValue(targetCellD, null, industry); // 给 D 列单元格赋值

const targetCellI = FR.columnRow2CellStr({col: 8, row: currentRow}); // I列

_g().setCellValue(targetCellI, null, country);

const targetCellJ = FR.columnRow2CellStr({col: 9, row: currentRow}); // J列

_g().setCellValue(targetCellJ, null, province);

const targetCellK = FR.columnRow2CellStr({col: 10, row: currentRow}); // K列

_g().setCellValue(targetCellK, null, city);

const targetCellL = FR.columnRow2CellStr({col: 11, row: currentRow}); // L列

_g().setCellValue(targetCellL, null, district);

}, 100); // 延迟100毫秒

FineReport Wjayon 发布于 2025-10-17 17:49
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2025-10-17 17:53(编辑于 2025-10-17 17:54)

https://help.fanruan.com/finereport/doc-view-534.html   参考根据控件值自动匹配数据、联动

------

同条件下,取数函数的性能排名为:value()>ds1.select()>sql()

  • 1关注人数
  • 11浏览人数
  • 最后回答于:2025-10-17 17:54
    请选择关闭问题的原因
    确定 取消
    返回顶部