diff --git a/src/api/configManage/neManage.ts b/src/api/configManage/neManage.ts index 9e80709f..7e84d25e 100644 --- a/src/api/configManage/neManage.ts +++ b/src/api/configManage/neManage.ts @@ -157,6 +157,70 @@ export function exportSet(data: Record) { }); } +/** + * 导入网元配置文件 + * @param data 网元对象 + * @returns object + */ +export function importFile(data: Record) { + let dataType: 'json' | 'form-data' = 'json'; + let url = `/systemManagement/v1/elementType/${data.neType}/objectType/cm?ne_id=${data.neId}`; + let obj: any = { fileName: data.fileName }; + if (data.importType === 'local') { + let formData = new FormData(); + formData.append('nfType', data.neType); + formData.append('nfId', data.neId); + formData.append('file', data.file); + obj = formData; + dataType = 'form-data'; + } + + // 处理FormData类型的data + return request({ + url, + method: 'post', + data: obj, + dataType, + }); + if (data instanceof FormData) { + // 处理FormData类型的data + return request({ + url: `/systemManagement/v1/elementType/${data.get( + 'nfType' + )}/objectType/cm?ne_id=${data.get('nfId')}`, + method: 'post', + data, + dataType: 'form-data', + }); + } else { + // 处理普通对象类型的data + return request({ + url: `/systemManagement/v1/elementType/${data.nfType}/objectType/cm?ne_id=${data.nfId}`, + method: 'post', + data: { fileName: data.fileName }, + }); + } +} + +/** + * 查询远程服务器上网元配置文件 + * @param data 网元对象 + * @returns object + */ +export async function listServerFile(data: Record) { + const result = await request({ + url: `databaseManagement/v1/omc_db/ne_backup?SQL= select * from ne_backup where ne_type ='${data.neType}'`, + method: 'get', + }); + // 解析数据 + if (result.code === RESULT_CODE_SUCCESS && Array.isArray(result.data.data)) { + let data = result.data.data[0]; + return Object.assign(result, { + data: parseObjLineToHump(data['ne_backup']), + }); + } + return result; +} /** * 启动网元 @@ -192,4 +256,4 @@ export function stopNf(data: Record) { url: `/systemManagement/v1/elementType/${data.neType}/objectType/service/stop?ne_id=${data.neId}`, method: 'post', }); -} \ No newline at end of file +} diff --git a/src/views/configManage/neManage/index.vue b/src/views/configManage/neManage/index.vue index a463db14..3c9b8c49 100644 --- a/src/views/configManage/neManage/index.vue +++ b/src/views/configManage/neManage/index.vue @@ -16,9 +16,13 @@ import { startNf, restartNf, stopNf, + importFile, + listServerFile, } from '@/api/configManage/neManage'; import { parseDateToStr } from '@/utils/date-utils'; import useI18n from '@/hooks/useI18n'; +import { FileType } from 'ant-design-vue/lib/upload/interface'; +import { UploadRequestOption } from 'ant-design-vue/lib/vc-upload/interface'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; const { t } = useI18n(); const route = useRoute(); @@ -26,6 +30,15 @@ const route = useRoute(); /**路由标题 */ let title = ref((route.meta.title as string) ?? '标题'); +/**表格所需option */ +const neManageOption = reactive({ + importType: [ + { label: t('views.configManage.neManage.server'), value: 'server' }, + { label: t('views.configManage.neManage.local'), value: 'local' }, + ], + serverFileName: [], +}); + /**查询参数 */ let queryParams = reactive({ /**网元类型 */ @@ -183,10 +196,14 @@ type ModalStateType = { visibleByView: boolean; /**新增框或修改框是否显示 */ visibleByEdit: boolean; + /**导入是否显示 */ + visibleByImport: boolean; /**标题 */ title: string; /**表单数据 */ from: Record; + /**导入表单数据 */ + importFrom: Record; /**确定按钮 loading */ confirmLoading: boolean; }; @@ -195,6 +212,7 @@ type ModalStateType = { let modalState: ModalStateType = reactive({ visibleByView: false, visibleByEdit: false, + visibleByImport: false, title: '网元', from: { dn: '', @@ -209,6 +227,14 @@ let modalState: ModalStateType = reactive({ rmUid: '', vendorName: '', }, + importFrom: { + neId: '', + neType: '', + importType: '', + file: undefined, + fileList: [], + fileName: '', + }, confirmLoading: false, }); @@ -226,6 +252,31 @@ const modalStateFrom = Form.useForm( }) ); +/**导入对话框内表单属性和校验规则 */ +const importStateFrom = Form.useForm( + modalState.importFrom, + reactive({ + file: [ + { + required: true, + message: t('views.configManage.softwareManage.updateFilePlease'), + }, + ], + importType: [ + { + required: true, + message: t('views.configManage.neManage.selectPlease'), + }, + ], + fileName: [ + { + required: true, + message: t('views.configManage.neManage.fileSelect'), + }, + ], + }) +); + /** * 对话框弹出显示为 新增或者修改 * @param noticeId 网元id, 不传为新增 @@ -292,6 +343,72 @@ function fnModalOk() { }); } +/** + * 导入对话框弹出确认执行函数 + * 进行表达规则校验 + */ +function fnImportModalOk() { + const from = toRaw(modalState.importFrom); + let validateName = ['importType']; + if (from.file) { + validateName.push('file'); + } else { + validateName.push('fileName'); + } + + importStateFrom + .validate(validateName) + .then(e => { + modalState.confirmLoading = true; + const hide = message.loading({ content: t('common.loading') }); + // let result = importFile(from); + // if (from.importType === 'local') { + // let formData = new FormData(); + // formData.append('nfType', from.neType); + // formData.append('nfId', from.neId); + // formData.append('file', from.file); + // result = importFile(formData); + // } + + importFile(from) + .then(res => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success({ + content: t('common.msgSuccess', { msg: modalState.title }), + duration: 3, + }); + modalState.visibleByEdit = false; + modalStateFrom.resetFields(); + } else { + message.error({ + content: `${res.msg}`, + duration: 3, + }); + } + }) + .finally(() => { + hide(); + modalState.confirmLoading = false; + // 获取列表数据 + fnGetList(); + }); + }) + .catch(e => { + console.error(e) + message.error(t('common.errorFields', { num: e.errorFields.length }), 3); + }); +} + +/** + * 导入对话框弹出关闭执行函数 + * 进行表达规则校验 + */ +function fnImportModalCancel() { + modalState.visibleByView = false; + modalState.visibleByImport = false; + importStateFrom.resetFields(); +} + /** * 对话框弹出关闭执行函数 * 进行表达规则校验 @@ -431,6 +548,12 @@ function fnFileModalVisible(type: string | number, row: Record) { tableState.loading = false; }); } + + if (type === 'import') { + modalState.importFrom = Object.assign(modalState.importFrom, row); + modalState.title = '导入'; + modalState.visibleByImport = true; + } } /**查询网元列表 */ @@ -450,6 +573,53 @@ function fnGetList() { }); } +/**查询网元远程服务器备份文件 */ +function typeChange(value: any) { + if (value === 'server') { + listServerFile(modalState.importFrom).then(res => { + if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) { + neManageOption.serverFileName = []; + res.data.forEach((item: any) => { + neManageOption.serverFileName.push({ + label: item.fileName, + value: item.fileName, + }); + }); + } + // else if (res.code === RESULT_CODE_SUCCESS && !res.data) { + // message.error({ + // content: `当前网元没有远程服务器备份文件`, + // key: 'importServer', + // duration: 2, + // }); + // } + }); + } +} + +/**上传前检查或转换压缩 */ +function fnBeforeUploadFile(file: FileType) { + if (modalState.confirmLoading) return false; + const fileName = file.name; + const suff = fileName.substring(fileName.lastIndexOf('.')); + const isLt60M = file.size / 1024 / 1024 > 60; + if (isLt60M) { + message.error('有效软件文件大小应不小于 60MB', 3); + return false; + } + return true; +} + +/**上传文件 */ +function fnUploadFile(up: UploadRequestOption) { + // 改为完成状态 + const file = modalState.importFrom.fileList[0]; + file.percent = 100; + file.status = 'done'; + // 预置到表单 + modalState.importFrom.file = up.file; +} + onMounted(() => { // 获取列表数据 fnGetList(); @@ -604,7 +774,7 @@ onMounted(() => { {{ t('views.configManage.neManage.start') }} - + {{ t('views.configManage.neManage.restart') }} @@ -807,6 +977,97 @@ onMounted(() => { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ t('views.configManage.neManage.fileSelect') }} + + + + +