mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 06:54:11 +08:00
优化输出面板表格字符串的显示
This commit is contained in:
parent
7597d18f76
commit
021cce5947
@ -62,7 +62,7 @@
|
|||||||
<q-resize-observer @resize="autoHeight" debounce="0" />
|
<q-resize-observer @resize="autoHeight" debounce="0" />
|
||||||
</div>
|
</div>
|
||||||
<q-menu v-if="selectText" touch-position @before-hide="clearSelect">
|
<q-menu v-if="selectText" touch-position @before-hide="clearSelect">
|
||||||
<ResultMenu :dense="true" :content="selectText" :textbtn="true" />
|
<ResultMenu :dense="true" :selectText="selectText" :textbtn="true" />
|
||||||
</q-menu>
|
</q-menu>
|
||||||
</q-card>
|
</q-card>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
|
@ -54,6 +54,7 @@ export default {
|
|||||||
imagebtn: Boolean,
|
imagebtn: Boolean,
|
||||||
closebtn: Boolean,
|
closebtn: Boolean,
|
||||||
runResult: Array,
|
runResult: Array,
|
||||||
|
selectText: String,
|
||||||
},
|
},
|
||||||
emits: ["updateResult"],
|
emits: ["updateResult"],
|
||||||
computed: {
|
computed: {
|
||||||
@ -133,11 +134,13 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
copyResult() {
|
copyResult() {
|
||||||
window.utools.copyText(this.getFormattedContent());
|
window.utools.copyText(this.selectText || this.getFormattedContent());
|
||||||
quickcommand.showMessageBox("已复制到剪贴板");
|
quickcommand.showMessageBox("已复制到剪贴板");
|
||||||
},
|
},
|
||||||
sendResult() {
|
sendResult() {
|
||||||
window.utools.hideMainWindowTypeString(this.getFormattedContent());
|
window.utools.hideMainWindowTypeString(
|
||||||
|
this.selectText || this.getFormattedContent()
|
||||||
|
);
|
||||||
},
|
},
|
||||||
dataUrlToImg() {
|
dataUrlToImg() {
|
||||||
const imagePattern = /data:image\/.*?;base64,.*/g;
|
const imagePattern = /data:image\/.*?;base64,.*/g;
|
||||||
@ -172,15 +175,33 @@ export default {
|
|||||||
];
|
];
|
||||||
if (!headers.length) return;
|
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 columnWidths = headers.map((header) => {
|
||||||
const maxDataWidth = Math.max(
|
const maxDataWidth = Math.max(
|
||||||
header.length,
|
getDisplayWidth(header),
|
||||||
...tableData.map((obj) => {
|
...tableData.map((obj) => {
|
||||||
const value = obj[header];
|
const value = obj[header];
|
||||||
return value === undefined || value === null
|
return value === undefined || value === null
|
||||||
? 0
|
? 0
|
||||||
: String(value).replace(/\n/g, "\\n").length;
|
: getDisplayWidth(String(value).replace(/\n/g, "\\n"));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return maxDataWidth;
|
return maxDataWidth;
|
||||||
@ -191,10 +212,12 @@ export default {
|
|||||||
"| " +
|
"| " +
|
||||||
cells
|
cells
|
||||||
.map((cell, index) => {
|
.map((cell, index) => {
|
||||||
|
const cellStr = String(cell);
|
||||||
|
const displayWidth = getDisplayWidth(cellStr);
|
||||||
const padding = " ".repeat(
|
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(" | ") +
|
.join(" | ") +
|
||||||
" |";
|
" |";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user