diff --git a/src/api/configManage/config.ts b/src/api/configManage/config.ts new file mode 100644 index 00000000..9f391bb9 --- /dev/null +++ b/src/api/configManage/config.ts @@ -0,0 +1,56 @@ +import { + RESULT_CODE_ERROR, + RESULT_CODE_SUCCESS, + RESULT_MSG_ERROR, +} from '@/constants/result-constants'; +import { request } from '@/plugins/http-fetch'; +import { parseObjLineToHump } from '@/utils/parse-utils'; + +/** + * 查询配置详细 + * @param tag 配置ID + * @returns object + */ +export async function getConfigInfo(tag: string) { + // 发起请求 + const result = await request({ + url: `/databaseManagement/v1/omc_db/config`, + method: 'get', + params: { + SQL: `SELECT * FROM config WHERE config_tag = '${tag}'`, + }, + }); + // 解析数据 + if (result.code === RESULT_CODE_SUCCESS && Array.isArray(result.data.data)) { + let data = result.data.data[0]; + return Object.assign(result, { + data: parseObjLineToHump(data['config'][0]), + }); + } + return result; +} + +/** + * 修改配置 + * @param data 配置对象 + * @returns object + */ +export async function updateConfig(tag: string, data: Record) { + const result = await request({ + url: `/databaseManagement/v1/omc_db/config?WHERE=config_tag='${tag}'`, + method: 'put', + data: { data }, + }); + // 解析数据 + if (result.code === RESULT_CODE_SUCCESS && result.data.data) { + let rows = result.data.data.affectedRows; + if (rows) { + delete result.data; + return result; + } else { + delete result.data; + return { code: RESULT_CODE_ERROR, msg: RESULT_MSG_ERROR }; + } + } + return result; +} diff --git a/src/i18n/locales/en-US.ts b/src/i18n/locales/en-US.ts index eaee9b53..d4f2e17f 100644 --- a/src/i18n/locales/en-US.ts +++ b/src/i18n/locales/en-US.ts @@ -100,6 +100,7 @@ export default { }, configManage: { backupManage: { + SetBackupTask: 'Set automatic backup time', neTypePlease: 'Query network element type', neType: 'Type', neID: 'Identifying', diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index c78b9a0e..202612c0 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -100,6 +100,7 @@ export default { }, configManage: { backupManage: { + SetBackupTask: '设置自动备份时间', neTypePlease: '查询网元类型', neType: '网元类型', neID: '网元内部标识', diff --git a/src/views/configManage/backupManage/index.vue b/src/views/configManage/backupManage/index.vue index 7a675e61..0f0bedba 100644 --- a/src/views/configManage/backupManage/index.vue +++ b/src/views/configManage/backupManage/index.vue @@ -2,7 +2,7 @@ import { useRoute } from 'vue-router'; import { reactive, ref, onMounted, toRaw } from 'vue'; import { PageContainer } from '@ant-design-vue/pro-layout'; -import { message, Modal } from 'ant-design-vue/lib'; +import { Form, message, Modal } from 'ant-design-vue/lib'; import { SizeType } from 'ant-design-vue/lib/config-provider'; import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface'; import { ColumnsType } from 'ant-design-vue/lib/table'; @@ -15,6 +15,7 @@ import { } from '@/api/configManage/backupManage'; import { saveAs } from 'file-saver'; import useI18n from '@/hooks/useI18n'; +import { getConfigInfo, updateConfig } from '@/api/configManage/config'; const { t } = useI18n(); const route = useRoute(); @@ -213,6 +214,104 @@ function fnGetList() { }); } +/**对话框对象信息状态类型 */ +type ModalStateType = { + /**新增框或修改框是否显示 */ + visibleByEdit: boolean; + /**标题 */ + title: string; + /**表单数据 */ + from: Record; + /**确定按钮 loading */ + confirmLoading: boolean; +}; + +/**对话框对象信息状态 */ +let modalState: ModalStateType = reactive({ + visibleByEdit: false, + title: '任务设置', + from: { + configTag: "", + autoBackupTime: "", + }, + confirmLoading: false, +}); + +/** + * 对话框弹出显示为 新增或者修改 + * @param noticeId 网元id, 不传为新增 + */ +function fnModalVisibleByEdit() { + if (modalState.confirmLoading) return; + const hide = message.loading('正在打开...', 0); + modalState.confirmLoading = true; + getConfigInfo('NfConfigSet').then(res => { + modalState.confirmLoading = false; + hide(); + if (res.code === RESULT_CODE_SUCCESS) { + modalState.from.configTag = res.data.configTag + modalState.from.autoBackupTime = res.data.value + modalState.title = t('views.configManage.backupManage.SetBackupTask'); + modalState.visibleByEdit = true; + } else { + message.error(`获取配置信息失败`, 2); + } + }); +} + +/**对话框内表单属性和校验规则 */ +const modalStateFrom = Form.useForm( + modalState.from, + reactive({ + autoBackupTime: [{ required: true, message: '备份时间不能为空' }], + }) +); +/** + * 对话框弹出确认执行函数 + * 进行表达规则校验 + */ + function fnModalOk() { + modalStateFrom + .validate() + .then(e => { + modalState.confirmLoading = true; + const from = toRaw(modalState.from); + const hide = message.loading({ content: t('common.loading') }); + updateConfig(from.configTag, {value: from.autoBackupTime}) + .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; + }); + }) + .catch(e => { + message.error(t('common.errorFields', { num: e.errorFields.length }), 3); + }); +} + +/** + * 对话框弹出关闭执行函数 + * 进行表达规则校验 + */ +function fnModalCancel() { + modalState.visibleByEdit = false; + modalStateFrom.resetFields(); +} + onMounted(() => { // 获取列表数据 fnGetList(); @@ -261,7 +360,14 @@ onMounted(() => { - + + + + + + + + + + + diff --git a/src/views/configManage/neManage/index.vue b/src/views/configManage/neManage/index.vue index 1cb88ae1..94c55211 100644 --- a/src/views/configManage/neManage/index.vue +++ b/src/views/configManage/neManage/index.vue @@ -212,13 +212,13 @@ let modalState: ModalStateType = reactive({ const modalStateFrom = Form.useForm( modalState.from, reactive({ - ne_type: [{ required: true, message: '网元类型不能为空' }], - ne_id: [{ required: true, message: '网元内部标识不能为空' }], - rm_uid: [{ required: true, message: '资源唯一标识不能为空' }], + neType: [{ required: true, message: '网元类型不能为空' }], + neId: [{ required: true, message: '网元内部标识不能为空' }], + rmUid: [{ required: true, message: '资源唯一标识不能为空' }], ip: [{ required: true, message: 'IP地址不能为空' }], port: [{ required: true, message: '端口不能为空' }], - pv_flag: [{ required: true, message: '请选择网元虚拟化标识' }], - ne_name: [{ required: true, message: '网元名称不能为空' }], + pvFlag: [{ required: true, message: '请选择网元虚拟化标识' }], + neName: [{ required: true, message: '网元名称不能为空' }], }) );