From 6c542de5648ca59f1455e6ff8fe3257ecb9d975f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E9=B9=8F?= <2916022834@qq.com> Date: Thu, 6 Nov 2025 11:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4log=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 1 - src/tool/consoleExport.js | 93 --------------------------------------- 2 files changed, 94 deletions(-) delete mode 100644 src/tool/consoleExport.js diff --git a/src/main.ts b/src/main.ts index 098dbb38..c59ee497 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,4 @@ import { createApp, defineComponent, h } from "vue"; -import "./tool/consoleExport.js"; import App from "./App.vue"; import router from "./router"; import store from "./store"; diff --git a/src/tool/consoleExport.js b/src/tool/consoleExport.js deleted file mode 100644 index a36334b1..00000000 --- a/src/tool/consoleExport.js +++ /dev/null @@ -1,93 +0,0 @@ -if (import.meta.env.VITE_USER_NODE_ENVh === "production") { - const log = console.log; - const error = console.error; - const warn = console.warn; - const info = console.info; - const list = []; - - class Item { - constructor(type, arrs) { - this.type = type - this.time = FormatDate() - this.content = arrs - } - } - - console.log = function () { - log(...arguments) - list.push(new Item('log', [...arguments])) - } - console.error = function () { - error(...arguments) - list.push(new Item('error', [...arguments])) - } - console.warn = function () { - warn(...arguments) - list.push(new Item('warn', [...arguments])) - } - console.info = function () { - info(...arguments) - list.push(new Item('info', [...arguments])) - } - - // 导出列表-json - const exportListJson = function () { - const json = JSON.stringify(list, null, 2) - const blob = new Blob([json], { type: 'application/json' }) - const url = URL.createObjectURL(blob) - const a = document.createElement('a') - a.href = url - a.download = `console_${FormatDate("yyyyMMddHHmmss")}.json` - a.click() - URL.revokeObjectURL(url) - } - - const keys = []; - document.addEventListener("keydown", (e) => { - if (e.key === "Control") return; - if (e.ctrlKey) { - keys.push(e.key) - const str = keys.join(''); - if (/m{5}/i.test(str)) { - exportListJson() - keys.splice(0, keys.length) - } - } else { - keys.splice(0, keys.length) - } - - }) -} - -/** 时间格式化-自定义格式 - * @param format 格式化字符串,默认值为 'yyyy-MM-dd HH:mm:ss' - * @returns 格式化后的时间字符串 - */ -function FormatDate(format = 'yyyy-MM-dd HH:mm:ss') { - const date = new Date(); - const yyyy = String(date.getFullYear()); - const yy = String(date.getFullYear()).slice(-2); - const MM = String(date.getMonth() + 1).padStart(2, '0'); - const M = String(date.getMonth() + 1); - const dd = String(date.getDate()).padStart(2, '0'); - const d = String(date.getDate()); - const HH = String(date.getHours()).padStart(2, '0'); - const H = String(date.getHours()); - const mm = String(date.getMinutes()).padStart(2, '0'); - const m = String(date.getMinutes()); - const ss = String(date.getSeconds()).padStart(2, '0'); - const s = String(date.getSeconds()); - const str = format.replaceAll('yyyy', yyyy) - .replaceAll('yy', yy) - .replaceAll('MM', MM) - .replaceAll('M', M) - .replaceAll('dd', dd) - .replaceAll('d', d) - .replaceAll('HH', HH) - .replaceAll('H', H) - .replaceAll('mm', mm) - .replaceAll('m', m) - .replaceAll('ss', ss) - .replaceAll('s', s); - return str; -} \ No newline at end of file