100J上传音频格式限制

This commit is contained in:
微微一笑
2026-03-19 15:48:44 +08:00
parent 444b3b35ac
commit bdea9dac4b

View File

@ -79,12 +79,6 @@
点击下方红色录制按钮开始录音吐字清晰语句流畅
</view>
</view>
<!-- 上传语音的提示仅支持 MP3 -->
<view v-if="Status.pageType==='File'">
<view class="tips" :class="{'displayNone':AudioData.tempFilePath}">
仅支持 MP3 格式请选择 .mp3 文件
</view>
</view>
<!-- 录音选择文件操作 -->
<view class="footer" v-if="Status.pageType!=='Txt'">
<view class="opt">
@ -472,11 +466,16 @@
this.showMsg("请先录制或选择音频文件");
return;
}
// 仅支持 MP3 格式
const uploadFilePath = this.AudioData.tempFilePath;
if (!uploadFilePath.toLowerCase().endsWith('.mp3')) {
this.showMsg("仅支持 MP3 格式,请选择 .mp3 文件");
return;
// 检查文件扩展名
const validExtensions = ['.mp3', '.wav', '.aac', '.m4a'];
let uploadFilePath = this.AudioData.tempFilePath;
const hasValidExtension = validExtensions.some(ext =>
uploadFilePath.toLowerCase().endsWith(ext)
);
if (!hasValidExtension) {
// 如果没有有效扩展名,添加.mp3扩展名
uploadFilePath = uploadFilePath + '.mp3';
console.log("自动添加.mp3扩展名新路径:", uploadFilePath);
}
console.log("上传文件路径:", uploadFilePath);
@ -754,15 +753,12 @@
handleUploadCallback(res) {
console.log("选择文件:", res);
if (res && res.data) {
if (this.Status.pageType === 'File') { //文件上传,仅支持 MP3
const file = res.data[0];
const name = (file.name || '').toLowerCase();
const isMp3 = name.endsWith('.mp3') || (file.type || '').includes('mpeg');
if (isMp3) {
this.cEdit.name = file.name;
this.playInit(file.tempFilePath);
if (this.Status.pageType === 'File') { //文件上传
if (res.data[0].type.indexOf('audio') > -1) {
this.cEdit.name = res.data[0].name;
this.playInit(res.data[0].tempFilePath);
} else {
this.showMsg("仅支持 MP3 格式,请选择 .mp3 文件");
this.showMsg("只能选择音频文件");
}
return;
}
@ -940,10 +936,7 @@
});
},
checkFile() {
const config = this.Status.pageType === 'File'
? { extension: ['.mp3'] }
: { extension: ['.txt', '.doc', '.docx'] };
this.$refs.XeUpload.upload('file', config);
this.$refs.XeUpload.upload('file');
},
toggleRecord() {
if (this.Status.recoderIntval) {