From 3a4d733c134e541dccb8745928b6e90f383ef7b2 Mon Sep 17 00:00:00 2001 From: MoonLeeeaf <150461955+MoonLeeeaf@users.noreply.github.com> Date: Sat, 1 Jun 2024 14:33:26 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9=E5=93=88=E5=B8=8C?= =?UTF-8?q?=E8=BE=93=E5=87=BA(Base64=E6=94=B9=E4=B8=BAHex)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ling_chair_http/utils.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/ling_chair_http/utils.js b/ling_chair_http/utils.js index 40a5567..48dab0a 100644 --- a/ling_chair_http/utils.js +++ b/ling_chair_http/utils.js @@ -62,6 +62,10 @@ function escapeHTML(str) { } class NData { + /** + * 获取 MD5sum + * @param {String} 数据 + */ static mount(node) { // 便捷获得指定组件 let es = node.querySelectorAll("[n-id]") @@ -80,6 +84,11 @@ class NData { } // https://www.runoob.com/w3cnote/javascript-copy-clipboard.html + +/** + * 复制文字 + * @param {String} 欲复制的文本 + */ function copyText(t) { let btn = $("[n-id=textCopierBtn]") btn.attr("data-clipboard-text", t) @@ -90,6 +99,13 @@ function copyText(t) { } // https://zhuanlan.zhihu.com/p/162910462 + +/** + * 格式化日期 + * @param {int} 时间戳 + * @param {String} 欲格式化的文本 + * @returns {String} 格式后的文本 + */ Date.prototype.format = function (tms, format) { let tmd = new Date(tms) /* @@ -164,11 +180,21 @@ class 通知 { } class Hash { + /** + * 获取 MD5sum + * @param {String} 数据 + * @returns {String} Hex化的哈希值 + */ static md5(data) { - return CryptoJS.MD5(data).toString(CryptoJS.enc.Base64) + return CryptoJS.MD5(data).toString(CryptoJS.enc.Hex) } + /** + * 获取 SHA256sum + * @param {String} 数据 + * @returns {String} Hex化的哈希值 + */ static sha256(data) { - return CryptoJS.SHA256(data).toString(CryptoJS.enc.Base64) + return CryptoJS.SHA256(data).toString(CryptoJS.enc.Hex) } }