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.
SCASS_project/FlightCrew/FlightCrew.js

405 lines
12 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

// pages/FlightCrew/FlightCrew.js
Page({
  data: {
    name:'FlightCrew',
    selectedTime: '--时--分',
    selectedDate: '--年--月--日',
    selectedIndex1: 0, 
    selectedIndex2: 0, 
    selectedIndex3: 0, 
    selectedIndex4: 0, 
    selectedIndex5: 0,
    selectedIndex6: 0,
    selectedIndex7: 0, 
    selectedIndex8: 0,
    selectedIndex9: 0,
    selectedIndex10: 0,
    selectedIndex11: 0,
    selectedIndex12: 0,
    selectedIndex13: 0,
    selectedIndex14: 0,
    selectedIndex15: 0,
    inputValue1: '',
    inputValue2: '',
    inputValue3: '',
    inputValue4: '',
    inputValue5: '',
    inputValue6: '',
    inputValue7: '',
    inputValue8: '',
    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'],
    workposition:['请选择','机长','副驾驶','责任机长','教员','学员','其他'],
    controll: ['请选择','是','否'],
    License:['请选择','私用驾驶员执照','商用驾驶员执照','航线运输驾驶员执照','临时执照','无','其它'],
    ACFT:['请选择','飞机','直升机','滑翔机','其它'],
    company:['请选择','运输航空公司','通用航空公司','公务航空公司','飞行训练机构','其它'],
    task:['请选择','客运','货运','训练','检查','调机','通用飞行','其它'],
    plan:['请选择','目视飞行计划','仪表飞行计划','其它'],
    phase:['请选择','地面/滑行','起飞','爬升','巡航/作业','下降','进近','复飞','着陆','其它'],
    weather:['请选择','IMC','VMC','雷暴','风切变','紊流','结冰','雨','雪','雾','多云','其它'],
    lv:['请选择','黎明','昼间','黄昏/曙暮光','夜间/月光','夜间/黑暗','未知'],
    ATS:['请选择','地面','塔台','进近','区调','其它'],
    ATC:['请选择','雷达管制','程序管制','雷达监视下的程序管制','其它'],
    TCAS:['请选择','是','否'],
    Advise:['请选择','是','否'],
  },
  //时间选择
  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
    });
  },
  //工作时间选择
  onInput1: function(event) {
    this.setData({
      inputValue1: event.detail.value
    });
  },
  onInput2: function(event) {
    this.setData({
      inputValue2: event.detail.value
    });
  },
  onInput3: function(event) {
    this.setData({
      inputValue3: event.detail.value
    });
  },
  //岗位选择
  onworkposition: function (event) {
    this.setData({
      selectedIndex2: event.detail.value
    });
  },
  //控制器选择
  oncontroll: function(event) {
    this.setData({
      selectedIndex3: event.detail.value
    });
  },
  //执照选择
  onLicense: function(event) {
    this.setData({
      selectedIndex4: event.detail.value
    });
  },
  //工作经验
  onInput4: function(event) {
    this.setData({
      inputValue4: event.detail.value
    });
  },
  onInput5: function(event) {
    this.setData({
      inputValue5: event.detail.value
    });
  },
  //航空器种类
  onACFT: function(event) {
    this.setData({
      selectedIndex5: event.detail.value
    });
  },
  //工作单位种类
  oncompany: function(event) {
    this.setData({
      selectedIndex6: event.detail.value
    });
  },
  //任务
  ontask: function(event) {
    this.setData({
      selectedIndex7: event.detail.value
    });
  },
  //计划
  onplan: function(event) {
    this.setData({
      selectedIndex8: event.detail.value
    });
  },
  //飞行阶段
  onphase: function(event) {
    this.setData({
      selectedIndex9: event.detail.value
    });
  },
  //飞行高度
  onInput6: function(event) {
    this.setData({
      inputValue6: event.detail.value
    });
  },
  //天气
  onweather: function(event) {
    this.setData({
      selectedIndex10: event.detail.value
    });
  },
  //光线条件和能见度
  onlv: function(event) {
    this.setData({
      selectedIndex11: event.detail.value
    });
  },
  onInput7: function(event) {
    this.setData({
      inputValue7: event.detail.value
    });
  },
  onInput8: function(event) {
    this.setData({
      inputValue8: event.detail.value
    });
  },
  //ATS
  onATS: function (event) {
    this.setData({
      selectedIndex12: event.detail.value
    });
  },
  //ATC
  onATC: function (event) {
    this.setData({
      selectedIndex13: event.detail.value
    });
  },
  //TCAS
  onTCAS: function (event) {
    this.setData({
      selectedIndex14: event.detail.value
    });
  },
  //Advise
  onAdvise: function (event) {
    this.setData({
      selectedIndex15: 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
    });
  },
  //事件经过
  onInput20: function(event) {
    this.setData({
      inputValue20: event.detail.value
    });
  },
  //提交与重写
  onReset() {
    this.setData({
      selectedTime: '--时--分',
      selectedDate: '--年--月--日',
      selectedIndex1: 0,
      selectedIndex2: 0,
      selectedIndex3: 0,
      selectedIndex4: 0,
      selectedIndex5: 0,
      selectedIndex6: 0,
      selectedIndex7: 0,
      selectedIndex8: 0,
      selectedIndex9: 0,
      selectedIndex10: 0,
      selectedIndex11: 0,
      selectedIndex12: 0,
      selectedIndex13: 0,
      selectedIndex14: 0,
      selectedIndex15: 0,
      inputValue1: '',
      inputValue2: '',
      inputValue3: '',
      inputValue4: '',
      inputValue5: '',
      inputValue6: '',
      inputValue7: '',
      inputValue8: '',
      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];
const workPositionText = data.workposition[data.selectedIndex2];
const licenseText = data.License[data.selectedIndex4];
const acftText = data.ACFT[data.selectedIndex5];
const taskText = data.task[data.selectedIndex7];
const phaseText = data.phase[data.selectedIndex9];
const weatherText = data.weather[data.selectedIndex10];
const lvText = data.lv[data.selectedIndex11];
const ats = data.ATS[data.selectedIndex12];
const atc = data.ATC[data.selectedIndex13];
const tcas = data.TCAS[data.selectedIndex14];
const advise = data.Advise[data.selectedIndex15];
wx.request({
url: 'http://192.168.144.1:8080/report/add',
method: 'POST',
header: {
'Authorization': `${token}`,
'content-type': 'application/json'
},
data: {
selectedTime: data.selectedTime,
selectedDate: data.selectedDate,
timezone: timezoneText,
workPosition: workPositionText,
license: licenseText,
acft: acftText,
task: taskText,
phase: phaseText,
weather: weatherText,
lv: lvText,
ats: ats,
atc: atc,
tcas: tcas,
advise: advise,
inputValue1: data.inputValue1,
inputValue2: data.inputValue2,
inputValue3: data.inputValue3,
inputValue4: data.inputValue4,
inputValue5: data.inputValue5,
inputValue6: data.inputValue6,
inputValue7: data.inputValue7,
inputValue8: data.inputValue8,
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() {
  }
})