Skip to content

Commit f8e0255

Browse files
committed
feat:primaryKeyOrder
1 parent 57e1e3d commit f8e0255

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,17 @@
9292
justify-content: center;
9393
align-items: center;
9494
cursor: pointer;
95+
position: relative;
9596
i{
9697
color: var(--color-warning);
9798
}
99+
span{
100+
position: absolute;
101+
font-weight: bold;
102+
right: 4px;
103+
bottom: -2px;
104+
transform: scale(0.8);
105+
}
98106
}
99107

100108
.operationBar {

chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const createInitialData = () => {
7171
autoIncrement: null,
7272
comment: null,
7373
primaryKey: null,
74+
primaryKeyOrder: null,
7475
schemaName: null,
7576
databaseName: null,
7677
typeName: null,
@@ -243,6 +244,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
243244
}}
244245
>
245246
{primaryKey && <Iconfont code="&#xe775;" />}
247+
{primaryKey && <span>{record.primaryKeyOrder}</span>}
246248
</div>
247249
</div>
248250
);
@@ -287,22 +289,46 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
287289

288290
const handelPrimaryKey = (_data: IColumnItemNew) => {
289291
const newData = dataSource.map((item) => {
292+
let primaryKeyOrder:null | number = item.primaryKeyOrder;
293+
294+
if(_data.primaryKey) {
295+
// 如果当前字段是主键,且当前字段的主键顺序大于当前编辑的字段的主键顺序,那么当前字段的主键顺序减1
296+
if(_data.primaryKeyOrder && item.primaryKeyOrder && item.primaryKeyOrder >= _data.primaryKeyOrder){
297+
primaryKeyOrder = item.primaryKeyOrder - 1;
298+
}
299+
}
300+
301+
// 增加主键的时候,主键顺序为当前表的最大主键顺序+1
302+
if(_data.key === item.key && !_data.primaryKey){
303+
primaryKeyOrder = Math.max(...dataSource.map(i => {
304+
return i.primaryKeyOrder || 0
305+
})) + 1;
306+
}
307+
308+
290309
if (item.key === _data?.key) {
291310
// 判断当前数据是新增的数据还是编辑后的数据
292311
let editStatus = item.editStatus;
293312
if (editStatus !== EditColumnOperationType.Add) {
294313
editStatus = EditColumnOperationType.Modify;
295314
}
315+
296316
const editingDataItem = {
297317
...item,
298318
primaryKey: !item.primaryKey,
319+
primaryKeyOrder,
299320
nullable: !item.primaryKey ? NullableType.NotNull : item.nullable,
300321
editStatus,
301322
};
302323
return editingDataItem;
303324
}
304-
return item;
325+
326+
return {
327+
...item,
328+
primaryKeyOrder,
329+
};
305330
});
331+
console.log(newData)
306332
setDataSource(newData);
307333
};
308334

chat2db-client/src/typings/editTable.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IndexesType, EditColumnOperationType, NullableType } from '@/constants';
1+
import { EditColumnOperationType, NullableType } from '@/constants';
22

33
// 编辑表时表的基础数据
44
export interface IBaseInfo {
@@ -26,6 +26,7 @@ export interface IColumnItemNew {
2626
autoIncrement: string | null; // 是否自增
2727
comment: string | null; // 注释
2828
primaryKey: boolean | null; // 是否主键
29+
primaryKeyOrder: number | null; // 主键顺序
2930
typeName: string | null; // 类型名
3031
columnSize: number | null; // 列的长度
3132
bufferLength: number | null; // 缓冲区长度
@@ -69,7 +70,7 @@ export interface IIndexItem {
6970
key?: string;
7071
name: string | null;
7172
comment?: string | null;
72-
type: IndexesType | null;
73+
type: any | null;
7374
columnList: IIndexIncludeColumnItem[];
7475
editStatus: EditColumnOperationType | null; // 操作类型
7576

0 commit comments

Comments
 (0)