Files
qctool/injection-sequence.html

178 lines
6.5 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-CN">
2022-04-10 23:25:26 +08:00
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
2022-07-16 00:43:41 +08:00
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>进样序列</title>
<link rel="stylesheet" href="./github.css">
<link rel="stylesheet" href="./theme.css">
<script src="./decimal.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
2022-04-10 23:25:26 +08:00
var decimal = Decimal.set(
{
rounding: Decimal.ROUND_HALF_EVEN,
precision: 12
}
);
$(document).ready(function () {
var output = document.getElementById("output");
//
var tip = "计算每一针走完的时间。<br>"
+ "设置时间提前量可以将每针的时间提前,用于给看样及配样等操作留时间。";
2022-04-10 23:25:26 +08:00
output.innerHTML = tip;
$("#ok").click(function () {
$("#output").empty();
2022-04-10 23:25:26 +08:00
var time = document.getElementById("time").value;
var num = document.getElementById("num").value;
var ptime = document.getElementById("ptime").value;
var stime = document.getElementById("stime").value;
var data = [];
2022-04-10 23:25:26 +08:00
// 生成数据
for (var i = 1; i <= num; i++) {
var t = InjectionSequenceToDate(time, ptime, stime, i);
data.push({
"id": i,
"time": t
});
}
2022-04-10 23:25:26 +08:00
if (data.length == 0) {
// 未生成数据,不进行结果展示
return;
}
output.appendChild(createTable(data));
});
$("#clear").click(function () {
time.value = "";
2022-04-10 23:25:26 +08:00
num.value = "";
ptime.value = "";
stime.value = "";
$("#output").empty();
});
$("#new_page").click(function () {
window.open(window.location.href, "_blank");
});
});
/**
* 计算进样时间,返回 yyyy-MM-dd hh:mm 格式的字符串
*/
function InjectionSequenceToDate(time, ptime, stime, num) {
var t = InjectionSequence(time, ptime, stime, num);
var t_hour = Math.floor(Math.abs(t) / 60);
var t_min = t % 60;
var date = new Date();
var dateAfter = new Date(date.getFullYear(), date.getMonth(), date.getDate(),
date.getHours() + t_hour, date.getMinutes() + t_min).format("yyyy-MM-dd hh:mm");
return dateAfter;
}
/**
* 创建表格元素并将数据填入其中。
*/
function createTable(data) {
var table = document.createElement("table");
2022-07-15 23:49:11 +08:00
table.setAttribute("style", "width: 100%;");
table.setAttribute("class", "pure-table");
var row = document.createElement("tr");
var th1 = document.createElement("th");
var th2 = document.createElement("th");
th1.innerText = "第几针";
th2.innerText = "进样时间";
row.appendChild(th1);
row.appendChild(th2);
table.appendChild(row);
data.forEach(element => {
var tr = document.createElement("tr");
if (element.id % 2 == 1) {
tr.className = "pure-table-odd";
}
var td_id = document.createElement("td");
var td_time = document.createElement("td");
td_id.innerText = element.id;
td_time.innerText = element.time;
tr.appendChild(td_id);
tr.appendChild(td_time);
table.appendChild(tr);
});
return table;
}
2022-04-10 23:25:26 +08:00
/**
* 计算总共的进样时间
* @param time 多少分钟一针
* @param ptime 时间需要提前多少分钟
* @param stime 现在这针运行多少分钟
* @param num 计算第n针后的时间
*/
function InjectionSequence(time, ptime, stime, num) {
// formal: InjectionSequence = time * num - ptime - stime
var t = new Decimal(time);
var p = new Decimal(ptime);
var s = new Decimal(stime);
var n = new Decimal(num);
var time = decimal.mul(t, n).sub(p).sub(s);
return time.toString();
}
// 为 Date 创建日期格式化方法
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
2022-04-10 23:25:26 +08:00
</script>
</head>
2022-04-10 23:25:26 +08:00
<body>
<h3>进样序列</h3>
<div class="input">
<div class="inputbox">
<input type="number" id="time" placeholder="多少分钟一针" inputmode="decimal" autocomplete="off">
<input type="number" id="num" placeholder="一共有多少针(包括正在运行的)" inputmode="decimal" autocomplete="off">
<input type="number" id="stime" placeholder="现在这针运行多少分钟" inputmode="decimal" autocomplete="off">
<input type="number" id="ptime" placeholder="时间提前量(分钟)" inputmode="decimal" autocomplete="off">
</div>
2022-04-10 23:25:26 +08:00
<br>
<div class="buttons">
<button id="new_page">新开标签页</button>
<button id="clear">清除内容</button>
<button id="ok">计算</button>
</div>
<br>
</div>
2022-07-15 23:49:11 +08:00
<div id="output"></div>
</body>
2022-04-10 23:25:26 +08:00
</html>