| | |
| | | accept="." |
| | | :file-list="imageUrl2" |
| | | :on-success="handleAvatarSuccess" |
| | | :on-remove="handleRemove"> |
| | | :on-remove="handleRemove" |
| | | :before-upload="beforeAvatarUpload"> |
| | | <i class="el-icon-plus"></i> |
| | | </el-upload> |
| | | <el-dialog :visible.sync="dialogVisible"> |
| | |
| | | }, |
| | | methods: { |
| | | handleAvatarSuccess(res, file) { |
| | | file.url =file.response |
| | | // 确保文件对象有完整的结构 |
| | | if (file && file.response) { |
| | | file.url = file.response; |
| | | } |
| | | TCarInfoDlg.goodsPicArray.push(res); |
| | | console.log(TCarInfoDlg.goodsPicArray) |
| | | console.log(TCarInfoDlg.goodsPicArray); |
| | | }, |
| | | // 添加 beforeUpload 钩子到 el-upload 组件 |
| | | beforeAvatarUpload(file) { |
| | | const isLt2M = file.size / 1024 / 1024 < 10; |
| | | if (!isLt2M) { |
| | |
| | | } |
| | | return isLt2M; |
| | | }, |
| | | // 修改 handleRemove 方法 |
| | | handleRemove(file, fileList) { |
| | | // 使用更安全的方式过滤 |
| | | TCarInfoDlg.goodsPicArray = TCarInfoDlg.goodsPicArray.filter(item => { |
| | | return item.uid != file.uid; |
| | | // 如果是文件对象,比较 uid;如果是字符串,比较值 |
| | | if (typeof item === 'object' && item !== null) { |
| | | return item.uid !== file.uid; |
| | | } else { |
| | | return item !== file.url; |
| | | } |
| | | }); |
| | | }, |
| | | changeImg(){ |
| | | var i = id.split(",") |
| | | for (let j = 0; j <i.length; j++) { |
| | | let obj={ |
| | | fileName:i[j], |
| | | uuid:i[j], |
| | | url:i[j], |
| | | response:i[j], |
| | | } |
| | | this.imageUrl2.push(obj) |
| | | if (!id) return; // 如果没有图片数据则返回 |
| | | |
| | | var i = id.split(",").filter(url => url.trim() !== ''); // 过滤空字符串 |
| | | for (let j = 0; j < i.length; j++) { |
| | | let obj = { |
| | | uid: 'existing-' + j + '-' + Date.now(), // 确保 uid 是唯一的字符串 |
| | | name: 'image-' + j + '.jpg', // 添加 name 属性 |
| | | url: i[j], |
| | | status: 'success' // 标记为已上传状态 |
| | | }; |
| | | this.imageUrl2.push(obj); |
| | | } |
| | | console.log( this.imageUrl2,111) |
| | | console.log(this.imageUrl2, 111); |
| | | }, |
| | | }, |
| | | created() { |