Commit 1099f528 authored by 刘斌's avatar 刘斌

fix: 修复照片上传可能失败的问题

parent 051c38de
...@@ -164,7 +164,11 @@ ...@@ -164,7 +164,11 @@
<div class="item-label">照片 <span style="color: #ee0a24">*</span></div> <div class="item-label">照片 <span style="color: #ee0a24">*</span></div>
<van-field <van-field
name="photo" name="photo"
:rules="[{ required: true, message: '请上传照片', validator: (val) => val && val.length > 0 }]" :rules="[{
required: true,
message: '请上传照片并等待上传成功',
validator: (val) => val && val.length > 0 && form.ossId > 0
}]"
:border="false" :border="false"
style="flex: 1; padding: 0; background: transparent;" style="flex: 1; padding: 0; background: transparent;"
> >
...@@ -174,6 +178,7 @@ ...@@ -174,6 +178,7 @@
:max-count="1" :max-count="1"
:max-size="20 * 1024 * 1024" :max-size="20 * 1024 * 1024"
:after-read="afterRead" :after-read="afterRead"
@delete="onDeletePhoto"
@oversize="onOversize" @oversize="onOversize"
/> />
</template> </template>
...@@ -859,7 +864,8 @@ const resumeEndValues = ref<string[]>([_todayYear + '', '01']); ...@@ -859,7 +864,8 @@ const resumeEndValues = ref<string[]>([_todayYear + '', '01']);
// } // }
async function afterRead(items: UploaderFileListItem | UploaderFileListItem[]) { async function afterRead(items: UploaderFileListItem | UploaderFileListItem[]) {
const item = Array.isArray(items) ? items[0] : items; const item = Array.isArray(items) ? items[0] : items;
// for (const item of items) { item.status = 'uploading';
item.message = '上传中...';
try { try {
const fd = new FormData(); const fd = new FormData();
fd.append('file', item.file as File); fd.append('file', item.file as File);
...@@ -871,27 +877,32 @@ async function afterRead(items: UploaderFileListItem | UploaderFileListItem[]) { ...@@ -871,27 +877,32 @@ async function afterRead(items: UploaderFileListItem | UploaderFileListItem[]) {
timeout: 60_000, timeout: 60_000,
}, },
); );
if (status >= 200 && status < 300) { if (status >= 200 && status < 300 && responseData.success) {
if (responseData.success) { const data = responseData.data;
const data = responseData.data; if (data.url) {
console.log('[data]', data); form.ossId = data.ossId;
const url = data.url; item.url = data.url;
if (url) { item.status = 'done';
form.ossId = data.ossId; item.message = '上传成功';
item.url = url;
}
// submitSuccess.value = true;
// showSuccessToast({message: '提交成功', duration: 5000});
} else { } else {
showFailToast('提交失败'); item.status = 'failed';
item.message = '上传失败';
showFailToast('上传失败');
} }
} else { } else {
showFailToast('提交失败'); item.status = 'failed';
item.message = '上传失败';
showFailToast(responseData.errMessage || '上传失败');
} }
} catch (e) { } catch (e) {
item.status = 'failed';
item.message = '上传失败';
showFailToast('图片上传失败'); showFailToast('图片上传失败');
} }
// } }
function onDeletePhoto() {
form.ossId = 0;
} }
function onOversize() { function onOversize() {
showFailToast('文件大小不能超过20MB'); showFailToast('文件大小不能超过20MB');
...@@ -1287,6 +1298,13 @@ async function onSubmit() { ...@@ -1287,6 +1298,13 @@ async function onSubmit() {
return; return;
} }
if (submitting.value) return; if (submitting.value) return;
// 再次检查图片上传状态
if (form.photoList.length > 0 && form.ossId === 0) {
showFailToast('照片正在上传或上传失败,请稍后重试');
return;
}
submitting.value = true; submitting.value = true;
try { try {
let externalResumeValue = ''; let externalResumeValue = '';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment