You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

定制计算器开发需求:根据Resin Temp与Ambient Temp匹配添加剂数值

定制添加剂用量计算器实现方案

要做这款基于**环境温度(左侧列)和树脂温度(顶部行)**区间匹配的添加剂用量查询工具,可按以下方式实现:

1. 先整理结构化数据

不管用哪种开发语言,首先得把温度区间和对应用量的关系整理成机器能识别的结构。两种常用方案:

方案A:直接用区间字符串作为键(适合固定区间、下拉选择场景)

// 示例数据:键是环境温度区间,值是对应树脂温度区间的用量映射
const additiveData = {
  "50-59": {
    "40-49": 0.15,
    "50-59": 0.175, // 对应示例:环境59、树脂50都在这个区间,取值0.175
    "60-69": 0.2
  },
  "60-69": {
    "40-49": 0.16,
    "50-59": 0.185,
    "60-69": 0.21
  }
  // 更多区间数据照着添加即可
};

方案B:用范围对象存储(适合用户输入具体温度值、自动匹配区间的场景)

const additiveData = [
  {
    ambientRange: { min: 50, max: 59 },
    resinRanges: [
      { min: 40, max: 49, value: 0.15 },
      { min: 50, max: 59, value: 0.175 },
      { min: 60, max: 69, value: 0.2 }
    ]
  },
  {
    ambientRange: { min: 60, max: 69 },
    resinRanges: [
      { min: 40, max: 49, value: 0.16 },
      { min: 50, max: 59, value: 0.185 },
      { min: 60, max: 69, value: 0.21 }
    ]
  }
];

2. 搭建交互界面

根据需求选两种交互方式:

方式1:下拉框选区间(用户操作简单,适合固定区间)

<div class="calc-container">
  <div class="input-item">
    <label>环境温度区间:</label>
    <select id="ambient-select">
      <option value="50-59">50-59℃</option>
      <option value="60-69">60-69℃</option>
    </select>
  </div>
  <div class="input-item">
    <label>树脂温度区间:</label>
    <select id="resin-select">
      <option value="50-59">50-59℃</option>
      <option value="60-69">60-69℃</option>
    </select>
  </div>
  <button onclick="getAdditive()">查询用量</button>
  <div class="result">
    所需添加剂用量:<span id="result">-</span>
  </div>
</div>

方式2:输入具体温度值(灵活度高,需要自动匹配区间)

<div class="calc-container">
  <div class="input-item">
    <label>环境温度:</label>
    <input type="number" id="ambient-temp" placeholder="输入温度值">
  </div>
  <div class="input-item">
    <label>树脂温度:</label>
    <input type="number" id="resin-temp" placeholder="输入温度值">
  </div>
  <button onclick="getAdditive()">查询用量</button>
  <div class="result">
    所需添加剂用量:<span id="result">-</span>
  </div>
</div>

3. 实现核心匹配逻辑

对应下拉框的简单逻辑

直接根据选中的区间字符串从数据里取值:

function getAdditive() {
  const ambientRange = document.getElementById('ambient-select').value;
  const resinRange = document.getElementById('resin-select').value;
  const resultEl = document.getElementById('result');

  const ambientData = additiveData[ambientRange];
  if (!ambientData) {
    resultEl.textContent = '无对应环境区间数据';
    return;
  }

  const value = ambientData[resinRange];
  resultEl.textContent = value !== undefined ? value : '无对应树脂区间数据';
}

对应输入温度值的自动匹配逻辑

先判断温度属于哪个区间,再找对应用量:

function getAdditive() {
  const ambientTemp = parseFloat(document.getElementById('ambient-temp').value);
  const resinTemp = parseFloat(document.getElementById('resin-temp').value);
  const resultEl = document.getElementById('result');

  // 校验输入是否为有效数字
  if (isNaN(ambientTemp) || isNaN(resinTemp)) {
    resultEl.textContent = '请输入有效的温度值';
    return;
  }

  // 匹配环境温度所在的区间
  const ambientMatch = additiveData.find(item => {
    return ambientTemp >= item.ambientRange.min && ambientTemp <= item.ambientRange.max;
  });

  if (!ambientMatch) {
    resultEl.textContent = '当前环境温度无对应数据';
    return;
  }

  // 匹配树脂温度所在的区间并取值
  const resinMatch = ambientMatch.resinRanges.find(range => {
    return resinTemp >= range.min && resinTemp <= range.max;
  });

  resultEl.textContent = resinMatch ? resinMatch.value : '当前树脂温度无对应数据';
}

4. 实用优化建议

  • 给输入框加范围限制,比如min="0",避免用户输入离谱的温度值
  • 如果需要支持区间外的插值估算,可以加线性计算逻辑
  • 把数据单独存成JSON文件,后续更新区间和用量不用改代码

内容的提问来源于stack exchange,提问作者Stephen Roberts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 06:45:32