feat: add "Copy as INSERT" to data grid context menu (#166)

This commit is contained in:
t8y2
2026-05-08 21:33:41 +08:00
parent 77ed6404a0
commit bd08d9865d
3 changed files with 15 additions and 0 deletions
+13
View File
@@ -1101,6 +1101,18 @@ function copyRow() {
copyText(JSON.stringify(obj, null, 2));
}
function copyRowAsInsert() {
if (!contextCell.value) return;
const item = getRowItem(contextCell.value.rowId);
if (!item) return;
const cols = props.result.columns.map((c) => quoteIdent(c)).join(", ");
const vals = item.data.map((v) => escapeVal(v)).join(", ");
const table = props.tableMeta
? (props.tableMeta.schema ? `${quoteIdent(props.tableMeta.schema)}.` : "") + quoteIdent(props.tableMeta.tableName)
: "table_name";
copyText(`INSERT INTO ${table} (${cols}) VALUES (${vals});`);
}
function copyAll() {
const header = props.result.columns.join("\t");
const body = displayItems.value.map((item) => item.data.map((c) => formatCell(c)).join("\t")).join("\n");
@@ -1732,6 +1744,7 @@ defineExpose({
<ContextMenuContent class="w-60">
<ContextMenuItem @click="copyCell">{{ t("grid.copyCell") }}</ContextMenuItem>
<ContextMenuItem @click="copyRow">{{ t("grid.copyRow") }}</ContextMenuItem>
<ContextMenuItem @click="copyRowAsInsert">{{ t("grid.copyRowInsert") }}</ContextMenuItem>
<ContextMenuItem @click="copyAll">{{ t("grid.copyAll") }}</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem v-if="contextCell" @click="openTranspose(contextCell.rowIndex)">
+1
View File
@@ -172,6 +172,7 @@ export default {
noFilteredRowsDescription: "Adjust the search text or row status filter.",
copyCell: "Copy Cell",
copyRow: "Copy Row (JSON)",
copyRowInsert: "Copy as INSERT",
copyAll: "Copy All (TSV)",
copySelectionTsv: "Copy Selection (TSV)",
copySelectionCsv: "Copy Selection (CSV)",
+1
View File
@@ -171,6 +171,7 @@ export default {
noFilteredRowsDescription: "调整搜索词或状态筛选试试。",
copyCell: "复制单元格",
copyRow: "复制行 (JSON)",
copyRowInsert: "复制为 INSERT 语句",
copyAll: "复制全部 (TSV)",
copySelectionTsv: "复制选区 (TSV)",
copySelectionCsv: "复制选区 (CSV)",