diff --git a/src/views/system/deviceUpgrade/index.vue b/src/views/system/deviceUpgrade/index.vue index c05b3d1..55bd3ee 100644 --- a/src/views/system/deviceUpgrade/index.vue +++ b/src/views/system/deviceUpgrade/index.vue @@ -7,6 +7,7 @@ class="upload-demo" ref="upload" action="#" + :on-change="handleFileChange" :before-upload="beforeUpload" :http-request="customUpload" :limit="1" @@ -193,19 +194,53 @@ export default { // 显示上传进度 console.log(this.progress); // 或者你可以使用其他方式来显示进度,比如使用进度条组件等。 }, + handleFileChange(file) { + const titleName = file.name; + console.log(titleName); + // 正则表达式检查文件名是否符合模式 + // const regex = + // /^(mpapp|MpMaster)_v\d+\.\d+(\.\d+)?_rel_\d{8}_([a-zA-Z0-9-]+)?\.apk$/; + const regex = + /^(mpapp|MpMaster)_v(\d+\.\d+(\.\d+)?)_rel_\d{8}(_([a-zA-Z0-9-]+))?\.apk$/; + + if (regex.test(titleName)) { + console.log(titleName); + // 提取版本号(v后面的数字) + const versionMatch = titleName.match(regex); + if (versionMatch) { + console.log(versionMatch); + // 构造新的文件名(去掉V和_rel_日期部分) + const baseName = titleName.startsWith("mpapp") ? "mpapp" : "mpmst"; // 注意:这里假设mpmaster应该改为mpmst + const version = versionMatch[2]; + // 提取架构信息(如果存在) + const architecture = versionMatch[4] || ""; // 如果没有架构信息,则为空字符串 + this.reportData.title = `${baseName}_v${version}${architecture}`; + } + } else { + this.reportData.title = ""; + } + console.log(this.reportData.title); + }, beforeUpload(file) { const fileName = file.name; // 正则表达式检查文件名是否符合模式 - const regex = /^(mpapp|MpMaster)_v\d+\.\d+(\.\d+)?_rel_\d{8}\.apk$/; + // const regex = + // /^(mpapp|MpMaster)_v(\d+\.\d+(\.\d+)?)_rel_\d{8}(_([a-zA-Z0-9-]+))?\.apk$/; + const regex = + /^(mpapp|MpMaster)_v(\d+\.\d+(\.\d+)?)_rel_\d{8}(_([a-zA-Z0-9-]+))?\.apk$/; if (regex.test(fileName)) { + console.log(fileName); // 提取版本号(v后面的数字) - const versionMatch = fileName.match(/v(\d+\.\d+(\.\d+)?)/); - if (versionMatch && versionMatch[1]) { + const versionMatch = fileName.match(regex); + if (versionMatch) { + console.log(versionMatch); // 构造新的文件名(去掉V和_rel_日期部分) const baseName = fileName.startsWith("mpapp") ? "mpapp" : "mpmst"; // 注意:这里假设mpmaster应该改为mpmst - const version = versionMatch[1]; + const version = versionMatch[2]; + // 提取架构信息(如果存在) + const architecture = versionMatch[4] || ""; // 如果没有架构信息,则为空字符串 this.reportData.modifiedName = `${baseName}_${version}.apk`; } } else {