表单设计-图斑组件修改、自动建表-添加子表功能
parent
a791a48de1
commit
7102fff2dd
|
|
@ -64,7 +64,6 @@
|
|||
<script lang="ts" setup>
|
||||
import { ref, provide, computed } from 'vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { BasicModal, useModal, useModalInner } from '@/components/Modal';
|
||||
// 子组件
|
||||
import AutomaticModal from './modal/AutomaticModal.vue';
|
||||
|
|
@ -106,11 +105,11 @@
|
|||
tableNames: schems.db[i].name,
|
||||
};
|
||||
await getOutKeyList(params).then((res: Recordable) => {
|
||||
console.log(res);
|
||||
// console.log(res);
|
||||
if (res.length > 0) {
|
||||
arr.push({
|
||||
name: schems.db[i].name,
|
||||
data: res[0].db_codecolumnsList,
|
||||
data: res[0]?.db_codecolumnsList,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -306,7 +305,7 @@
|
|||
tableNames: data.table[0].name,
|
||||
};
|
||||
getOutKeyList(params).then((res: Recordable) => {
|
||||
res[0].db_codecolumnsList.forEach((item) => {
|
||||
res[0]?.db_codecolumnsList.forEach((item) => {
|
||||
if (item.isPrimaryKey == 1) {
|
||||
primaryKey.value = item.dbColumnName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -619,13 +619,13 @@
|
|||
item.relationalTable = optionsArr;
|
||||
getOutKeyList({ tableNames: item.name, dbCode: anyformobj.value.DbCode }).then(
|
||||
(data: Recordable) => {
|
||||
item.FieldTablesArr = data[0].db_codecolumnsList;
|
||||
item.FieldTablesArr = data[0]?.db_codecolumnsList;
|
||||
},
|
||||
);
|
||||
if (item.relationName) {
|
||||
getOutKeyList({ tableNames: item.relationName, dbCode: anyformobj.value.DbCode }).then(
|
||||
(data: Recordable) => {
|
||||
item.relationalTieldTable = data[0].db_codecolumnsList;
|
||||
item.relationalTieldTable = data[0]?.db_codecolumnsList;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -643,14 +643,14 @@
|
|||
if (item.type !== 'main') {
|
||||
getOutKeyList({ tableNames: item.name, dbCode: anyformobj.value.DbCode }).then(
|
||||
(data: Recordable) => {
|
||||
item.outColumnKey = data[0].db_codecolumnsList;
|
||||
item.outColumnKey = data[0]?.db_codecolumnsList;
|
||||
},
|
||||
);
|
||||
item.relationalTable = record.filter((val) => item.name !== val.name);
|
||||
if (item.relationName) {
|
||||
getOutKeyList({ tableNames: item.relationName, dbCode: anyformobj.value.DbCode }).then(
|
||||
(data: Recordable) => {
|
||||
item.relationalTieldTable = data[0].db_codecolumnsList;
|
||||
item.relationalTieldTable = data[0]?.db_codecolumnsList;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -669,7 +669,7 @@
|
|||
if (item.name == record.name) {
|
||||
getOutKeyList({ tableNames: record.relationName, dbCode: anyformobj.value.DbCode }).then(
|
||||
(data: Recordable) => {
|
||||
item.relationalTieldTable = data[0].db_codecolumnsList;
|
||||
item.relationalTieldTable = data[0]?.db_codecolumnsList;
|
||||
item.relationField = undefined;
|
||||
},
|
||||
);
|
||||
|
|
@ -685,7 +685,7 @@
|
|||
if (item.index == record.index) {
|
||||
getOutKeyList({ tableNames: record.relationName, dbCode: anyformobj.value.DbCode }).then(
|
||||
(data: Recordable) => {
|
||||
item.relationalTieldTable = data[0].db_codecolumnsList;
|
||||
item.relationalTieldTable = data[0]?.db_codecolumnsList;
|
||||
item.relationField = undefined;
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
@ok="submit"
|
||||
@visible-change="
|
||||
() => {
|
||||
dbTableInfo_new = [];
|
||||
dbTableInfo_new_list = [];
|
||||
dbColumnInfo_new = [];
|
||||
dbColumnInfo_new_list = [];
|
||||
dbColumnInfo_new_children = [];
|
||||
|
|
@ -42,7 +44,7 @@
|
|||
<div>
|
||||
<a-input
|
||||
v-model:value="record.tableName"
|
||||
:disabled="!props.isAddVisible"
|
||||
:disabled="!props.isAddVisible && !dbTableInfo_new_list.includes(record.tableName)"
|
||||
@change="record.name = record.tableName"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -183,6 +185,7 @@
|
|||
// 子表
|
||||
let tableInfo_list: any = ref([]);
|
||||
let scheme_chlid_db: any = [];
|
||||
let chlidNumber: number = 0;
|
||||
// 表结构初始值
|
||||
let dbColumnInfo = {
|
||||
tableName: '',
|
||||
|
|
@ -195,6 +198,10 @@
|
|||
isPrimarykey: 0,
|
||||
decimalDigits: 0,
|
||||
};
|
||||
|
||||
// 新增表
|
||||
let dbTableInfo_new: any = [];
|
||||
let dbTableInfo_new_list: any = [];
|
||||
// 新增列
|
||||
let dbColumnInfo_new: any = [];
|
||||
let dbColumnInfo_new_list: any = [];
|
||||
|
|
@ -216,10 +223,7 @@
|
|||
const [dbMainTable, { getDataSource: dbMain_getDataSource, setTableData: dbMain_setTableData }] =
|
||||
useTable();
|
||||
|
||||
const [
|
||||
dbColumnInfoTable,
|
||||
{ getDataSource: dbColumnInfo_getTableData, setTableData: dbColumnInfo_setTableData },
|
||||
] = useTable();
|
||||
const [dbColumnInfoTable, { setTableData: dbColumnInfo_setTableData }] = useTable();
|
||||
|
||||
// 异步传参
|
||||
const [automaticModal, { closeModal }] = useModalInner(async (data) => {
|
||||
|
|
@ -232,19 +236,34 @@
|
|||
data_json.db = result_json.db;
|
||||
data.saveFormDatas.scheme.scheme = JSON.stringify(data_json);
|
||||
}
|
||||
console.log(data.saveFormDatas.scheme.scheme);
|
||||
|
||||
// 表名和备注
|
||||
let scheme = JSON.parse(data.saveFormDatas.scheme.scheme);
|
||||
tableInfo_list.value = [];
|
||||
scheme_chlid_db = [];
|
||||
setDefaultValue(scheme);
|
||||
// 制作表格
|
||||
scheme = getSchemasReturnScheme(scheme, data.saveFormDatas.info.DbCode, 'father', '');
|
||||
|
||||
// 表格赋值
|
||||
dbMain_setTableData(scheme.db.concat(scheme_chlid_db));
|
||||
dbColumnInfo_setTableData(tableInfo_main.dbColumnInfoList);
|
||||
data.saveFormDatas.scheme.scheme = JSON.stringify(scheme);
|
||||
saveFormDatas = data.saveFormDatas;
|
||||
saveFormDatas.scheme.scheme = JSON.stringify(scheme);
|
||||
});
|
||||
|
||||
// 设置初始值
|
||||
function setDefaultValue(scheme) {
|
||||
tableInfo_list.value = [];
|
||||
scheme_chlid_db = [];
|
||||
chlidNumber = scheme ? scheme.db.length - 1 : 0;
|
||||
dbTableInfo_new = [];
|
||||
dbTableInfo_new_list = [];
|
||||
dbColumnInfo_new = [];
|
||||
dbColumnInfo_new_list = [];
|
||||
dbColumnInfo_new_children = [];
|
||||
dbColumnInfo_new_children_list = [];
|
||||
}
|
||||
|
||||
// 制作表格
|
||||
function getSchemasReturnScheme(scheme: any, dbCode, type, mainTableName) {
|
||||
let schemas: any = '';
|
||||
|
|
@ -253,7 +272,7 @@
|
|||
if (type == 'father') {
|
||||
// 主表
|
||||
schemas = scheme.formInfo.schemas;
|
||||
tableInfo_temp.name = scheme.db[0].tableName || scheme.db[0].name;
|
||||
tableInfo_temp.name = scheme.db[0].name || scheme.db[0].tableName;
|
||||
tableInfo_temp.tableName = scheme.db[0].tableName || scheme.db[0].name;
|
||||
tableInfo_temp.description = scheme.db[0].description || '主表';
|
||||
tableInfo_temp.type = 'main';
|
||||
|
|
@ -265,7 +284,8 @@
|
|||
if (props.isAddVisible) {
|
||||
// 新增
|
||||
// 子表
|
||||
tableInfo_temp.name = 'tableGrid' + new Date().getTime() + Math.random();
|
||||
chlidNumber++;
|
||||
tableInfo_temp.name = mainTableName + '_grid' + chlidNumber;
|
||||
tableInfo_temp.tableName = tableInfo_temp.name;
|
||||
tableInfo_temp.description = '子表';
|
||||
tableInfo_temp.type = 'chlid';
|
||||
|
|
@ -282,13 +302,33 @@
|
|||
scheme_chlid_db.push(chlid_db);
|
||||
} else {
|
||||
// 编辑
|
||||
tableInfo_temp = scheme.columns[0].child_db;
|
||||
tableInfo_temp.name = scheme.columns[0].child_db.name;
|
||||
tableInfo_temp.tableName = scheme.columns[0].child_db.tableName;
|
||||
tableInfo_temp.description = scheme.columns[0].child_db.description;
|
||||
tableInfo_temp.type = scheme.columns[0].child_db.type;
|
||||
tableInfo_temp.dbCode = dbCode;
|
||||
tableInfo_temp.dbColumnInfoList = [];
|
||||
if (scheme.columns[0].child_db) {
|
||||
tableInfo_temp = scheme.columns[0].child_db;
|
||||
tableInfo_temp.dbCode = dbCode;
|
||||
tableInfo_temp.dbColumnInfoList = [];
|
||||
chlid_db = scheme.columns[0].child_db;
|
||||
} else {
|
||||
// 新增
|
||||
// 子表
|
||||
chlidNumber++;
|
||||
tableInfo_temp.name = mainTableName + '_grid' + chlidNumber;
|
||||
tableInfo_temp.tableName = tableInfo_temp.name;
|
||||
tableInfo_temp.description = '子表';
|
||||
tableInfo_temp.type = 'chlid';
|
||||
tableInfo_temp.dbCode = dbCode;
|
||||
tableInfo_temp.dbColumnInfoList = [];
|
||||
// 表名db
|
||||
chlid_db = {
|
||||
name: tableInfo_temp.name,
|
||||
tableName: tableInfo_temp.tableName,
|
||||
description: tableInfo_temp.description,
|
||||
type: tableInfo_temp.type,
|
||||
relationName: mainTableName,
|
||||
};
|
||||
scheme_chlid_db.push(chlid_db);
|
||||
dbTableInfo_new.push(tableInfo_temp);
|
||||
dbTableInfo_new_list.push(tableInfo_temp.tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -390,20 +430,25 @@
|
|||
tableInfo_list.value?.forEach(async (e) => {
|
||||
await AddTable(e);
|
||||
});
|
||||
// } else if (dbColumnInfo_new_list.length == tableInfo_main.dbColumnInfoList.length) {
|
||||
// tableInfo_list?.forEach(async (e) => {
|
||||
// await AddTable(e);
|
||||
// });
|
||||
} else if (dbColumnInfo_new_children) {
|
||||
// 编辑
|
||||
dbColumnInfo_new_children?.forEach(async (item) => {
|
||||
await AddColumn(item);
|
||||
});
|
||||
} else {
|
||||
if (dbTableInfo_new) {
|
||||
// 编辑-新增表
|
||||
dbTableInfo_new?.forEach(async (e) => {
|
||||
await AddTable(e);
|
||||
});
|
||||
}
|
||||
console.log(dbTableInfo_new_list);
|
||||
console.log(dbColumnInfo_new_children);
|
||||
if (dbColumnInfo_new_children) {
|
||||
// 编辑-新增行
|
||||
dbColumnInfo_new_children?.forEach(async (item) => {
|
||||
if (!dbTableInfo_new_list.includes(item.tableName)) {
|
||||
await AddColumn(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
dbColumnInfo_new = [];
|
||||
dbColumnInfo_new_list = [];
|
||||
dbColumnInfo_new_children = [];
|
||||
dbColumnInfo_new_children_list = [];
|
||||
setDefaultValue(null);
|
||||
getFromAndTable();
|
||||
}
|
||||
|
||||
|
|
@ -412,17 +457,7 @@
|
|||
let schems = JSON.parse(saveFormDatas.scheme.scheme);
|
||||
// db
|
||||
schems.db = dbMain_getDataSource();
|
||||
// schemas
|
||||
let i = 0;
|
||||
schems.formInfo.schemas.forEach((item, index) => {
|
||||
if (item.dbColumnInfo) {
|
||||
item.dbColumnInfo = dbColumnInfo_getTableData()[index - i];
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
});
|
||||
saveFormDatas.scheme.scheme = JSON.stringify(schems);
|
||||
|
||||
emit('automatic-modal-submitsuccess', saveFormDatas);
|
||||
closeModal();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue