Feature: SQL 编辑器右键支持编辑表结构 (#2456)

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
zipg 2026-07-02 20:20:32 +08:00 committed by GitHub
parent d249bd5ac8
commit 4c96aa6e40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View File

@ -1135,6 +1135,12 @@ function onViewTableDdl(tableName: string) {
showQueryEditorDdlDialog.value = true;
}
function onEditTableStructure(tableName: string) {
const target = tableTargetFromActiveTab(tableName);
if (!target) return;
queryStore.openTableStructure(target.connectionId, target.database, target.schema, target.tableName);
}
async function changeActiveConnection(connectionId: string) {
const tab = activeTab.value;
if (!tab) return;
@ -1839,6 +1845,7 @@ onUnmounted(() => {
@execute-sql="onExecuteSql"
@click-table="onClickTable"
@view-table-data="onViewTableData"
@edit-table-structure="onEditTableStructure"
@view-table-ddl="onViewTableDdl"
@open-object-table="
(target) =>

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated, watch, shallowRef, computed, nextTick } from "vue";
import { CaseLower, CaseUpper, FileCode, Play, Copy, Table2, TextSelect } from "@lucide/vue";
import { CaseLower, CaseUpper, FileCode, PencilRuler, Play, Copy, Table2, TextSelect } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import type { CompletionContext } from "@codemirror/autocomplete";
import type { EditorView as EditorViewType } from "@codemirror/view";
@ -89,6 +89,7 @@ const emit = defineEmits<{
clickTable: [tableName: string];
viewTableData: [tableName: string];
viewTableDdl: [tableName: string];
editTableStructure: [tableName: string];
clickColumn: [columns: Array<{ name: string; table: string; schema?: string }>, error?: string | undefined];
closeColumnPanel: [];
viewportChange: [viewport: { scrollTop: number; scrollLeft: number }];
@ -581,6 +582,12 @@ function openTableFromContextMenu() {
focusEditor();
}
function editTableStructureFromContextMenu() {
if (!contextTableName.value) return;
emit("editTableStructure", contextTableName.value);
focusEditor();
}
function openTableDdlFromContextMenu() {
if (!contextTableName.value) return;
emit("viewTableDdl", contextTableName.value);
@ -630,6 +637,12 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => [
disabled: !contextTableName.value,
icon: Table2,
},
{
label: t("contextMenu.editStructure"),
action: editTableStructureFromContextMenu,
disabled: !contextTableName.value,
icon: PencilRuler,
},
{
label: t("contextMenu.viewDdl"),
action: openTableDdlFromContextMenu,

View File

@ -133,6 +133,7 @@ const emit = defineEmits<{
clickTable: [tableName: string];
viewTableData: [tableName: string];
viewTableDdl: [tableName: string];
editTableStructure: [tableName: string];
openObjectTable: [target: { tableName: string; schema?: string }];
objectSchemaChange: [schema: string | undefined];
structureEditorSaved: [commentChanged: boolean];
@ -561,6 +562,10 @@ function onHandleViewTableDdl(tableName: string) {
emit("viewTableDdl", tableName);
}
function onHandleEditTableStructure(tableName: string) {
emit("editTableStructure", tableName);
}
function onHandleCloseColumnPanel() {
showColumnInfo.value = false;
columnInfoColumns.value = [];
@ -681,6 +686,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget, requestQueryEditorExe
@save="emit('saveSql')"
@click-table="onHandleClickTable"
@view-table-data="onHandleViewTableData"
@edit-table-structure="onHandleEditTableStructure"
@view-table-ddl="onHandleViewTableDdl"
@click-column="onHandleClickColumn"
@close-column-panel="onHandleCloseColumnPanel"