增加备份和导出功能

This commit is contained in:
dushixiang
2021-11-15 14:21:46 +08:00
parent 52309870d8
commit 1d232f7269
14 changed files with 472 additions and 134 deletions

View File

@ -32,7 +32,7 @@ class Setting extends Component {
vncSettingFormRef = React.createRef();
guacdSettingFormRef = React.createRef();
mailSettingFormRef = React.createRef();
otherSettingFormRef = React.createRef();
logSettingFormRef = React.createRef();
componentDidMount() {
this.getProperties();
@ -94,8 +94,8 @@ class Setting extends Component {
this.mailSettingFormRef.current.setFieldsValue(properties)
}
if (this.otherSettingFormRef.current) {
this.otherSettingFormRef.current.setFieldsValue(properties)
if (this.logSettingFormRef.current) {
this.logSettingFormRef.current.setFieldsValue(properties)
}
} else {
message.error(result['message']);
@ -106,6 +106,35 @@ class Setting extends Component {
this.getProperties()
}
handleImport = () => {
let files = window.document.getElementById('file-upload').files;
if (files.length === 0) {
return;
}
const reader = new FileReader();
reader.onload = async () => {
let backup = JSON.parse(reader.result.toString());
this.setState({
importBtnLoading: true
})
try {
let result = await request.post('/backup/import', backup);
if (result['code'] === 1) {
message.success('恢复成功', 3);
} else {
message.error(result['message'], 10);
}
} finally {
this.setState({
importBtnLoading: false
})
window.document.getElementById('file-upload').value = "";
}
};
reader.readAsText(files[0]);
}
render() {
return (
<>
@ -419,7 +448,7 @@ class Setting extends Component {
},
]}
>
<Switch checkedChildren="开启" unCheckedChildren="关闭" onChange={(checked, event) => {
<Switch checkedChildren="开启" unCheckedChildren="关闭" onChange={(checked) => {
this.setState({
properties: {
...this.state.properties,
@ -528,9 +557,9 @@ class Setting extends Component {
</Form>
</TabPane>
<TabPane tab="其他配置" key="other">
<TabPane tab="日志配置" key="log">
<Title level={3}>其他配置</Title>
<Form ref={this.otherSettingFormRef} name="other" onFinish={this.changeProperties}
<Form ref={this.logSettingFormRef} name="log" onFinish={this.changeProperties}
layout="vertical">
<Form.Item
@ -587,9 +616,13 @@ class Setting extends Component {
导出备份
</Button>
<Button type="dashed">
<Button type="dashed" loading={this.state['importBtnLoading']} onClick={() => {
window.document.getElementById('file-upload').click();
}}>
恢复备份
</Button>
<input type="file" id="file-upload" style={{display: 'none'}}
onChange={this.handleImport}/>
</Space>
</Space>

View File

@ -95,14 +95,9 @@ class User extends Component {
} else {
message.error(result.message, 10);
}
} catch (e) {
} finally {
const items = data.items.map(item => {
return {'key': item['id'], ...item}
})
this.setState({
items: items,
items: data.items,
total: data.total,
queryParams: queryParams,
loading: false
@ -145,7 +140,7 @@ class User extends Component {
});
};
handleCancelModal = e => {
handleCancelModal = () => {
this.setState({
modalVisible: false,
modalTitle: ''
@ -245,13 +240,6 @@ class User extends Component {
}
}
handleAssetCancel = () => {
this.loadTableData()
this.setState({
assetVisible: false
})
}
handleChangePassword = async (values) => {
this.setState({
changePasswordConfirmLoading: true
@ -362,7 +350,7 @@ class User extends Component {
dataIndex: 'username',
key: 'username',
sorter: true,
render: (username, record, index) => {
render: (username, record) => {
return (
<Button type="link" size='small'
onClick={async () => {
@ -384,7 +372,7 @@ class User extends Component {
title: '用户类型',
dataIndex: 'type',
key: 'type',
render: (text, record) => {
render: (text) => {
if (text === 'user') {
return (
@ -419,7 +407,7 @@ class User extends Component {
title: '双因素认证',
dataIndex: 'totpSecret',
key: 'totpSecret',
render: (text, record) => {
render: (text) => {
if (text === '1') {
return <Tag icon={<InsuranceOutlined/>} color="success">已开启</Tag>;
@ -442,7 +430,7 @@ class User extends Component {
title: '授权资产',
dataIndex: 'sharerAssetCount',
key: 'sharerAssetCount',
render: (text, record, index) => {
render: (text, record) => {
return <Button type='link' onClick={async () => {
this.setState({
assetVisible: true,
@ -454,7 +442,7 @@ class User extends Component {
title: '创建日期',
dataIndex: 'created',
key: 'created',
render: (text, record) => {
render: (text) => {
return (
<Tooltip title={text}>
{dayjs(text).fromNow()}
@ -519,6 +507,7 @@ class User extends Component {
return (
<div>
<Button type="link" size='small'
disabled={getCurrentUser()['id'] === record['id']}
onClick={async () => {
let result = await request.get(`/users/${record['id']}`);
if (result['code'] !== 1) {
@ -541,7 +530,7 @@ class User extends Component {
const selectedRowKeys = this.state.selectedRowKeys;
const rowSelection = {
selectedRowKeys: this.state.selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => {
onChange: (selectedRowKeys) => {
this.setState({selectedRowKeys});
},
};
@ -699,9 +688,6 @@ class User extends Component {
.then(values => {
this.changePasswordFormRef.current.resetFields();
this.handleChangePassword(values);
})
.catch(info => {
});
}}
onCancel={() => {