Commit ee75a64b authored by 皮倩雯's avatar 皮倩雯

fix: '数据库升级交互重写'

parent 7cf6b6fe
Pipeline #62402 passed with stages
...@@ -45,6 +45,11 @@ const ManagementDataBase = () => { ...@@ -45,6 +45,11 @@ const ManagementDataBase = () => {
const [list, setlist] = useState(['表', '字段', '主外键', '主键', '索引', '复合索引']); const [list, setlist] = useState(['表', '字段', '主外键', '主键', '索引', '复合索引']);
const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 保存已选自动升级表键值 const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 保存已选自动升级表键值
const [keepCheckList, setKeepChecklist] = useState([]); // 保存已选自动升级表值 const [keepCheckList, setKeepChecklist] = useState([]); // 保存已选自动升级表值
const [keepData, setKeepData] = useState([]); // 保存分类数组
const [allchecked, setAllChecked] = useState(true);
const [indeterminateAll, setIndeterminateAll] = useState(false);
const [typeFilters, setTypeFilters] = useState([]); // type列筛选
const [filteredValue, setFilteredValue] = useState([]);
// 检查数据库表 // 检查数据库表
useEffect(() => { useEffect(() => {
setCheckLoading(true); setCheckLoading(true);
...@@ -78,7 +83,6 @@ const ManagementDataBase = () => { ...@@ -78,7 +83,6 @@ const ManagementDataBase = () => {
tableCheckNew() tableCheckNew()
.then(resnew => { .then(resnew => {
setCheckLoading(false); setCheckLoading(false);
console.log(resnew);
if (resnew.code == 0) { if (resnew.code == 0) {
let res = resnew.data; let res = resnew.data;
const { Autolist, ManualList } = res; const { Autolist, ManualList } = res;
...@@ -92,31 +96,57 @@ const ManagementDataBase = () => { ...@@ -92,31 +96,57 @@ const ManagementDataBase = () => {
item.key = index; item.key = index;
return item; return item;
}); });
console.log(list);
console.log(res.RepairTypeList);
let data = []; let data = [];
list.map(i => { list.map(i => {
console.log(i);
if (res.RepairTypeList.indexOf(i) != -1) { if (res.RepairTypeList.indexOf(i) != -1) {
data.push(i); data.push(i);
} }
}); });
console.log(data); console.log(arr); // 所有数据
console.log(arr); let qq = arr.map(item => item.Type);
qq = qq.filter((value, index) => qq.indexOf(value) === index);
console.log(qq);
console.log(qq.map(item => ({ text: item, value: item })));
setTypeFilters(qq.map(item => ({ text: item, value: item })));
let datalist = []; let datalist = [];
if (arr.length > 0) { if (arr.length > 0) {
arr.map(i => { arr.map(i => {
datalist.push(i.key); datalist.push(i.key);
}); });
} }
console.log(datalist); console.log(datalist); // 所有数据的key
setKeepData(data);
setSelectedRowKeys(datalist); setSelectedRowKeys(datalist);
setKeepChecklist(arr); setKeepChecklist(arr);
setKeepValue(res.RepairTypeList); setKeepValue(res.RepairTypeList);
setRepairTypeList(data); console.log(data); // 分类数组
let aa = [];
if (data.length > 0) {
data.map(i => {
let vv = [];
let ff = []; // key
arr.map(j => {
if (j.Type == i) {
vv.push(j);
ff.push(j.key);
}
});
let a = {};
a.name = i;
a.checked = true;
a.indeterminate = false;
a.value = vv;
a.key = ff;
aa.push(a);
});
}
console.log(aa);
setRepairTypeList(aa);
setAutoCheck(arr); setAutoCheck(arr);
setAutoCheckList(arr); setAutoCheckList(arr);
setCheckList(arr2); setCheckList(arr2);
setAllChecked(true);
setIndeterminateAll(false);
} }
}) })
.catch(err => { .catch(err => {
...@@ -167,13 +197,14 @@ const ManagementDataBase = () => { ...@@ -167,13 +197,14 @@ const ManagementDataBase = () => {
// 检查功能 // 检查功能
const handleCheck = () => { const handleCheck = () => {
setCheckFlag(checkFlag + 1); setCheckFlag(checkFlag + 1);
setFilteredValue([]);
}; };
// 升级功能 // 升级功能
const handleUpdate = () => { const handleUpdate = () => {
console.log(keepCheckList); console.log(keepCheckList);
console.log(selectedRowKeys); console.log(selectedRowKeys);
if (repairTypeList.length > 0) { if (repairTypeList.length > 0) {
if (keepValue.length > 0 && keepCheckList.length > 0) { if (keepCheckList.length > 0) {
setCheckLoading(true); setCheckLoading(true);
newUpdateDateBase(keepCheckList) newUpdateDateBase(keepCheckList)
.then(res => { .then(res => {
...@@ -181,6 +212,7 @@ const ManagementDataBase = () => { ...@@ -181,6 +212,7 @@ const ManagementDataBase = () => {
setCheckFlag(checkFlag + 1); setCheckFlag(checkFlag + 1);
setUpFlag(upFlag + 1); setUpFlag(upFlag + 1);
if (res.code === 0) { if (res.code === 0) {
setFilteredValue([]);
notification.success({ notification.success({
message: '通知', message: '通知',
duration: 3, duration: 3,
...@@ -213,6 +245,7 @@ const ManagementDataBase = () => { ...@@ -213,6 +245,7 @@ const ManagementDataBase = () => {
setCheckFlag(checkFlag + 1); setCheckFlag(checkFlag + 1);
setUpFlag(upFlag + 1); setUpFlag(upFlag + 1);
if (res.code === 0) { if (res.code === 0) {
setFilteredValue([]);
notification.success({ notification.success({
message: '通知', message: '通知',
duration: 3, duration: 3,
...@@ -282,6 +315,9 @@ const ManagementDataBase = () => { ...@@ -282,6 +315,9 @@ const ManagementDataBase = () => {
key: 'Type', key: 'Type',
width: 180, width: 180,
ellipsis: true, ellipsis: true,
filters: typeFilters,
onFilter: (value, record) => record.Type === value,
filteredValue,
}, },
{ {
title: '差异比较', title: '差异比较',
...@@ -427,62 +463,159 @@ const ManagementDataBase = () => { ...@@ -427,62 +463,159 @@ const ManagementDataBase = () => {
setCheckSql(e); setCheckSql(e);
}; };
const onChange = e => { // 复选框
let aa = [...autoCheck]; const rowSelection = {
let data = []; selectedRowKeys,
let name = []; columnTitle: ' ',
aa.map(i => { hideDefaultSelections: true,
if (e.indexOf(i.Type) != -1) { onChange: (RowKeys, Rows) => {
data.push(i); // 找到勾选/取消勾选项的Type
let aa = [];
// 取消
if (keepCheckList.length > Rows.length) {
keepCheckList.map(i => {
if (Rows.indexOf(i) == -1) {
aa.push(i.Type);
}
});
} }
}); // 勾选
setAutoCheckList(data); if (keepCheckList.length < Rows.length) {
Rows.map(i => {
let a = [...keepCheckList]; if (keepCheckList.indexOf(i) == -1) {
let b = [...selectedRowKeys]; aa.push(i.Type);
if (e.length > keepValue.length) { }
e.map(k => { });
if (keepValue.indexOf(k) == -1) { }
aa.map(j => { // 找到勾选/取消勾选项的下标
if (j.Type == k) { let index = [];
a.push(j); repairTypeList.map((j, k) => {
b.push(j.key); if (j.name == aa[0]) {
} index.push(k);
});
} }
}); });
setKeepChecklist(a); // 全部勾选数据按照type分类存储
setSelectedRowKeys(b); let list11 = [];
if (keepData.length > 0) {
keepData.map(i => {
let vv = [];
Rows.map(j => {
if (j.Type == i) {
vv.push(j);
}
});
list11.push(vv);
});
}
// 控制分组全选
if (
list11[index[0]].length < repairTypeList[index[0]].value.length &&
list11[index[0]].length !== 0
) {
repairTypeList[index[0]].indeterminate = true;
repairTypeList[index[0]].checked = false;
} else if (list11[index[0]].length === 0) {
repairTypeList[index[0]].indeterminate = false;
repairTypeList[index[0]].checked = false;
} else if (list11[index[0]].length === repairTypeList[index[0]].value.length) {
repairTypeList[index[0]].indeterminate = false;
repairTypeList[index[0]].checked = true;
}
// 控制全选
if (RowKeys.length < autoCheckList.length && RowKeys.length !== 0) {
setAllChecked(false);
setIndeterminateAll(true);
} else if (RowKeys.length === 0) {
setAllChecked(false);
setIndeterminateAll(false);
} else if (RowKeys.length === autoCheckList.length) {
setAllChecked(true);
setIndeterminateAll(false);
}
setSelectedRowKeys(RowKeys);
setKeepChecklist(Rows);
},
};
// 分类全选
const onChangeAll = (e, j) => {
let data1 = [...repairTypeList];
data1[j].checked = e.target.checked;
data1[j].indeterminate = false;
setRepairTypeList(data1);
if (e.target.checked) {
let aa = [...keepCheckList];
let bb = [...selectedRowKeys];
let data = [...new Set(aa.concat(data1[j].value))];
let data2 = [...new Set(bb.concat(data1[j].key))];
// 控制全选
if (data.length < autoCheckList.length && data.length !== 0) {
setAllChecked(false);
setIndeterminateAll(true);
} else if (data.length === 0) {
setAllChecked(false);
setIndeterminateAll(false);
} else if (data.length === autoCheckList.length) {
setAllChecked(true);
setIndeterminateAll(false);
}
setKeepChecklist(data);
setSelectedRowKeys(data2);
} else { } else {
let listaa = []; let aa = []; // 全部已选数据
let listbb = []; let bb = []; // 全部已选数据key
a.map(i => { keepCheckList.map(i => {
if (data.indexOf(i) != -1) { if (data1[j].value.indexOf(i) == -1) {
listaa.push(i); aa.push(i);
listbb.push(i.key); bb.push(i.key);
} }
}); });
setKeepChecklist(listaa); // 控制全选
setSelectedRowKeys(listbb); if (aa.length < autoCheckList.length && aa.length !== 0) {
setAllChecked(false);
setIndeterminateAll(true);
} else if (aa.length === 0) {
setAllChecked(false);
setIndeterminateAll(false);
} else if (aa.length === autoCheckList.length) {
setAllChecked(true);
setIndeterminateAll(false);
}
setKeepChecklist(aa);
setSelectedRowKeys(bb);
} }
setKeepValue(e);
}; };
// 复选框 // 全选
const rowSelection = { const onChange1 = e => {
selectedRowKeys, setAllChecked(e.target.checked);
onChange: (RowKeys, Rows) => { setIndeterminateAll(false);
console.log(RowKeys); if (e.target.checked) {
console.log(Rows); let aa = [...repairTypeList];
setSelectedRowKeys(RowKeys); aa.map(i => {
setKeepChecklist(Rows); i.checked = true;
let aa = []; i.indeterminate = false;
Rows.map(i => {
aa.push(i.Type);
}); });
let data = [...new Set(aa)]; setKeepChecklist(autoCheckList);
// setKeepValue(data); let bb = [];
}, autoCheckList.map(i => {
bb.push(i.key);
});
setSelectedRowKeys(bb);
} else {
let aa = [...repairTypeList];
aa.map(i => {
i.checked = false;
i.indeterminate = false;
});
setKeepChecklist([]);
setSelectedRowKeys([]);
}
};
const onChangeInput = filters => {
console.log('filters', filters);
setFilteredValue(filters.Type);
}; };
return ( return (
...@@ -494,13 +627,23 @@ const ManagementDataBase = () => { ...@@ -494,13 +627,23 @@ const ManagementDataBase = () => {
<span style={{ marginRight: '100px' }}>升级详情</span> <span style={{ marginRight: '100px' }}>升级详情</span>
{repairTypeList.length > 0 && ( {repairTypeList.length > 0 && (
<> <>
<span>类型筛选:</span> <Checkbox
<div style={{ display: 'inline-block' }}> checked={allchecked}
<Checkbox.Group onChange={onChange1}
options={repairTypeList} indeterminate={indeterminateAll}
value={keepValue} >
onChange={onChange} 全选
/> </Checkbox>
<div style={{ display: 'inline-block', marginLeft: '10px' }}>
{repairTypeList.map((i, j) => (
<Checkbox
checked={i.checked}
onChange={e => onChangeAll(e, j)}
indeterminate={i.indeterminate}
>
{i.name}
</Checkbox>
))}
</div> </div>
</> </>
)} )}
...@@ -521,6 +664,7 @@ const ManagementDataBase = () => { ...@@ -521,6 +664,7 @@ const ManagementDataBase = () => {
}} }}
className={styles.mgTop20} className={styles.mgTop20}
columns={autoCheckColumns} columns={autoCheckColumns}
hideSelectAll
dataSource={autoCheckList} dataSource={autoCheckList}
bordered bordered
size="small" size="small"
...@@ -534,6 +678,7 @@ const ManagementDataBase = () => { ...@@ -534,6 +678,7 @@ const ManagementDataBase = () => {
showQuickJumper: true, showQuickJumper: true,
showSizeChanger: true, showSizeChanger: true,
}} }}
onChange={onChangeInput}
/> />
<div className={styles.btnBox}> <div className={styles.btnBox}>
<Space> <Space>
...@@ -541,8 +686,14 @@ const ManagementDataBase = () => { ...@@ -541,8 +686,14 @@ const ManagementDataBase = () => {
检查 检查
</Button> </Button>
<Popconfirm <Popconfirm
title=" title={
是否根据已选数据,升级当前连接数据库?" <span>
已选
<span style={{ color: 'rgb(24, 144, 255)' }}>{keepCheckList.length}</span>/
{autoCheckList.length}
条数据,是否根据已选数据,升级当前连接数据库?
</span>
}
okText="确认" okText="确认"
cancelText="取消" cancelText="取消"
onConfirm={() => { onConfirm={() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment