Page({ data: { OM: '', // 有机质含量 CL: '', // 土壤粘粒重量 H: '', // 氢离子含量 Al: '', // 铝离子含量 ph: '', }, // 更新有机质含量 onOMChange: function(e) { this.setData({ OM: e.detail.value }); }, // 更新土壤粘粒重量 onCLChange: function(e) { this.setData({ CL: e.detail.value }); }, // 更新氢离子含量 onHChange: function(e) { this.setData({ H: e.detail.value }); }, // 更新铝离子含量 onAlChange: function(e) { this.setData({ Al: e.detail.value }); }, onPhChange: function(e) { this.setData({ ph: e.detail.value }); }, // 计算方法 calculate: function() { console.log('开始计算...'); const data = { model_name: "rf_model_1214_1008", parameters: { pH: this.data.ph, OM: this.data.OM, CL: this.data.CL, H: this.data.H, Al: this.data.Al, }, }; wx.request({ url: 'http://localhost:5000/predict', method: 'POST', data: JSON.stringify(data), header: { 'content-type': 'application/json' }, success: (res) => { console.log('预测结果:', res.data.predictions); wx.navigateTo({ url: `/pages/Result/Result?result=${encodeURIComponent(JSON.stringify(res.data.predictions))}` }); }, fail: (error) => { console.error('请求失败:', error); } }); } });