Calculation.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // pages/Calculation/Calculation.js
  2. Page({
  3. data: {
  4. OM: '', // 有机质含量
  5. CL: '', // 土壤粘粒重量
  6. CEC: '', // 阳离子交换量
  7. H: '', // 氢离子含量
  8. HN: '', // 铵离子含量
  9. Al: '', // 铝离子含量
  10. free_alumina: '', // 游离氧化铝含量
  11. free_iron_oxides: '', // 游离氧化铁含量
  12. collection_location: '', // 采样地点
  13. collection_date: '', // 采样时间
  14. initialPH: '', // 土壤初始 pH
  15. targetPH: '', // 土壤目标 pH
  16. materials: ['石灰石(粉)CaCO3', '生石灰(粉)', '纯CaO (粉)', '熟石灰(粉)', '白云石 (粉)', '硅钙钾镁肥', '其他含CaO和MgO材料'],
  17. selectedMaterialIndex: 0, // 默认选中的碱性物料索引
  18. selectedMaterial: '石灰石(粉)CaCO3', // 默认物料
  19. },
  20. // 更新有机质含量
  21. onOMChange: function(e) {
  22. this.setData({
  23. OM: e.detail.value
  24. });
  25. },
  26. // 更新土壤粘粒重量
  27. onCLChange: function(e) {
  28. this.setData({
  29. CL: e.detail.value
  30. });
  31. },
  32. // 更新阳离子交换量
  33. onCECChange: function(e) {
  34. this.setData({
  35. CEC: e.detail.value
  36. });
  37. },
  38. // 更新氢离子含量
  39. onHChange: function(e) {
  40. this.setData({
  41. H: e.detail.value
  42. });
  43. },
  44. // 更新铵离子含量
  45. onHNChange: function(e) {
  46. this.setData({
  47. HN: e.detail.value
  48. });
  49. },
  50. // 更新铝离子含量
  51. onAlChange: function(e) {
  52. this.setData({
  53. Al: e.detail.value
  54. });
  55. },
  56. // 更新游离氧化铝含量
  57. onFreeAluminaChange: function(e) {
  58. this.setData({
  59. free_alumina: e.detail.value
  60. });
  61. },
  62. // 更新游离氧化铁含量
  63. onFreeIronOxidesChange: function(e) {
  64. this.setData({
  65. free_iron_oxides: e.detail.value
  66. });
  67. },
  68. // 更新采样地点
  69. onCollectionLocationChange: function(e) {
  70. this.setData({
  71. collection_location: e.detail.value
  72. });
  73. },
  74. // 更新采样时间
  75. onBindDateChange: function(e) {
  76. this.setData({
  77. collection_date: e.detail.value
  78. });
  79. },
  80. // 处理土壤初始 pH 的输入
  81. onInitialPHChange(e) {
  82. this.setData({
  83. initialPH: e.detail.value,
  84. });
  85. },
  86. // 处理土壤目标 pH 的输入
  87. onTargetPHChange(e) {
  88. this.setData({
  89. targetPH: e.detail.value,
  90. });
  91. },
  92. // 处理碱性物料选择
  93. onSelectMaterial(e) {
  94. const index = e.detail.value;
  95. this.setData({
  96. selectedMaterialIndex: index,
  97. selectedMaterial: this.data.materials[index],
  98. });
  99. },
  100. // 计算方法
  101. calculate: function() {
  102. console.log('开始计算...');
  103. const data = {
  104. organic_matter: this.data.OM,
  105. chloride: this.data.CL,
  106. cec: this.data.CEC,
  107. h_concentration: this.data.H,
  108. hn: this.data.HN,
  109. al_concentration: this.data.Al,
  110. free_alumina: this.data.free_alumina,
  111. free_iron: this.data.free_iron_oxides,
  112. delta_ph: this.data.targetPH - this.data.initialPH // 假设delta_ph是目标pH和初始pH的差值
  113. };
  114. wx.request({
  115. url: 'http://localhost:5000/predict',
  116. method: 'POST',
  117. data: JSON.stringify(data),
  118. header: {
  119. 'content-type': 'application/json'
  120. },
  121. success: (res) => {
  122. console.log('预测结果:', res.data.predictions);
  123. wx.navigateTo({
  124. url: `/pages/Result/Result?result=${encodeURIComponent(JSON.stringify(res.data.predictions))}`
  125. });
  126. },
  127. fail: (error) => {
  128. console.error('请求失败:', error);
  129. }
  130. });
  131. }
  132. })