feat: 网元软件包支持携带依赖进行记录
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, onMounted, toRaw, watch } from 'vue';
|
||||
import { message, Form, Upload, notification } from 'ant-design-vue/lib';
|
||||
import { message, Upload, notification } from 'ant-design-vue/lib';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { NE_TYPE_LIST } from '@/constants/ne-constants';
|
||||
import { NE_TYPE_LIST, NE_EXPAND_LIST } from '@/constants/ne-constants';
|
||||
import { UploadRequestOption } from 'ant-design-vue/lib/vc-upload/interface';
|
||||
import { addNeSoftware } from '@/api/ne/neSoftware';
|
||||
import { FileType } from 'ant-design-vue/lib/upload/interface';
|
||||
@@ -21,6 +21,9 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
|
||||
/**网元支持 */
|
||||
const NE_TYPE_EXP = NE_EXPAND_LIST.concat(NE_TYPE_LIST);
|
||||
|
||||
/**对话框对象信息状态类型 */
|
||||
type ModalStateType = {
|
||||
/**新增框或修改框是否显示 */
|
||||
@@ -32,8 +35,6 @@ type ModalStateType = {
|
||||
neType: string;
|
||||
name: string;
|
||||
path: string;
|
||||
status: 'done' | 'uploading' | 'error';
|
||||
uid: string;
|
||||
version: string;
|
||||
description: string;
|
||||
}[];
|
||||
@@ -41,6 +42,8 @@ type ModalStateType = {
|
||||
confirmLoading: boolean;
|
||||
/**上传文件 */
|
||||
uploadFiles: any[];
|
||||
/**上传文件-依赖包 */
|
||||
uploadFilesDep: any[];
|
||||
};
|
||||
|
||||
/**对话框对象信息状态 */
|
||||
@@ -50,13 +53,14 @@ let modalState: ModalStateType = reactive({
|
||||
from: [],
|
||||
confirmLoading: false,
|
||||
uploadFiles: [],
|
||||
uploadFilesDep: [],
|
||||
});
|
||||
|
||||
/**
|
||||
* 对话框弹出确认执行函数
|
||||
* 进行表达规则校验
|
||||
*/
|
||||
function fnModalOk() {
|
||||
async function fnModalOk() {
|
||||
if (modalState.confirmLoading) return;
|
||||
if (modalState.uploadFiles.length < 1) {
|
||||
message.warning({
|
||||
@@ -68,39 +72,76 @@ function fnModalOk() {
|
||||
// 处理上传文件过滤
|
||||
const uploadFiles = toRaw(modalState.uploadFiles);
|
||||
const from = toRaw(modalState.from);
|
||||
const softwareData: any[] = [];
|
||||
for (const hasFile of uploadFiles) {
|
||||
for (const itemFile of from) {
|
||||
if (itemFile.uid === hasFile.uid) {
|
||||
softwareData.push(itemFile);
|
||||
}
|
||||
const expandFile: Record<string, string> = {};
|
||||
for (const item of uploadFiles) {
|
||||
if (item.status !== 'done' || !item.path) continue;
|
||||
const neSoftware = from.find(s => s.name === item.name);
|
||||
if (neSoftware && NE_TYPE_LIST.includes(neSoftware.neType)) {
|
||||
neSoftware.path = item.path;
|
||||
}
|
||||
if (neSoftware && NE_EXPAND_LIST.includes(neSoftware.neType)) {
|
||||
expandFile[neSoftware.neType] = item.path;
|
||||
}
|
||||
}
|
||||
// 新增软件文件
|
||||
modalState.confirmLoading = true;
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
Promise.all(softwareData.map(s => addNeSoftware(s)))
|
||||
.then(resArr => {
|
||||
const rows: any[] = [];
|
||||
resArr.forEach((res, i) => {
|
||||
const info = softwareData[i];
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
rows.push(info);
|
||||
} else {
|
||||
message.error({
|
||||
content: `${info.neType} ${res.msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
|
||||
// IMS拼接拓展包
|
||||
const ims = from.find(s => s.neType === 'IMS');
|
||||
if (ims) {
|
||||
const pkgArr = [];
|
||||
if (expandFile['ADB']) {
|
||||
pkgArr.push(expandFile['ADB']);
|
||||
}
|
||||
if (expandFile['RTPROXY']) {
|
||||
pkgArr.push(expandFile['RTPROXY']);
|
||||
}
|
||||
if (expandFile['MF']) {
|
||||
pkgArr.push(expandFile['MF']);
|
||||
}
|
||||
pkgArr.push(ims.path);
|
||||
ims.path = pkgArr.join(',');
|
||||
}
|
||||
// UDM拼接拓展包
|
||||
const udm = from.find(s => s.neType === 'UDM');
|
||||
if (udm && expandFile['ADB']) {
|
||||
udm.path = [expandFile['ADB'], udm.path].join(',');
|
||||
}
|
||||
|
||||
// 安装带依赖包-指定网元时
|
||||
if (props.neType && modalState.uploadFilesDep.length > 0) {
|
||||
const neInfo = from.find(s => s.neType === props.neType);
|
||||
if (neInfo) {
|
||||
const depFiles = [];
|
||||
for (const depFile of modalState.uploadFilesDep) {
|
||||
if (depFile.status === 'done' && depFile.path) {
|
||||
depFiles.push(depFile.path);
|
||||
}
|
||||
});
|
||||
Object.assign(modalState.from, rows);
|
||||
emit('ok', rows);
|
||||
fnModalCancel();
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
modalState.confirmLoading = false;
|
||||
});
|
||||
}
|
||||
depFiles.push(neInfo.path);
|
||||
neInfo.path = depFiles.join(',');
|
||||
}
|
||||
}
|
||||
|
||||
// 开始添加到软件包数据
|
||||
const rows: any[] = [];
|
||||
modalState.confirmLoading = true;
|
||||
for (const item of from.filter(s => NE_TYPE_LIST.includes(s.neType))) {
|
||||
try {
|
||||
const res = await addNeSoftware(item);
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
rows.push(item);
|
||||
} else {
|
||||
message.error({
|
||||
content: `${item.neType} ${res.msg}`,
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
emit('ok', rows);
|
||||
fnModalCancel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +153,7 @@ function fnModalCancel() {
|
||||
modalState.confirmLoading = false;
|
||||
modalState.from = [];
|
||||
modalState.uploadFiles = [];
|
||||
modalState.uploadFilesDep = [];
|
||||
emit('cancel');
|
||||
emit('update:visible', false);
|
||||
}
|
||||
@@ -137,7 +179,7 @@ function fnBeforeUploadFile(file: FileType) {
|
||||
if (neTypeIndex !== -1) {
|
||||
neType = fileName.substring(0, neTypeIndex).toUpperCase();
|
||||
}
|
||||
if (!NE_TYPE_LIST.includes(neType)) {
|
||||
if (!NE_TYPE_EXP.includes(neType)) {
|
||||
notification.warning({
|
||||
message: fileName,
|
||||
description: t('views.ne.neSoftware.fileCheckType'),
|
||||
@@ -182,9 +224,7 @@ function fnBeforeUploadFile(file: FileType) {
|
||||
name: fileName,
|
||||
neType: neType,
|
||||
version: version,
|
||||
uid: file.uid,
|
||||
status: 'uploading',
|
||||
path: '',
|
||||
path: '', // 上传完成后提交注入
|
||||
description: '',
|
||||
});
|
||||
return true;
|
||||
@@ -192,29 +232,105 @@ function fnBeforeUploadFile(file: FileType) {
|
||||
|
||||
/**表单上传文件 */
|
||||
function fnUploadFile(up: UploadRequestOption) {
|
||||
const file = up.file as File;
|
||||
const fromItem = modalState.from.find(item => item.uid === (file as any).uid);
|
||||
if (!fromItem) {
|
||||
return;
|
||||
}
|
||||
const uploadFile = modalState.uploadFiles.find(
|
||||
item => item.uid === (up.file as any).uid
|
||||
);
|
||||
if (!uploadFile) return;
|
||||
|
||||
// 发送请求
|
||||
fromItem.status = 'uploading';
|
||||
uploadFileChunk(file, 5, 'software').then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
// 改为完成状态
|
||||
const uploadFile = modalState.uploadFiles.find(
|
||||
item => item.uid === (file as any).uid
|
||||
);
|
||||
uploadFile.percent = 100;
|
||||
uploadFile.status = 'done';
|
||||
// 预置到表单
|
||||
fromItem.status = 'done';
|
||||
fromItem.path = res.data.fileName;
|
||||
} else {
|
||||
fromItem.status = 'error';
|
||||
message.error(res.msg, 3);
|
||||
}
|
||||
});
|
||||
uploadFileChunk(up.file as File, 5, 'software')
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
// 改为完成状态
|
||||
uploadFile.percent = 100;
|
||||
uploadFile.status = 'done';
|
||||
uploadFile.path = res.data.fileName;
|
||||
} else {
|
||||
message.error(res.msg, 3);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
uploadFile.percent = 0;
|
||||
uploadFile.status = 'error';
|
||||
uploadFile.response = error.message;
|
||||
})
|
||||
.finally(() => {
|
||||
modalState.confirmLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**表单上传前检查或转换压缩-依赖包 */
|
||||
function fnBeforeUploadFileDep(file: FileType) {
|
||||
if (modalState.confirmLoading) return false;
|
||||
const fileName = file.name;
|
||||
const suff = fileName.substring(fileName.lastIndexOf('.'));
|
||||
if (!['.deb', '.rpm'].includes(suff)) {
|
||||
message.error(
|
||||
t('views.configManage.softwareManage.onlyAble', {
|
||||
fileText: '(.deb、.rpm)',
|
||||
}),
|
||||
3
|
||||
);
|
||||
return Upload.LIST_IGNORE;
|
||||
}
|
||||
|
||||
// 已存在同名文件
|
||||
const hasItem = modalState.uploadFilesDep.find(
|
||||
item => item.name === fileName
|
||||
);
|
||||
if (hasItem) {
|
||||
notification.warning({
|
||||
message: fileName,
|
||||
description: t('views.ne.neSoftware.fileNameExists'),
|
||||
});
|
||||
return Upload.LIST_IGNORE;
|
||||
}
|
||||
|
||||
// 取网元类型判断是否支持
|
||||
let neType = '';
|
||||
const neTypeIndex = fileName.indexOf('-');
|
||||
if (neTypeIndex !== -1) {
|
||||
neType = fileName.substring(0, neTypeIndex).toUpperCase();
|
||||
}
|
||||
// 依赖包类型
|
||||
if (!NE_EXPAND_LIST.includes(neType)) {
|
||||
notification.warning({
|
||||
message: fileName,
|
||||
description: t('views.ne.neSoftware.fileCheckTypeDep'),
|
||||
});
|
||||
return Upload.LIST_IGNORE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**表单上传文件-依赖包 */
|
||||
function fnUploadFileDep(up: UploadRequestOption) {
|
||||
const uploadFile = modalState.uploadFilesDep.find(
|
||||
item => item.uid === (up.file as any).uid
|
||||
);
|
||||
if (!uploadFile) return;
|
||||
|
||||
// 发送请求
|
||||
uploadFileChunk(up.file as File, 5, 'software')
|
||||
.then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
// 改为完成状态
|
||||
uploadFile.percent = 100;
|
||||
uploadFile.status = 'done';
|
||||
uploadFile.path = res.data.fileName;
|
||||
} else {
|
||||
message.error(res.msg, 3);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
uploadFile.percent = 0;
|
||||
uploadFile.status = 'error';
|
||||
uploadFile.response = error.message;
|
||||
})
|
||||
.finally(() => {
|
||||
modalState.confirmLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**监听是否显示,初始数据 */
|
||||
@@ -258,8 +374,11 @@ onMounted(() => {});
|
||||
|
||||
<a-form-item
|
||||
:label="t('views.ne.neSoftware.path')"
|
||||
name="file"
|
||||
:help="t('views.ne.neSoftware.uploadFileName')"
|
||||
:required="true"
|
||||
:validate-on-rule-change="false"
|
||||
:validateTrigger="[]"
|
||||
name="file"
|
||||
>
|
||||
<a-upload
|
||||
name="file"
|
||||
@@ -284,27 +403,67 @@ onMounted(() => {});
|
||||
</a-button>
|
||||
</a-upload>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
name="dep"
|
||||
:label="t('views.ne.neSoftware.dependFile')"
|
||||
:help="t('views.ne.neSoftware.dependFileTip')"
|
||||
>
|
||||
<a-upload
|
||||
name="file"
|
||||
v-model:file-list="modalState.uploadFilesDep"
|
||||
accept=".rpm,.deb"
|
||||
list-type="text"
|
||||
:multiple="true"
|
||||
:max-count="5"
|
||||
:show-upload-list="{
|
||||
showPreviewIcon: false,
|
||||
showRemoveIcon: true,
|
||||
showDownloadIcon: false,
|
||||
}"
|
||||
:before-upload="fnBeforeUploadFileDep"
|
||||
:custom-request="fnUploadFileDep"
|
||||
:disabled="modalState.confirmLoading"
|
||||
>
|
||||
<a-button type="dashed">
|
||||
<template #icon>
|
||||
<UploadOutlined />
|
||||
</template>
|
||||
{{ t('views.ne.neSoftware.upload') }}
|
||||
</a-button>
|
||||
</a-upload>
|
||||
</a-form-item>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<a-form-item :label="t('common.description')">
|
||||
{{
|
||||
t('views.ne.neSoftware.uploadBatchMax', {
|
||||
txt: NE_TYPE_LIST.length,
|
||||
txt: NE_TYPE_EXP.length,
|
||||
})
|
||||
}}
|
||||
<br />
|
||||
{{ t('views.ne.neSoftware.uploadFileName') }}
|
||||
</a-form-item>
|
||||
<a-form-item :label="t('views.ne.neSoftware.path')" name="file">
|
||||
<a-form-item
|
||||
:label="t('views.ne.neSoftware.path')"
|
||||
:required="true"
|
||||
:validate-on-rule-change="false"
|
||||
:validateTrigger="[]"
|
||||
name="file"
|
||||
>
|
||||
<a-upload
|
||||
name="file"
|
||||
v-model:file-list="modalState.uploadFiles"
|
||||
accept=".rpm,.deb"
|
||||
list-type="text"
|
||||
:multiple="true"
|
||||
:max-count="NE_TYPE_LIST.length"
|
||||
:show-upload-list="false"
|
||||
:max-count="NE_TYPE_EXP.length"
|
||||
:show-upload-list="{
|
||||
showPreviewIcon: false,
|
||||
showRemoveIcon: true,
|
||||
showDownloadIcon: false,
|
||||
}"
|
||||
:before-upload="fnBeforeUploadFile"
|
||||
:custom-request="fnUploadFile"
|
||||
:disabled="modalState.confirmLoading"
|
||||
@@ -317,40 +476,9 @@ onMounted(() => {});
|
||||
</a-button>
|
||||
</a-upload>
|
||||
</a-form-item>
|
||||
|
||||
<div class="moreFile">
|
||||
<p :key="item.uid" v-for="item in modalState.from">
|
||||
<template v-if="item.status === 'done'">
|
||||
<a-alert
|
||||
:message="`${item.neType}-${item.version}`"
|
||||
type="success"
|
||||
show-icon
|
||||
/>
|
||||
</template>
|
||||
<template v-if="item.status === 'uploading'">
|
||||
<a-alert
|
||||
:message="`${item.neType}-${item.version}`"
|
||||
type="info"
|
||||
show-icon
|
||||
/>
|
||||
</template>
|
||||
<template v-if="item.status === 'error'">
|
||||
<a-alert
|
||||
:message="`${item.neType}-${item.version}`"
|
||||
type="error"
|
||||
show-icon
|
||||
/>
|
||||
</template>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.moreFile {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
<style lang="less" scoped></style>
|
||||
|
||||
Reference in New Issue
Block a user