liu
2026-09-03 a806a54c13a832b423d9cf1dfbe510a32ee63b30
src/views/wls/barcode/config/index.vue
@@ -22,17 +22,26 @@
  destroyOnClose: true,
});
/** 自动生成开关变更 */
/**
 * 自动生成开关变更
 *
 * 注意:CellSwitch 的 beforeChange 调用约定为 (newVal, row)
 * —— 第一个参数是开关新值(antd Switch 配置 checkedValue=1/unCheckedValue=0,
 * 因此取值是数字 1/0),第二个参数才是整行数据。原先把 newVal 当成了 row,
 * 导致 updateBarcodeConfig(row) 的请求体被序列化成数字 1/0,后端解析 500。
 */
async function handleAutoGenerateChange(
  newVal: number | boolean,
  row: MesWmBarcodeConfigApi.BarcodeConfig,
): Promise<boolean> {
  const text = row.autoGenerateFlag ? '启用' : '停用';
  const next = newVal === true || newVal === 1; // 统一转成布尔
  const text = next ? '启用' : '停用';
  try {
    await confirm(`确认要${text}自动生成吗?`);
  } catch {
    return false;
  }
  await updateBarcodeConfig(row);
  await updateBarcodeConfig({ ...row, autoGenerateFlag: next });
  message.success(`${text}成功`);
  return true;
}