From efa8764bd16322420338ffb6a5ae06b1fa9d2d50 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 9 Jul 2024 10:05:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9B=B4=E8=BF=9E=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ne/neConfig.ts | 66 ++++ .../configParamTreeTable/index.vue | 351 +++++++++++------- 2 files changed, 280 insertions(+), 137 deletions(-) create mode 100644 src/api/ne/neConfig.ts diff --git a/src/api/ne/neConfig.ts b/src/api/ne/neConfig.ts new file mode 100644 index 00000000..dcd1e8dd --- /dev/null +++ b/src/api/ne/neConfig.ts @@ -0,0 +1,66 @@ +import { request } from '@/plugins/http-fetch'; + +/** + * 网元参数配置可用属性值列表指定网元类型全部无分页 + * @param query 查询参数 + * @returns object + */ +export function getAllNeConfig(neType: string) { + return request({ + url: `/ne/config/list/${neType}`, + method: 'get', + timeout: 60_000, + }); +} + +/** + * 网元参数配置数据信息 + * @param params 数据 {neType,neId,paramName} + * @returns object + */ +export function getNeConfigData(params: Record) { + return request({ + url: `/ne/config/data`, + params, + method: 'get', + }); +} + +/** + * 网元参数配置数据更新 + * @param data 数据 {neType,neId,paramName:"参数名",paramData:{参数},loc:"层级index仅array"} + * @returns object + */ +export function editNeConfigData(data: Record) { + return request({ + url: `/ne/config/data`, + method: 'put', + data: data, + }); +} + +/** + * 网元参数配置数据新增(array) + * @param data 数据 {neType,neId,paramName:"参数名",paramData:{参数},loc:"层级index"} + * @returns object + */ +export function addNeConfigData(data: Record) { + return request({ + url: `/ne/config/data`, + method: 'post', + data: data, + }); +} + +/** + * 网元参数配置数据删除(array) + * @param params 数据 {neType,neId,paramName:"参数名",loc:"层级index"} + * @returns object + */ +export function delNeConfigData(params: Record) { + return request({ + url: `/ne/config/data`, + method: 'delete', + params, + }); +} diff --git a/src/views/configManage/configParamTreeTable/index.vue b/src/views/configManage/configParamTreeTable/index.vue index 7a767392..007f2ac3 100644 --- a/src/views/configManage/configParamTreeTable/index.vue +++ b/src/views/configManage/configParamTreeTable/index.vue @@ -17,6 +17,13 @@ import useOptions from './hooks/useOptions'; import useSMFOptions from './hooks/useSMFOptions'; import { SizeType } from 'ant-design-vue/lib/config-provider'; import { DataNode } from 'ant-design-vue/lib/tree'; +import { + addNeConfigData, + delNeConfigData, + editNeConfigData, + getAllNeConfig, + getNeConfigData, +} from '@/api/ne/neConfig'; const neInfoStore = useNeInfoStore(); const { t } = useI18n(); const { ruleVerification } = useOptions(); @@ -43,7 +50,16 @@ type TreeStateType = { /**网元配置 tree */ data: DataNode[]; /**选择对应Node一级 tree */ - selectNode: Record; + selectNode: { + title: string; + key: string; + // 可选属性数据 + paramName: string; + paramDisplay: string; + paramType: string; + paramPerms: string[]; + paramData: Record[]; + }; /**选择 loading */ selectLoading: boolean; }; @@ -52,29 +68,24 @@ let treeState: TreeStateType = reactive({ loading: true, data: [], selectNode: { - topDisplay: '' as string, - topTag: '' as string, - method: [] as string[], - // - title: '' as string, - key: '' as string, - type: 'list' as 'list' | 'array', + paramName: '', + paramDisplay: '', + paramType: '', + paramPerms: [], + paramData: [], + // 树形节点需要有 + title: '', + key: '', }, selectLoading: true, }); /**查询可选命令列表 */ function fnSelectConfigNode(_: any, info: any) { - const { title, key, method } = info.node; - treeState.selectNode.topDisplay = title; - treeState.selectNode.topTag = key; - if (method) { - treeState.selectNode.method = method.split(','); - } else { - treeState.selectNode.method = ['post', 'put', 'delete']; + const { key } = info.node; + if (treeState.selectNode.paramName == key) { + return; } - treeState.selectNode.title = title; - treeState.selectNode.key = key; fnActiveConfigNode(key); } @@ -83,26 +94,76 @@ function fnActiveConfigNode(key: string | number) { listState.data = []; arrayState.data = []; treeState.selectLoading = true; - if (key !== '#') { - treeState.selectNode.topTag = key as string; + if (key === '#') { + key = treeState.selectNode.paramName; + } else { + treeState.selectNode.paramName = key as string; } - // 获取数据 - const neType = neTypeSelect.value[0]; - const neId = neTypeSelect.value[1]; - const topTag = treeState.selectNode.topTag; - getParamConfigInfoForm(neType, topTag, neId).then(res => { - if (res.code === RESULT_CODE_SUCCESS && res.data.type) { + const param = treeState.data.find(item => item.key === key); + if (!param) { + message.warning({ + content: t('common.noData'), + duration: 3, + }); + return; + } + treeState.selectNode = JSON.parse(JSON.stringify(param)); + + // 获取网元端的配置数据 + getNeConfigData({ + neType: neTypeSelect.value[0], + neId: neTypeSelect.value[1], + paramName: treeState.selectNode.paramName, + }).then(res => { + if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) { treeState.selectLoading = false; - treeState.selectNode.topTag = topTag; - treeState.selectNode.type = res.data.type; - if (res.data.type === 'list') { - listState.data = res.data.data; + const ruleArr = param.paramData; + const dataArr = res.data; + if (param.paramType === 'list') { + // 列表项数据 + const dataList = []; + for (const item of dataArr) { + for (const key in item) { + // 规则为准 + for (const rule of ruleArr) { + if (rule['name'] === key) { + const ruleItem = Object.assign(rule, { + optional: 'true', + value: item[key], + }); + dataList.push(ruleItem); + break; + } + } + } + } + listState.data = dataList; listEditClose(); } - if (res.data.type === 'array') { - arrayState.data = res.data.data; - arrayState.dataRule = res.data.dataRule; + if (param.paramType === 'array') { + // 列表项数据 + const dataArray = []; + for (const item of dataArr) { + const index = item['index']; + let record: Record[] = []; + for (const key in item) { + // 规则为准 + for (const rule of ruleArr) { + if (rule['name'] === key) { + const ruleItem = Object.assign({ optional: 'true' }, rule, { + value: item[key], + }); + record.push(ruleItem); + break; + } + } + } + dataArray.push({ title: `Index-${index}`, key: index, record }); + } + arrayState.data = dataArray; + // 无数据时,用于新增 + arrayState.dataRule = { title: `Index-0`, key: 0, record: ruleArr }; // 列表数据 const columnsData: Record[] = []; @@ -114,7 +175,6 @@ function fnActiveConfigNode(key: string | number) { columnsData.push(row); } arrayState.columnsData = columnsData; - // 列表字段 const columns: Record[] = []; for (const rule of arrayState.dataRule.record) { @@ -142,15 +202,17 @@ function fnActiveConfigNode(key: string | number) { } } else { message.warning({ - content: t('common.noData'), + content: `${param.paramDisplay} ${t( + 'views.configManage.configParamForm.noConfigData' + )}`, duration: 3, }); } }); } -/**查询配置Tag标签 */ -function fnGetParamConfigTopTab() { +/**查询配置可选属性值列表 */ +function fnGetNeConfig() { const neType = neTypeSelect.value[0]; if (!neType) { message.warning({ @@ -162,31 +224,33 @@ function fnGetParamConfigTopTab() { treeState.loading = true; // 获取数据 - getParamConfigTopTab(neType).then(res => { + getAllNeConfig(neType).then(res => { if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) { - treeState.data = res.data.map(item => ({ - children: undefined, - title: item.topDisplay, - key: item.topTag, - ...item, - })); + const arr = []; + for (const item of res.data) { + let paramPerms: string[] = []; + if (item.paramPerms) { + paramPerms = item.paramPerms.split(','); + } else { + paramPerms = ['post', 'put', 'delete']; + } + arr.push({ + ...item, + children: undefined, + title: item.paramDisplay, + key: item.paramName, + paramPerms, + }); + } + treeState.data = arr; treeState.loading = false; // 取首个tag if (res.data.length > 0) { - const itemOne = res.data[0]; - treeState.selectNode = { - title: itemOne.topDisplay, - key: itemOne.topTag, - type: 'list', - ...itemOne, - }; - fnActiveConfigNode(itemOne.topTag); + const item = JSON.parse(JSON.stringify(treeState.data[0])); + treeState.selectNode = item; + treeState.selectLoading = false; + fnActiveConfigNode(item.key); } - } else { - message.warning({ - content: t('views.configManage.configParamForm.noConfigData'), - duration: 3, - }); } }); } @@ -249,18 +313,14 @@ function listEditOk() { // 发送 const hide = message.loading(t('common.loading'), 0); - let data = { - [from['name']]: from['value'], - }; - updateParamConfigInfo( - 'list', - { - neType: neTypeSelect.value[0], - neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, + editNeConfigData({ + neType: neTypeSelect.value[0], + neId: neTypeSelect.value[1], + paramName: treeState.selectNode.paramName, + paramData: { + [from['name']]: from['value'], }, - data - ) + }) .then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -270,9 +330,9 @@ function listEditOk() { duration: 3, }); // 改变表格数据 - const item = listState.data.filter( + const item = listState.data.find( (item: Record) => from['name'] === item['name'] - )[0]; + ); if (item) { Object.assign(item, listState.editRecord); } @@ -360,7 +420,7 @@ function arrayEdit(rowIndex: Record) { modalState.from = row; modalState.type = 'arrayEdit'; - modalState.title = `${treeState.selectNode.topDisplay} ${from.title}`; + modalState.title = `${treeState.selectNode.paramDisplay} ${from.title}`; modalState.key = from.key; modalState.data = from.record.filter((v: any) => !Array.isArray(v.array)); modalState.visible = true; @@ -377,8 +437,6 @@ function arrayEditClose() { /**多列表编辑确认 */ function arrayEditOk(from: Record) { - const loc = from['index']['value']; - const neType = neTypeSelect.value[0]; // 遍历提取属性和值 let data: Record = {}; for (const key in from) { @@ -400,16 +458,13 @@ function arrayEditOk(from: Record) { // 发送 const hide = message.loading(t('common.loading'), 0); - updateParamConfigInfo( - 'array', - { - neType: neType, - neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, - loc, - }, - data - ) + editNeConfigData({ + neType: neTypeSelect.value[0], + neId: neTypeSelect.value[1], + paramName: treeState.selectNode.paramName, + paramData: data, + loc: from['index']['value'], + }) .then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -434,8 +489,8 @@ function arrayEditOk(from: Record) { /**多列表删除单行 */ function arrayDelete(rowIndex: Record) { - const index = rowIndex.value; - const title = `${treeState.selectNode.topDisplay} Index-${index}`; + const loc = rowIndex.value; + const title = `${treeState.selectNode.paramDisplay} Index-${loc}`; Modal.confirm({ title: t('common.tipTitle'), @@ -443,11 +498,11 @@ function arrayDelete(rowIndex: Record) { num: title, }), onOk() { - delParamConfigInfo({ + delNeConfigData({ neType: neTypeSelect.value[0], neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, - loc: index, + paramName: treeState.selectNode.paramName, + loc: loc, }).then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -484,7 +539,7 @@ function arrayAdd() { modalState.from = row; modalState.type = 'arrayAdd'; - modalState.title = `${treeState.selectNode.topDisplay} ${from.title}`; + modalState.title = `${treeState.selectNode.paramDisplay} ${from.title}`; modalState.key = from.key; modalState.data = from.record.filter((v: any) => !Array.isArray(v.array)); modalState.visible = true; @@ -492,8 +547,6 @@ function arrayAdd() { /**多列表新增单行确认 */ function arrayAddOk(from: Record) { - const index = from['index']['value']; - const neType = neTypeSelect.value[0]; // 遍历提取属性和值 let data: Record = {}; for (const key in from) { @@ -515,15 +568,13 @@ function arrayAddOk(from: Record) { // 发送 const hide = message.loading(t('common.loading'), 0); - addParamConfigInfo( - { - neType: neType, - neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, - loc: index, - }, - data - ) + addNeConfigData({ + neType: neTypeSelect.value[0], + neId: neTypeSelect.value[1], + paramName: treeState.selectNode.paramName, + paramData: data, + loc: from['index']['value'], + }) .then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -703,9 +754,7 @@ function arrayChildEdit(rowIndex: Record) { /**多列表嵌套行编辑确认 */ function arrayChildEditOk(from: Record) { - const index = from['index']['value']; - const loc = `${arrayChildState.loc}/${index}`; - const neType = neTypeSelect.value[0]; + const loc = `${arrayChildState.loc}/${from['index']['value']}`; let data: Record = {}; for (const key in from) { @@ -727,16 +776,13 @@ function arrayChildEditOk(from: Record) { // 发送 const hide = message.loading(t('common.loading'), 0); - updateParamConfigInfo( - 'array', - { - neType: neType, - neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, - loc, - }, - data - ) + editNeConfigData({ + neType: neTypeSelect.value[0], + neId: neTypeSelect.value[1], + paramName: treeState.selectNode.paramName, + paramData: data, + loc, + }) .then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -771,10 +817,10 @@ function arrayChildDelete(rowIndex: Record) { num: title, }), onOk() { - delParamConfigInfo({ + delNeConfigData({ neType: neTypeSelect.value[0], neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, + paramName: treeState.selectNode.paramName, loc, }).then(res => { if (res.code === RESULT_CODE_SUCCESS) { @@ -819,8 +865,7 @@ function arrayChildAdd() { /**多列表新增单行确认 */ function arrayChildAddOk(from: Record) { - const index = from['index']['value']; - const loc = `${arrayChildState.loc}/${index}`; + const loc = `${arrayChildState.loc}/${from['index']['value']}`; const neType = neTypeSelect.value[0]; let data: Record = {}; @@ -843,15 +888,13 @@ function arrayChildAddOk(from: Record) { // 发送 const hide = message.loading(t('common.loading'), 0); - addParamConfigInfo( - { - neType: neType, - neId: neTypeSelect.value[1], - topTag: treeState.selectNode.topTag, - loc, - }, - data - ) + addNeConfigData({ + neType: neType, + neId: neTypeSelect.value[1], + paramName: treeState.selectNode.paramName, + paramData: data, + loc, + }) .then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -1055,7 +1098,7 @@ onMounted(() => { const info = neCascaderOptions.value[0].children[0]; neTypeSelect.value = [info.neType, info.neId]; } - fnGetParamConfigTopTab(); + fnGetNeConfig(); } } else { message.warning({ @@ -1069,6 +1112,32 @@ onMounted(() => { - - {{ treeState.selectNode.topDisplay }} + + {{ treeState.selectNode.paramDisplay }} {{ t('views.configManage.configParamForm.treeSelectTip') }} @@ -1128,6 +1197,14 @@ onMounted(() => {