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.

221 lines
6.4 KiB

// pages/Students/students.js
Page({
data: {
name:'Students',
selectedTime: '--时--分',
selectedDate: '--年--月--日',
selectedIndex1: 0,
selectedIndex9: 0,
selectedIndex22: 0,
selectedIndex23: 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'],
phase:['请选择','场外维护','加油','装载食品/货物','登机','推飞机','发动机开车/试车','滑行','其它'],
involve:['请选择','是','否'],
student:['请选择','飞行学生','地面学生','其它']
},
//时间选择
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
});
},
//学生类型
onstudent: function(event) {
this.setData({
selectedIndex23: event.detail.value
});
},
//飞行阶段
onphase: function(event) {
this.setData({
selectedIndex9: event.detail.value
});
},
//是否涉及航空器
oninvolve: function(event) {
this.setData({
selectedIndex22: event.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,
selectedIndex22: 0,
selectedIndex23: 0,
selectedIndex9: 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 = this.data.timezones[data.selectedIndex1]; // 获取时区文本
const phaseText = this.data.phase[data.selectedIndex9]; // 获取飞行阶段文本
const involveText = this.data.involve[data.selectedIndex22]; // 获取是否涉及航空器的文本
const studentText = this.data.student[data.selectedIndex23]; // 获取学生类型的文本
// 提交的数据中只包含实际选择的文本内容
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, // 时区对应的文本
phase: phaseText, // 飞行阶段对应的文本
involve: involveText, // 是否涉及航空器对应的文本
studentType: studentText, // 学生类型对应的文本
inputValue20: data.inputValue20,
inputValue21: data.inputValue21,
inputValue22: data.inputValue22,
inputValue23: data.inputValue23,
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() {
}
})