fix: 数据源管理 删除行

This commit is contained in:
easy 2023-03-13 17:05:16 +08:00
parent e121ae9a81
commit 6dfc0cb1db
4 changed files with 41 additions and 5 deletions

View File

@ -22,3 +22,7 @@ export const rdbTree_api = (id: string) => server.get(`/datasource/rdb/${id}/tab
export const rdbTables_api = (id: string,key:string) => server.get(`/datasource/rdb/${id}/table/${key}`); export const rdbTables_api = (id: string,key:string) => server.get(`/datasource/rdb/${id}/table/${key}`);
// 保存表格 // 保存表格
export const saveTable_api = (id: string,data:object) => server.patch(`/datasource/rdb/${id}/table`,data); export const saveTable_api = (id: string,data:object) => server.patch(`/datasource/rdb/${id}/table`,data);
/**
*
*/
export const delSaveRow_api = (datasourceId: string, table: string, data: any) => server.post(`/datasource/rdb/${datasourceId}/table/${table}/drop-column`,data);

View File

@ -164,9 +164,11 @@ import {
rdbTree_api, rdbTree_api,
rdbTables_api, rdbTables_api,
saveTable_api, saveTable_api,
delSaveRow_api,
} from '@/api/system/dataSource'; } from '@/api/system/dataSource';
import { FormInstance, message } from 'ant-design-vue'; import { FormInstance, message } from 'ant-design-vue';
import { DataNode } from 'ant-design-vue/lib/tree'; import { DataNode } from 'ant-design-vue/lib/tree';
import { cloneDeep } from 'lodash';
import type { dbColumnType, dictItemType, sourceItemType } from '../typing'; import type { dbColumnType, dictItemType, sourceItemType } from '../typing';
const id = useRoute().query.id as string; const id = useRoute().query.id as string;
@ -292,7 +294,9 @@ const table = reactive({
getTabelData: (key: string) => { getTabelData: (key: string) => {
rdbTables_api(id, key).then((resp: any) => { rdbTables_api(id, key).then((resp: any) => {
table.data = resp.result.columns; table.data = resp.result.columns.map(
(item: object, index: number) => ({ ...item, index }),
);
}); });
}, },
addRow: () => { addRow: () => {
@ -307,9 +311,11 @@ const table = reactive({
table.data.push(initData); table.data.push(initData);
}, },
clickSave: () => { clickSave: () => {
const columns = cloneDeep(table.data);
columns.forEach((item) => delete item.index);
const params = { const params = {
name: leftData.selectedKeys[0], name: leftData.selectedKeys[0],
columns: table.data, columns,
}; };
saveTable_api(id, params).then((resp) => { saveTable_api(id, params).then((resp) => {
if (resp.status === 200) { if (resp.status === 200) {
@ -318,7 +324,15 @@ const table = reactive({
} }
}); });
}, },
clickDel: (row: any) => {}, clickDel: (row: any) => {
if (row.scale !== undefined) {
delSaveRow_api(id, leftData.selectedKeys[0], [row.name]).then(
(resp: any) => {
if (resp.status === 200) table.data.splice(row.index, 1);
},
);
} else table.data.splice(row.index, 1);
},
}); });
const addFormRef = ref<FormInstance>(); const addFormRef = ref<FormInstance>();

View File

@ -45,7 +45,14 @@
<j-form-item <j-form-item
:name="['shareConfig', 'url']" :name="['shareConfig', 'url']"
label="URL" label="URL"
:rules="[{ required: true, message: '请输入URL' }]" :rules="[
{
required: true,
message: '请输入URL',
trigger: 'change',
},
{ validator: form.checkUrl, trigger: 'blur' },
]"
> >
<j-input <j-input
v-model:value="form.data.shareConfig.url" v-model:value="form.data.shareConfig.url"
@ -183,6 +190,7 @@ import {
saveDataSource_api, saveDataSource_api,
} from '@/api/system/dataSource'; } from '@/api/system/dataSource';
import { FormInstance, message } from 'ant-design-vue'; import { FormInstance, message } from 'ant-design-vue';
import { Rule } from 'ant-design-vue/lib/form';
import type { dictItemType, optionItemType, sourceItemType } from '../typing'; import type { dictItemType, optionItemType, sourceItemType } from '../typing';
const emits = defineEmits(['confirm', 'update:visible']); const emits = defineEmits(['confirm', 'update:visible']);
@ -218,6 +226,15 @@ const form = reactive({
typeOptions: [] as optionItemType[], typeOptions: [] as optionItemType[],
checkUrl: (_rule: Rule, value: string): Promise<any> => {
if (!value) return Promise.reject('请输入URL');
const arr = value.split(':');
if (arr?.[0] === 'jdbc' || arr?.[0] === 'r2dbc') {
return Promise.resolve();
} else {
return Promise.reject('请输入正确的URL');
}
},
getTypeOption: () => { getTypeOption: () => {
getDataTypeDict_api().then((resp: any) => { getDataTypeDict_api().then((resp: any) => {
const result = resp.result as dictItemType[]; const result = resp.result as dictItemType[];

View File

@ -33,5 +33,6 @@ export type dbColumnType = {
notnull: boolean, notnull: boolean,
comment: string, comment: string,
name: string, name: string,
scale?:number scale?:number,
index?:number
} }