Calculation.js 2.5 KB

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