From 513da9162dea3a96d2178354459f2a1c6b900a0f Mon Sep 17 00:00:00 2001 From: wjxgit Date: Tue, 3 Oct 2023 14:33:00 +0800 Subject: [PATCH] =?UTF-8?q?Log.Float=20=E5=AF=B9=E8=B1=A1=E4=B8=8E?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E7=9A=84=E5=B1=95=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunctionTools_JS/FunctionToolsJS.js | 81 +++++++++++++++++++++++++--- FunctionTools_JS/test/css/test.css | 2 + FunctionTools_JS/test/js/test.js | 21 ++++++++ FunctionTools_JS/test/test.html | 4 +- LearningNotes/~$webAPI.docx | Bin 0 -> 162 bytes 5 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 LearningNotes/~$webAPI.docx diff --git a/FunctionTools_JS/FunctionToolsJS.js b/FunctionTools_JS/FunctionToolsJS.js index 76732ca..ecb9ba8 100644 --- a/FunctionTools_JS/FunctionToolsJS.js +++ b/FunctionTools_JS/FunctionToolsJS.js @@ -223,6 +223,7 @@ const Log = { wordWrap: "break-word", transition: "all 0.2s", overflow: "auto", + position: "relative", overflowY: "scroll" }) css.style(span, { @@ -375,19 +376,86 @@ const Log = { if (isInput) { let rel = eval(msg) if (typeof eval("(" + msg + ")") == "object") rel = eval("(" + msg + ")") - if (typeof rel == "number") p.innerHTML += `

控制台: ${msg + " --> "}${rel}

` - else if (typeof rel == "boolean") p.innerHTML += `

控制台: ${msg + " --> "}${rel}

` - else p.innerHTML += `

控制台: ${msg + " --> "}${rel}

` + if (typeof rel == "number") { + p.innerHTML += `

控制台: ${msg + " --> "}${rel}

` + } else if (typeof rel == "boolean") { + p.innerHTML += `

控制台: ${msg + " --> "}${rel}

` + } else if (rel instanceof Array) { + p.innerHTML += `

控制台: ${msg + " --> "}${_expandMsg( + rel + )}

` + } else if (rel instanceof Object) { + p.innerHTML += `

控制台: ${msg + " --> "}${_expandMsg( + rel + )}

` + } else { + p.innerHTML += `

控制台: ${msg + " --> "}${rel}

` + } isInput = false input.value = "" p.scrollTop = p.scrollHeight } else { - if (typeof msg == "number") p.innerHTML += `

${msg}

` - else if (typeof msg == "boolean") p.innerHTML += `

${msg}

` - else p.innerHTML += `

${msg}

` + if (typeof msg == "number") { + p.innerHTML += `

${msg}

` + } else if (typeof msg == "boolean") { + p.innerHTML += `

${msg}

` + } else if (msg instanceof Array) { + p.innerHTML += `

${_expandMsg(msg)}

` + } else if (msg instanceof Object) { + p.innerHTML += `

${_expandMsg(msg)}

` + } else { + p.innerHTML += `

${msg}

` + } p.scrollTop = p.scrollHeight } + function _expandMsg(msg, num = 1) { + let temp = "" + //数组 + if (msg instanceof Array) { + temp = `(${msg.length}) [
` + for (let i = 0; i < msg.length; i++) { + if (typeof msg[i] == "function") { + temp += `${nbspNum(num)}${i}: function(),
` + } else if (msg[i] instanceof Object) { + temp += `${nbspNum(num)}${i}: ${_expandMsg(msg[i], num + 1)},
` + } else if (typeof msg[i] == "string") { + temp += `${nbspNum(num)}${i}: "${msg[i]}",
` + } else { + temp += `${nbspNum(num)}${i}: ${msg[i]},
` + } + } + temp = temp.substring(0, temp.length - 6) + `
${nbspNum(num - 1)}]` + } + //对象 + else if (msg instanceof Object) { + temp = `{
` + for (const key in msg) { + if (key != "singleLayer") { + if (typeof msg[key] == "function") { + temp += `${nbspNum(num)}${key}: function(),
` + } else if (msg[key] instanceof Array) { + temp += `${nbspNum(num)}${key}: ${_expandMsg(msg[key], num + 1)},
` + } else if (typeof msg[key] == "string") { + temp += `${nbspNum(num)}${key}: "${msg[key]}",
` + } else { + temp += `${nbspNum(num)}${key}: ${msg[key]},
` + } + } + } + temp = temp.substring(0, temp.length - 6) + `
${nbspNum(num - 1)}}` + } + //对齐空格 + function nbspNum(num) { + let str = "" + for (let i = 0; i < num; i++) { + str += `    ` + } + return str + } + return temp + } } + console.dir = function (msg) { let objOpen = "" if (typeof msg != "string") { @@ -486,7 +554,6 @@ const Log = { } } } - /** * 秒数格式化,根据输入秒数,转化为年月日时分秒格式,如果某一项为零则不打印 * @param {秒数} second Number diff --git a/FunctionTools_JS/test/css/test.css b/FunctionTools_JS/test/css/test.css index eae21ce..4eaa4e4 100644 --- a/FunctionTools_JS/test/css/test.css +++ b/FunctionTools_JS/test/css/test.css @@ -4,4 +4,6 @@ overflow: auto; word-wrap: normal; overflow-wrap: break-word; + font-weight: 700; + position: relative; } \ No newline at end of file diff --git a/FunctionTools_JS/test/js/test.js b/FunctionTools_JS/test/js/test.js index 7faad20..5114f78 100644 --- a/FunctionTools_JS/test/js/test.js +++ b/FunctionTools_JS/test/js/test.js @@ -3,3 +3,24 @@ * ### 此文件用来引入工具类JS,进行测试 ### * */ +Log.Float() +console.log([ + 1, + 2, + "123", + function () { + console.log(123) + }, + 4, + { name: 123 }, + 6 +]) +console.log({ + name: 123, + a: 4, + d: [4, 5, 6, 7], + ww: function () { + console.log(123) + }, + bb: "654" +}) diff --git a/FunctionTools_JS/test/test.html b/FunctionTools_JS/test/test.html index 37275f2..20e89f0 100644 --- a/FunctionTools_JS/test/test.html +++ b/FunctionTools_JS/test/test.html @@ -10,8 +10,8 @@ - - + +