|
@@ -104,7 +104,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
export default {
|
|
export default {
|
|
- props: ["englishList", "myAnswerList1","userid"],
|
|
|
|
|
|
+ props: ["englishList", "myAnswerList1", "userid"],
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
type: 0,
|
|
type: 0,
|
|
@@ -115,7 +115,7 @@ export default {
|
|
},
|
|
},
|
|
uploadDialogVisible: false,
|
|
uploadDialogVisible: false,
|
|
noneBtnImg: false,
|
|
noneBtnImg: false,
|
|
- aiImageNav: [],
|
|
|
|
|
|
+ baseFile: "",
|
|
};
|
|
};
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
@@ -159,14 +159,17 @@ export default {
|
|
uploadIsType() {
|
|
uploadIsType() {
|
|
this.type = 1;
|
|
this.type = 1;
|
|
this.uploadDialogVisible = false;
|
|
this.uploadDialogVisible = false;
|
|
- // this.getImageNav();
|
|
|
|
|
|
+ this.getImageNav();
|
|
},
|
|
},
|
|
- checkImage(){
|
|
|
|
- // if(this.myAnswerList.imgList.length > 0 && this.myAnswerList.imgList[0].url){
|
|
|
|
- // this.getImageNav();
|
|
|
|
- // }else{
|
|
|
|
- // this.uploadDialogVisible = false;
|
|
|
|
- // }
|
|
|
|
|
|
+ checkImage() {
|
|
|
|
+ if (
|
|
|
|
+ this.myAnswerList.imgList.length > 0 &&
|
|
|
|
+ this.myAnswerList.imgList[0].url
|
|
|
|
+ ) {
|
|
|
|
+ this.getImageNav();
|
|
|
|
+ } else {
|
|
|
|
+ this.uploadDialogVisible = false;
|
|
|
|
+ }
|
|
this.uploadDialogVisible = false;
|
|
this.uploadDialogVisible = false;
|
|
},
|
|
},
|
|
async beforeUpload(event) {
|
|
async beforeUpload(event) {
|
|
@@ -245,6 +248,7 @@ export default {
|
|
name: file.name,
|
|
name: file.name,
|
|
url: data.Location,
|
|
url: data.Location,
|
|
});
|
|
});
|
|
|
|
+ _this.pngToWhiteBg(file);
|
|
_this.imgChange();
|
|
_this.imgChange();
|
|
console.log(data.Location);
|
|
console.log(data.Location);
|
|
// _this.$message.success('上传成功'+data.Location)
|
|
// _this.$message.success('上传成功'+data.Location)
|
|
@@ -252,8 +256,34 @@ export default {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- getImageNav(){
|
|
|
|
- let url = this.myAnswerList.imgList[0].url;
|
|
|
|
|
|
+ pngToWhiteBg(file) {
|
|
|
|
+ const _file = file;
|
|
|
|
+ let read = new FileReader();
|
|
|
|
+ read.readAsDataURL(file); // 文件转base64
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ read.onload = (e) => {
|
|
|
|
+ let img = new Image();
|
|
|
|
+ img.src = e.target.result;
|
|
|
|
+ img.onload = async () => {
|
|
|
|
+ // 生成canvas
|
|
|
|
+ let canvas = document.createElement("canvas");
|
|
|
|
+ let context = canvas.getContext("2d");
|
|
|
|
+ // 绘制图片到canvas上
|
|
|
|
+ canvas.width = img.width;
|
|
|
|
+ canvas.height = img.height;
|
|
|
|
+
|
|
|
|
+ // 在canvas绘制前填充白色背景
|
|
|
|
+ context.fillStyle = "#fff";
|
|
|
|
+ context.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
+ context.drawImage(img, 0, 0);
|
|
|
|
+ let base64 = canvas.toDataURL(file["type"], 1);
|
|
|
|
+ this.baseFile = base64;
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ getImageNav() {
|
|
|
|
+ let url = this.baseFile;
|
|
const loading = this.$loading.service({
|
|
const loading = this.$loading.service({
|
|
background: "rgba(255, 255, 255)",
|
|
background: "rgba(255, 255, 255)",
|
|
target: document.querySelectorAll(".loadingImageText")[0],
|
|
target: document.querySelectorAll(".loadingImageText")[0],
|
|
@@ -262,20 +292,22 @@ export default {
|
|
messages: [
|
|
messages: [
|
|
{
|
|
{
|
|
role: "user",
|
|
role: "user",
|
|
- content:[
|
|
|
|
- { type: "image_url",text: "提取图片里面的英语文章,要求返回格式是JSON{title:'标题',content:'内容'}" },
|
|
|
|
- {
|
|
|
|
|
|
+ content: [
|
|
|
|
+ {
|
|
|
|
+ type: "text",
|
|
|
|
+ text: "这张图片里面有哪些文字?返回格式为{title:标题,content:内容}",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
type: "image_url",
|
|
type: "image_url",
|
|
image_url: {
|
|
image_url: {
|
|
url: url,
|
|
url: url,
|
|
- detail: "low"
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
},
|
|
},
|
|
],
|
|
],
|
|
max_tokens: 4096,
|
|
max_tokens: 4096,
|
|
- uid: this.userid,
|
|
|
|
|
|
+ uid: "a77e9404-efec-11e9-96f9-028edca3b798",
|
|
stream: false,
|
|
stream: false,
|
|
};
|
|
};
|
|
this.ajax.post("https://gpt4.cocorobo.cn/imageAnalyse", param).then(
|
|
this.ajax.post("https://gpt4.cocorobo.cn/imageAnalyse", param).then(
|
|
@@ -289,14 +321,17 @@ export default {
|
|
loading.close();
|
|
loading.close();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- let aiImageNav = res.data.FunctionResponse.choices ? res.data.FunctionResponse.choices[0].message.content : '';
|
|
|
|
|
|
+ let aiImageNav = res.data.FunctionResponse.choices
|
|
|
|
+ ? res.data.FunctionResponse.choices[0].message.content
|
|
|
|
+ : "";
|
|
try {
|
|
try {
|
|
- aiImageNav = JSON.parse(aiImageNav)
|
|
|
|
|
|
+ aiImageNav = JSON.parse(aiImageNav);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- this.getImageNav()
|
|
|
|
|
|
+ this.getImageNav();
|
|
}
|
|
}
|
|
- console.log(aiImageNav)
|
|
|
|
- this.aiImageNav = aiImageNav;
|
|
|
|
|
|
+ console.log(aiImageNav);
|
|
|
|
+ this.myAnswerList.engTitle = aiImageNav.title;
|
|
|
|
+ this.myAnswerList.engText = aiImageNav.content;
|
|
this.type = 1;
|
|
this.type = 1;
|
|
loading.close();
|
|
loading.close();
|
|
},
|
|
},
|
|
@@ -304,7 +339,7 @@ export default {
|
|
console.log(err);
|
|
console.log(err);
|
|
loading.close();
|
|
loading.close();
|
|
}
|
|
}
|
|
- );
|
|
|
|
|
|
+ );
|
|
},
|
|
},
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|