From fc233c38ea886ce22360c3515c7c0af613191345 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 10 Apr 2025 21:07:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=BD=91=E5=85=83?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=A4=87=E4=BB=BD=E7=9A=84?= =?UTF-8?q?FTP=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ne/neConfigBackup.ts | 44 ++++- src/views/ne/neConfigBackup/index.vue | 251 ++++++++++++++++++++++++-- 2 files changed, 279 insertions(+), 16 deletions(-) diff --git a/src/api/ne/neConfigBackup.ts b/src/api/ne/neConfigBackup.ts index 56e12ec0..e6b8c817 100644 --- a/src/api/ne/neConfigBackup.ts +++ b/src/api/ne/neConfigBackup.ts @@ -1,4 +1,6 @@ +import { CACHE_SESSION_CRYPTO_API } from '@/constants/cache-keys-constants'; import { request } from '@/plugins/http-fetch'; +import { sessionGet } from '@/utils/cache-session-utils'; /** * 网元配置文件备份记录列表 @@ -80,4 +82,44 @@ export function importNeConfigBackup(data: Record) { method: 'POST', data: data, }); -} \ No newline at end of file +} + +/** + * 更新FTP信息 + * @param data 数据 + * @returns object + */ +export function updateFTPInfo(data: Record) { + return request({ + url: `/ne/config/backup/ftp`, + method: 'POST', + data: data, + crypto: sessionGet(CACHE_SESSION_CRYPTO_API) !== 'false', + }); +} + +/** + * 获取FTP信息 + * @param data 数据 + * @returns object + */ +export function getFTPInfo() { + return request({ + url: `/ne/config/backup/ftp`, + method: 'GET', + crypto: sessionGet(CACHE_SESSION_CRYPTO_API) !== 'false', + }); +} + +/** + * 发送FTP文件 + * @param data 数据 + * @returns object + */ +export function putFTPInfo(path: string) { + return request({ + url: `/ne/config/backup/ftp`, + method: 'PUT', + data: { path }, + }); +} diff --git a/src/views/ne/neConfigBackup/index.vue b/src/views/ne/neConfigBackup/index.vue index 66cd6865..3cd1e855 100644 --- a/src/views/ne/neConfigBackup/index.vue +++ b/src/views/ne/neConfigBackup/index.vue @@ -11,11 +11,15 @@ import useDictStore from '@/store/modules/dict'; import { NE_TYPE_LIST } from '@/constants/ne-constants'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { parseDateToStr } from '@/utils/date-utils'; +import { regExpIPv4 } from '@/utils/regular-utils'; import { delNeConfigBackup, downNeConfigBackup, listNeConfigBackup, updateNeConfigBackup, + getFTPInfo, + putFTPInfo, + updateFTPInfo, } from '@/api/ne/neConfigBackup'; import saveAs from 'file-saver'; const { t } = useI18n(); @@ -58,8 +62,6 @@ type TabeStateType = { loading: boolean; /**紧凑型 */ size: SizeType; - /**搜索栏 */ - seached: boolean; /**记录数据 */ data: any[]; /**勾选记录 */ @@ -70,7 +72,6 @@ type TabeStateType = { let tableState: TabeStateType = reactive({ loading: false, size: 'middle', - seached: false, data: [], selectedRowKeys: [], }); @@ -98,12 +99,12 @@ let tableColumns = ref([ { title: t('common.createTime'), dataIndex: 'createTime', - align: 'center', + align: 'left', customRender(opt) { if (!opt.value) return ''; return parseDateToStr(opt.value); }, - width: 150, + width: 200, }, { title: t('views.ne.neConfigBackup.name'), @@ -179,7 +180,7 @@ function fnGetList(pageNum?: number) { queryParams.pageNum = pageNum; } listNeConfigBackup(toRaw(queryParams)).then(res => { - if (res.code === RESULT_CODE_SUCCESS) { + if (res.code === RESULT_CODE_SUCCESS) { const { total, rows } = res.data; tablePagination.total = total; tableState.data = rows; @@ -387,12 +388,125 @@ onMounted(() => { fnGetList(); }); }); + +/**FTP日志对象信息状态 */ +let modalStateFTP: ModalStateType = reactive({ + openByEdit: false, + title: '设置远程备份配置', + from: { + username: '', + password: '', + toIp: '', + toPort: 22, + enable: false, + dir: '', + }, + confirmLoading: false, +}); + +/**FTP日志对象信息内表单属性和校验规则 */ +const modalStateFTPFrom = Form.useForm( + modalStateFTP.from, + reactive({ + toIp: [ + { + required: true, + pattern: regExpIPv4, + message: 'Please enter the service login IP', + }, + ], + username: [ + { + required: true, + trigger: 'blur', + message: 'Please enter the service login user name', + }, + ], + dir: [ + { + required: true, + trigger: 'blur', + message: 'Please enter the service address target file directory', + }, + ], + }) +); + +/** + * 对话框弹出显示为 新增或者修改 + * @param configId 参数编号id, 不传为新增 + */ +function fnModalFTPVisibleByEdit() { + if (modalStateFTP.confirmLoading) return; + const hide = message.loading(t('common.loading'), 0); + modalStateFTP.confirmLoading = true; + getFTPInfo().then(res => { + modalStateFTP.confirmLoading = false; + hide(); + if (res.code === RESULT_CODE_SUCCESS && res.data) { + modalStateFTP.from = Object.assign(modalStateFTP.from, res.data); + modalStateFTP.title = 'Setting Remote Backup'; + modalStateFTP.openByEdit = true; + } else { + message.error(res.msg, 3); + modalStateFTP.title = 'Setting Remote Backup'; + modalStateFTP.openByEdit = false; + } + }); +} + +/**FTP对象保存 */ +function fnModalFTPOk() { + modalStateFTPFrom.validate().then(() => { + modalStateFTP.confirmLoading = true; + const from = toRaw(modalStateFTP.from); + updateFTPInfo(from) + .then(res => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success(`Configuration saved successfully`, 3); + fnModalFTPCancel(); + } else { + message.warning(`Configuration save exception`, 3); + } + }) + .finally(() => { + modalStateFTP.confirmLoading = false; + }); + }); +} + +/** + * 对话框弹出关闭执行函数 + * 进行表达规则校验 + */ +function fnModalFTPCancel() { + modalStateFTP.openByEdit = false; + modalStateFTPFrom.resetFields(); +} + +/** + * 同步文件到FTP + * @param row + */ +function fnSyncFileToFTP(row: Record) { + modalStateFTP.confirmLoading = true; + putFTPInfo(row.path) + .then(res => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success(t('common.operateOk'), 3); + } else { + message.warning(res.msg, 3); + } + }) + .finally(() => { + modalStateFTP.confirmLoading = false; + }); +}