|
|
@@ -34,6 +34,20 @@
|
|
|
<el-form-item label="案例故事" prop="story">
|
|
|
<el-input v-model="form.story" type="textarea" :rows="8" placeholder="请输入案例故事,详细描述两人的相识、相知、相爱过程" maxlength="2000" show-word-limit />
|
|
|
</el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="案例图片" prop="imageUrl">
|
|
|
+ <el-upload
|
|
|
+ class="image-uploader"
|
|
|
+ action="#"
|
|
|
+ :show-file-list="false"
|
|
|
+ :before-upload="handleBeforeUpload"
|
|
|
+ :http-request="handleUpload"
|
|
|
+ >
|
|
|
+ <el-image v-if="form.imageUrl" :src="form.imageUrl" class="uploaded-image" fit="cover" />
|
|
|
+ <el-icon v-else class="uploader-icon"><Plus /></el-icon>
|
|
|
+ </el-upload>
|
|
|
+ <div class="upload-tip">支持 JPG、PNG 等图片格式,大小不超过 10MB</div>
|
|
|
+ </el-form-item>
|
|
|
|
|
|
<el-row :gutter="20">
|
|
|
<el-col :span="12">
|
|
|
@@ -70,6 +84,7 @@
|
|
|
import { ref, reactive, onMounted } from 'vue'
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
+import { Plus } from '@element-plus/icons-vue'
|
|
|
import request from '@/utils/request'
|
|
|
import { API_ENDPOINTS } from '@/config/api'
|
|
|
|
|
|
@@ -86,6 +101,7 @@ const form = reactive({
|
|
|
femaleUserNickname: '',
|
|
|
quote: '',
|
|
|
story: '',
|
|
|
+ imageUrl: '',
|
|
|
marriageDate: null,
|
|
|
matchmakerName: '',
|
|
|
caseStatus: 1
|
|
|
@@ -123,7 +139,10 @@ const loadDetail = async (id) => {
|
|
|
console.log('案例详情响应:', response)
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
- Object.assign(form, response.data)
|
|
|
+ Object.assign(form, {
|
|
|
+ ...response.data,
|
|
|
+ imageUrl: response.data?.imageUrl || response.data?.image_url || ''
|
|
|
+ })
|
|
|
console.log('加载的表单数据:', form)
|
|
|
} else {
|
|
|
ElMessage.error(response.message || '加载详情失败')
|
|
|
@@ -166,6 +185,52 @@ const handleSubmit = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const handleBeforeUpload = (file) => {
|
|
|
+ const isImage = file.type.startsWith('image/')
|
|
|
+ const isLt10M = file.size / 1024 / 1024 < 10
|
|
|
+
|
|
|
+ if (!isImage) {
|
|
|
+ ElMessage.error('只能上传图片文件!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (!isLt10M) {
|
|
|
+ ElMessage.error('图片大小不能超过 10MB!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+const handleUpload = async (options) => {
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', options.file)
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await request.post(API_ENDPOINTS.UPLOAD_IMAGE, formData, {
|
|
|
+ headers: { 'Content-Type': 'multipart/form-data' }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (response.code === 200) {
|
|
|
+ let imageUrl = ''
|
|
|
+ if (typeof response.data === 'string') {
|
|
|
+ imageUrl = response.data
|
|
|
+ } else if (response.data && response.data.url) {
|
|
|
+ imageUrl = response.data.url
|
|
|
+ } else if (response.data && response.data.path) {
|
|
|
+ imageUrl = response.data.path
|
|
|
+ } else {
|
|
|
+ imageUrl = String(response.data || '')
|
|
|
+ }
|
|
|
+ form.imageUrl = imageUrl
|
|
|
+ ElMessage.success('图片上传成功')
|
|
|
+ } else {
|
|
|
+ ElMessage.error(response.message || '图片上传失败')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('上传异常:', error)
|
|
|
+ ElMessage.error('图片上传失败,请重试')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
const caseId = route.params.id
|
|
|
if (caseId) {
|
|
|
@@ -178,5 +243,38 @@ onMounted(() => {
|
|
|
<style scoped>
|
|
|
.success-case-form-container { padding: 0; }
|
|
|
.page-title { font-size: 24px; font-weight: bold; color: #333; margin: 0 0 20px 0; }
|
|
|
+
|
|
|
+.image-uploader :deep(.el-upload) {
|
|
|
+ border: 1px dashed #d9d9d9;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ width: 150px;
|
|
|
+ height: 150px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+}
|
|
|
+
|
|
|
+.image-uploader :deep(.el-upload:hover) {
|
|
|
+ border-color: #409EFF;
|
|
|
+}
|
|
|
+
|
|
|
+.uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+}
|
|
|
+
|
|
|
+.uploaded-image {
|
|
|
+ width: 150px;
|
|
|
+ height: 150px;
|
|
|
+ display: block;
|
|
|
+ border-radius: 6px;
|
|
|
+}
|
|
|
+
|
|
|
+.upload-tip {
|
|
|
+ font-size: 12px;
|
|
|
+ color: #999;
|
|
|
+ margin-top: 8px;
|
|
|
+}
|
|
|
</style>
|
|
|
|