From 021cce59471edc53278ded9dc59ebc87fdea21d5 Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 14 Jan 2025 22:06:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BE=93=E5=87=BA=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E8=A1=A8=E6=A0=BC=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 2 +- src/components/popup/ResultMenu.vue | 35 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 0b2f476..f74b8ae 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -62,7 +62,7 @@ - + diff --git a/src/components/popup/ResultMenu.vue b/src/components/popup/ResultMenu.vue index d5e20b5..2439dcf 100644 --- a/src/components/popup/ResultMenu.vue +++ b/src/components/popup/ResultMenu.vue @@ -54,6 +54,7 @@ export default { imagebtn: Boolean, closebtn: Boolean, runResult: Array, + selectText: String, }, emits: ["updateResult"], computed: { @@ -133,11 +134,13 @@ export default { }, methods: { copyResult() { - window.utools.copyText(this.getFormattedContent()); + window.utools.copyText(this.selectText || this.getFormattedContent()); quickcommand.showMessageBox("已复制到剪贴板"); }, sendResult() { - window.utools.hideMainWindowTypeString(this.getFormattedContent()); + window.utools.hideMainWindowTypeString( + this.selectText || this.getFormattedContent() + ); }, dataUrlToImg() { const imagePattern = /data:image\/.*?;base64,.*/g; @@ -172,15 +175,33 @@ export default { ]; if (!headers.length) return; + // 计算字符串显示宽度的辅助函数 + const getDisplayWidth = (str) => { + return String(str) + .split("") + .reduce((width, char) => { + // 判断是否为全角字符 + // 包括:中文字符、全角标点符号、全角空格、日韩字符等 + return ( + width + + (/[\u2E80-\u2FFF\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3200-\u32FF\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF]/.test( + char + ) + ? 2 + : 1) + ); + }, 0); + }; + // 计算每列的最大宽度 const columnWidths = headers.map((header) => { const maxDataWidth = Math.max( - header.length, + getDisplayWidth(header), ...tableData.map((obj) => { const value = obj[header]; return value === undefined || value === null ? 0 - : String(value).replace(/\n/g, "\\n").length; + : getDisplayWidth(String(value).replace(/\n/g, "\\n")); }) ); return maxDataWidth; @@ -191,10 +212,12 @@ export default { "| " + cells .map((cell, index) => { + const cellStr = String(cell); + const displayWidth = getDisplayWidth(cellStr); const padding = " ".repeat( - Math.max(0, columnWidths[index] - String(cell).length) + Math.max(0, columnWidths[index] - displayWidth) ); - return String(cell) + padding; + return cellStr + padding; }) .join(" | ") + " |";