Calculation.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. Page({
  2. data: {
  3. OM: '', // 有机质含量
  4. CL: '', // 土壤粘粒重量
  5. CEC: '', // 阳离子交换量
  6. H: '', // 氢离子含量
  7. HN: '', // 铵离子含量
  8. Al: '', // 铝离子含量
  9. free_alumina: '', // 游离氧化铝含量
  10. free_iron_oxides: '', // 游离氧化铁含量
  11. delta_ph: '',
  12. },
  13. // 更新有机质含量
  14. onOMChange: function(e) {
  15. this.setData({
  16. OM: e.detail.value
  17. });
  18. },
  19. // 更新土壤粘粒重量
  20. onCLChange: function(e) {
  21. this.setData({
  22. CL: e.detail.value
  23. });
  24. },
  25. // 更新阳离子交换量
  26. onCECChange: function(e) {
  27. this.setData({
  28. CEC: e.detail.value
  29. });
  30. },
  31. // 更新氢离子含量
  32. onHChange: function(e) {
  33. this.setData({
  34. H: e.detail.value
  35. });
  36. },
  37. // 更新铵离子含量
  38. onHNChange: function(e) {
  39. this.setData({
  40. HN: e.detail.value
  41. });
  42. },
  43. // 更新铝离子含量
  44. onAlChange: function(e) {
  45. this.setData({
  46. Al: e.detail.value
  47. });
  48. },
  49. // 更新游离氧化铝含量
  50. onFreeAluminaChange: function(e) {
  51. this.setData({
  52. free_alumina: e.detail.value
  53. });
  54. },
  55. // 更新游离氧化铁含量
  56. onFreeIronOxidesChange: function(e) {
  57. this.setData({
  58. free_iron_oxides: e.detail.value
  59. });
  60. },
  61. onDeltaPhChange: function(e) {
  62. this.setData({
  63. delta_ph: e.detail.value
  64. });
  65. },
  66. // 计算方法
  67. calculate: function() {
  68. console.log('开始计算...');
  69. const data = {
  70. model_name: "RF_filt",
  71. parameters: {
  72. organic_matter: this.data.OM,
  73. chloride: this.data.CL,
  74. cec: this.data.CEC,
  75. h_concentration: this.data.H,
  76. hn: this.data.HN,
  77. al_concentration: this.data.Al,
  78. free_alumina: this.data.free_alumina,
  79. free_iron: this.data.free_iron_oxides,
  80. delta_ph: this.data.delta_ph,
  81. },
  82. };
  83. wx.request({
  84. url: 'http://localhost:5000/predict',
  85. method: 'POST',
  86. data: JSON.stringify(data),
  87. header: {
  88. 'content-type': 'application/json'
  89. },
  90. success: (res) => {
  91. console.log('预测结果:', res.data.predictions);
  92. wx.navigateTo({
  93. url: `/pages/Result/Result?result=${encodeURIComponent(JSON.stringify(res.data.predictions))}`
  94. });
  95. },
  96. fail: (error) => {
  97. console.error('请求失败:', error);
  98. }
  99. });
  100. }
  101. });