+ 炽灼残渣新增保存功能

+ 格式化代码
This commit is contained in:
2022-11-20 00:19:56 +08:00
parent 0cff88322b
commit c120bf3fdd
9 changed files with 481 additions and 398 deletions

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="zh-CN">
<html lang="zh-cmn-Hans">
<head>
<meta charset="UTF-8">
@@ -11,104 +11,95 @@
<script src="./decimal.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
var decimal = Decimal.set(
{
rounding: Decimal.ROUND_HALF_EVEN,
precision: 12
}
);
$(document).ready(function () {
var output = document.getElementById("output");
//
var tip = "计算每一针走完的时间。<br>"
+ "设置时间提前量可以将每针的时间提前,用于给看样及配样等操作留时间。";
output.innerHTML = tip;
let decimal = Decimal.set({
rounding: Decimal.ROUND_HALF_EVEN,
precision: 12
})
$(document).ready(() => {
let tip = `
计算每一针走完的时间。<br>
设置时间提前量可以将每针的时间提前,用于给看样及配样等操作留时间。`
$("#output").append(tip)
$("#ok").click(function () {
$("#output").empty();
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 = [];
$("#ok").click(() => {
let time = $("#time").val()
let num = $("#num").val()
let ptime = $("#ptime").val()
let stime = $("#stime").val()
let data = []
// 生成数据
for (var i = 1; i <= num; i++) {
var t = InjectionSequenceToDate(time, ptime, stime, i);
for (let i = 1; i <= num; i++) {
let t = injectionSequenceToDate(time, ptime, stime, i)
data.push({
"id": i,
"time": t
});
})
}
if (data.length == 0) {
// 未生成数据,不进行结果展示
return;
}
output.appendChild(createTable(data));
});
// 未生成数据,不进行结果展示
if (data.length == 0) return
$("#output").empty()
$("#output").append(createTable(data))
})
$("#clear").click(function () {
time.value = "";
num.value = "";
ptime.value = "";
stime.value = "";
$("#output").empty();
});
$("#clear").click(() => {
$("#time").val("")
$("#num").val("")
$("#ptime").val("")
$("#stime").val("")
$("#output").empty()
$("#output").append(tip)
})
$("#new_page").click(function () {
window.open(window.location.href, "_blank");
});
});
$("#new_page").click(() => {
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 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) {
var table = document.createElement("table");
table.setAttribute("style", "width: 100%;");
table.setAttribute("class", "pure-table");
let table = document.createElement("table")
table.setAttribute("style", "width: 100%; text-align: center;")
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);
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 => {
var tr = document.createElement("tr");
let tr = document.createElement("tr")
let td_id = document.createElement("td")
let td_time = document.createElement("td")
if (element.id % 2 == 1) {
tr.className = "pure-table-odd";
}
td_id.innerText = element.id
td_time.innerText = element.time
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;
tr.appendChild(td_id)
tr.appendChild(td_time)
table.appendChild(tr)
})
return table
}
/**
@@ -118,37 +109,35 @@
* @param stime 现在这针运行多少分钟
* @param num 计算第n针后的时间
*/
function InjectionSequence(time, ptime, stime, num) {
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();
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()
}
// 为 Date 创建日期格式化方法
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
let 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));
"S": this.getMilliseconds() //毫秒
}
for (var k in o) {
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
}
for (let 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)));
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
}
}
return fmt;
return fmt
}
</script>