表单设计-自动建表最终版

zzq
滕嵩 2024-06-10 15:38:43 +08:00
parent 561814557d
commit 3e6068de87
1 changed files with 120 additions and 59 deletions

View File

@ -35,10 +35,18 @@
</a-tag>
</a-col>
<a-col class="gutter-row" :span="11">
<a-input v-model:value="db.tableName" @change="db.name = db.tableName" />
<a-input
v-model:value="db.tableName"
:disabled="!isNewTable(db)"
@change="changeTableName(db)"
/>
</a-col>
<a-col class="gutter-row" :span="11">
<a-input v-model:value="db.description" placeholder="请输入备注" />
<a-input
v-model:value="db.description"
placeholder="请输入备注"
:disabled="!isNewTable(db)"
/>
</a-col>
</a-row>
<BasicTable
@ -53,7 +61,7 @@
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'dbColumnName'">
<div>
<a-input v-model:value="record.dbColumnName" :disabled="!props.isAddVisible" />
<a-input v-model:value="record.dbColumnName" :disabled="!isNewFormItem(record)" />
</div>
</template>
<template v-if="column.key === 'length'">
@ -61,7 +69,9 @@
<a-input
v-model:value="record.length"
defaultValue="200"
:disabled="record.length == 0 && record.dataType == 'bool'"
:disabled="
!isNewFormItem(record) || (record.length == 0 && record.dataType == 'bool')
"
/>
</div>
</template>
@ -71,9 +81,10 @@
ref="select"
size="small"
placeholder="请选择"
style="width: 100%; text-align: left"
v-model:value="record.dataType"
:options="dataTypeOptions"
style="width: 100%; text-align: left"
:disabled="!isNewFormItem(record)"
@change="isBoolChangeLength(record)"
/>
</div>
@ -115,6 +126,7 @@
let db_list: any = ref([]);
//
let primaryKey = '';
let oldDb: any = [];
//
let dbColumnInfo = {
tableName: '',
@ -127,7 +139,6 @@
isPrimarykey: 0,
decimalDigits: 0,
};
// -
let dataTypeOptions = [
{ label: '字符串', value: 'varchar' },
@ -151,44 +162,47 @@
let result_json = JSON.parse(result.scheme.scheme);
let data_json = JSON.parse(data.saveFormDatas.scheme.scheme);
data_json.db = result_json.db;
oldDb = result_json.db;
data.saveFormDatas.scheme.scheme = JSON.stringify(data_json);
}
//
let scheme = JSON.parse(data.saveFormDatas.scheme.scheme);
console.log(160, scheme);
//
//
db_list.value = [];
scheme = getSchemeByscheme(
scheme,
data.saveFormDatas.info.DbCode,
'father',
'main',
scheme.db,
scheme.db[0].tableName,
'',
'main',
cloneDeep(tableInfo),
);
// dbdb
if (!props.isAddVisible) {
changeOldDb();
}
saveFormDatas = data.saveFormDatas;
saveFormDatas.scheme.scheme = JSON.stringify(scheme);
});
//
function getSchemeByscheme(
scheme: any,
dbCode,
type, //
schemedb,
mainTableName,
chlidTableName,
mainTableName, //
chlidTableName, //
gridType, //
db_temp,
) {
let schemas: any = '';
// let db_temp = cloneDeep(tableInfo);
// console.log(gridType, db_temp);
// -db
if (type == 'father') {
if (type == 'main') {
// 使
if (props.isAddVisible) {
db_temp.name = scheme.db[0].name || scheme.db[0].tableName;
@ -203,9 +217,9 @@
if (gridType == 'main') {
db_temp = schemedb[0];
db_temp.dbColumnInfoList = [];
} else {
// 使
console.log(207, db_temp);
// } else {
// // 使
// console.log(207, db_temp);
}
mainTableName = db_temp.tableName;
}
@ -242,7 +256,7 @@
}
// -table
if (type == 'father') {
if (type == 'main') {
let mainEach: any = [];
if (gridType == 'main') {
mainEach = scheme.formInfo.tabList;
@ -418,7 +432,6 @@
children: temp,
});
}
console.log(412, mainEach);
//
mainEach.forEach((sch, i) => {
schemas = sch.children;
@ -667,22 +680,32 @@
return scheme;
}
//
function getBoolean(item, db_temp) {
if (db_temp) {
let res = db_temp.dbColumnInfoList.find(
(t) => t.dbColumnName === item.componentProps.fieldName,
);
if (res) {
return true;
} else {
return false;
// dbdb
function changeOldDb() {
let oldTableNameArray = oldDb.map((old) => old.tableName);
db_list.value.forEach((db, db_index) => {
//
if (oldTableNameArray.includes(db.tableName)) {
let oldTable = oldDb.find((old) => {
return old.tableName == db.tableName;
});
//
db.dbColumnInfoList?.forEach((dbColumn, dbColumn_index) => {
oldTable.dbColumnInfoList?.forEach((oldDbColumn) => {
if (dbColumn.dbColumnName == oldDbColumn.dbColumnName) {
// varchar
db_list.value[db_index].dbColumnInfoList[dbColumn_index] = oldDbColumn;
}
});
});
}
}
});
}
//
async function submit() {
// relationField
getRelationField();
if (props.isAddVisible) {
db_list.value.forEach(async (db) => {
@ -690,29 +713,33 @@
await AddTable(db);
});
} else {
let schems = JSON.parse(saveFormDatas.scheme.scheme);
let schemsArray = new Array(schems.map((sch) => sch.tableName));
schems.forEach(async (sch) => {
let schArray = new Array(sch.dbColumnInfoList.map((s) => s.tableName));
db_list.value.forEach(async (db) => {
//
if (!schemsArray.includes(db.tableName)) {
await AddTable(db);
} else {
//
db.dbColumnInfoList.forEach(async (d) => {
if (!schArray.includes(d.tableName)) {
await AddColumn(d);
}
});
}
});
//
let oldTableNameArray = oldDb.map((old) => old.tableName);
db_list.value.forEach(async (db) => {
//
if (!oldTableNameArray.includes(db.tableName)) {
await AddTable(db);
} else {
//
oldDb.forEach((old) => {
//
if (old.tableName == db.tableName) {
//
let oldDbColumnArray = old.dbColumnInfoList.map((o) => o.dbColumnName);
db.dbColumnInfoList.forEach(async (dbColumn) => {
if (!oldDbColumnArray.includes(dbColumn.dbColumnName)) {
await AddColumn(dbColumn);
}
});
}
});
}
});
}
getFromAndTable();
}
// relationField
// relationField
function getRelationField() {
// primaryKey
if (db_list.value[0].dbColumnInfoList.length > 0) {
@ -736,15 +763,6 @@
saveFormDatas.scheme.scheme = JSON.stringify(schems);
}
// varchar
function isBoolChangeLength(record: Recordable) {
if (record.dataType == 'bool') {
record.length = 0;
} else {
record.length = 200;
}
}
// saveFormDatas
function getFromAndTable() {
let schems = JSON.parse(saveFormDatas.scheme.scheme);
@ -755,9 +773,52 @@
item.relationField = primaryKey;
}
});
// console.log(schems.db);
saveFormDatas.scheme.scheme = JSON.stringify(schems);
emit('automatic-modal-submitsuccess', saveFormDatas);
closeModal();
}
//
function changeTableName(db) {
let scheme_replace = JSON.stringify(saveFormDatas.scheme.scheme);
scheme_replace = scheme_replace.replace(db.name, db.tableName);
saveFormDatas.scheme.scheme = JSON.parse(scheme_replace);
db.name = db.tableName;
db.dbColumnInfoList?.forEach((d) => {
d.tableName = db.tableName;
});
}
// varchar
function isBoolChangeLength(record: Recordable) {
if (record.dataType == 'bool') {
record.length = 0;
} else {
record.length = 200;
}
}
//
function isNewTable(item: any) {
let flag = true;
oldDb.forEach((old) => {
if (old.tableName == item.tableName) {
flag = false;
}
});
return flag;
}
//
function isNewFormItem(item: any) {
let flag = true;
oldDb?.forEach((old) => {
old?.dbColumnInfoList?.forEach((li) => {
if (li.dbColumnName == item.dbColumnName) {
flag = false;
}
});
});
return flag;
}
</script>