fix: 网元配置改回原先单网元配置
This commit is contained in:
@@ -10,14 +10,13 @@ import { reactive, watch } from 'vue';
|
||||
|
||||
/**
|
||||
* 参数配置array类型
|
||||
* @param param 父级传入 { t, treeState, neTypeSelect, neIdSelect, fnActiveConfigNode, ruleVerification, modalState, fnModalCancel}
|
||||
* @param param 父级传入 { t, treeState, neTypeSelect, fnActiveConfigNode, ruleVerification, modalState, fnModalCancel}
|
||||
* @returns
|
||||
*/
|
||||
export default function useConfigArray({
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
fnActiveConfigNode,
|
||||
ruleVerification,
|
||||
modalState,
|
||||
@@ -131,22 +130,8 @@ export default function useConfigArray({
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
// 发送
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
@@ -154,38 +139,20 @@ export default function useConfigArray({
|
||||
paramData: data,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.updateItem', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
} else {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -205,64 +172,27 @@ export default function useConfigArray({
|
||||
num: title,
|
||||
}),
|
||||
onOk() {
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.error({
|
||||
content: `${rejected.reason}`,
|
||||
duration: 2,
|
||||
});
|
||||
} else {
|
||||
}).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.delItemOk', {
|
||||
num: title,
|
||||
}),
|
||||
duration: 2,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
fnActiveConfigNode('#');
|
||||
} else {
|
||||
message.error({
|
||||
content: `${res.msg}`,
|
||||
duration: 2,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -334,22 +264,8 @@ export default function useConfigArray({
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc: `${from['index']['value']}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
// 发送
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
@@ -357,38 +273,20 @@ export default function useConfigArray({
|
||||
paramData: data,
|
||||
loc: `${from['index']['value']}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.addItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.addItemOk', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
} else {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.addItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
@@ -10,14 +10,13 @@ import { nextTick, reactive } from 'vue';
|
||||
|
||||
/**
|
||||
* 参数配置array类型的嵌套array
|
||||
* @param param 父级传入 { t, treeState, neTypeSelect, neIdSelect, fnActiveConfigNode, ruleVerification, modalState, arrayState, arrayInitEdit, arrayInitAdd, arrayEditClose}
|
||||
* @param param 父级传入 { t, treeState, neTypeSelect, fnActiveConfigNode, ruleVerification, modalState, arrayState, arrayInitEdit, arrayInitAdd, arrayEditClose}
|
||||
* @returns
|
||||
*/
|
||||
export default function useConfigArrayChild({
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
fnActiveConfigNode,
|
||||
ruleVerification,
|
||||
modalState,
|
||||
@@ -199,22 +198,8 @@ export default function useConfigArrayChild({
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
// 发送
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
@@ -222,38 +207,20 @@ export default function useConfigArrayChild({
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.updateItem', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
} else {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -274,64 +241,27 @@ export default function useConfigArrayChild({
|
||||
num: title,
|
||||
}),
|
||||
onOk() {
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.error({
|
||||
content: `${rejected.reason}`,
|
||||
duration: 2,
|
||||
});
|
||||
} else {
|
||||
}).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.delItemOk', {
|
||||
num: title,
|
||||
}),
|
||||
duration: 2,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
fnActiveConfigNode('#');
|
||||
} else {
|
||||
message.error({
|
||||
content: `${res.msg}`,
|
||||
duration: 2,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -379,22 +309,8 @@ export default function useConfigArrayChild({
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
// 发送
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
@@ -402,38 +318,20 @@ export default function useConfigArrayChild({
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.addItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.addItemOk', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
} else {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.addItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
@@ -6,14 +6,13 @@ import { reactive, toRaw } from 'vue';
|
||||
|
||||
/**
|
||||
* list类型参数处理
|
||||
* @param param 父级传入 {t, treeState, neTypeSelect, neIdSelect, ruleVerification}
|
||||
* @param param 父级传入 {t, treeState, neTypeSelect, ruleVerification}
|
||||
* @returns
|
||||
*/
|
||||
export default function useConfigList({
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
ruleVerification,
|
||||
}: any) {
|
||||
/**单列表状态类型 */
|
||||
@@ -84,23 +83,9 @@ export default function useConfigList({
|
||||
return;
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: {
|
||||
[from['name']]: from['value'],
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
// 发送
|
||||
listState.confirmLoading = true;
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
@@ -109,39 +94,14 @@ export default function useConfigList({
|
||||
[from['name']]: from['value'],
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
listState.confirmLoading = false;
|
||||
listState.editRecord = {};
|
||||
return;
|
||||
}
|
||||
|
||||
listState.confirmLoading = true;
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateValueErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.updateValue', {
|
||||
num: from['display'],
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
// 改变表格数据
|
||||
const item = listState.data.find(
|
||||
(item: Record<string, any>) => from['name'] === item['name']
|
||||
@@ -149,6 +109,11 @@ export default function useConfigList({
|
||||
if (item) {
|
||||
Object.assign(item, listState.editRecord);
|
||||
}
|
||||
} else {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateValueErr'),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, onMounted, toRaw, watch, computed } from 'vue';
|
||||
import { reactive, ref, onMounted, toRaw, watch } from 'vue';
|
||||
import { PageContainer } from 'antdv-pro-layout';
|
||||
import { ProModal } from 'antdv-pro-modal';
|
||||
import { message, TreeSelect, type TreeSelectProps } from 'ant-design-vue/es';
|
||||
import { message } from 'ant-design-vue/es';
|
||||
import { DataNode } from 'ant-design-vue/es/tree';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
import TableColumnsDnd from '@/components/TableColumnsDnd/index.vue';
|
||||
@@ -19,105 +19,11 @@ const { ruleVerification, smfByUPFIdLoadData, smfByUPFIdOptions } = useOptions({
|
||||
t,
|
||||
});
|
||||
|
||||
/**网元类型 type,[](type,id) */
|
||||
/**网元类型_多neId */
|
||||
let neCascaderOptions = ref<Record<string, any>[]>([]);
|
||||
/**网元类型 [](label,value,children) */
|
||||
let neSelectTreeDate = ref<TreeSelectProps['treeData']>([]);
|
||||
|
||||
/**网元类型选择 type,id */
|
||||
let neTypeSelect = ref<string[]>(['', '']);
|
||||
/**网元类型选择 id */
|
||||
let neIdSelect = ref<string[]>([]);
|
||||
let neTypeSelectStatus = ref(true);
|
||||
/**网元类型neType选择 */
|
||||
async function fnSelectNeType(_: any, info: any) {
|
||||
if (!info) return;
|
||||
await fnGetNeConfig(info.value);
|
||||
if (treeState.data.length === 0) {
|
||||
message.warning({
|
||||
content: `${t('views.ne.neConfig.noConfigData')}`,
|
||||
duration: 3,
|
||||
});
|
||||
treeState.selectLoading = true;
|
||||
neIdSelect.value = [];
|
||||
neSelectTreeDate.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
neTypeSelect.value[0] = info.value;
|
||||
neTypeSelect.value[1] = 'SYNC';
|
||||
treeState.selectLoading = true;
|
||||
neTypeSelectStatus.value = true;
|
||||
neIdSelect.value = [];
|
||||
neSelectTreeDate.value = [];
|
||||
// 构建可选树形数据
|
||||
if (Array.isArray(info.children) && info.children.length > 0) {
|
||||
const neArr = info.children.concat();
|
||||
for (let index = 0; index < neArr.length; index++) {
|
||||
const v = neArr[index];
|
||||
const ne = {
|
||||
label: v.neName,
|
||||
value: v.neId,
|
||||
disabled: false,
|
||||
};
|
||||
|
||||
// 检查下级网元是否可用
|
||||
const res = await getNeConfigData({
|
||||
neType: v.neType,
|
||||
neId: v.neId,
|
||||
paramName: `${treeState.data[0].key}`,
|
||||
});
|
||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
||||
ne.disabled = !res.data.length;
|
||||
} else {
|
||||
ne.disabled = true;
|
||||
}
|
||||
|
||||
// 添加到树形数据
|
||||
const root = neSelectTreeDate.value?.find(s => s.label === v.province);
|
||||
if (root && Array.isArray(root.children)) {
|
||||
root.children.push(ne);
|
||||
} else {
|
||||
neSelectTreeDate.value?.push({
|
||||
label: v.province,
|
||||
value: 'SYNC_' + v.province,
|
||||
children: [ne],
|
||||
});
|
||||
}
|
||||
|
||||
const key = 'SYNC_' + v.province;
|
||||
// 初始区域
|
||||
if (neIdSelect.value.length === 0) {
|
||||
neTypeSelect.value[1] = key;
|
||||
}
|
||||
// 同区域内添加
|
||||
if (neTypeSelect.value[1] === key) {
|
||||
neIdSelect.value.push(v.neId);
|
||||
}
|
||||
}
|
||||
}
|
||||
fnActiveConfigNode(treeState.data[0].key);
|
||||
neTypeSelectStatus.value = false;
|
||||
}
|
||||
/**网元类型neId选择 */
|
||||
function fnSelectNeId(_: any, info: any) {
|
||||
if (info.children && Array.isArray(info.children)) {
|
||||
const okArr = info.children.filter((item: any) => !item.disabled);
|
||||
if (Array.isArray(okArr) && okArr.length === 0) {
|
||||
message.warning({
|
||||
content: `${t('views.ne.neConfig.noConfigdDisabled')}`,
|
||||
duration: 3,
|
||||
});
|
||||
neIdSelect.value = [];
|
||||
return;
|
||||
}
|
||||
neTypeSelect.value[1] = info.value;
|
||||
neIdSelect.value = okArr.map((item: any) => item.value);
|
||||
} else {
|
||||
neTypeSelect.value[1] = info.value;
|
||||
neIdSelect.value = [info.value];
|
||||
}
|
||||
fnActiveConfigNode(treeState.data[0].key);
|
||||
}
|
||||
|
||||
/**左侧导航是否可收起 */
|
||||
let collapsible = ref<boolean>(true);
|
||||
@@ -143,7 +49,6 @@ type TreeStateType = {
|
||||
paramType: string;
|
||||
paramPerms: string[];
|
||||
paramData: Record<string, any>[];
|
||||
visible: string;
|
||||
};
|
||||
/**选择 loading */
|
||||
selectLoading: boolean;
|
||||
@@ -158,7 +63,6 @@ let treeState: TreeStateType = reactive({
|
||||
paramType: '',
|
||||
paramPerms: [],
|
||||
paramData: [],
|
||||
visible: 'public',
|
||||
// 树形节点需要有
|
||||
title: '',
|
||||
key: '',
|
||||
@@ -196,134 +100,22 @@ function fnActiveConfigNode(key: string | number) {
|
||||
}
|
||||
treeState.selectNode = JSON.parse(JSON.stringify(param));
|
||||
|
||||
let neId = neTypeSelect.value[1];
|
||||
// 无neId时取首个可连接的
|
||||
if (neId.startsWith('SYNC')) {
|
||||
const oneNeId = neIdSelect.value[0];
|
||||
if (oneNeId) {
|
||||
neId = oneNeId;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取网元端的配置数据
|
||||
fnGetNeConfigData(neTypeSelect.value[0], neId, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询配置可选属性值列表
|
||||
* neTypeSelect.value[0]
|
||||
*/
|
||||
async function fnGetNeConfig(neType: string) {
|
||||
if (!neType) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neTypePleace'),
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
treeState.loading = true;
|
||||
// 获取数据
|
||||
const res = await getAllNeConfig(neType);
|
||||
getNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: key,
|
||||
}).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
||||
const arr = [];
|
||||
for (const v of res.data) {
|
||||
const item = JSON.parse(JSON.stringify(v));
|
||||
// 规则项
|
||||
let paramData: Record<string, string>[] = [];
|
||||
for (let index = 0; index < item.paramData.length; index++) {
|
||||
const element = item.paramData[index];
|
||||
if (!element['visible']) {
|
||||
element['visible'] = 'public';
|
||||
}
|
||||
paramData.push(element);
|
||||
}
|
||||
// 权限控制
|
||||
let paramPerms: string[] = [];
|
||||
if (item.paramPerms) {
|
||||
paramPerms = item.paramPerms.split(',');
|
||||
} else {
|
||||
paramPerms = ['post', 'put', 'delete'];
|
||||
}
|
||||
arr.push({
|
||||
children: undefined,
|
||||
title: item.paramDisplay,
|
||||
key: item.paramName,
|
||||
paramName: item.paramName,
|
||||
paramDisplay: item.paramDisplay,
|
||||
paramType: item.paramType,
|
||||
paramPerms: paramPerms,
|
||||
paramData: paramData,
|
||||
visible: item.visible,
|
||||
});
|
||||
}
|
||||
treeState.data = arr;
|
||||
treeState.loading = false;
|
||||
} else {
|
||||
treeState.data = [];
|
||||
neTypeSelectStatus.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**过滤可见项 */
|
||||
const treeStateData = computed(() => {
|
||||
// 公共
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
return treeState.data.filter(item => item.visible === 'public');
|
||||
}
|
||||
// 具体网元
|
||||
const arr: DataNode[] = [];
|
||||
for (const item of treeState.data) {
|
||||
if (item.visible === 'self') {
|
||||
arr.push(item);
|
||||
} else if (item.paramType === 'list') {
|
||||
for (let index = 0; index < item.paramData.length; index++) {
|
||||
const element = item.paramData[index];
|
||||
if (element['visible'] === 'self') {
|
||||
arr.push(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
});
|
||||
|
||||
/**
|
||||
* 查询配置属性值数据
|
||||
* paramName = treeState.data[0].key
|
||||
*/
|
||||
function fnGetNeConfigData(
|
||||
neType: string,
|
||||
neId: string,
|
||||
paramName: string | number
|
||||
) {
|
||||
const param = treeState.selectNode;
|
||||
// 获取网元端的配置数据
|
||||
getNeConfigData({ neType, neId, paramName }).then(res => {
|
||||
// 数据处理
|
||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
||||
const ruleArr: Record<string, any>[] = JSON.parse(
|
||||
JSON.stringify(param.paramData)
|
||||
);
|
||||
const ruleArr = param.paramData;
|
||||
const dataArr = res.data;
|
||||
if (param.paramType === 'list') {
|
||||
// 过滤可见规则项
|
||||
let ruleArrFilter: Record<string, any>[] = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
ruleArrFilter = ruleArr.filter(item => item['visible'] === 'public');
|
||||
} else {
|
||||
ruleArrFilter = ruleArr.filter(item => item['visible'] === 'self');
|
||||
}
|
||||
// 列表项数据
|
||||
const dataList = [];
|
||||
for (const item of dataArr) {
|
||||
for (const key in item) {
|
||||
// 规则为准
|
||||
for (const rule of ruleArrFilter) {
|
||||
// 取到对应规则key设置值
|
||||
for (const rule of ruleArr) {
|
||||
if (rule['name'] === key) {
|
||||
const ruleItem = Object.assign(rule, {
|
||||
optional: 'true',
|
||||
@@ -398,7 +190,6 @@ function fnGetNeConfigData(
|
||||
tablePagination.current = 1;
|
||||
arrayEditClose();
|
||||
}
|
||||
// 有数据关闭loading
|
||||
setTimeout(() => {
|
||||
treeState.selectLoading = false;
|
||||
}, 300);
|
||||
@@ -411,6 +202,50 @@ function fnGetNeConfigData(
|
||||
});
|
||||
}
|
||||
|
||||
/**查询配置可选属性值列表 */
|
||||
function fnGetNeConfig() {
|
||||
const neType = neTypeSelect.value[0];
|
||||
if (!neType) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neTypePleace'),
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
treeState.loading = true;
|
||||
// 获取数据
|
||||
getAllNeConfig(neType).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
||||
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 item = JSON.parse(JSON.stringify(treeState.data[0]));
|
||||
treeState.selectNode = item;
|
||||
treeState.selectLoading = false;
|
||||
fnActiveConfigNode(item.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**对话框对象信息状态类型 */
|
||||
type ModalStateType = {
|
||||
/**添加框是否显示 */
|
||||
@@ -478,18 +313,13 @@ watch(
|
||||
val => {
|
||||
// SMF需要选择配置的UPF id
|
||||
if (val && neTypeSelect.value[0] === 'SMF') {
|
||||
let neId = neTypeSelect.value[1];
|
||||
// 无neId时取首个可连接的
|
||||
if (neId.startsWith('SYNC')) {
|
||||
neId = neIdSelect.value[0];
|
||||
}
|
||||
smfByUPFIdLoadData(neId);
|
||||
smfByUPFIdLoadData(neTypeSelect.value[1]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const { tablePagination, listState, listEdit, listEditClose, listEditOk } =
|
||||
useConfigList({ t, treeState, neTypeSelect, neIdSelect, ruleVerification });
|
||||
useConfigList({ t, treeState, neTypeSelect, ruleVerification });
|
||||
|
||||
const {
|
||||
arrayState,
|
||||
@@ -505,7 +335,6 @@ const {
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
fnActiveConfigNode,
|
||||
ruleVerification,
|
||||
modalState,
|
||||
@@ -524,7 +353,6 @@ const {
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
fnActiveConfigNode,
|
||||
ruleVerification,
|
||||
modalState,
|
||||
@@ -555,14 +383,13 @@ onMounted(() => {
|
||||
// 默认选择AMF
|
||||
const item = neCascaderOptions.value.find(s => s.value === 'AMF');
|
||||
if (item && item.children) {
|
||||
fnSelectNeType(null, item);
|
||||
// const info = item.children[0];
|
||||
// neTypeSelect.value = [info.neType, info.neId];
|
||||
const info = item.children[0];
|
||||
neTypeSelect.value = [info.neType, info.neId];
|
||||
} else {
|
||||
fnSelectNeType(null, neCascaderOptions.value[0]);
|
||||
// const info = neCascaderOptions.value[0].children[0];
|
||||
// neTypeSelect.value = [info.neType, info.neId];
|
||||
const info = neCascaderOptions.value[0].children[0];
|
||||
neTypeSelect.value = [info.neType, info.neId];
|
||||
}
|
||||
fnGetNeConfig();
|
||||
}
|
||||
} else {
|
||||
message.warning({
|
||||
@@ -590,40 +417,17 @@ onMounted(() => {
|
||||
{{ t('views.ne.neConfig.treeTitle') }}
|
||||
</template>
|
||||
<a-form layout="vertical" autocomplete="off">
|
||||
<a-form-item name="neTypeSelect ">
|
||||
<a-input-group compact>
|
||||
<a-select
|
||||
:disabled="neTypeSelectStatus"
|
||||
:value="neTypeSelect[0]"
|
||||
<a-form-item name="neId ">
|
||||
<a-cascader
|
||||
v-model:value="neTypeSelect"
|
||||
:options="neCascaderOptions"
|
||||
:allow-clear="false"
|
||||
@change="fnSelectNeType"
|
||||
style="width: 40%"
|
||||
>
|
||||
</a-select>
|
||||
<a-tree-select
|
||||
v-model:value="neTypeSelect[1]"
|
||||
:status="neIdSelect.length === 0 ? 'warning' : ''"
|
||||
:disabled="treeState.selectLoading"
|
||||
:tree-data="neSelectTreeDate"
|
||||
:maxTagCount="1"
|
||||
:show-search="true"
|
||||
:allow-clear="false"
|
||||
:tree-default-expand-all="true"
|
||||
:tree-checkable="false"
|
||||
:show-checked-strategy="TreeSelect.SHOW_PARENT"
|
||||
placement="bottomRight"
|
||||
tree-node-filter-prop="label"
|
||||
style="width: 60%"
|
||||
@select="fnSelectNeId"
|
||||
>
|
||||
</a-tree-select>
|
||||
</a-input-group>
|
||||
@change="fnGetNeConfig"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item name="treeStateData">
|
||||
<a-tree
|
||||
:disabled="neTypeSelectStatus"
|
||||
:tree-data="treeStateData"
|
||||
:tree-data="treeState.data"
|
||||
:selected-keys="[treeState.selectNode.paramName]"
|
||||
@select="fnSelectConfigNode"
|
||||
>
|
||||
|
||||
513
src/views/ne/neConfigHA/hooks/useConfigArray.ts
Normal file
513
src/views/ne/neConfigHA/hooks/useConfigArray.ts
Normal file
@@ -0,0 +1,513 @@
|
||||
import {
|
||||
addNeConfigData,
|
||||
delNeConfigData,
|
||||
editNeConfigData,
|
||||
} from '@/api/ne/neConfig';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { Modal, message } from 'ant-design-vue/es';
|
||||
import { SizeType } from 'ant-design-vue/es/config-provider';
|
||||
import { reactive, watch } from 'vue';
|
||||
|
||||
/**
|
||||
* 参数配置array类型
|
||||
* @param param 父级传入 { t, treeState, neTypeSelect, neIdSelect, fnActiveConfigNode, ruleVerification, modalState, fnModalCancel}
|
||||
* @returns
|
||||
*/
|
||||
export default function useConfigArray({
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
fnActiveConfigNode,
|
||||
ruleVerification,
|
||||
modalState,
|
||||
fnModalCancel,
|
||||
}: any) {
|
||||
/**多列列表状态类型 */
|
||||
type ArrayStateType = {
|
||||
/**紧凑型 */
|
||||
size: SizeType;
|
||||
/**多列嵌套记录字段 */
|
||||
columns: Record<string, any>[];
|
||||
/**表格字段列排序 */
|
||||
columnsDnd: Record<string, any>[];
|
||||
/**多列记录数据 */
|
||||
columnsData: Record<string, any>[];
|
||||
/**多列嵌套展开key */
|
||||
arrayChildExpandKeys: any[];
|
||||
|
||||
/**多列记录数据 */
|
||||
data: Record<string, any>[];
|
||||
/**多列记录规则 */
|
||||
dataRule: Record<string, any>;
|
||||
};
|
||||
|
||||
/**多列列表状态 */
|
||||
let arrayState: ArrayStateType = reactive({
|
||||
size: 'small',
|
||||
columns: [],
|
||||
columnsDnd: [],
|
||||
columnsData: [],
|
||||
arrayChildExpandKeys: [],
|
||||
data: [],
|
||||
dataRule: {},
|
||||
});
|
||||
|
||||
/**多列表编辑 */
|
||||
function arrayEdit(rowIndex: Record<string, any>) {
|
||||
const item = arrayState.data.find((s: any) => s.key === rowIndex.value);
|
||||
if (!item) return;
|
||||
const from = arrayInitEdit(item, arrayState.dataRule);
|
||||
// 处理信息
|
||||
const row: Record<string, any> = {};
|
||||
for (const v of from.record) {
|
||||
if (Array.isArray(v.array)) {
|
||||
continue;
|
||||
}
|
||||
row[v.name] = Object.assign({}, v);
|
||||
}
|
||||
|
||||
// 特殊SMF-upfid选择
|
||||
if (neTypeSelect.value[0] === 'SMF' && Reflect.has(row, 'upfId')) {
|
||||
const v = row.upfId.value;
|
||||
if (typeof v === 'string') {
|
||||
if (v === '') {
|
||||
row.upfId.value = [];
|
||||
} else if (v.includes(';')) {
|
||||
row.upfId.value = v.split(';');
|
||||
} else if (v.includes(',')) {
|
||||
row.upfId.value = v.split(',');
|
||||
} else {
|
||||
row.upfId.value = [v];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modalState.from = row;
|
||||
modalState.type = 'arrayEdit';
|
||||
modalState.title = `${treeState.selectNode.paramDisplay} ${from.title}`;
|
||||
modalState.key = from.key;
|
||||
modalState.data = from.record.filter((v: any) => !Array.isArray(v.array));
|
||||
modalState.open = true;
|
||||
|
||||
// 关闭嵌套
|
||||
arrayState.arrayChildExpandKeys = [];
|
||||
}
|
||||
|
||||
/**多列表编辑关闭 */
|
||||
function arrayEditClose() {
|
||||
arrayState.arrayChildExpandKeys = [];
|
||||
fnModalCancel();
|
||||
}
|
||||
|
||||
/**多列表编辑确认 */
|
||||
function arrayEditOk(from: Record<string, any>) {
|
||||
const loc = `${from['index']['value']}`;
|
||||
|
||||
// 特殊SMF-upfid选择
|
||||
if (neTypeSelect.value[0] === 'SMF' && Reflect.has(from, 'upfId')) {
|
||||
const v = from.upfId.value;
|
||||
if (Array.isArray(v)) {
|
||||
from.upfId.value = v.join(';');
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历提取属性和值
|
||||
let data: Record<string, any> = {};
|
||||
for (const key in from) {
|
||||
// 子嵌套的不插入
|
||||
if (from[key]['array']) {
|
||||
continue;
|
||||
}
|
||||
// 检查规则
|
||||
const [ok, msg] = ruleVerification(from[key]);
|
||||
if (!ok) {
|
||||
message.warning({
|
||||
content: `${msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.updateItem', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
});
|
||||
}
|
||||
|
||||
/**多列表删除单行 */
|
||||
function arrayDelete(rowIndex: Record<string, any>) {
|
||||
const loc = `${rowIndex.value}`;
|
||||
const title = `${treeState.selectNode.paramDisplay} Index-${loc}`;
|
||||
|
||||
Modal.confirm({
|
||||
title: t('common.tipTitle'),
|
||||
content: t('views.ne.neConfig.delItemTip', {
|
||||
num: title,
|
||||
}),
|
||||
onOk() {
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc: loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.error({
|
||||
content: `${rejected.reason}`,
|
||||
duration: 2,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.delItemOk', {
|
||||
num: title,
|
||||
}),
|
||||
duration: 2,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**多列表新增单行 */
|
||||
function arrayAdd() {
|
||||
const from = arrayInitAdd(arrayState.data, arrayState.dataRule);
|
||||
|
||||
// 处理信息
|
||||
const row: Record<string, any> = {};
|
||||
for (const v of from.record) {
|
||||
if (Array.isArray(v.array)) {
|
||||
continue;
|
||||
}
|
||||
row[v.name] = Object.assign({}, v);
|
||||
}
|
||||
|
||||
// 特殊SMF-upfid选择
|
||||
if (neTypeSelect.value[0] === 'SMF' && Reflect.has(row, 'upfId')) {
|
||||
const v = row.upfId.value;
|
||||
if (typeof v === 'string') {
|
||||
if (v === '') {
|
||||
row.upfId.value = [];
|
||||
} else if (v.includes(';')) {
|
||||
row.upfId.value = v.split(';');
|
||||
} else if (v.includes(',')) {
|
||||
row.upfId.value = v.split(',');
|
||||
} else {
|
||||
row.upfId.value = [v];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modalState.from = row;
|
||||
modalState.type = 'arrayAdd';
|
||||
modalState.title = `${treeState.selectNode.paramDisplay} ${from.title}`;
|
||||
modalState.key = from.key;
|
||||
modalState.data = from.record.filter((v: any) => !Array.isArray(v.array));
|
||||
modalState.open = true;
|
||||
}
|
||||
|
||||
/**多列表新增单行确认 */
|
||||
function arrayAddOk(from: Record<string, any>) {
|
||||
// 特殊SMF-upfid选择
|
||||
if (neTypeSelect.value[0] === 'SMF' && Reflect.has(from, 'upfId')) {
|
||||
const v = from.upfId.value;
|
||||
if (Array.isArray(v)) {
|
||||
from.upfId.value = v.join(';');
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历提取属性和值
|
||||
let data: Record<string, any> = {};
|
||||
for (const key in from) {
|
||||
// 子嵌套的不插入
|
||||
if (from[key]['array']) {
|
||||
continue;
|
||||
}
|
||||
// 检查规则
|
||||
const [ok, msg] = ruleVerification(from[key]);
|
||||
if (!ok) {
|
||||
message.warning({
|
||||
content: `${msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc: `${from['index']['value']}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc: `${from['index']['value']}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.addItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.addItemOk', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
});
|
||||
}
|
||||
|
||||
/**多列表编辑行数据初始化 */
|
||||
function arrayInitEdit(data: Record<string, any>, dataRule: any) {
|
||||
const dataFrom = data.record;
|
||||
const ruleFrom = Object.assign({}, JSON.parse(JSON.stringify(dataRule)));
|
||||
for (const row of ruleFrom.record) {
|
||||
// 子嵌套的不初始
|
||||
if (row.array) {
|
||||
row.value = [];
|
||||
continue;
|
||||
}
|
||||
// 查找项的值
|
||||
const item = dataFrom.find((s: any) => s.name === row.name);
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
// 可选的
|
||||
row.optional = 'true';
|
||||
// 根据规则类型转值
|
||||
if (['enum', 'int'].includes(row.type)) {
|
||||
row.value = Number(item.value);
|
||||
} else if ('bool' === row.type) {
|
||||
row.value = Boolean(item.value);
|
||||
} else {
|
||||
row.value = item.value;
|
||||
}
|
||||
}
|
||||
ruleFrom.key = data.key;
|
||||
ruleFrom.title = data.title;
|
||||
return ruleFrom;
|
||||
}
|
||||
|
||||
/**多列表新增行数据初始化 */
|
||||
function arrayInitAdd(data: any[], dataRule: any) {
|
||||
// 有数据时取得最后的index
|
||||
let dataLastIndex = 0;
|
||||
if (data.length !== 0) {
|
||||
const lastFrom = Object.assign(
|
||||
{},
|
||||
JSON.parse(JSON.stringify(data.at(-1)))
|
||||
);
|
||||
if (lastFrom.record.length > 0) {
|
||||
dataLastIndex = parseInt(lastFrom.key);
|
||||
dataLastIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
const ruleFrom = Object.assign({}, JSON.parse(JSON.stringify(dataRule)));
|
||||
for (const row of ruleFrom.record) {
|
||||
// 子嵌套的不初始
|
||||
if (row.array) {
|
||||
row.value = [];
|
||||
continue;
|
||||
}
|
||||
// 可选的
|
||||
row.optional = 'true';
|
||||
// index值
|
||||
if (row.name === 'index') {
|
||||
let newIndex =
|
||||
dataLastIndex !== 0 ? dataLastIndex : parseInt(row.value);
|
||||
if (isNaN(newIndex)) {
|
||||
newIndex = 0;
|
||||
}
|
||||
row.value = newIndex;
|
||||
ruleFrom.key = newIndex;
|
||||
ruleFrom.title = `Index-${newIndex}`;
|
||||
continue;
|
||||
}
|
||||
// 根据规则类型转值
|
||||
if (['enum', 'int'].includes(row.type)) {
|
||||
row.value = Number(row.value);
|
||||
}
|
||||
if ('bool' === row.type) {
|
||||
row.value = Boolean(row.value);
|
||||
}
|
||||
|
||||
// 特殊SMF-upfid选择
|
||||
if (neTypeSelect.value[0] === 'SMF' && row.name === 'upfId') {
|
||||
const v = row.value;
|
||||
if (typeof v === 'string') {
|
||||
if (v === '') {
|
||||
row.value = [];
|
||||
} else if (v.includes(';')) {
|
||||
row.value = v.split(';');
|
||||
} else if (v.includes(',')) {
|
||||
row.value = v.split(',');
|
||||
} else {
|
||||
row.value = [v];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ruleFrom;
|
||||
}
|
||||
|
||||
// 监听表格字段列排序变化关闭展开
|
||||
watch(
|
||||
() => arrayState.columnsDnd,
|
||||
() => {
|
||||
arrayEditClose();
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
arrayState,
|
||||
arrayEdit,
|
||||
arrayEditClose,
|
||||
arrayEditOk,
|
||||
arrayDelete,
|
||||
arrayAdd,
|
||||
arrayAddOk,
|
||||
arrayInitEdit,
|
||||
arrayInitAdd,
|
||||
};
|
||||
}
|
||||
454
src/views/ne/neConfigHA/hooks/useConfigArrayChild.ts
Normal file
454
src/views/ne/neConfigHA/hooks/useConfigArrayChild.ts
Normal file
@@ -0,0 +1,454 @@
|
||||
import {
|
||||
addNeConfigData,
|
||||
editNeConfigData,
|
||||
delNeConfigData,
|
||||
} from '@/api/ne/neConfig';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { Modal, message } from 'ant-design-vue/es';
|
||||
import { SizeType } from 'ant-design-vue/es/config-provider';
|
||||
import { nextTick, reactive } from 'vue';
|
||||
|
||||
/**
|
||||
* 参数配置array类型的嵌套array
|
||||
* @param param 父级传入 { t, treeState, neTypeSelect, neIdSelect, fnActiveConfigNode, ruleVerification, modalState, arrayState, arrayInitEdit, arrayInitAdd, arrayEditClose}
|
||||
* @returns
|
||||
*/
|
||||
export default function useConfigArrayChild({
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
fnActiveConfigNode,
|
||||
ruleVerification,
|
||||
modalState,
|
||||
arrayState,
|
||||
arrayInitEdit,
|
||||
arrayInitAdd,
|
||||
arrayEditClose,
|
||||
}: any) {
|
||||
/**多列嵌套列表状态类型 */
|
||||
type ArrayChildStateType = {
|
||||
/**标题 */
|
||||
title: string;
|
||||
/**层级index */
|
||||
loc: string;
|
||||
/**紧凑型 */
|
||||
size: SizeType;
|
||||
/**多列嵌套记录字段 */
|
||||
columns: Record<string, any>[];
|
||||
/**表格字段列排序 */
|
||||
columnsDnd: Record<string, any>[];
|
||||
/**多列记录数据 */
|
||||
columnsData: Record<string, any>[];
|
||||
|
||||
/**多列嵌套记录数据 */
|
||||
data: Record<string, any>[];
|
||||
/**多列嵌套记录规则 */
|
||||
dataRule: Record<string, any>;
|
||||
};
|
||||
|
||||
/**多列嵌套表格状态 */
|
||||
let arrayChildState: ArrayChildStateType = reactive({
|
||||
title: '',
|
||||
loc: '',
|
||||
size: 'small',
|
||||
columns: [],
|
||||
columnsDnd: [],
|
||||
columnsData: [],
|
||||
data: [],
|
||||
dataRule: {},
|
||||
});
|
||||
|
||||
/**多列表展开嵌套行 */
|
||||
function arrayChildExpand(
|
||||
indexRow: Record<string, any>,
|
||||
row: Record<string, any>
|
||||
) {
|
||||
const loc = indexRow.value;
|
||||
if (arrayChildState.loc === `${loc}/${row.name}`) {
|
||||
arrayChildState.loc = '';
|
||||
arrayState.arrayChildExpandKeys = [];
|
||||
return;
|
||||
}
|
||||
arrayChildState.loc = '';
|
||||
arrayState.arrayChildExpandKeys = [];
|
||||
const from = Object.assign({}, JSON.parse(JSON.stringify(row)));
|
||||
// 无数据时
|
||||
if (!Array.isArray(from.value)) {
|
||||
from.value = [];
|
||||
}
|
||||
const dataArr = Object.freeze(from.value);
|
||||
const ruleArr = Object.freeze(from.array);
|
||||
|
||||
// 列表项数据
|
||||
const dataArray: Record<string, any>[] = [];
|
||||
for (const item of dataArr) {
|
||||
const index = item['index'];
|
||||
let record: Record<string, any>[] = [];
|
||||
for (const key of Object.keys(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(record);
|
||||
dataArray.push({ title: `Index-${index}`, key: index, record });
|
||||
}
|
||||
arrayChildState.data = dataArray;
|
||||
|
||||
// 无数据时,用于新增
|
||||
arrayChildState.dataRule = {
|
||||
title: `Index-0`,
|
||||
key: 0,
|
||||
record: ruleArr,
|
||||
};
|
||||
|
||||
// 列表数据
|
||||
const columnsData: Record<string, any>[] = [];
|
||||
for (const v of arrayChildState.data) {
|
||||
const row: Record<string, any> = {};
|
||||
for (const item of v.record) {
|
||||
row[item.name] = item;
|
||||
}
|
||||
columnsData.push(row);
|
||||
}
|
||||
arrayChildState.columnsData = columnsData;
|
||||
|
||||
// 列表字段
|
||||
const columns: Record<string, any>[] = [];
|
||||
for (const rule of arrayChildState.dataRule.record) {
|
||||
columns.push({
|
||||
title: rule.display,
|
||||
dataIndex: rule.name,
|
||||
align: 'left',
|
||||
resizable: true,
|
||||
width: 50,
|
||||
minWidth: 50,
|
||||
maxWidth: 250,
|
||||
});
|
||||
}
|
||||
columns.push({
|
||||
title: t('common.operate'),
|
||||
dataIndex: 'index',
|
||||
key: 'index',
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
width: 100,
|
||||
});
|
||||
arrayChildState.columns = columns;
|
||||
|
||||
nextTick(() => {
|
||||
// 设置展开key
|
||||
arrayState.arrayChildExpandKeys = [indexRow];
|
||||
// 层级标识
|
||||
arrayChildState.loc = `${loc}/${from['name']}`;
|
||||
// 设置展开列表标题
|
||||
arrayChildState.title = `${from['display']}`;
|
||||
});
|
||||
}
|
||||
|
||||
/**多列表嵌套行编辑 */
|
||||
function arrayChildEdit(rowIndex: Record<string, any>) {
|
||||
const item = arrayChildState.data.find(
|
||||
(s: any) => s.key === rowIndex.value
|
||||
);
|
||||
if (!item) return;
|
||||
const from = arrayInitEdit(item, arrayChildState.dataRule);
|
||||
// 处理信息
|
||||
const row: Record<string, any> = {};
|
||||
for (const v of from.record) {
|
||||
if (Array.isArray(v.array)) {
|
||||
continue;
|
||||
}
|
||||
row[v.name] = Object.assign({}, v);
|
||||
}
|
||||
|
||||
modalState.from = row;
|
||||
modalState.type = 'arrayChildEdit';
|
||||
modalState.title = `${arrayChildState.title} ${from.title}`;
|
||||
modalState.key = from.key;
|
||||
modalState.data = from.record.filter((v: any) => !Array.isArray(v.array));
|
||||
modalState.open = true;
|
||||
}
|
||||
|
||||
/**多列表嵌套行编辑确认 */
|
||||
function arrayChildEditOk(from: Record<string, any>) {
|
||||
const loc = `${arrayChildState.loc}/${from['index']['value']}`;
|
||||
|
||||
let data: Record<string, any> = {};
|
||||
for (const key in from) {
|
||||
// 子嵌套的不插入
|
||||
if (from[key]['array']) {
|
||||
continue;
|
||||
}
|
||||
// 检查规则
|
||||
const [ok, msg] = ruleVerification(from[key]);
|
||||
if (!ok) {
|
||||
message.warning({
|
||||
content: `${msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.updateItem', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
});
|
||||
}
|
||||
|
||||
/**多列表嵌套行删除单行 */
|
||||
function arrayChildDelete(rowIndex: Record<string, any>) {
|
||||
const index = rowIndex.value;
|
||||
const loc = `${arrayChildState.loc}/${index}`;
|
||||
const title = `${arrayChildState.title} Index-${index}`;
|
||||
|
||||
Modal.confirm({
|
||||
title: t('common.tipTitle'),
|
||||
content: t('views.ne.neConfig.delItemTip', {
|
||||
num: title,
|
||||
}),
|
||||
onOk() {
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
delNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.error({
|
||||
content: `${rejected.reason}`,
|
||||
duration: 2,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.delItemOk', {
|
||||
num: title,
|
||||
}),
|
||||
duration: 2,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**多列表嵌套行新增单行 */
|
||||
function arrayChildAdd() {
|
||||
const from = arrayInitAdd(arrayChildState.data, arrayChildState.dataRule);
|
||||
// 处理信息
|
||||
const row: Record<string, any> = {};
|
||||
for (const v of from.record) {
|
||||
if (Array.isArray(v.array)) {
|
||||
continue;
|
||||
}
|
||||
row[v.name] = Object.assign({}, v);
|
||||
}
|
||||
|
||||
modalState.from = row;
|
||||
modalState.type = 'arrayChildAdd';
|
||||
modalState.title = `${arrayChildState.title} ${from.title}`;
|
||||
modalState.key = from.key;
|
||||
modalState.data = from.record.filter((v: any) => !Array.isArray(v.array));
|
||||
modalState.open = true;
|
||||
}
|
||||
|
||||
/**多列表新增单行确认 */
|
||||
function arrayChildAddOk(from: Record<string, any>) {
|
||||
const loc = `${arrayChildState.loc}/${from['index']['value']}`;
|
||||
|
||||
let data: Record<string, any> = {};
|
||||
for (const key in from) {
|
||||
// 子嵌套的不插入
|
||||
if (from[key]['array']) {
|
||||
continue;
|
||||
}
|
||||
// 检查规则
|
||||
const [ok, msg] = ruleVerification(from[key]);
|
||||
if (!ok) {
|
||||
message.warning({
|
||||
content: `${msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
data[key] = from[key]['value'];
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
addNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: data,
|
||||
loc,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
arrayEditClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.addItemErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.addItemOk', {
|
||||
num: modalState.title,
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
fnActiveConfigNode('#');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
arrayEditClose();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
arrayChildState,
|
||||
arrayChildExpand,
|
||||
arrayChildEdit,
|
||||
arrayChildEditOk,
|
||||
arrayChildDelete,
|
||||
arrayChildAdd,
|
||||
arrayChildAddOk,
|
||||
};
|
||||
}
|
||||
187
src/views/ne/neConfigHA/hooks/useConfigList.ts
Normal file
187
src/views/ne/neConfigHA/hooks/useConfigList.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
import { editNeConfigData } from '@/api/ne/neConfig';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { SizeType } from 'ant-design-vue/es/config-provider';
|
||||
import { message } from 'ant-design-vue/es';
|
||||
import { reactive, toRaw } from 'vue';
|
||||
|
||||
/**
|
||||
* list类型参数处理
|
||||
* @param param 父级传入 {t, treeState, neTypeSelect, neIdSelect, ruleVerification}
|
||||
* @returns
|
||||
*/
|
||||
export default function useConfigList({
|
||||
t,
|
||||
treeState,
|
||||
neTypeSelect,
|
||||
neIdSelect,
|
||||
ruleVerification,
|
||||
}: any) {
|
||||
/**单列表状态类型 */
|
||||
type ListStateType = {
|
||||
/**紧凑型 */
|
||||
size: SizeType;
|
||||
/**单列记录字段 */
|
||||
columns: Record<string, any>[];
|
||||
/**单列记录数据 */
|
||||
data: Record<string, any>[];
|
||||
/**编辑行记录 */
|
||||
editRecord: Record<string, any>;
|
||||
/**确认提交等待 */
|
||||
confirmLoading: boolean;
|
||||
};
|
||||
|
||||
/**单列表状态 */
|
||||
let listState: ListStateType = reactive({
|
||||
size: 'small',
|
||||
columns: [
|
||||
{
|
||||
title: 'Key',
|
||||
dataIndex: 'display',
|
||||
align: 'left',
|
||||
width: '30%',
|
||||
},
|
||||
{
|
||||
title: 'Value',
|
||||
dataIndex: 'value',
|
||||
align: 'left',
|
||||
width: '70%',
|
||||
},
|
||||
],
|
||||
data: [],
|
||||
confirmLoading: false,
|
||||
editRecord: {},
|
||||
});
|
||||
|
||||
/**单列表编辑 */
|
||||
function listEdit(row: Record<string, any>) {
|
||||
if (
|
||||
listState.confirmLoading ||
|
||||
['read-only', 'read', 'ro'].includes(row.access)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
listState.editRecord = Object.assign({}, row);
|
||||
}
|
||||
|
||||
/**单列表编辑关闭 */
|
||||
function listEditClose() {
|
||||
listState.confirmLoading = false;
|
||||
listState.editRecord = {};
|
||||
}
|
||||
|
||||
/**单列表编辑确认 */
|
||||
function listEditOk() {
|
||||
if (listState.confirmLoading) return;
|
||||
const from = toRaw(listState.editRecord);
|
||||
// 检查规则
|
||||
const [ok, msg] = ruleVerification(from);
|
||||
if (!ok) {
|
||||
message.warning({
|
||||
content: `${msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 请求
|
||||
const reqArr = [];
|
||||
if (neTypeSelect.value[1].startsWith('SYNC')) {
|
||||
for (const neId of neIdSelect.value) {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neId,
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: {
|
||||
[from['name']]: from['value'],
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
reqArr.push(
|
||||
editNeConfigData({
|
||||
neType: neTypeSelect.value[0],
|
||||
neId: neTypeSelect.value[1],
|
||||
paramName: treeState.selectNode.paramName,
|
||||
paramData: {
|
||||
[from['name']]: from['value'],
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
// 无请求提示
|
||||
if (reqArr.length === 0) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.neIdSyncPleace'),
|
||||
duration: 3,
|
||||
});
|
||||
listState.confirmLoading = false;
|
||||
listState.editRecord = {};
|
||||
return;
|
||||
}
|
||||
|
||||
listState.confirmLoading = true;
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.allSettled(reqArr)
|
||||
.then(resArr => {
|
||||
const rejected = resArr.find(res => res.status === 'rejected');
|
||||
if (rejected) {
|
||||
message.warning({
|
||||
content: t('views.ne.neConfig.updateValueErr'),
|
||||
duration: 3,
|
||||
});
|
||||
} else {
|
||||
message.success({
|
||||
content: t('views.ne.neConfig.updateValue', {
|
||||
num: from['display'],
|
||||
}),
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
const fulfilled = resArr.find(res => res.status === 'fulfilled');
|
||||
if (fulfilled) {
|
||||
// 改变表格数据
|
||||
const item = listState.data.find(
|
||||
(item: Record<string, any>) => from['name'] === item['name']
|
||||
);
|
||||
if (item) {
|
||||
Object.assign(item, listState.editRecord);
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
listState.confirmLoading = false;
|
||||
listState.editRecord = {};
|
||||
});
|
||||
}
|
||||
|
||||
/**表格分页器参数 */
|
||||
let tablePagination = reactive({
|
||||
/**当前页数 */
|
||||
current: 1,
|
||||
/**每页条数 */
|
||||
pageSize: 10,
|
||||
/**默认的每页条数 */
|
||||
defaultPageSize: 10,
|
||||
/**指定每页可以显示多少条 */
|
||||
pageSizeOptions: ['10', '20', '50', '100'],
|
||||
/**只有一页时是否隐藏分页器 */
|
||||
hideOnSinglePage: true,
|
||||
/**是否可以快速跳转至某页 */
|
||||
showQuickJumper: true,
|
||||
/**是否可以改变 pageSize */
|
||||
showSizeChanger: true,
|
||||
/**数据总数 */
|
||||
total: 0,
|
||||
showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
|
||||
onChange: (page: number, pageSize: number) => {
|
||||
tablePagination.current = page;
|
||||
tablePagination.pageSize = pageSize;
|
||||
},
|
||||
});
|
||||
|
||||
return { tablePagination, listState, listEdit, listEditClose, listEditOk };
|
||||
}
|
||||
192
src/views/ne/neConfigHA/hooks/useOptions.ts
Normal file
192
src/views/ne/neConfigHA/hooks/useOptions.ts
Normal file
@@ -0,0 +1,192 @@
|
||||
import { getNeConfigData } from '@/api/ne/neConfig';
|
||||
import { regExpIPv4, regExpIPv6, validURL } from '@/utils/regular-utils';
|
||||
import { ref } from 'vue';
|
||||
|
||||
/**
|
||||
* 参数公共函数
|
||||
* @param param 父级传入 {t}
|
||||
* @returns
|
||||
*/
|
||||
export default function useOptions({ t }: any) {
|
||||
/**规则校验 */
|
||||
function ruleVerification(row: Record<string, any>): (string | boolean)[] {
|
||||
let result = [true, ''];
|
||||
const type = row.type;
|
||||
const value = row.value;
|
||||
const filter = row.filter;
|
||||
const display = row.display;
|
||||
|
||||
// 子嵌套的不检查
|
||||
if (row.array) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 可选的同时没有值不检查
|
||||
if (row.optional === 'true' && !value) {
|
||||
return result;
|
||||
}
|
||||
switch (type) {
|
||||
case 'int':
|
||||
// filter: "0~128"
|
||||
|
||||
if (filter && filter.indexOf('~') !== -1) {
|
||||
const filterArr = filter.split('~');
|
||||
const minInt = parseInt(filterArr[0]);
|
||||
const maxInt = parseInt(filterArr[1]);
|
||||
const valueInt = parseInt(value);
|
||||
if (valueInt < minInt || valueInt > maxInt) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireInt', {
|
||||
display,
|
||||
filter,
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'ipv4':
|
||||
if (!regExpIPv4.test(value)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireIpv4', { display }),
|
||||
];
|
||||
}
|
||||
break;
|
||||
case 'ipv6':
|
||||
if (!regExpIPv6.test(value)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireIpv6', { display }),
|
||||
];
|
||||
}
|
||||
break;
|
||||
case 'enum':
|
||||
if (filter && filter.indexOf('{') === 1) {
|
||||
let filterJson: Record<string, any> = {};
|
||||
try {
|
||||
filterJson = JSON.parse(filter); //string---json
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (!Object.keys(filterJson).includes(`${value}`)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireEnum', { display }),
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'bool':
|
||||
// filter: '{"0":"false", "1":"true"}'
|
||||
|
||||
if (filter && filter.indexOf('{') === 1) {
|
||||
let filterJson: Record<string, any> = {};
|
||||
try {
|
||||
filterJson = JSON.parse(filter); //string---json
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (!Object.values(filterJson).includes(`${value}`)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireBool', { display }),
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
// filter: "0~128"
|
||||
|
||||
// 字符串长度判断
|
||||
if (filter && filter.indexOf('~') !== -1) {
|
||||
try {
|
||||
const filterArr = filter.split('~');
|
||||
let rule = new RegExp(
|
||||
'^\\S{' + filterArr[0] + ',' + filterArr[1] + '}$'
|
||||
);
|
||||
if (!rule.test(value)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireString', {
|
||||
display,
|
||||
}),
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
// 字符串http判断
|
||||
if (value.startsWith('http')) {
|
||||
try {
|
||||
if (!validURL(value)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireString', {
|
||||
display,
|
||||
}),
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'regex':
|
||||
// filter: "^[0-9]{3}$"
|
||||
|
||||
if (filter) {
|
||||
try {
|
||||
let regex = new RegExp(filter);
|
||||
if (!regex.test(value)) {
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireString', {
|
||||
display,
|
||||
}),
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return [
|
||||
false,
|
||||
t('views.ne.neConfig.requireUn', { display }),
|
||||
];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**upfId可选择 */
|
||||
const smfByUPFIdOptions = ref<{ value: string; label: string }[]>([]);
|
||||
/**加载smf配置的upfId */
|
||||
function smfByUPFIdLoadData(neId: string) {
|
||||
getNeConfigData({
|
||||
neType: 'SMF',
|
||||
neId: neId,
|
||||
paramName: 'upfConfig',
|
||||
}).then(res => {
|
||||
smfByUPFIdOptions.value = [];
|
||||
for (const s of res.data) {
|
||||
smfByUPFIdOptions.value.push({
|
||||
value: s.id,
|
||||
label: s.id,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
ruleVerification,
|
||||
smfByUPFIdLoadData,
|
||||
smfByUPFIdOptions,
|
||||
};
|
||||
}
|
||||
1143
src/views/ne/neConfigHA/index.vue
Normal file
1143
src/views/ne/neConfigHA/index.vue
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user