|
|
@ -1,4 +1,4 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import React, { useEffect, useState, useMemo } from 'react' |
|
|
|
import { Spin, Popconfirm, Select, Row, Col, Button, Input, Table } from 'antd'; |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import ProTable from '@ant-design/pro-table'; |
|
|
@ -6,12 +6,15 @@ import moment from 'moment'; |
|
|
|
import BackupsModal from '../components/backupsModal'; |
|
|
|
|
|
|
|
import './style.less'; |
|
|
|
import { ApiTable, useFsRequest } from '$utils'; |
|
|
|
|
|
|
|
function Member(props) { |
|
|
|
const { loading, clientHeight, actions, dispatch, backups, user, dataSources } = props; |
|
|
|
const { loading, clientHeight, actions, dispatch, backups, backupsIsRequesting, dataSources } = props; |
|
|
|
const [pageSize, setPageSize] = useState(10); |
|
|
|
const [currentPage, setCurrentPage] = useState(1); |
|
|
|
const [searchValue, setSearchValue] = useState(''); |
|
|
|
const [addLoading, setAddLoading] = useState(false) |
|
|
|
const [autoSearchValue, setAutoSearchValue] = useState(''); |
|
|
|
const queryData = (search) => { |
|
|
|
const query = { |
|
|
|
limit: search ? 10 : pageSize || 10, |
|
|
@ -22,6 +25,18 @@ function Member(props) { |
|
|
|
dispatch(actions.backups.getBackupsList(query)); |
|
|
|
} |
|
|
|
|
|
|
|
const { data: tableData = {} } = useFsRequest({ |
|
|
|
url: ApiTable.getBackupsList, |
|
|
|
query: { |
|
|
|
limit: pageSize || 10, |
|
|
|
page: currentPage || 1, |
|
|
|
name: autoSearchValue, |
|
|
|
}, |
|
|
|
ready: !backupsIsRequesting, |
|
|
|
refreshDeps: [pageSize, currentPage, autoSearchValue], |
|
|
|
pollingInterval: 1000 |
|
|
|
}); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
dispatch(actions.metadataAcquisition.getDataSources()); |
|
|
|
}, []) |
|
|
@ -66,20 +81,17 @@ function Member(props) { |
|
|
|
render: (text, record) => { |
|
|
|
const options = []; |
|
|
|
options.push( |
|
|
|
<Popconfirm |
|
|
|
key="del" |
|
|
|
placement="top" |
|
|
|
title={<><div>是否确认重置该数据备份密码?</div> |
|
|
|
</>} |
|
|
|
onConfirm={() => { |
|
|
|
dispatch(actions.backups.modifyBackups(record.id, { password: 'e10adc3949ba59abbe56e057f20f883e' }, '重置密码')) |
|
|
|
}} |
|
|
|
okText="是" |
|
|
|
cancelText="否" |
|
|
|
> |
|
|
|
<a>恢复</a> |
|
|
|
</Popconfirm>) |
|
|
|
options.push(<a onClick={() => { window.open('/assets/files/backups/1.sql') }}>下载</a>) |
|
|
|
record?.source ? <BackupsModal |
|
|
|
dataSources={dataSources} |
|
|
|
triggerRender={<a type='primary'>恢复</a>} |
|
|
|
title="恢复数据备份" |
|
|
|
onFinish={onFinish} |
|
|
|
key="addModel" |
|
|
|
/> : <a style={{ color: 'gray' }}>恢复</a>) |
|
|
|
options.push( |
|
|
|
record?.source ? |
|
|
|
<a a onClick={() => { window.open(record?.source) }}> 下载</a> : <a style={{ color: 'gray' }}>下载</a> |
|
|
|
) |
|
|
|
|
|
|
|
options.push( |
|
|
|
<Popconfirm |
|
|
@ -106,20 +118,46 @@ function Member(props) { |
|
|
|
}; |
|
|
|
|
|
|
|
const onFinish = async (values, editData) => { |
|
|
|
setAddLoading(true) |
|
|
|
return dispatch(actions.backups.addBackups({ |
|
|
|
...values, |
|
|
|
})).then(res => { |
|
|
|
setAddLoading(false) |
|
|
|
if (res.success) { |
|
|
|
queryData(); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}); |
|
|
|
if (values?.title == '恢复数据备份') { |
|
|
|
return dispatch(actions.backups.restoreBackups({ |
|
|
|
id: editData.id, |
|
|
|
source: editData.source, |
|
|
|
databases: values.databases |
|
|
|
})).then(res => { |
|
|
|
setAddLoading(false) |
|
|
|
if (res.success) { |
|
|
|
queryData(); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
setAddLoading(true) |
|
|
|
return dispatch(actions.backups.addBackups({ |
|
|
|
...values, |
|
|
|
})).then(res => { |
|
|
|
setAddLoading(false) |
|
|
|
if (res.success) { |
|
|
|
queryData(); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const tableDataFilter = useMemo(() => { |
|
|
|
if (tableData?.count && backups?.count) { |
|
|
|
return tableData.time > backups.time ? tableData : backups; |
|
|
|
} else { |
|
|
|
return backups; |
|
|
|
} |
|
|
|
}, [tableData, backups]) |
|
|
|
|
|
|
|
return <Spin spinning={loading || addLoading}> |
|
|
|
<Row className='protable-title'> |
|
|
|
<Col span={12}> |
|
|
@ -137,10 +175,12 @@ function Member(props) { |
|
|
|
style={{ width: 220, marginRight: 15 }} placeholder="请输入" /> |
|
|
|
|
|
|
|
<Button onClick={() => { |
|
|
|
setAutoSearchValue(searchValue) |
|
|
|
setCurrentPage(1) |
|
|
|
setPageSize(10) |
|
|
|
queryData(true) |
|
|
|
}} type='primary'>查询</Button></Col> |
|
|
|
}} type='primary'>查询</Button> |
|
|
|
</Col> |
|
|
|
|
|
|
|
</Row> |
|
|
|
<ProTable |
|
|
@ -155,7 +195,7 @@ function Member(props) { |
|
|
|
} |
|
|
|
pagination={{ |
|
|
|
size: 'large', |
|
|
|
total: backups?.count, |
|
|
|
total: tableDataFilter?.count, |
|
|
|
showSizeChanger: true, |
|
|
|
showQuickJumper: true, |
|
|
|
current: currentPage, |
|
|
@ -176,7 +216,7 @@ function Member(props) { |
|
|
|
|
|
|
|
} |
|
|
|
}} |
|
|
|
dataSource={backups?.rows || []} |
|
|
|
dataSource={tableDataFilter?.rows || []} |
|
|
|
options={false} |
|
|
|
/> |
|
|
|
</Spin> |
|
|
@ -194,6 +234,7 @@ function mapStateToProps(state) { |
|
|
|
backups: backups?.data || {}, |
|
|
|
user: auth.user, |
|
|
|
dataSources: datasources?.data || {}, |
|
|
|
backupsIsRequesting: backups.isRequesting |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|