From af3c1f0993f073b1c069e27a961d64416cd2022a Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Fri, 16 Jun 2023 14:29:45 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=88*=EF=BC=89=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/backups/index.js | 2 +- api/app/lib/models/backups.js | 2 +- api/app/lib/routes/backups/index.js | 10 +- .../src/sections/backups/actions/backups.js | 56 +++++++++++ .../src/sections/backups/actions/index.js | 4 +- .../src/sections/backups/actions/member.js | 56 ----------- .../src/sections/backups/actions/task.js | 69 -------------- .../backups/components/backupsModal.js | 93 +++++++++++++++++++ .../backups/components/memberModal.js | 78 ---------------- .../backups/components/resetPassword.js | 61 ------------ .../sections/backups/containers/backupTask.js | 75 +++++++-------- .../sections/memberManagement/actions/task.js | 69 -------------- web/client/src/utils/webapi.js | 5 + 13 files changed, 195 insertions(+), 385 deletions(-) create mode 100644 web/client/src/sections/backups/actions/backups.js delete mode 100644 web/client/src/sections/backups/actions/member.js delete mode 100644 web/client/src/sections/backups/actions/task.js create mode 100644 web/client/src/sections/backups/components/backupsModal.js delete mode 100644 web/client/src/sections/backups/components/memberModal.js delete mode 100644 web/client/src/sections/backups/components/resetPassword.js delete mode 100644 web/client/src/sections/memberManagement/actions/task.js diff --git a/api/app/lib/controllers/backups/index.js b/api/app/lib/controllers/backups/index.js index 7370180..7198a6e 100644 --- a/api/app/lib/controllers/backups/index.js +++ b/api/app/lib/controllers/backups/index.js @@ -8,7 +8,7 @@ function getBackupsList(opts) { let errMsg = { message: '获取数据备份失败' } try { let searchWhere = { - username: { $not: 'SuperAdmin' } + } let option = { where: searchWhere, diff --git a/api/app/lib/models/backups.js b/api/app/lib/models/backups.js index a8de8a7..bd7b52a 100644 --- a/api/app/lib/models/backups.js +++ b/api/app/lib/models/backups.js @@ -62,7 +62,7 @@ module.exports = dc => { autoIncrement: false }, state: { - type: user - defined, + type: DataTypes.STRING, allowNull: true, defaultValue: null, comment: null, diff --git a/api/app/lib/routes/backups/index.js b/api/app/lib/routes/backups/index.js index 458fa37..a13b4e1 100644 --- a/api/app/lib/routes/backups/index.js +++ b/api/app/lib/routes/backups/index.js @@ -5,19 +5,19 @@ const backups = require('../../controllers/backups/index'); module.exports = function (app, router, opts, AuthCode) { app.fs.api.logAttr['POST/meta/backups'] = { content: '增加数据备份', visible: true }; - router.post('/meta/backups', backups.addUser(opts)) + router.post('/meta/backups', backups.addBackups(opts)) // 修改数据备份信息 app.fs.api.logAttr['PUT/meta/backups/:id'] = { content: '修改数据备份信息', visible: true }; - router.put('/meta/backups/:id', backups.editUser(opts)) + router.put('/meta/backups/:id', backups.editBackups(opts)) // 删除数据备份信息 app.fs.api.logAttr['DEL/meta/backups/:id'] = { content: '删除数据备份信息', visible: true }; - router.del('/meta/backups/:id', backups.deleteUser(opts)) + router.del('/meta/backups/:id', backups.deleteBackups(opts)) //获取数据备份信息列表 - app.fs.api.logAttr['GET/meta/backupss'] = { content: '获取数据备份信息列表', visible: true }; - router.get('/meta/backupss', backups.getUserList(opts)); + app.fs.api.logAttr['GET/meta/backups'] = { content: '获取数据备份信息列表', visible: true }; + router.get('/meta/backups', backups.getBackupsList(opts)); }; diff --git a/web/client/src/sections/backups/actions/backups.js b/web/client/src/sections/backups/actions/backups.js new file mode 100644 index 0000000..ad8fdbd --- /dev/null +++ b/web/client/src/sections/backups/actions/backups.js @@ -0,0 +1,56 @@ +'use strict'; + +import { basicAction } from '@peace/utils' +import { ApiTable } from '$utils' + +export function getBackupsList(query) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query || {}, + actionType: 'GET_BACKUPS_REPORT', + url: `${ApiTable.getBackupsList}`, + msg: { error: '获取数据备份列表失败' }, + reducer: { name: 'backups' } + }); +} + + +export function addBackups(params) { + return (dispatch) => basicAction({ + type: 'post', + data: params, + dispatch, + actionType: 'ADD_BACKUPS_REPORT', + url: ApiTable.addBackups, + msg: { + option: '数据备份新增', + }, + }); +} + +export function deleteBackups(id) { + return (dispatch) => basicAction({ + type: 'del', + dispatch, + actionType: 'DELETE_BACKUPS_REPORT', + url: ApiTable.modifyBackups.replace('{id}', id), + msg: { + option: '数据备份删除', + }, + }); +} + +export function modifyBackups(id, params, msg) { + return (dispatch) => basicAction({ + type: 'put', + data: params, + dispatch, + actionType: 'MODIFY_BACKUPS_REPORT', + url: ApiTable.modifyBackups.replace('{id}', id), + msg: { + option: msg || '数据备份编辑', + }, + }); +} + diff --git a/web/client/src/sections/backups/actions/index.js b/web/client/src/sections/backups/actions/index.js index 5abd7d2..8a7a73e 100644 --- a/web/client/src/sections/backups/actions/index.js +++ b/web/client/src/sections/backups/actions/index.js @@ -1,6 +1,6 @@ 'use strict'; -import * as member from './member'; +import * as backups from './backups'; export default { - ...member + ...backups } \ No newline at end of file diff --git a/web/client/src/sections/backups/actions/member.js b/web/client/src/sections/backups/actions/member.js deleted file mode 100644 index ec6ab27..0000000 --- a/web/client/src/sections/backups/actions/member.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -import { basicAction } from '@peace/utils' -import { ApiTable } from '$utils' - -export function getUserList(query) { - return dispatch => basicAction({ - type: 'get', - dispatch: dispatch, - query: query || {}, - actionType: 'GET_MEMBER_REPORT', - url: `${ApiTable.getUserList}`, - msg: { error: '获取用户列表失败' }, - reducer: { name: 'member' } - }); -} - - -export function addUser(params) { - return (dispatch) => basicAction({ - type: 'post', - data: params, - dispatch, - actionType: 'ADD_MEMBER_REPORT', - url: ApiTable.addUser, - msg: { - option: '用户新增', - }, - }); -} - -export function deleteUser(id) { - return (dispatch) => basicAction({ - type: 'del', - dispatch, - actionType: 'DELETE_MEMBER_REPORT', - url: ApiTable.modifyUser.replace('{id}', id), - msg: { - option: '用户删除', - }, - }); -} - -export function modifyUser(id, params, msg) { - return (dispatch) => basicAction({ - type: 'put', - data: params, - dispatch, - actionType: 'MODIFY_MEMBER_REPORT', - url: ApiTable.modifyUser.replace('{id}', id), - msg: { - option: msg || '用户编辑', - }, - }); -} - diff --git a/web/client/src/sections/backups/actions/task.js b/web/client/src/sections/backups/actions/task.js deleted file mode 100644 index 11d8ce3..0000000 --- a/web/client/src/sections/backups/actions/task.js +++ /dev/null @@ -1,69 +0,0 @@ -'use strict'; - -import { basicAction } from '@peace/utils' -import { ApiTable } from '$utils' - -export function addTask(params, msg) { - return (dispatch) => basicAction({ - type: 'post', - data: params, - dispatch, - actionType: 'ADD_ACQ_TASK', - url: ApiTable.addTask, - msg: { - option: msg || '新增采集任务', - }, - }); -} - -export function getTasks(query) { - return dispatch => basicAction({ - type: 'get', - dispatch: dispatch, - query: query || {}, - actionType: 'GET_ACQ_TASKS', - url: `${ApiTable.getTasks}`, - msg: { error: '获取采集任务列表失败' }, - reducer: { name: 'tasks' } - }); -} - -export function deleteTask(id) { - return (dispatch) => basicAction({ - type: 'del', - dispatch, - actionType: 'DELETE_ACQ_TASK', - url: ApiTable.modifyTask.replace('{id}', id), - msg: { - option: '采集任务删除', - }, - }); -} - -export function modifyTask(id, params, msg) { - return (dispatch) => basicAction({ - type: 'put', - data: params, - dispatch, - actionType: 'MODIFY_ACQ_TASK', - url: ApiTable.modifyTask.replace('{id}', id), - msg: { - option: msg || '采集任务编辑', - }, - }); -} - -export function runTask(params, msg) { - return (dispatch) => basicAction({ - type: 'post', - data: params, - dispatch, - actionType: 'RUN_ACQ_TASK', - url: ApiTable.runTask, - msg: { - option: msg || '任务执行', - }, - }); -} - - diff --git a/web/client/src/sections/backups/components/backupsModal.js b/web/client/src/sections/backups/components/backupsModal.js new file mode 100644 index 0000000..ce33fab --- /dev/null +++ b/web/client/src/sections/backups/components/backupsModal.js @@ -0,0 +1,93 @@ +import React, { useRef } from 'react'; +import { Button, Form } from 'antd'; +import { InfoCircleOutlined } from '@ant-design/icons'; +import { + ModalForm, + ProFormTreeSelect, + ProFormText, +} from '@ant-design/pro-form'; +import moment from 'moment'; +export default (props) => { + const { title, triggerRender, editData = null, onFinish, dataSources } = props; + const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 16 } }; + const initialValues = editData ? { + ...editData, + } : {}; + const [form] = Form.useForm(); + const formRef = useRef(); + return ( + + {title || ''} + + } + layout="horizontal" + grid={true} + {...formItemLayout} + modalProps={{ + destroyOnClose: true, + onCancel: () => { }, + }} + onFinish={async (values) => { + values.databases = dataSources?.rows?.find(s => s.id == values?.databases?.value)?.config; + values.createTime = moment(); + values.state = '备份中'; + return onFinish && await onFinish(values, editData, form) + // return true; + }} + width={500} + > + + + { + return [ + { + title: 'postgre', + disabled: true, + value: '0-0', + children: dataSources?.rows?.filter(s => s?.type != '备份数据库')?.map(s => { + return { + title: s.name, + value: s.id, + } + }) + }, + ]; + }} + rules={[{ required: true, message: '请选择数据源' }]} + // tree-select args + fieldProps={{ + showArrow: false, + filterTreeNode: true, + showSearch: true, + popupMatchSelectWidth: false, + labelInValue: true, + autoClearSearchValue: true, + multiple: false, + treeDefaultExpandAll: true, + treeNodeFilterProp: 'title', + fieldNames: { + label: 'title', + }, + }} + /> + + + ); +}; \ No newline at end of file diff --git a/web/client/src/sections/backups/components/memberModal.js b/web/client/src/sections/backups/components/memberModal.js deleted file mode 100644 index e2e7a26..0000000 --- a/web/client/src/sections/backups/components/memberModal.js +++ /dev/null @@ -1,78 +0,0 @@ -import React, { useRef } from 'react'; -import { Button, Form } from 'antd'; -import { InfoCircleOutlined } from '@ant-design/icons'; -import { - ModalForm, - ProFormSelect, - ProFormTextArea, - ProFormDigit, - ProFormText, - ProFormSwitch -} from '@ant-design/pro-form'; - -export default (props) => { - const { title, triggerRender, editData = null, onFinish, paramsName } = props; - const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 16 } }; - const initialValues = editData ? { - ...editData, - } : {}; - const [form] = Form.useForm(); - const formRef = useRef(); - return ( - - {title || ''} - - } - layout="horizontal" - grid={true} - {...formItemLayout} - modalProps={{ - destroyOnClose: true, - onCancel: () => { }, - }} - onFinish={async (values) => { - return onFinish && await onFinish(values, editData, form) - // return true; - }} - width={500} - > - - - - - - - - - ); -}; \ No newline at end of file diff --git a/web/client/src/sections/backups/components/resetPassword.js b/web/client/src/sections/backups/components/resetPassword.js deleted file mode 100644 index f633c36..0000000 --- a/web/client/src/sections/backups/components/resetPassword.js +++ /dev/null @@ -1,61 +0,0 @@ -import React, { useRef } from 'react'; -import { Button, Form } from 'antd'; -import { - ModalForm, - ProFormText, -} from '@ant-design/pro-form'; - -export default (props) => { - const { title, triggerRender, editData = null, onFinish } = props; - const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 16 } }; - const initialValues = {}; - const [form] = Form.useForm(); - const formRef = useRef(); - return ( - - {title || ''} - - } - layout="horizontal" - grid={true} - {...formItemLayout} - modalProps={{ - destroyOnClose: true, - onCancel: () => { }, - }} - onFinish={async (values) => { - return onFinish && await onFinish({ ...values, msg: '重置密码' }, editData, '重置密码') - }} - width={500} - > - - - - - - - ); -}; \ No newline at end of file diff --git a/web/client/src/sections/backups/containers/backupTask.js b/web/client/src/sections/backups/containers/backupTask.js index 9c901a4..14f6c82 100644 --- a/web/client/src/sections/backups/containers/backupTask.js +++ b/web/client/src/sections/backups/containers/backupTask.js @@ -3,12 +3,11 @@ import { Spin, Popconfirm, Select, Row, Col, Button, Input, Table } from 'antd'; import { connect } from 'react-redux'; import ProTable from '@ant-design/pro-table'; import moment from 'moment'; -import MemberModal from '../components/memberModal'; -import ResetPasswordModal from '../components/resetPassword'; -import { useFsRequest, ApiTable } from '$utils'; +import BackupsModal from '../components/backupsModal'; + import './style.less'; function Member(props) { - const { loading, clientHeight, actions, dispatch, member, user } = props; + const { loading, clientHeight, actions, dispatch, backups, user, dataSources } = props; const [pageSize, setPageSize] = useState(10); const [currentPage, setCurrentPage] = useState(1); const [searchValue, setSearchValue] = useState('') @@ -19,9 +18,12 @@ function Member(props) { name: searchValue, } - dispatch(actions.memberManagement.getUserList(query)); + dispatch(actions.backups.getBackupsList(query)); } + useEffect(() => { + dispatch(actions.metadataAcquisition.getDataSources()); + }, []) useEffect(() => { queryData(); @@ -44,13 +46,11 @@ function Member(props) { { title: '备份时间', dataIndex: 'createTime', + render: (text, record) => { return moment(record?.createTime).format('YYYY-MM-DD HH:mm:ss') } }, { title: '状态', dataIndex: 'state', - render: (text, record) => { - return ● {record?.enabled ? '正常' : '禁用'} - } }, { title: '操作', @@ -60,34 +60,35 @@ function Member(props) { render: (text, record) => { const options = []; + options.push(
是否确认删除该用户?
+ title={<>
是否确认重置该数据备份密码?
} - onConfirm={() => handleDelete(record.id)} + onConfirm={() => { + dispatch(actions.backups.modifyBackups(record.id, { password: 'e10adc3949ba59abbe56e057f20f883e' }, '重置密码')) + }} okText="是" cancelText="否" > - 删除 + 恢复
) - user?.username == 'SuperAdmin' && options.push( + options.push(下载) + + options.push(
是否确认重置该用户密码?
+ title={<>
是否确认删除该数据备份?
} - onConfirm={() => { - dispatch(actions.memberManagement.modifyUser(record.id, { password: 'e10adc3949ba59abbe56e057f20f883e' }, '重置密码')) - }} + onConfirm={() => handleDelete(record.id)} okText="是" cancelText="否" > - 重置密码 + 删除
) - - return options; }, @@ -95,27 +96,13 @@ function Member(props) { ]; const handleDelete = (id) => { - dispatch(actions.memberManagement.deleteUser(id)).then(() => { + dispatch(actions.backups.deleteBackups(id)).then(() => { queryData(); }); }; const onFinish = async (values, editData) => { - if (editData) { - const dataToSave = { ...values } - return dispatch( - actions.memberManagement.modifyUser(editData.id, dataToSave, values?.msg || ''), - ).then((res) => { - if (res.success) { - queryData(); - return true; - } else { - return false; - } - }); - } - - return dispatch(actions.memberManagement.addUser({ + return dispatch(actions.backups.addBackups({ ...values, })).then(res => { if (res.success) { @@ -130,9 +117,10 @@ function Member(props) { return - 新建} - title="新建用户" + title="新建数据备份" onFinish={onFinish} key="addModel" /> @@ -161,7 +149,7 @@ function Member(props) { } pagination={{ size: 'large', - total: member?.count, + total: backups?.count, showSizeChanger: true, showQuickJumper: true, current: currentPage, @@ -182,7 +170,7 @@ function Member(props) { } }} - dataSource={member?.rows || []} + dataSource={backups?.rows || []} options={false} /> @@ -191,14 +179,15 @@ function Member(props) { function mapStateToProps(state) { const { - auth, global, datasources, member + auth, global, datasources, backups } = state; return { - loading: datasources.isRequesting, + loading: backups.isRequesting || datasources.isRequesting, clientHeight: global.clientHeight, actions: global.actions, - member: member?.data || {}, - user: auth.user + backups: backups?.data || {}, + user: auth.user, + dataSources: datasources?.data || {}, }; } diff --git a/web/client/src/sections/memberManagement/actions/task.js b/web/client/src/sections/memberManagement/actions/task.js deleted file mode 100644 index 11d8ce3..0000000 --- a/web/client/src/sections/memberManagement/actions/task.js +++ /dev/null @@ -1,69 +0,0 @@ -'use strict'; - -import { basicAction } from '@peace/utils' -import { ApiTable } from '$utils' - -export function addTask(params, msg) { - return (dispatch) => basicAction({ - type: 'post', - data: params, - dispatch, - actionType: 'ADD_ACQ_TASK', - url: ApiTable.addTask, - msg: { - option: msg || '新增采集任务', - }, - }); -} - -export function getTasks(query) { - return dispatch => basicAction({ - type: 'get', - dispatch: dispatch, - query: query || {}, - actionType: 'GET_ACQ_TASKS', - url: `${ApiTable.getTasks}`, - msg: { error: '获取采集任务列表失败' }, - reducer: { name: 'tasks' } - }); -} - -export function deleteTask(id) { - return (dispatch) => basicAction({ - type: 'del', - dispatch, - actionType: 'DELETE_ACQ_TASK', - url: ApiTable.modifyTask.replace('{id}', id), - msg: { - option: '采集任务删除', - }, - }); -} - -export function modifyTask(id, params, msg) { - return (dispatch) => basicAction({ - type: 'put', - data: params, - dispatch, - actionType: 'MODIFY_ACQ_TASK', - url: ApiTable.modifyTask.replace('{id}', id), - msg: { - option: msg || '采集任务编辑', - }, - }); -} - -export function runTask(params, msg) { - return (dispatch) => basicAction({ - type: 'post', - data: params, - dispatch, - actionType: 'RUN_ACQ_TASK', - url: ApiTable.runTask, - msg: { - option: msg || '任务执行', - }, - }); -} - - diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index bfee838..ab25d42 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -84,6 +84,11 @@ export const ApiTable = { //元数据检索 searchMetadata: "meta/data/search", + + //备份恢复 + getBackupsList: 'meta/backups', + addBackups: 'meta/backups', + modifyBackups: 'meta/backups/{id}', }; export const RouteTable = {