|
|
|
@ -29,7 +29,31 @@ |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<el-dialog |
|
|
|
|
:visible.sync="dialogVisible" |
|
|
|
|
title="输入图片位置" |
|
|
|
|
:visible.sync="positionDialogVisible" |
|
|
|
|
width="400" |
|
|
|
|
@close="resetPosition" |
|
|
|
|
:modal="false" |
|
|
|
|
append-to-body |
|
|
|
|
> |
|
|
|
|
<div> |
|
|
|
|
<el-form :model="position" :rules="rules" ref="positionForm"> |
|
|
|
|
<el-form-item label="X 坐标" prop="x"> |
|
|
|
|
<el-input v-model="position.x" type="number"></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item label="Y 坐标" prop="y"> |
|
|
|
|
<el-input v-model="position.y" type="number"></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
</el-form> |
|
|
|
|
</div> |
|
|
|
|
<span slot="footer" class="dialog-footer"> |
|
|
|
|
<el-button @click="positionDialogVisible = false">取消</el-button> |
|
|
|
|
<el-button type="primary" @click="confirmPosition">确定</el-button> |
|
|
|
|
</span> |
|
|
|
|
</el-dialog> |
|
|
|
|
|
|
|
|
|
<el-dialog |
|
|
|
|
:visible.sync="previewDialogVisible" |
|
|
|
|
title="预览" |
|
|
|
|
width="800" |
|
|
|
|
append-to-body |
|
|
|
@ -67,6 +91,11 @@ export default { |
|
|
|
|
isShowTip: { |
|
|
|
|
type: Boolean, |
|
|
|
|
default: true |
|
|
|
|
}, |
|
|
|
|
// 是否显示位置信息输入框 |
|
|
|
|
showPositionInput: { |
|
|
|
|
type: Boolean, |
|
|
|
|
default: false |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
data() { |
|
|
|
@ -74,11 +103,22 @@ export default { |
|
|
|
|
number: 0, |
|
|
|
|
uploadList: [], |
|
|
|
|
dialogImageUrl: "", |
|
|
|
|
dialogVisible: false, |
|
|
|
|
positionDialogVisible: false, // 控制位置输入弹窗的显示 |
|
|
|
|
previewDialogVisible: false, // 控制预览弹窗的显示 |
|
|
|
|
hideUpload: false, |
|
|
|
|
uploadFileUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // 请求地址 |
|
|
|
|
headers: { Authorization: "Bearer " + getAccessToken() }, // 设置上传的请求头部 |
|
|
|
|
fileList: [] |
|
|
|
|
fileList: [], |
|
|
|
|
currentFile: null, // 当前上传的文件 |
|
|
|
|
position: { x: '', y: '' }, // 新增位置数据 |
|
|
|
|
rules: { |
|
|
|
|
x: [ |
|
|
|
|
{ required: true, message: 'X 坐标为必填项', trigger: 'blur' } |
|
|
|
|
], |
|
|
|
|
y: [ |
|
|
|
|
{ required: true, message: 'Y 坐标为必填项', trigger: 'blur' } |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
watch: { |
|
|
|
@ -114,19 +154,71 @@ export default { |
|
|
|
|
// 删除图片 |
|
|
|
|
handleRemove(file, fileList) { |
|
|
|
|
const findex = this.fileList.map(f => f.name).indexOf(file.name); |
|
|
|
|
if(findex > -1) { |
|
|
|
|
if (findex > -1) { |
|
|
|
|
this.fileList.splice(findex, 1); |
|
|
|
|
this.$emit("input", this.listToString(this.fileList)); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 取消上传的图片 |
|
|
|
|
cancelUpload() { |
|
|
|
|
if (this.currentFile) { |
|
|
|
|
// 调用 handleRemove 方法删除当前文件 |
|
|
|
|
this.handleRemove(this.currentFile, this.fileList); |
|
|
|
|
} |
|
|
|
|
this.currentFile = null; // 清空当前文件信息 |
|
|
|
|
this.positionDialogVisible = false; // 关闭位置输入弹窗 |
|
|
|
|
this.$modal.closeLoading(); // 关闭加载框 |
|
|
|
|
}, |
|
|
|
|
resetPosition() { |
|
|
|
|
this.position.x = ''; |
|
|
|
|
this.position.y = ''; |
|
|
|
|
this.cancelUpload(); // 取消上传的图片 |
|
|
|
|
}, |
|
|
|
|
// 上传成功回调 |
|
|
|
|
handleUploadSuccess(res) { |
|
|
|
|
// edit by 芋道源码 |
|
|
|
|
this.uploadList.push({ name: res.data, url: res.data }); |
|
|
|
|
if (this.uploadList.length === this.number) { |
|
|
|
|
er |
|
|
|
|
this.currentFile = { name: res.data, url: res.data }; |
|
|
|
|
|
|
|
|
|
// 检查当前文件是否已经存在于 fileList 中 |
|
|
|
|
const exists = this.fileList.some(file => file.name === this.currentFile.name); |
|
|
|
|
if (!exists) { |
|
|
|
|
this.fileList.push(this.currentFile); // 确保将当前文件添加到 fileList |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.showPositionInput) { |
|
|
|
|
this.positionDialogVisible = true; // 显示位置输入弹窗 |
|
|
|
|
} else { |
|
|
|
|
// 只在 uploadList 中添加当前文件 |
|
|
|
|
this.uploadList.push(this.currentFile); |
|
|
|
|
this.updateFileList(); // 更新文件列表 |
|
|
|
|
this.$modal.closeLoading(); // 关闭加载框 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
confirmPosition() { |
|
|
|
|
this.$refs.positionForm.validate((valid) => { |
|
|
|
|
if (valid) { |
|
|
|
|
const positionUrl = `${this.currentFile.url}?x=${this.position.x}&y=${this.position.y}`; |
|
|
|
|
this.uploadList.push({ name: this.currentFile.name, url: positionUrl }); |
|
|
|
|
this.updateFileList1(); |
|
|
|
|
this.positionDialogVisible = false; // 关闭位置输入弹窗 |
|
|
|
|
} else { |
|
|
|
|
// this.$message.error('请填写必填项'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
// 更新文件列表 |
|
|
|
|
updateFileList() { |
|
|
|
|
if (this.uploadList.length > 0) { |
|
|
|
|
// this.fileList = this.fileList.concat(this.uploadList); |
|
|
|
|
this.uploadList = []; // 清空 uploadList |
|
|
|
|
this.$emit("input", this.listToString(this.fileList)); |
|
|
|
|
this.$modal.closeLoading(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
updateFileList1() { |
|
|
|
|
if (this.uploadList.length > 0) { |
|
|
|
|
this.fileList = this.fileList.concat(this.uploadList); |
|
|
|
|
this.uploadList = []; |
|
|
|
|
this.number = 0; |
|
|
|
|
this.uploadList = []; // 清空 uploadList |
|
|
|
|
this.$emit("input", this.listToString(this.fileList)); |
|
|
|
|
this.$modal.closeLoading(); |
|
|
|
|
} |
|
|
|
@ -173,7 +265,7 @@ export default { |
|
|
|
|
// 预览 |
|
|
|
|
handlePictureCardPreview(file) { |
|
|
|
|
this.dialogImageUrl = file.url; |
|
|
|
|
this.dialogVisible = true; |
|
|
|
|
this.previewDialogVisible = true; // 显示预览弹窗 |
|
|
|
|
}, |
|
|
|
|
// 对象转成指定字符串分隔 |
|
|
|
|
listToString(list, separator) { |
|
|
|
|