Commit cc15a1f0 by 前端

api

1 parent 76ee2511
import api from "~/utils/request/request.js"; import api from "~/utils/request/request.js";
export default { export default {
//处理对练环节的请求,并根据不同的环节提供相应的建议或执行相应的操作。
sparring(data = {}) { sparring(data = {}) {
return api.post( return api.post(
"", "",
data, data,
[], [],
"/router/sparring", "/router/sparring/1.0.0",
"AI" "AI"
); );
}, },
//获取防守建议
defense(data = {}) { defense(data = {}) {
return api.post( return api.post(
"", "",
data, data,
[], [],
"/router/defense", "/router/defense/1.0.0",
"AI"
);
},
//通过POST请求获取灵感建议。
inspiration(data = {}) {
return api.post(
"",
data,
[],
"/router/inspiration/1.0.0",
"AI"
);
},
//异步函数,通过分析历史消息来获取改进建议和润色表达的提示。
enhancement(data = {}) {
return api.post(
"",
data,
[],
"/router/enhancement/1.0.0",
"AI"
);
},
//根据提供的历史消息、用户ID、批次ID和持续时间,获取销售能力模拟评测的结果,并将结果数据存储数据库。
scoring(data = {}) {
return api.post(
"",
data,
[],
"/router/scoring/1.0.0",
"AI" "AI"
); );
}, },
......
...@@ -23,29 +23,21 @@ const productList = [{ ...@@ -23,29 +23,21 @@ const productList = [{
} }
] ]
import aiApi from '../../../aiApi' import aiApi from '../../../aiApi'
import {WELCOME} from './data'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
productInfo: {}, productInfo: {},
step: 'reception',// 当前对练的环节,可选值为"reception"(接待)、"defense"(攻防)、"referral"(转介)、"over"(结束),用于指示当前处理的环节。
navStyle: 'background-image: linear-gradient(0deg, #FAFAFA 0%, #EBF3FF 100%);', navStyle: 'background-image: linear-gradient(0deg, #FAFAFA 0%, #EBF3FF 100%);',
showChat: false, // false 展示介绍页,true展示聊天页 showChat: false, // false 展示介绍页,true展示聊天页
showScenePopup: false, // 场弹窗 showScenePopup: false, // 场弹窗
showSpeechPopup: false, // 语音弹窗 showSpeechPopup: false, // 语音弹窗
popType: '', // script 话术攻防,inspiration 对话灵感,scene 场景 popType: '', // script 话术攻防,inspiration 对话灵感,scene 场景
controlBoxStyle: '', // 控制控制台的层级 controlBoxStyle: '', // 控制控制台的层级
chatList: [{ chatList: [],
role: 1,
content: '控制控制台的层级',
time: 5,
}, {
role: 2,
content: '控制控制台的层级',
time: 5,
show:false,
loading:false
}],
scriptList: [ // 话术攻防数据 scriptList: [ // 话术攻防数据
{ {
content: '这个车我用两年就换了,没必要买延保。' content: '这个车我用两年就换了,没必要买延保。'
...@@ -100,11 +92,11 @@ Page({ ...@@ -100,11 +92,11 @@ Page({
popType: type, popType: type,
controlBoxStyle controlBoxStyle
}) })
setTimeout(() => { if(type == 'inspiration') {
this.setData({ this.getInspiration()
inspirationContent: '当然,我很高兴能为您提供帮助。我们的新款车型性能优越,安全性能出色,而且售后服务也非常完善。您可以放心购买,我们会为您提供最优质的购车体验。您有什么特别需求或偏好吗?' }else {
}) this.getDefense()
}, 3000) }
}, },
// 弹窗取消 // 弹窗取消
cancel() { cancel() {
...@@ -113,47 +105,109 @@ Page({ ...@@ -113,47 +105,109 @@ Page({
}) })
}, },
send(e) { send(e) {
const {result:content,filePath} = e.detail const {
const {chatList} = this.data; result: content,
filePath
} = e.detail
const {
chatList
} = this.data;
chatList.push({ chatList.push({
role:2, role: 2,
content, content,
filePath, filePath,
loading: false, loading: true,
show:false, show: false,
}) })
this.setData({ this.setData({
chatList, chatList,
showSpeechPopup:false showSpeechPopup: false
}) })
aiApi.sparring({}).then(res=>{ this.getSparring(content);
this.getEnhancement(content);
},
//获取改进建议和润色表达
getEnhancement(last_message) {
aiApi.enhancement({last_message}).then(res=>{
console.log(res) console.log(res)
}) })
}, },
//获取防守建议
getDefense() {
aiApi.inspiration({}).then(res=>{
this.setData({scriptList:[1,2,3]})
})
},
//获取灵感建议
getInspiration() {
aiApi.inspiration({}).then(res=>{
this.setData({
inspirationContent: '当然,我很高兴能为您提供帮助。我们的新款车型性能优越,安全性能出色,而且售后服务也非常完善。您可以放心购买,我们会为您提供最优质的购车体验。您有什么特别需求或偏好吗?'
})
})
},
//提供相应的建议
getSparring(user_message) {
const {step} = this.data
let history_message
if(!user_message) {
history_message = WELCOME
}else {
history_message = '5'
}
aiApi.sparring({
user_message,
history_message,
step,
main_point: 4,
defense_step: 4,
round: 0
}).then(res => {
const {chatList} = this.data;
const {sale_message} = res
chatList.push({
role: 1,
content: sale_message,
time: Math.floor(sale_message.length / 3)
})
this.setData({chatList})
})
},
//重置 //重置
resetChat() { resetChat() {
const {chatList} = this.data; const {
chatList
} = this.data;
chatList.pop(); chatList.pop();
chatList.pop(); chatList.pop();
this.setData({chatList}) this.setData({
chatList
})
}, },
handleShow(e) { handleShow(e) {
const {index} = e.currentTarget.dataset const {
const {chatList} = this.data; index
} = e.currentTarget.dataset
const {
chatList
} = this.data;
chatList[index].show = true; chatList[index].show = true;
this.setData({chatList}) this.setData({
chatList
})
}, },
// 点击说话 // 点击说话
handleSpeak() { handleSpeak() {
this.setData({ this.setData({
showSpeechPopup: true showSpeechPopup: true,
controlBoxStyle:'z-index: 0;'
}) })
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
this.getSparring('')
}, },
/** /**
......
export const WELCOME =
`
销售说:您好,张先生,我是这里的质保经理李强。首先,恭喜您提车,成为我们M7车型的尊贵车主!在您享受驾驶乐趣的同时,稍后我会向您详细介绍车辆的使用注意事项以及我们提供的保养和质保相关服务。
`
\ No newline at end of file \ No newline at end of file
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
} from './http.js' } from './http.js'
// console.log(secretKey, 'secretKey') // console.log(secretKey, 'secretKey')
import util from '~/utils/util.js' import util from '~/utils/util.js'
import qs from '~/utils/lib/qs'
/**接口 */ /**接口 */
class Request { class Request {
get(method, data, noSignAttr, requestPath, domainName) { get(method, data, noSignAttr, requestPath, domainName) {
...@@ -24,16 +25,27 @@ class Request { ...@@ -24,16 +25,27 @@ class Request {
{ {
'content-type': 'application/x-www-form-urlencoded' 'content-type': 'application/x-www-form-urlencoded'
} : } :
{} {};
if(domainName != 'AI') let url = `${domain[domainName]}${requestPath || path}`;
data = _this.getData(data, method, noSignAttr , domainName == 'merchants') if(method) {
data = _this.getData(data, method, noSignAttr , domainName == 'merchants')
url = `${domain[domainName]}${requestPath || path}?method=${method}`;
}else {
const queryString = qs.stringify(data, {
arrayFormat: 'indices',
allowDots: true,
encodeValuesOnly: true
})
url = `${domain[domainName]}${requestPath || path}?${queryString}`
data = null
}
// console.log('reqData',data?.sessionId); // console.log('reqData',data?.sessionId);
// delete // delete
// if (data?.sessionId) { // if (data?.sessionId) {
// delete data?.sessionId // delete data?.sessionId
// } // }
wx.request({ wx.request({
url: `${domain[domainName]}${requestPath || path}?method=${method}`, url,
data, data,
method: RequestMethods, method: RequestMethods,
header, header,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!