You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.5 KiB

// pages/Fast/Fast.js
Page({
data: {
name:'Fast',
selectedTime: '--时--分',
selectedDate: '--年--月--日',
selectedIndex1: 0,
inputValue20: '',
inputValue21: '',
inputValue22: '',
inputValue23: '',
timezones: ['请选择','UTC-12:00', 'UTC-11:00', 'UTC-10:00', 'UTC-9:00', 'UTC-8:00', 'UTC-7:00', 'UTC-6:00', 'UTC-5:00', 'UTC-4:00', 'UTC-3:00', 'UTC-2:00', 'UTC-1:00', 'UTC+0:00', 'UTC+1:00', 'UTC+2:00', 'UTC+3:00', 'UTC+4:00', 'UTC+5:00', 'UTC+6:00', 'UTC+7:00', 'UTC+8:00', 'UTC+9:00', 'UTC+10:00', 'UTC+11:00', 'UTC+12:00'],
},
//时间选择
onTimeChange: function (event) {
this.setData({
selectedTime: event.detail.value
});
},
onTimezoneChange: function (event) {
this.setData({
selectedIndex1: event.detail.value
});
},
onDateChange: function(e) {
this.setData({
selectedDate: e.detail.value
});
},
//事件经过
onInput20: function(event) {
this.setData({
inputValue20: event.detail.value
});
},
//个人信息//姓名电话邮箱
onInput21: function(event) {
this.setData({
inputValue21: event.detail.value
});
},
onInput22: function(event) {
this.setData({
inputValue22: event.detail.value
});
},
onInput23: function(event) {
this.setData({
inputValue23: event.detail.value
});
},
//提交与重写
onReset() {
this.setData({
selectedTime: '--时--分',
selectedDate: '--年--月--日',
selectedIndex1: 0,
inputValue20: '',
inputValue21: '',
inputValue22: '',
inputValue23: '',
},() => {
console.log('Form has been reset');
})
},
//提交数据
onSubmit: function () {
// 获取存储中的 token
const token = wx.getStorageSync('token');
if (!token) {
console.log('Token 不存在,请先登录');
wx.showToast({
title: '请先登录',
icon: 'none'
});
return; // 终止提交
}
const data = this.data;
// 获取各选择项的实际文本值
const timezoneText = data.timezones[data.selectedIndex1]; // 获取时区的实际文本
// 提交数据到后端
wx.request({
url: 'http://192.168.137.1:8080/report/add',
method: 'POST',
header: {
'Authorization': `${token}`,
'content-type': 'application/json'
},
data: {
selectedTime: data.selectedTime, // 提交的选定时间
selectedDate: data.selectedDate, // 提交的选定日期
timezone: timezoneText, // 提交时区的实际文本
inputValue20: data.inputValue20, // 提交输入值20
inputValue21: data.inputValue21, // 提交输入值21
inputValue22: data.inputValue22, // 提交输入值22
inputValue23: data.inputValue23, // 提交输入值23
name: data.name // 提交姓名
},
success: function (res) {
console.log('Data submitted successfully:', res);
},
fail: function (err) {
console.error('Error submitting data:', err);
}
});
// 使用腾讯混元智能体的 API 调用
wx.request({
url: 'https://yuanqi.tencent.com/openapi/v1/agent/chat/completions',
method: 'POST',
header: {
'X-Source': 'openapi',
'Content-Type': 'application/json',
'Authorization': 'Bearer jSNTZONSnnzJ2uuQT7IEgXlPzfE4lX5f' // 替换为你的实际 Bearer Token
},
data: {
assistant_id: 'ty1W9unZM9IY', // 替换为实际的 assistant_id
user_id: '123456', // 替换为实际的用户ID
stream: false,
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: JSON.stringify(data) // 将用户填写的数据转换为字符串
}
]
}
]
},
success: function (res) {
console.log('API 调用成功: ', res); // 打印完整的 API 响应
console.log('API 返回的 choices:', res.data.choices); // 检查数据结构
// 检查选择项并从中提取智能体回复
if (res.data && res.data.choices && res.data.choices.length > 0) {
// 确保 message 字段的内容可以被访问
const messageContent = res.data.choices[0].message?.content;
let agentReply;
// 如果 messageContent 存在并且是一个数组,则提取内容
if (Array.isArray(messageContent) && messageContent.length > 0) {
agentReply = messageContent[0].text; // 假设内容在数组的第一个元素中
} else {
agentReply = messageContent || '无法获取智能体的回复';
}
// 跳转到详情页面并传递数据和智能体的回复
wx.navigateTo({
url: '/pages/FlightCrewDetails/FlightCrewDetails',
success: function (navRes) {
navRes.eventChannel.emit('sendData', {
details: data, // 用户输入的数据
agentReply: agentReply // 智能体的回复
});
}
});
} else {
console.log('API 响应中没有 choices');
}
},
fail: function (err) {
console.log('智能体调用失败', err);
}
});
},
onLoad(options) {
},
onReady() {
},
onShow() {
},
onHide() {
},
onUnload() {
},
onPullDownRefresh() {
},
onReachBottom() {
},
onShareAppMessage() {
}
})