大概就是需要实现六个输入框,然后主要实现计算其他六个结果框的结果
import { widget } from "@smartbi/api";
// 获取输入框 A、B、C 和 D 的值
function getInputValues(): number[] {
return [
widget.getWidgetByName("A").getValue() as number,
widget.getWidgetByName("B").getValue() as number,
widget.getWidgetByName("C").getValue() as number,
widget.getWidgetByName("D").getValue() as number,
];
}
// 计算四个值之和
function calculateSum(): number {
const values = getInputValues();
return values.reduce((prev, curr) => prev + curr, 0);
}
// 设置总和到文本控件
function setSumToTextWidget(): void {
const sum = calculateSum();
const textWidget = widget.getWidgetByName("总和");
textWidget.setValue(sum.toString());
}
// 监听输入框的值变化
function listenToInputChanges(): void {
const inputWidgets = ["A", "B", "C", "D"].map(name => widget.getWidgetByName(name));
inputWidgets.forEach(widget => widget.on("valueChanged", setSumToTextWidget));
}
// 初始化
function init(): void {
listenToInputChanges();
setSumToTextWidget();
}
init();