|
|
|
|
@ -34,201 +34,200 @@
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
aitext: '',
|
|
|
|
|
aitext: "",
|
|
|
|
|
timer: null,
|
|
|
|
|
timer1: null,
|
|
|
|
|
defaultPercent: 0,
|
|
|
|
|
ailoading: false,
|
|
|
|
|
aiConfig: {
|
|
|
|
|
token: '',
|
|
|
|
|
id: '',
|
|
|
|
|
token: "",
|
|
|
|
|
id: "",
|
|
|
|
|
},
|
|
|
|
|
chooseImgShow: false,
|
|
|
|
|
currentImg: '',
|
|
|
|
|
}
|
|
|
|
|
currentImg: "",
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.getAiToken()
|
|
|
|
|
this.getAiToken();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
openCore(respons) {
|
|
|
|
|
console.log('open sse:', respons)
|
|
|
|
|
console.log("open sse:", respons);
|
|
|
|
|
},
|
|
|
|
|
errorCore(err) {
|
|
|
|
|
console.log('error sse:', err)
|
|
|
|
|
console.log("error sse:", err);
|
|
|
|
|
},
|
|
|
|
|
messageCore(msg) {
|
|
|
|
|
let that = this
|
|
|
|
|
console.log('message sse:', msg)
|
|
|
|
|
if (msg.event == 'Done') {
|
|
|
|
|
clearInterval(that.timer)
|
|
|
|
|
that.ailoading = false
|
|
|
|
|
} else if (msg.event == 'Message') {
|
|
|
|
|
let info = JSON.parse(msg.data)
|
|
|
|
|
if (info.node_type == 'End') {
|
|
|
|
|
this.setInfo(info)
|
|
|
|
|
let that = this;
|
|
|
|
|
console.log("message sse:", msg);
|
|
|
|
|
if (msg.event == "Done") {
|
|
|
|
|
clearInterval(that.timer);
|
|
|
|
|
that.ailoading = false;
|
|
|
|
|
} else if (msg.event == "Message") {
|
|
|
|
|
let info = JSON.parse(msg.data);
|
|
|
|
|
if (info.node_type == "End") {
|
|
|
|
|
this.setInfo(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getAiToken() {
|
|
|
|
|
let that = this
|
|
|
|
|
that.G.Get('/yishoudan/common/structure/getConfig', {}, (res) => {
|
|
|
|
|
console.log('res', res)
|
|
|
|
|
let that = this;
|
|
|
|
|
that.G.Get("/yishoudan/common/structure/getConfig", {}, (res) => {
|
|
|
|
|
console.log("res", res);
|
|
|
|
|
that.aiConfig = {
|
|
|
|
|
token: res.token,
|
|
|
|
|
id: res.workflowId,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
uploadPhoto($sourceType) {
|
|
|
|
|
let that = this
|
|
|
|
|
console.log('$sourceType', $sourceType)
|
|
|
|
|
let that = this;
|
|
|
|
|
console.log("$sourceType", $sourceType);
|
|
|
|
|
uni.chooseImage({
|
|
|
|
|
count: 1, //默认9
|
|
|
|
|
sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
|
|
|
|
|
sizeType: ["original"], //可以指定是原图还是压缩图,默认二者都有
|
|
|
|
|
sourceType: [$sourceType], //album 从相册选图,camera 使用相机
|
|
|
|
|
success: function (res) {
|
|
|
|
|
console.log('选取文件数据:', res)
|
|
|
|
|
that.uploadCozeFile(res.tempFilePaths[0])
|
|
|
|
|
console.log("选取文件数据:", res);
|
|
|
|
|
that.uploadCozeFile(res.tempFilePaths[0]);
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
uploadCozeFile(tempFilePath) {
|
|
|
|
|
let that = this
|
|
|
|
|
that.chooseImgShow = false
|
|
|
|
|
that.currentImg = tempFilePath
|
|
|
|
|
let that = this;
|
|
|
|
|
that.chooseImgShow = false;
|
|
|
|
|
that.currentImg = tempFilePath;
|
|
|
|
|
uni.uploadFile({
|
|
|
|
|
url: 'https://api.coze.cn/v1/files/upload',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: "https://api.coze.cn/v1/files/upload",
|
|
|
|
|
method: "POST",
|
|
|
|
|
filePath: tempFilePath,
|
|
|
|
|
name: 'file',
|
|
|
|
|
name: "file",
|
|
|
|
|
header: {
|
|
|
|
|
Authorization: 'Bearer ' + that.aiConfig.token,
|
|
|
|
|
'Content-Type': 'multipart/form-data',
|
|
|
|
|
Authorization: "Bearer " + that.aiConfig.token,
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
},
|
|
|
|
|
formData: {},
|
|
|
|
|
success: function (res) {
|
|
|
|
|
console.log('文件', res)
|
|
|
|
|
let data = JSON.parse(res.data)
|
|
|
|
|
that.appCoze(data.data.id)
|
|
|
|
|
console.log("文件", res);
|
|
|
|
|
let data = JSON.parse(res.data);
|
|
|
|
|
that.appCoze(data.data.id);
|
|
|
|
|
},
|
|
|
|
|
fail: function (err) {
|
|
|
|
|
console.log(err)
|
|
|
|
|
console.log(err);
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
uploadPhotoByChat() {
|
|
|
|
|
let that = this
|
|
|
|
|
let that = this;
|
|
|
|
|
uni.chooseMessageFile({
|
|
|
|
|
count: 1,
|
|
|
|
|
type: 'image',
|
|
|
|
|
type: "image",
|
|
|
|
|
success(res) {
|
|
|
|
|
console.log('resresresresresres', res)
|
|
|
|
|
if (res.errMsg == 'chooseMessageFile:ok') {
|
|
|
|
|
console.log('res', res)
|
|
|
|
|
that.uploadCozeFile(res.tempFiles[0].path)
|
|
|
|
|
console.log("resresresresresres", res);
|
|
|
|
|
if (res.errMsg == "chooseMessageFile:ok") {
|
|
|
|
|
console.log("res", res);
|
|
|
|
|
that.uploadCozeFile(res.tempFiles[0].path);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
getClipboard() {
|
|
|
|
|
let that = this
|
|
|
|
|
let that = this;
|
|
|
|
|
if (this.aitext) {
|
|
|
|
|
this.aitext = ''
|
|
|
|
|
this.aitext = "";
|
|
|
|
|
} else {
|
|
|
|
|
uni.getClipboardData({
|
|
|
|
|
success(res) {
|
|
|
|
|
console.log(res)
|
|
|
|
|
if(res.data){
|
|
|
|
|
that.aitext = res.data
|
|
|
|
|
}else{
|
|
|
|
|
console.log(res);
|
|
|
|
|
if (res.data) {
|
|
|
|
|
that.aitext = res.data;
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '请先复制内容',
|
|
|
|
|
icon: 'none',
|
|
|
|
|
})
|
|
|
|
|
title: "请先复制内容",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fail() {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '读取剪切板失败',
|
|
|
|
|
icon: 'none',
|
|
|
|
|
})
|
|
|
|
|
title: "读取剪切板失败",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
setInfo(parsed) {
|
|
|
|
|
let that = this
|
|
|
|
|
const finalData = JSON.parse(parsed.content)
|
|
|
|
|
let that = this;
|
|
|
|
|
const finalData = JSON.parse(parsed.content);
|
|
|
|
|
if (finalData) {
|
|
|
|
|
console.log('解析后的用户信息:', finalData)
|
|
|
|
|
console.log("解析后的用户信息:", finalData);
|
|
|
|
|
let info = {
|
|
|
|
|
idCard: finalData.idcard,
|
|
|
|
|
address: finalData.address,
|
|
|
|
|
name: finalData.username,
|
|
|
|
|
nation: finalData.nation,
|
|
|
|
|
userName: finalData.username,
|
|
|
|
|
sex: finalData.sex ? (finalData.sex == '男' ? 1 : 2) : '',
|
|
|
|
|
sex: finalData.sex ? (finalData.sex == "男" ? 1 : 2) : "",
|
|
|
|
|
age: finalData.age,
|
|
|
|
|
tel: finalData.tel,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// uni.$emit('getTownsman', { info })
|
|
|
|
|
that.$emit('outputInfo', info)
|
|
|
|
|
that.$emit("outputInfo", info);
|
|
|
|
|
// 将解析后的信息填充到表单中
|
|
|
|
|
that.ailoading = false
|
|
|
|
|
that.ailoading = false;
|
|
|
|
|
} else {
|
|
|
|
|
that.ailoading = false
|
|
|
|
|
that.ailoading = false;
|
|
|
|
|
}
|
|
|
|
|
clearInterval(that.timer)
|
|
|
|
|
clearInterval(that.timer);
|
|
|
|
|
},
|
|
|
|
|
getCoze() {
|
|
|
|
|
let that = this
|
|
|
|
|
let that = this;
|
|
|
|
|
if (!that.aitext) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '请粘贴内容',
|
|
|
|
|
icon: 'none',
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
title: "请粘贴内容",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.appCoze()
|
|
|
|
|
this.appCoze();
|
|
|
|
|
},
|
|
|
|
|
appCoze(_id) {
|
|
|
|
|
let that = this
|
|
|
|
|
let parameters = {}
|
|
|
|
|
let that = this;
|
|
|
|
|
let parameters = {};
|
|
|
|
|
// 重置内容
|
|
|
|
|
that.ailoading = true
|
|
|
|
|
that.defaultPercent = 3
|
|
|
|
|
that.ailoading = true;
|
|
|
|
|
that.defaultPercent = 3;
|
|
|
|
|
|
|
|
|
|
that.timer = setInterval(() => {
|
|
|
|
|
that.defaultPercent = that.defaultPercent < 15 ? (that.defaultPercent = 15) : that.defaultPercent + 3
|
|
|
|
|
that.defaultPercent = that.defaultPercent < 15 ? (that.defaultPercent = 15) : that.defaultPercent + 3;
|
|
|
|
|
// console.log('12313123123123123')
|
|
|
|
|
if (that.defaultPercent >= 99) {
|
|
|
|
|
clearInterval(that.timer)
|
|
|
|
|
clearInterval(that.timer);
|
|
|
|
|
}
|
|
|
|
|
}, 150)
|
|
|
|
|
}, 150);
|
|
|
|
|
that.timer1 = setTimeout(() => {
|
|
|
|
|
console.log('5687678678678678678')
|
|
|
|
|
that.ailoading = false
|
|
|
|
|
clearInterval(that.timer)
|
|
|
|
|
console.log("5687678678678678678");
|
|
|
|
|
that.ailoading = false;
|
|
|
|
|
clearInterval(that.timer);
|
|
|
|
|
// setLoading()
|
|
|
|
|
}, 30000)
|
|
|
|
|
}, 30000);
|
|
|
|
|
if (_id) {
|
|
|
|
|
parameters = {
|
|
|
|
|
img: {
|
|
|
|
|
file_id: _id,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
parameters = {
|
|
|
|
|
txt: that.aitext,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
this.$refs.sseTest.startChat({
|
|
|
|
|
/**
|
|
|
|
|
@ -236,26 +235,28 @@ export default {
|
|
|
|
|
* 注意:
|
|
|
|
|
* 如果使用 sse-server.js 要在手机端使用的话,请确保你的手机和电脑处在一个局域网下并且是正常的ip地址
|
|
|
|
|
*/
|
|
|
|
|
url: 'https://api.coze.cn/v1/workflow/stream_run',
|
|
|
|
|
url: "https://api.coze.cn/v1/workflow/stream_run",
|
|
|
|
|
// 请求头
|
|
|
|
|
headers: {
|
|
|
|
|
// that.aiConfig.token
|
|
|
|
|
Authorization: 'Bearer ' + that.aiConfig.token,
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: "Bearer " + that.aiConfig.token,
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
// 默认为 post
|
|
|
|
|
method: 'post',
|
|
|
|
|
method: "post",
|
|
|
|
|
body: {
|
|
|
|
|
parameters,
|
|
|
|
|
// workflow_id: that.aiConfig.id,
|
|
|
|
|
workflow_id: '7520814905613664310',
|
|
|
|
|
workflow_id: "7520814905613664310",
|
|
|
|
|
// workflow_id: '7492238568816656410',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
ressetAitext() {
|
|
|
|
|
this.aitext = "";
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
</style>
|
|
|
|
|
<style></style>
|
|
|
|
|
|