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/AircraftMaintenance/AircraftMaintenance.js

310 lines
8.8 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/AircraftMaintenance/AircraftMaintenance.js
Page({
data: {
name:'AircraftMaintenance',
selectedTime: '--时--分',
selectedDate: '--年--月--日',
selectedIndex1: 0,
selectedIndex4: 0,
selectedIndex5: 0,
selectedIndex17: 0,
selectedIndex18: 0,
selectedIndex19: 0,
inputValue1: '',
inputValue2: '',
inputValue3: '',
inputValue15: '',
inputValue16: '',
inputValue17: '',
inputValue18: '',
inputValue19: '',
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'],
License:['请选择','航空器维修人员执照','航空器部件维修人员执照','航空器维修管理人员执照','维护检验执照','修理检验执照','其它'],
ACFT:['请选择','飞机','直升机','滑翔机','其它'],
FixT:['请选择','A检','B检','C检','D检','其它'],
FixH:['请选择','航前检查','过站检查','航后检查','其它'],
AARC:['请选择','飞机放行','飞机记录完整','不能放行','未知'],
},
//时间选择
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
});
},
//执照选择
onLicense: function(event) {
this.setData({
selectedIndex4: event.detail.value
});
},
//工作经历
onInput15: function(event) {
this.setData({
inputValue15: event.detail.value
});
},
onInput16: function(event) {
this.setData({
inputValue16: event.detail.value
});
},
//航空器种类
onACFT: function(event) {
this.setData({
selectedIndex5: event.detail.value
});
},
//事件发生阶段
onFixT: function(event) {
this.setData({
selectedIndex17: event.detail.value
});
},
onFixH: function(event) {
this.setData({
selectedIndex18: event.detail.value
});
},
//涉及的系统部件
onInput17: function(event) {
this.setData({
inputValue17: event.detail.value
});
},
onInput18: function(event) {
this.setData({
inputValue18: event.detail.value
});
},
onInput19: function(event) {
this.setData({
inputValue19: event.detail.value
});
},
//航空器适航情况
onAARC: function(event) {
this.setData({
selectedIndex19: 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,
selectedIndex4: 0,
selectedIndex5: 0,
selectedIndex17: 0,
selectedIndex18: 0,
selectedIndex19: 0,
inputValue1: '',
inputValue2: '',
inputValue3: '',
inputValue15: '',
inputValue16: '',
inputValue17: '',
inputValue18: '',
inputValue19: '',
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 licenseText = data.License[data.selectedIndex4]; // 获取执照类型的实际文本
const acftText = data.ACFT[data.selectedIndex5]; // 获取航空器类型的实际文本
const fixTText = data.FixT[data.selectedIndex17]; // 获取事件阶段的实际文本
const fixHText = data.FixH[data.selectedIndex18]; // 获取维护检查的实际文本
const aarcText = data.AARC[data.selectedIndex19]; // 获取适航情况的实际文本
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, // 提交时区的实际文本
license: licenseText, // 提交执照类型的实际文本
acftType: acftText, // 提交航空器类型的实际文本
fixStage: fixTText, // 提交事件阶段的实际文本
fixCheck: fixHText, // 提交维护检查的实际文本
aarcStatus: aarcText, // 提交适航情况的实际文本
inputValue1: data.inputValue1,
inputValue2: data.inputValue2,
inputValue3: data.inputValue3,
inputValue15: data.inputValue15,
inputValue16: data.inputValue16,
inputValue17: data.inputValue17,
inputValue18: data.inputValue18,
inputValue19: data.inputValue19,
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() {
}
})