创建表前查看数据库有无重名表
parent
3e6068de87
commit
d61e401f63
|
|
@ -11,6 +11,7 @@ enum Api {
|
||||||
createPicTable = '/api/createTable/createTable', //图形化建表
|
createPicTable = '/api/createTable/createTable', //图形化建表
|
||||||
updateTable = '/api/CreateTable/UpdateTable', //图形化建表-修改
|
updateTable = '/api/CreateTable/UpdateTable', //图形化建表-修改
|
||||||
loadTableRecordInfo = '/api/CreateTable/LoadTableRecordInfo', //图形化建表记录
|
loadTableRecordInfo = '/api/CreateTable/LoadTableRecordInfo', //图形化建表记录
|
||||||
|
CheckTableExist = '/api/CreateTable/CheckTableExist', //图形化建表-新建检查
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,3 +47,6 @@ export const updateTable = (params: AccountParams) =>
|
||||||
|
|
||||||
export const loadTableRecordInfo = (params: AccountParams) =>
|
export const loadTableRecordInfo = (params: AccountParams) =>
|
||||||
defHttp.get<AccountListGetResultModel>({ url: Api.loadTableRecordInfo, params });
|
defHttp.get<AccountListGetResultModel>({ url: Api.loadTableRecordInfo, params });
|
||||||
|
|
||||||
|
export const CheckTableExist = (params: AccountParams) =>
|
||||||
|
defHttp.get<AccountListGetResultModel>({ url: Api.CheckTableExist, params });
|
||||||
|
|
|
||||||
|
|
@ -100,11 +100,14 @@
|
||||||
import { CollapseContainer } from '@/components/Container';
|
import { CollapseContainer } from '@/components/Container';
|
||||||
import { BasicTable } from '@/components/Table';
|
import { BasicTable } from '@/components/Table';
|
||||||
import { BasicModal, useModalInner } from '@/components/Modal';
|
import { BasicModal, useModalInner } from '@/components/Modal';
|
||||||
import { dbColumnInfoColumns } from './modelData';
|
import { useMessage } from '@/hooks/web/useMessage';
|
||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
|
import { dbColumnInfoColumns } from './modelData';
|
||||||
import { functionGetForm, AddTable, AddColumn } from '@/api/demo/formScheme';
|
import { functionGetForm, AddTable, AddColumn } from '@/api/demo/formScheme';
|
||||||
|
import { CheckTableExist } from '@/api/database/index';
|
||||||
|
|
||||||
const emit = defineEmits(['automatic-modal-submitsuccess']);
|
const emit = defineEmits(['automatic-modal-submitsuccess']);
|
||||||
|
const { createMessage } = useMessage();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
isAddVisible: {
|
isAddVisible: {
|
||||||
|
|
@ -705,6 +708,12 @@
|
||||||
|
|
||||||
// 提交
|
// 提交
|
||||||
async function submit() {
|
async function submit() {
|
||||||
|
// 检测:数据库是否有此表
|
||||||
|
let results = checkTablesAndWarn();
|
||||||
|
const checkflag = (await results).some(Boolean);
|
||||||
|
if (checkflag) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 设置子表的relationField
|
// 设置子表的relationField
|
||||||
getRelationField();
|
getRelationField();
|
||||||
if (props.isAddVisible) {
|
if (props.isAddVisible) {
|
||||||
|
|
@ -739,6 +748,24 @@
|
||||||
getFromAndTable();
|
getFromAndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测:数据库是否有此表
|
||||||
|
async function checkTablesAndWarn() {
|
||||||
|
const promises = db_list.value.map(async (db) => {
|
||||||
|
if (isNewTable(db)) {
|
||||||
|
let query: any = { tableName: db.tableName };
|
||||||
|
let res = await CheckTableExist(query);
|
||||||
|
if (res) {
|
||||||
|
createMessage.warn('数据库已有表' + db.tableName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
const results = await Promise.all(promises);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
// 设置子表的relationField
|
// 设置子表的relationField
|
||||||
function getRelationField() {
|
function getRelationField() {
|
||||||
// 确定primaryKey
|
// 确定primaryKey
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@
|
||||||
import { columns, columns_isDetail } from './modal.data';
|
import { columns, columns_isDetail } from './modal.data';
|
||||||
import { useMessage } from '@/hooks/web/useMessage';
|
import { useMessage } from '@/hooks/web/useMessage';
|
||||||
// api
|
// api
|
||||||
import { createPicTable, updateTable } from '@/api/database/index';
|
import { createPicTable, updateTable, CheckTableExist } from '@/api/database/index';
|
||||||
import { getLoad } from '@/api/sys/sysDataItemDetail';
|
import { getLoad } from '@/api/sys/sysDataItemDetail';
|
||||||
|
|
||||||
const emit = defineEmits(['submit']);
|
const emit = defineEmits(['submit']);
|
||||||
|
|
@ -222,7 +222,9 @@
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
// 提交
|
// 提交
|
||||||
function handleOk() {
|
async function handleOk() {
|
||||||
|
// 删除两端空格、制表符和换行符
|
||||||
|
tableName.value = tableName.value.trim();
|
||||||
// 检测:表名
|
// 检测:表名
|
||||||
if (!tableName.value) {
|
if (!tableName.value) {
|
||||||
createMessage.warn('表名是必填项!');
|
createMessage.warn('表名是必填项!');
|
||||||
|
|
@ -233,6 +235,13 @@
|
||||||
createMessage.warn('表名不符合数据库表名的命名规则!');
|
createMessage.warn('表名不符合数据库表名的命名规则!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 检测:数据库是否有此表
|
||||||
|
let query: any = { tableName: tableName.value };
|
||||||
|
let res = await CheckTableExist(query);
|
||||||
|
if (res) {
|
||||||
|
createMessage.warn('数据库已有此表名!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
let arr = getDataSource();
|
let arr = getDataSource();
|
||||||
// 检测:字段行
|
// 检测:字段行
|
||||||
if (!arr || arr.length == 0) {
|
if (!arr || arr.length == 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue