Commit 65fff149 authored by 皮倩雯's avatar 皮倩雯

fix: '数据库初始化'

parent b957ac42
Pipeline #55692 waiting for manual action with stages
......@@ -39,6 +39,7 @@ import {
InitEditDataBase, // 二次初始化
} from '@/services/database/api';
import styles from './InitDataBase.less';
import InitModal from './initModal';
const { TabPane } = Tabs;
const { Option } = Select;
......@@ -77,7 +78,13 @@ const InitDataBase = props => {
const [initLoading, setInitLoading] = useState(false);
const [initList, setInitList] = useState([]); // 数据库初始化产品数据
const [dbExists, setDbExists] = useState(false); // 数据库是否存在
const [visibleModel, setVisibleModel] = useState(false);
const [keepDb, setKeepDb] = useState([]);
const [keepProduct, setKeepProduct] = useState([]);
const scroll = useRef(null);
const [keep, setKeep] = useState([]);
const [flag, setFlag] = useState(0);
const [keepData, setKeepData] = useState({});
// 获取数据库配置信息
useEffect(() => {
......@@ -223,6 +230,13 @@ const InitDataBase = props => {
.then(resnew => {
setCardLoading(false);
if (resnew.code === 0) {
setFlag(flag + 1);
setKeepData({
ip: obj.ip,
dbName: obj.dbName,
userName: obj.userName,
password: obj.password,
});
// setUpData(upData + 1);
getConnRecordData();
notification.success({
......@@ -413,6 +427,44 @@ const InitDataBase = props => {
console.error(err);
});
};
const GetDb = () => {
let obj = form.getFieldsValue();
GetDbProduct({ ...obj }).then(res => {
if (res.code === 0) {
console.log(res.data);
if (res.data.Product) {
console.log(res.data.Product);
let aa = [];
res.data.Product.map(i => {
aa.push(i.name);
});
console.log(aa);
setKeep(res.data.Product);
setKeepProduct(aa);
}
setDbExists(res.data.DBExists);
setKeepDb(res.data);
if (!res.data.DBExists) {
setVisibleModel(true);
} else if (res.data.DBExists && res.data.Product.length > 0) {
setVisibleModel(true);
} else {
notification.warning({
message: '提示',
duration: 15,
description: '当前数据库不可初始化',
});
}
} else {
notification.warning({
message: '提示',
duration: 15,
description: res.msg,
});
}
});
};
// 获取数据库初始化回显列表
const getInitList = () => {
setInitList([]);
......@@ -553,17 +605,21 @@ const InitDataBase = props => {
return list;
});
};
const onOK = (arr, code) => {
initDatabasePro(arr, code);
};
// 数据库初始化
const initDatabasePro = () => {
let productSetting = initList;
const initDatabasePro = (e, j) => {
let productSetting = e;
let obj = form.getFieldsValue();
// 数据库存在调用编辑接口否则调用新增接口
setInitLoading(true);
setVisibleModel(false);
handleShowModal('initVisible', false);
setInitVisible(true);
doInitLog();
if (dbExists) {
InitEditDataBase({ ...obj, productSetting }).then(res => {
InitEditDataBase({ ...obj, productSetting, license: j }).then(res => {
setInitLoading(false);
if (res.code === 0) {
notification.success({
......@@ -574,14 +630,14 @@ const InitDataBase = props => {
} else {
notification.error({
message: '提示',
duration: 15,
duration: 5,
description: res.msg,
});
}
});
return;
}
InitAddDataBase({ ...obj, productSetting }).then(res => {
InitAddDataBase({ ...obj, productSetting, license: j }).then(res => {
setInitLoading(false);
if (res.code === 0) {
notification.success({
......@@ -592,7 +648,7 @@ const InitDataBase = props => {
} else {
notification.error({
message: '提示',
duration: 15,
duration: 5,
description: res.msg,
});
}
......@@ -668,6 +724,27 @@ const InitDataBase = props => {
),
},
];
const flagChange = () => {
const obj = form.getFieldsValue();
console.log(keepData);
console.log(obj);
if (
keepData.ip == obj.ip &&
keepData.dbName == obj.dbName &&
keepData.userName == obj.userName &&
keepData.password == obj.password
) {
GetDb();
deleteInitDBLogNew();
} else {
notification.warning({
message: '提示',
duration: 15,
description: '请先保存连接',
});
}
};
return (
<>
<PageContainer className={styles.InitDataBaseContainer}>
......@@ -683,16 +760,73 @@ const InitDataBase = props => {
onFinish={onFinish}
onValuesChange={onValuesChange}
>
<Form.Item label={`${formLables.ip}:`} name="ip">
<Form.Item
label={`${formLables.ip}:`}
name="ip"
rules={[
{
validator: (rule, value) => {
if (form.getFieldValue().ip == '') {
return Promise.reject('ip必填');
}
return Promise.resolve();
},
},
]}
>
<Input placeholder="请输入服务器名或IP地址" />
</Form.Item>
<Form.Item label={`${formLables.userName}:`} name="userName">
<Form.Item
label={`${formLables.userName}:`}
name="userName"
rules={[
{
validator: (rule, value) => {
if (form.getFieldValue().userName == '') {
return Promise.reject('用户名称必填');
}
return Promise.resolve();
},
},
]}
>
<Input placeholder="请输入用户名称" />
</Form.Item>
<Form.Item label={`${formLables.password}:`} name="password">
<Form.Item
label={`${formLables.password}:`}
name="password"
rules={[
{
validator: (rule, value) => {
console.log(form.getFieldValue().password);
if (form.getFieldValue().password == '') {
return Promise.reject('用户密码必填');
}
return Promise.resolve();
},
},
]}
>
<Input placeholder="请输入用户密码" type="password" />
</Form.Item>
<Form.Item label={`${formLables.dbName}:`} name="dbName">
<Form.Item
label={`${formLables.dbName}:`}
name="dbName"
rules={[
{
validator: (rule, value) => {
console.log(form.getFieldValue().dbName);
if (
form.getFieldValue().dbName == '' ||
form.getFieldValue().dbName == undefined
) {
return Promise.reject('数据库名称必填');
}
return Promise.resolve();
},
},
]}
>
<Select
showSearch
mode="tags"
......@@ -734,9 +868,12 @@ const InitDataBase = props => {
<Space>
<Button
type="primary"
// onClick={() => {
// getInitList();
// deleteInitDBLogNew();
// }}
onClick={() => {
getInitList();
deleteInitDBLogNew();
flagChange();
}}
>
数据库初始化
......@@ -763,6 +900,7 @@ const InitDataBase = props => {
onRow={record => ({
onClick: () => {
tableClick(record);
setFlag(0);
}, // 点击行
})}
/>
......@@ -845,6 +983,14 @@ const InitDataBase = props => {
</Col>
</Row>
</Modal>
<InitModal
visible={visibleModel}
onCancel={() => setVisibleModel(false)}
keepDb={keepDb}
callBackSubmit={onOK}
keepProduct={keepProduct}
keep={keep}
/>
{/* 初始化选择产品弹窗 */}
<Modal
title="初始化"
......
......@@ -18,13 +18,12 @@
.ant-modal-header {
height: 70px;
}
InitDataBaseContainer{
InitDataBaseContainer {
.ant-card-body {
padding-bottom: 0px !important;
}
}
.cardContainer {
margin-top: 10px;
border: 1px solid #ecf0fa;
......@@ -47,5 +46,15 @@ InitDataBaseContainer{
padding-left: 20px;
box-sizing: border-box;
}
}
.initItemData {
.ant-checkbox-wrapper {
width: 300px;
margin-bottom: 10px;
margin-left: 8px;
}
.view:hover {
cursor: not-allowed;
}
}
This diff is collapsed.
......@@ -191,6 +191,12 @@ export const GetUserAuthSet = params => get(`${PUBLISH_SERVICE}/WebSite/GetUserA
// 获取产品列表
export const GetProductList = params => get(`${PUBLISH_SERVICE}/DBManager/GetProductList`, params);
// 获取产品列表清单
export const GetProductListByLicense = params =>
get(`${PUBLISH_SERVICE}/DBManager/GetProductListByLicense`, params);
// 判断License是否已使用
export const GetLicenseStatus = params =>
get(`${PUBLISH_SERVICE}/DBManager/GetLicenseStatus`, params);
// 获取产品方案配置
export const GetDbProduct = params => post(`${PUBLISH_SERVICE}/DBManager/GetDbProduct`, params);
// 数据库初始化
......
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