feat: 图片上传
This commit is contained in:
@@ -230,23 +230,24 @@
|
||||
if (file.type.startsWith('image/')) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
uploadImage(formData).then((res) => {
|
||||
console.log(res)
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
uploadedImages.value.push({
|
||||
url: e.target?.result as string,
|
||||
name: file.name,
|
||||
path: res
|
||||
})
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
uploadImage(formData).then((res) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
uploadedImages.value.push({
|
||||
url: e.target?.result as string,
|
||||
name: file.name,
|
||||
path: res
|
||||
})
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
// 清空input的value,允许重复选择同一文件
|
||||
nextTick(() => {
|
||||
editorRef.value?.focus()
|
||||
})
|
||||
input.value = ''
|
||||
}
|
||||
|
||||
@@ -481,9 +482,14 @@
|
||||
if (!inputValue.value.trim()) return
|
||||
const imageUrlList = uploadedImages.value.map((item) => item.path)
|
||||
|
||||
const payload = { text: inputValue.value.trim(), images: imageUrlList }
|
||||
const payload = {
|
||||
text: inputValue.value.trim(),
|
||||
images: imageUrlList,
|
||||
tempImages: uploadedImages.value
|
||||
}
|
||||
emits('send', payload)
|
||||
|
||||
// 发送后清空图片列表
|
||||
uploadedImages.value = []
|
||||
// 发送后清空输入框
|
||||
if (editorRef.value) {
|
||||
editorRef.value.innerHTML = ''
|
||||
@@ -572,12 +578,14 @@
|
||||
// 保存初始数据到 store
|
||||
agentStore.setInitialProjectData({
|
||||
text: inputValue.value.trim(),
|
||||
images: uploadedImages.value,
|
||||
images: uploadedImages.value.map((item) => item.path),
|
||||
tempImages: uploadedImages.value,
|
||||
...params
|
||||
})
|
||||
|
||||
// console.log('Create project with:', params)
|
||||
router.push(`/home/agent/${projectres}`, { query: params })
|
||||
uploadedImages.value = []
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
@@ -793,6 +801,7 @@
|
||||
max-height: initial;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
min-height: 5rem;
|
||||
}
|
||||
}
|
||||
.operate {
|
||||
|
||||
Reference in New Issue
Block a user