Files
qctool/injection-sequence.html

167 lines
6.2 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-cmn-Hans">
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>
let decimal = Decimal.set({
rounding: Decimal.ROUND_HALF_EVEN,
precision: 12
})
$(document).ready(() => {
let tip = `
计算每一针走完的时间。<br>
设置时间提前量可以将每针的时间提前,用于给看样及配样等操作留时间。`
$("#output").append(tip)
$("#ok").click(() => {
let time = $("#time").val()
let num = $("#num").val()
let ptime = $("#ptime").val()
let stime = $("#stime").val()
let data = []
2022-04-10 23:25:26 +08:00
// 生成数据
for (let i = 1; i <= num; i++) {
let 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").empty()
$("#output").append(createTable(data))
})
$("#clear").click(() => {
$("#time").val("")
$("#num").val("")
$("#ptime").val("")
$("#stime").val("")
$("#output").empty()
$("#output").append(tip)
})
$("#new_page").click(() => {
window.open(window.location.href, "_blank")
})
})
/**
* 计算进样时间,返回 yyyy-MM-dd hh:mm 格式的字符串
*/
function injectionSequenceToDate(time, ptime, stime, num) {
let t = injectionSequence(time, ptime, stime, num)
let t_hour = Math.floor(Math.abs(t) / 60)
let t_min = t % 60
let date = new Date()
let 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) {
let table = document.createElement("table")
table.setAttribute("style", "width: 100%; text-align: center;")
table.setAttribute("class", "pure-table")
let row = document.createElement("tr")
let th1 = document.createElement("th")
let th2 = document.createElement("th")
th1.innerText = "第几针"
th2.innerText = "进样时间"
row.appendChild(th1)
row.appendChild(th2)
table.appendChild(row)
data.forEach(element => {
let tr = document.createElement("tr")
let td_id = document.createElement("td")
let 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) {
2022-04-10 23:25:26 +08:00
// formal: InjectionSequence = time * num - ptime - stime
let t = new Decimal(time)
let p = new Decimal(ptime)
let s = new Decimal(stime)
let n = new Decimal(num)
return decimal.mul(t, n).sub(p).sub(s).toString()
2022-04-10 23:25:26 +08:00
}
// 为 Date 创建日期格式化方法
Date.prototype.format = function (fmt) {
let o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
2022-04-10 23:25:26 +08:00
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
}
2022-04-10 23:25:26 +08:00
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
2022-04-10 23:25:26 +08:00
}
for (let k in o) {
2022-04-10 23:25:26 +08:00
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
2022-04-10 23:25:26 +08:00
}
}
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>