|
|
@ -9,7 +9,8 @@ |
|
|
|
<div class="table-container" style="flex: 1; overflow-y: auto;"> |
|
|
|
<el-table :data="tableData" style="width: 100%" class="gift-table" :row-style="{ height: '60px' }"> |
|
|
|
<el-table-column type="index" label="ID" width="100" align="center"> |
|
|
|
<template #default="scope">{{ scope.$index + 1 + (pagination.pageNum - 1) * pagination.pageSize }}</template> |
|
|
|
<template #default="scope">{{ scope.$index + 1 + (pagination.pageNum - 1) * pagination.pageSize |
|
|
|
}}</template> |
|
|
|
</el-table-column> |
|
|
|
<el-table-column label="礼品图片" width="200" align="center"> |
|
|
|
<template #default="scope"> |
|
|
@ -48,7 +49,7 @@ |
|
|
|
</el-select> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="礼品图片" :rules="{ required: true, message: '请上传图片', trigger: 'change' }"> |
|
|
|
<el-upload ref="uploadRef" list-type="picture-card" :auto-upload="false" :http-request="customUpload" |
|
|
|
<el-upload ref="uploadRef" list-type="picture-card" :auto-upload="false" :http-request="customUpload" |
|
|
|
:on-change="handleImageChange" :on-success="handleUploadSuccess" :on-error="handleUploadError" |
|
|
|
:before-upload="beforeUpload" :show-file-list="false"> |
|
|
|
<!-- :action="uploadUrl" --> |
|
|
@ -57,7 +58,7 @@ |
|
|
|
</el-icon> |
|
|
|
<template #tip> |
|
|
|
<div class="el-upload__tip"> |
|
|
|
只能上传jpg、png格式的图片,且不超过500KB |
|
|
|
只能上传jpg、png格式的图片,且不超过1MB |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</el-upload> |
|
|
@ -86,7 +87,7 @@ |
|
|
|
</el-select> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="礼品图片" :rules="{ required: true, message: '请上传图片', trigger: 'change' }"> |
|
|
|
<el-upload ref="uploadRef" list-type="picture-card" :auto-upload="false" |
|
|
|
<el-upload ref="uploadRef" list-type="picture-card" :auto-upload="false" :http-request="customUpload" |
|
|
|
:on-change="handleImageChange" :on-success="handleUploadSuccess" :on-error="handleUploadError" |
|
|
|
:before-upload="beforeUpload" :show-file-list="false"> |
|
|
|
<!-- :action="uploadUrl" --> |
|
|
@ -95,7 +96,7 @@ |
|
|
|
</el-icon> |
|
|
|
<template #tip> |
|
|
|
<div class="el-upload__tip"> |
|
|
|
只能上传jpg、png格式的图片,且不超过500KB |
|
|
|
只能上传jpg、png格式的图片,且不超过1MB |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</el-upload> |
|
|
@ -142,7 +143,7 @@ const addForm = ref({ |
|
|
|
}) |
|
|
|
const editForm = ref({ |
|
|
|
prizeName: '', |
|
|
|
gradeId: '', |
|
|
|
gradeId: null, |
|
|
|
imageUrl: null |
|
|
|
}) |
|
|
|
const uploadUrl = import.meta.env.VITE_UPLOAD_URL |
|
|
@ -214,7 +215,7 @@ const submitAdd = async () => { |
|
|
|
ElMessage.error('请上传图片'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(addForm.value.prizeName.length > 15){ |
|
|
|
if (addForm.value.prizeName.length > 15) { |
|
|
|
ElMessage.error('奖品名称最多输入15个字符'); |
|
|
|
return; |
|
|
|
} |
|
|
@ -280,7 +281,7 @@ const submitEdit = async () => { |
|
|
|
ElMessage.error('请上传图片'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(editForm.value.prizeName.length > 15){ |
|
|
|
if (editForm.value.prizeName.length > 15) { |
|
|
|
ElMessage.error('奖品名称最多输入15个字符'); |
|
|
|
return; |
|
|
|
} |
|
|
@ -333,11 +334,11 @@ const customUpload = async (options) => { |
|
|
|
'Authorization': `Bearer ${localStorage.getItem('token')}` |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
console.log('看看路径', import.meta.env.VITE_UPLOAD_URL) |
|
|
|
if (response.data.code === 200 && response.data.data) { |
|
|
|
// 传递原始文件对象和响应数据 |
|
|
|
handleUploadSuccess(response.data, options.file); |
|
|
|
ElMessage.success('上传成功'); |
|
|
|
ElMessage.success(response.data.msg || '上传成功'); |
|
|
|
} else { |
|
|
|
ElMessage.error(response.data.msg || '上传失败'); |
|
|
|
} |
|
|
@ -354,63 +355,64 @@ const handleImageChange = (file) => { |
|
|
|
uploadRef.value.submit(); |
|
|
|
} |
|
|
|
const handleUploadSuccess = (response, file, fileList) => { |
|
|
|
if (response.code === 200) { |
|
|
|
try { |
|
|
|
if (addVisible.value) { |
|
|
|
addForm.value.imageUrl = response.data.url; |
|
|
|
} else if (editVisible.value) { |
|
|
|
editForm.value.imageUrl = response.data.url; |
|
|
|
} else { |
|
|
|
if (addVisible.value) { |
|
|
|
addForm.value.imageUrl = null; |
|
|
|
} else if (editVisible.value) { |
|
|
|
editForm.value.imageUrl = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} catch (error) { |
|
|
|
ElMessage.error(response.msg || '图片上传失败'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const handleUploadError = (error) => { |
|
|
|
console.error('上传失败:', error); |
|
|
|
if (addVisible.value) { |
|
|
|
addForm.value.imageUrl = null; |
|
|
|
} else if (editVisible.value) { |
|
|
|
editForm.value.imageUrl = null; |
|
|
|
} |
|
|
|
ElMessage.error(response.message || '图片上传失败'); |
|
|
|
ElMessage.error('图片上传失败,请重试'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const handleUploadError = (error) => { |
|
|
|
console.error('上传失败:', error); |
|
|
|
if (addVisible.value) { |
|
|
|
addForm.value.imageUrl = null; |
|
|
|
} else if (editVisible.value) { |
|
|
|
editForm.value.imageUrl = null; |
|
|
|
} |
|
|
|
ElMessage.error('图片上传失败,请重试'); |
|
|
|
} |
|
|
|
const beforeUpload = (file) => { |
|
|
|
const isJPG = file.type === 'image/jpeg'; |
|
|
|
const isPNG = file.type === 'image/png'; |
|
|
|
const isLt1 = file.size / 1024 < 1024; |
|
|
|
|
|
|
|
const beforeUpload = (file) => { |
|
|
|
const isJPG = file.type === 'image/jpeg'; |
|
|
|
const isPNG = file.type === 'image/png'; |
|
|
|
const isLt500K = file.size / 1024 < 500; |
|
|
|
|
|
|
|
if (!isJPG && !isPNG) { |
|
|
|
ElMessage.error('上传图片只能是 JPG 或 PNG 格式'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!isLt500K) { |
|
|
|
ElMessage.error('上传图片大小不能超过 500KB'); |
|
|
|
return false; |
|
|
|
if (!isJPG && !isPNG) { |
|
|
|
ElMessage.error('上传图片只能是 JPG 或 PNG 格式'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!isLt1) { |
|
|
|
ElMessage.error('上传图片大小不能超过1MB'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
const handleSizeChange = (val) => { |
|
|
|
pagination.value.pageSize = val |
|
|
|
pagination.value.pageNum = 1 |
|
|
|
getPrizes() |
|
|
|
} |
|
|
|
const handleSizeChange = (val) => { |
|
|
|
pagination.value.pageSize = val |
|
|
|
pagination.value.pageNum = 1 |
|
|
|
getPrizes() |
|
|
|
} |
|
|
|
|
|
|
|
const handleCurrentChange = (val) => { |
|
|
|
pagination.value.pageNum = val |
|
|
|
getPrizes() |
|
|
|
} |
|
|
|
const handleCurrentChange = (val) => { |
|
|
|
pagination.value.pageNum = val |
|
|
|
getPrizes() |
|
|
|
} |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
getPrizes() |
|
|
|
getGradeNames() |
|
|
|
}) |
|
|
|
onMounted(() => { |
|
|
|
getPrizes() |
|
|
|
getGradeNames() |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
<style scoped> |
|
|
|