feat:删除remark和smdata的校验

This commit is contained in:
zhongzm
2025-04-11 16:42:41 +08:00
parent 58919ad4d4
commit b1bfb7a915

View File

@@ -124,13 +124,6 @@ let tableColumns = ref<ColumnsType>([
sorter: true,
width: 100,
},
{
title: 'TAG',
dataIndex: 'tag',
align: 'center',
width: 150,
key: 'tag'
},
{
title: 'TenantID',
dataIndex: 'tenantID',
@@ -150,6 +143,13 @@ let tableColumns = ref<ColumnsType>([
align: 'center',
width: 150,
},
{
title: 'TAG',
dataIndex: 'tag',
align: 'center',
width: 150,
key: 'tag'
},
{
title: t('common.operate'),
key: 'imsi',
@@ -241,7 +241,6 @@ let modalState: ModalStateType = reactive({
tag: '0',
vni: '',
num: 1,
remark: '',
},
BatchDelForm: {
num: 1,
@@ -304,262 +303,17 @@ const modalStateFromOption = reactive({
],
});
//新增时初始SM Data
const bigRows = ref<any[]>([
{
id: 0,
sst: '',
sd: '',
smallRows: [
{
id: 0,
dnn: '',
smStaticIp: '',
msIp: '',
},
{
id: 1,
dnn: 'ims',
smStaticIp: '',
msIp: '',
},
],
},
]);
//小数组的index
let smallRowIndexCounter = 0;
/**
* 针对修改框的截取每位数值
* @param num 二进制值: 10001 n:长度有几位
*/
function PrefixZero(num: any, n: any) {
return (Array(n).join('0') + num).slice(-n);
}
/**
* 对话框弹出显示为 批量新增,批量删除
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByBatch() {
modalStateBatchDelFrom.resetFields(); //重置表单
modalState.title =
t('views.neUser.sub.batchDelText') + t('views.neUser.sub.subInfo');
modalState.openByBatchDel = true;
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByAdd() {
modalStateFrom.resetFields();
modalState.title = t('common.addText') + t('views.neUser.sub.subInfo');
modalState.openByAdd = true;
}
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
num: [
{
required: true,
message: t('views.neUser.sub.numAdd') + t('common.unableNull'),
},
],
imsi: [
{
required: computed(() => modalState.from.tag === '1'),
message: 'IMSI' + t('common.unableNull')
},
{ min: 15, max: 15, message: t('views.neUser.auth.imsiConfirm') },
],
msisdn: [
{ required: true, message: 'MSISDN' + t('common.unableNull') },
],
tag: [
{ required: true, message: 'TAG' + t('common.unableNull') },
],
vni: [
{ required: true, message: 'VNI' + t('common.unableNull') },
],
})
);
/**
* 封装为SM Data
*/
function transformData(data: any) {
let transformedData = data.map((item: any) => {
if (!item.sst || !item.smallRows.every((smallRow: any) => smallRow.dnn)) {
message.error({
content: `${t('views.neUser.sub.smDataArrTip')}`,
duration: 3,
});
throw new Error('sst, sd, and all dnn are required fields');
}
let sstSd = item.sd
? item.sst + '-' + item.sd.padStart(6, '0')
: item.sst + '-';
let smallRowData = item.smallRows
.map((smallRow: any) => {
let parts = [smallRow.dnn];
if (smallRow.smStaticIp) {
parts.push(smallRow.smStaticIp);
}
if (smallRow.msIp) {
parts.push(smallRow.msIp);
}
return parts.join('-');
})
.join('&');
return sstSd + '&' + smallRowData;
});
return transformedData;
}
/**
* 拆解SM Data成表单数据
*/
function transformFormData(data: any) {
let allData = data ? data.split(';') : [];
let bigIDFlag = 0;
let smallIDFlag = 0;
let transformedData = allData.map((item: any) => {
let json: any = {
id: bigIDFlag++,
sst: item.split('&')[0].split('-')[0],
sd: item.split('&')[0].split('-')[1]
? item.split('&')[0].split('-')[1]
: '',
smallRows: [],
};
item
.split('&')
.slice(1)
.forEach((single: any) => {
let smallRowJson: any = {
id: smallIDFlag++,
dnn: single.split('-')[0],
smStaticIp: '',
msIp: '',
};
let smStaticIpArr: any = [];
single
.split('-')
.slice(1)
.forEach((dnnParts: any) => {
if (dnnParts.includes('/') && dnnParts.includes(':')) {
//IPV6 既有/ 又有:
smStaticIpArr.push(dnnParts);
}
if (!dnnParts.includes('/') && !dnnParts.includes(':')) {
const pattern = /^(\d{1,3}\.){3}\d{1,3}$/;
if (pattern.test(dnnParts)) {
// 验证数值范围
const isValid = dnnParts.split('.').every((num: any) => {
const n = parseInt(num, 10);
return n >= 0 && n <= 255;
});
// 只有当验证通过时才添加 IP
if (isValid) {
smStaticIpArr.push(dnnParts);
}
} else {
//无/ 无:也有可能为dnn的字符串
smallRowJson.dnn += '-' + dnnParts;
}
}
if (dnnParts.includes('/') && !dnnParts.includes(':')) {
//msIp 只有/ 没有:
smallRowJson.msIp = dnnParts;
}
});
smallRowJson.smStaticIp = smStaticIpArr.join('-');
json.smallRows.push(smallRowJson);
});
return json;
});
if (transformedData.length > 0) {
bigRows.value = transformedData;
} else {
bigRows.value = [
{
id: 0,
sst: '',
sd: '',
smallRows: [
{
id: 0,
dnn: '',
smStaticIp: '',
msIp: '',
},
{
id: 1,
dnn: 'ims',
smStaticIp: '',
msIp: '',
},
],
},
];
}
}
/**
* 对话框弹出确认执行函数
* 进行表达规则校验
*/
function fnModalOk() {
const from = Object.assign({}, toRaw(modalState.from));
try {
from.smData = transformData(bigRows.value).join(';');
} catch (error: any) {
console.error(error.message);
return false;
}
modalStateFrom
.validate()
.then(e => {
modalState.confirmLoading = true;
let ardArr = [0, 0, 0, 0, 0, 0, 0, 0];
let hplmnArr = [0, 0, 0, 0, 0, 0, 0, 0];
let odbArr = [0, 0, 0, 0, 0, 0, 0, 0, 0];
from.ard.forEach((item: any) => {
ardArr[item] = 1;
});
from.hplmnOdb.forEach((item: any) => {
hplmnArr[item] = 1;
});
from.epsOdb.forEach((item: any) => {
odbArr[item] = 1;
});
from.epsOdb = '' + parseInt(odbArr.join(''), 2);
from.hplmnOdb = '' + parseInt(hplmnArr.join(''), 2);
from.ard = '' + parseInt(ardArr.join(''), 2);
// 4G APN Context List
from.apnContext = from.apnContext
.map((item: number) => `${item}`.padStart(2, '0'))
.join('');
from.activeTime = `${from.activeTime}`;
from.rfspIndex = `${from.rfspIndex}`;
from.regTimer = `${from.regTimer}`;
from.ueUsageType = `${from.ueUsageType}`;
from.neId = queryParams.neId || '-';
const result = from.num === 1
? addIMSSub(from)//单条新增
@@ -614,60 +368,6 @@ function fnModalOk() {
});
}
/**对话框内批量添加表单属性和校验规则 */
const modalStateBatchDelFrom = Form.useForm(
modalState.BatchDelForm,
reactive({
num: [
{
required: true,
message: t('views.neUser.sub.numDel') + t('common.unableNull'),
},
],
imsi: [{ required: true, message: 'IMSI' + t('common.unableNull') }],
})
);
/**
* 对话框弹出 批量删除确认执行函数
* 进行表达规则校验
*/
function fnBatchDelModalOk() {
modalStateBatchDelFrom
.validate()
.then(e => {
modalState.confirmLoading = true;
const from = toRaw(modalState.BatchDelForm);
const neId = queryParams.neId || '-';
batchDelIMSSub(neId, from.imsi, from.num).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
const timerS = Math.ceil(+from.num / 1500) + 1;
notification.success({
message: modalState.title,
description: t('common.operateOk'),
duration: timerS,
});
setTimeout(() => {
modalState.openByBatchDel = false;
modalState.confirmLoading = false;
modalStateBatchDelFrom.resetFields();
fnGetList(1);
}, timerS * 1000);
} else {
modalState.confirmLoading = false;
notification.error({
message: modalState.title,
description: res.msg,
duration: 3,
});
}
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
/**
* 对话框弹出关闭执行函数
* 进行表达规则校验
@@ -675,38 +375,36 @@ function fnBatchDelModalOk() {
function fnModalCancel() {
modalState.openByAdd = false;
modalStateFrom.resetFields();
bigRows.value = [
{
id: 0,
sst: '',
sd: '',
smallRows: [
{
id: 0,
dnn: '',
smStaticIp: '',
msIp: '',
},
{
id: 1,
dnn: 'ims',
smStaticIp: '',
msIp: '',
},
],
},
];
smallRowIndexCounter = 0;
}
/**
* 批量删除对话框弹出关闭执行函数
* 进行表达规则校验
*/
function fnBatchDelModalCancel() {
modalState.openByBatchDel = false;
modalStateBatchDelFrom.resetFields();
}
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
num: [
{
required: true,
message: t('views.neUser.sub.numAdd') + t('common.unableNull'),
},
],
imsi: [
{
required: computed(() => modalState.from.tag === '1'),
message: 'IMSI' + t('common.unableNull')
},
{ min: 15, max: 15, message: t('views.neUser.auth.imsiConfirm') },
],
msisdn: [
{ required: true, message: 'MSISDN' + t('common.unableNull') },
],
tag: [
{ required: true, message: 'TAG' + t('common.unableNull') },
],
vni: [
{ required: true, message: 'VNI' + t('common.unableNull') },
],
})
);
/**
* UDM签约用户删除
@@ -1014,41 +712,6 @@ function fnModalUploadImportUpload(file: File) {
});
}
function addSmallRow(bigIndex: any) {
const newSmallRow = {
id: ++smallRowIndexCounter,
dnn: '',
smStaticIp: '',
msIp: '',
};
bigRows.value[bigIndex].smallRows.push(newSmallRow);
}
function addBigRow() {
const newBigRow = {
id: bigRows.value.length,
sst: '',
sd: '',
smallRows: [
{
id: 0,
dnn: '',
smStaticIp: '',
msIp: '',
},
],
};
bigRows.value.push(newBigRow);
}
function delDNN(sonIndex: any, bigIndex: any) {
bigRows.value[bigIndex].smallRows.splice(sonIndex, 1);
}
function delBigRow(bigIndex: any) {
bigRows.value.splice(bigIndex, 1);
}
function fnTenantNameFocus() {
Promise.allSettled([listTenant({ parentId: 0 })]).then(resArr => {
if (resArr[0].status === 'fulfilled') {
@@ -1071,6 +734,104 @@ function fnTenantNameFocus() {
});
}
/**
* 对话框弹出显示为 新增
*/
function fnModalVisibleByAdd() {
modalState.openByAdd = true;
modalState.title = t('common.addText') + t('views.neUser.sub.subInfo');
modalState.from = {
imsi: '',
msisdn: '',
tag: '0',
vni: '',
num: 1,
};
}
/**
* 对话框弹出显示为 批量删除
*/
function fnModalVisibleByBatch() {
modalState.openByBatchDel = true;
modalState.title = t('views.neUser.auth.batchDelText');
modalState.BatchDelForm = {
num: 1,
imsi: '',
};
}
/**
* 批量删除对话框确认
*/
function fnBatchDelModalOk() {
modalStateBatchDelFrom
.validate()
.then(() => {
modalState.confirmLoading = true;
const hide = message.loading(t('common.loading'), 0);
const neId = queryParams.neId;
if (!neId) return;
batchDelIMSSub(neId, modalState.BatchDelForm.imsi, modalState.BatchDelForm.num)
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
const timerS = Math.max(
Math.ceil(modalState.BatchDelForm.num / 500),
`${modalState.BatchDelForm.num}`.length * 5
);
notification.success({
message: modalState.title,
description: t('common.operateOk'),
duration: timerS,
});
setTimeout(() => {
fnGetList(1);
}, timerS * 1000);
} else {
notification.error({
message: modalState.title,
description: res.msg,
duration: 3,
});
}
})
.finally(() => {
hide();
fnBatchDelModalCancel();
modalState.confirmLoading = false;
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
/**
* 批量删除对话框取消
*/
function fnBatchDelModalCancel() {
modalState.openByBatchDel = false;
modalStateBatchDelFrom.resetFields();
}
/**批量删除对话框内表单属性和校验规则 */
const modalStateBatchDelFrom = Form.useForm(
modalState.BatchDelForm,
reactive({
imsi: [
{ required: true, message: 'IMSI' + t('common.unableNull') },
{ min: 15, max: 15, message: t('views.neUser.auth.imsiConfirm') },
],
num: [
{
required: true,
message: t('views.neUser.sub.numDel') + t('common.unableNull'),
},
],
})
);
onMounted(() => {
// 获取网元网元列表
useNeInfoStore()
@@ -1152,6 +913,18 @@ onMounted(() => {
:placeholder="t('common.inputPlease')"></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item
:label="t('views.neUser.sub.tenantName')"
name="tenantName"
>
<a-auto-complete
v-model:value="queryParams.tenantName"
:options="modalStateFromOption.tenantName"
@focus="fnTenantNameFocus"
></a-auto-complete>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item label="TAG" name="tag">
<a-select
@@ -1165,18 +938,6 @@ onMounted(() => {
/>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item
:label="t('views.neUser.sub.tenantName')"
name="tenantName"
>
<a-auto-complete
v-model:value="queryParams.tenantName"
:options="modalStateFromOption.tenantName"
@focus="fnTenantNameFocus"
></a-auto-complete>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item>
<a-space :size="8">
@@ -1530,20 +1291,6 @@ onMounted(() => {
</a-form-item>
</a-col>
</a-row>
<a-form-item
:label="t('common.remark')"
:label-col="{ span: 3 }"
:label-wrap="true"
>
<a-textarea
v-model:value="modalState.from.remark"
:auto-size="{ minRows: 1, maxRows: 6 }"
:maxlength="500"
:show-count="true"
:placeholder="t('common.inputPlease')"
/>
</a-form-item>
</a-form>
</ProModal>
<!-- 批量删除-->