Skip to content

Commit 816bf09

Browse files
committed
添加表编辑
1 parent a58b1fe commit 816bf09

File tree

6 files changed

+132
-14
lines changed

6 files changed

+132
-14
lines changed

DataProviders/HiDb.DataProvider.SqlServer/TableDataProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ LEFT JOIN
3838

3939
public List<TableColumnOutput> GetDbColumnList(TableColumnInput input)
4040
{
41-
var use = @$"use [{input.DataBase}];";
42-
return GetList<TableColumnOutput>(use + @$"SELECT
41+
return GetList<TableColumnOutput>(@$"SELECT
4342
COLUMN_NAME AS Name,
4443
DATA_TYPE AS Type,
4544
IS_NULLABLE AS AllowNull

DataProviders/HiDb.DataProvider/Dtos/Tables/TableColumnInput.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -8,10 +9,12 @@ namespace HiDb.DataProvider.Dtos.Tables
89
{
910
public class TableColumnInput
1011
{
12+
[Required]
1113
public string DataBase { get; set; }
1214

1315
public string Mode { get; set; }
1416

17+
[Required]
1518
public string Table { get; set; }
1619
}
1720
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import request from '@renderer/utils/request'
2+
3+
// 获取列表
4+
export function getTableColumnList(data, dbtype) {
5+
return request({
6+
url: '/table/column/list',
7+
method: 'post',
8+
data: data,
9+
headers: {
10+
'dbtype': dbtype
11+
}
12+
})
13+
}
14+
15+
// 获取详情
16+
export function getTableColumnDetail(data, dbtype) {
17+
return request({
18+
url: '/table/column/detail',
19+
method: 'post',
20+
data: data,
21+
headers: {
22+
'dbtype': dbtype
23+
}
24+
})
25+
}

Gui/HiDb.Vue/src/renderer/components/MainPage.vue

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<a-dropdown :trigger="['contextmenu']">
100100
<span>{{ title }}</span>
101101
<template #overlay>
102-
<a-menu @click="({ key: menuKey }) => onContextMenuClick(treeKey, menuKey)">
102+
<a-menu @click="({ key: menuKey }) => onContextMenuClick(treeKey, menuKey,currRightData)">
103103
<div v-if="currRightData.type == 'db'">
104104
<a-menu-item key="11">查看数据库</a-menu-item>
105105
<a-menu-item key="12">删除数据库</a-menu-item>
@@ -110,9 +110,9 @@
110110
</div> -->
111111
<div v-if="currRightData.type == 'table'">
112112
<a-menu-item key="31">查看表数据</a-menu-item>
113-
<!-- <a-menu-item key="32">编辑表结构</a-menu-item>
113+
<a-menu-item key="32">编辑表结构</a-menu-item>
114114
<a-menu-item key="33">删除表</a-menu-item>
115-
<a-menu-item key="34">归档表</a-menu-item> -->
115+
<a-menu-item key="34">归档表</a-menu-item>
116116
</div>
117117
</a-menu>
118118
</template>
@@ -190,7 +190,11 @@
190190
</div>
191191
</div>
192192
<div v-show="viewMode == 3" class="work" :style="{ 'width': bodyWidth }">
193-
编辑表结构
193+
<my-sql-edit
194+
:database="editTableData.database"
195+
:table="editTableData.table"
196+
:mode="editTableData.mode"
197+
:dbtype="editTableData.dbtype"></my-sql-edit>
194198
</div>
195199
<div v-show="viewMode == 1" class="work" :style="{ 'width': bodyWidth }">
196200
编辑数据库
@@ -319,7 +323,7 @@
319323

320324
<script lang="ts" setup>
321325
import { cloneDeep } from 'lodash-es';
322-
import { h, ref, watch, onMounted, UnwrapRef, reactive } from 'vue';
326+
import { h, ref, watch, onMounted, UnwrapRef, reactive, defineComponent } from 'vue';
323327
import MySql from './icons/MySql.vue';
324328
import SqlServer from './icons/SqlServer.vue';
325329
import PgSql from './icons/PgSql.vue';
@@ -334,7 +338,7 @@ import { DataType } from 'vue-request';
334338
import { getGuid } from '@renderer/utils/guid';
335339
import { life } from '../api/life';
336340
import * as monaco from 'monaco-editor';
337-
341+
import MySqlEdit from './table-edit/MySqlEdit.vue';
338342
const sh = 280;
339343
const pageHeight = ref(0);
340344
const dftPageHeight = ref(0);
@@ -398,6 +402,12 @@ import * as monaco from 'monaco-editor';
398402
console.log('onResize:' + pageHeight.value);
399403
};
400404
const viewMode = ref(0); // 视图模式,0数据视图,1 编辑表视图 2编辑模式视图 3编辑数据库视图
405+
const editTableData = ref({
406+
table: '',
407+
database: '',
408+
mode: '',
409+
dbtype: 0
410+
}); // 当前标记表
401411
const searchValue = ref<string>(''); // 左侧搜索内容
402412
const expandedMenuKeys = ref<string[]>([]); // tree搜索key
403413
const selectedMenuKeys = ref<string[]>([]); // tree选择key
@@ -587,8 +597,7 @@ import * as monaco from 'monaco-editor';
587597
encrypt: true,
588598
saveLocal: true
589599
});
590-
const onContextMenuClick = (treeKey: string, menuKey: string | number) => {
591-
console.log(`treeKey: ${treeKey}, menuKey: ${menuKey}`);
600+
const onContextMenuClick = (treeKey: string, menuKey: string | number, data: any) => {
592601
if (menuKey == '11') {
593602
viewMode.value = 1;
594603
} else if (menuKey == '12') {
@@ -602,6 +611,13 @@ import * as monaco from 'monaco-editor';
602611
}
603612
searchData();
604613
} else if (menuKey == '32') {
614+
editTableData.value = {
615+
database: currRightData.value.database,
616+
table: currRightData.value.title,
617+
mode: currRightData.value.mode,
618+
dbtype: currDatabase.value.type
619+
}
620+
console.log(editTableData)
605621
viewMode.value = 3;
606622
} else if (menuKey == '33') {
607623
viewMode.value = 3;
@@ -814,14 +830,13 @@ import * as monaco from 'monaco-editor';
814830
type: 'tablenull',
815831
}];
816832
} else {
817-
console.log('getTable:' + JSON.stringify(res.data));
818-
console.log(res.data);
819833
treeNode.dataRef.children = res.data.map(c => {
820834
return {
821835
title: c.name,
822836
key: c.name,
823837
isLeaf: true,
824838
type: 'table',
839+
mode: treeNode.title,
825840
database: treeNode.type == 'db' ? treeNode.title : treeNode.type == 'mode' ? treeNode.parent.key : ''
826841
}
827842
});

Gui/HiDb.Vue/src/renderer/components/table-edit/MySqlEdit.vue

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,30 @@
4747
</template>
4848
<script setup lang="ts">
4949
import { cloneDeep } from 'lodash-es';
50-
import { UnwrapRef, reactive, ref } from 'vue';
50+
import { UnwrapRef, reactive, ref, watchEffect } from 'vue';
5151
import { ConnectDbInput } from '../model/MainPageMode';
52+
import { getTableColumnList } from '../../api/table';
53+
54+
const props = defineProps(['database','mode','table','dbtype'])
5255
5356
// 表格数据列
5457
const dbColumns = ref<any[]>([{
5558
title: '名称',
5659
dataIndex: 'name',
60+
sorter: false
61+
},
62+
{
63+
title: '字段类型',
64+
dataIndex: 'type',
65+
sorter: false,
66+
width: 150
67+
},
68+
{
69+
title: '是否允许null',
70+
dataIndex: 'allowNull',
5771
sorter: false,
58-
width: 150}
72+
width: 80
73+
}
5974
]);
6075
// 可编辑的列
6176
const allowEditColumns = ref<string[]>(['name','type']);
@@ -81,6 +96,26 @@ const cancel = (key: string) => {
8196
delete editableData[key];
8297
};
8398
99+
const loading = ref(false);
100+
// 加载字段配置
101+
const loadTableColumn = ()=>{
102+
loading.value = true;
103+
getTableColumnList({
104+
database: props.database,
105+
mode: props.mode,
106+
table: props.table
107+
}, props.dbtype).then((res: any) => {
108+
loading.value = false;
109+
currdbData.value = res;
110+
},()=> {
111+
loading.value = false;
112+
})
113+
}
114+
watchEffect(()=>{
115+
console.log('watch');
116+
loadTableColumn();
117+
});
118+
84119
</script>
85120
<style scoped lang="scss">
86121
.content {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using HiDb.DataProvider.Dtos.Search;
2+
using HiDb.DataProvider.Dtos.Tables;
3+
using HiDb.DataProvider.Factory;
4+
using Microsoft.AspNetCore.Authorization;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace HiDb.Api.Controllers;
8+
9+
/// <summary>
10+
/// Search
11+
/// </summary>
12+
/// <param name="searchDataProvider"></param>
13+
[ApiController]
14+
[AllowAnonymous]
15+
[Route("table")]
16+
public class TableController : MainController
17+
{
18+
/// <summary>
19+
/// 获取属性详情
20+
/// </summary>
21+
/// <param name="input"></param>
22+
/// <returns></returns>
23+
[HttpPost("column/detail")]
24+
public TableColumnFullOutput GetDbColumnFullInfo(TableColumnFullInput input)
25+
{
26+
var data = GetService(ServiceFactory.GetTable).GetDbColumnFullInfo(input);
27+
return data;
28+
}
29+
30+
/// <summary>
31+
/// 获取表属性列表
32+
/// </summary>
33+
/// <param name="input"></param>
34+
/// <returns></returns>
35+
[HttpPost("column/list")]
36+
public List<TableColumnOutput> GetDbColumnList(TableColumnInput input)
37+
{
38+
var data = GetService(ServiceFactory.GetTable).GetDbColumnList(input);
39+
return data;
40+
}
41+
}

0 commit comments

Comments
 (0)