thres.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="container">
  3. <!-- 降酸阈值 -->
  4. <el-card class="threshold-card">
  5. <h3>降酸阈值</h3>
  6. <p><strong>当前阈值:</strong> {{ currentThresholdReduce }}</p>
  7. <el-input
  8. v-model="newThresholdReduce"
  9. placeholder="请输入新的降酸阈值"
  10. class="input"
  11. ></el-input>
  12. <el-button
  13. type="success"
  14. @click="updateThreshold('reduce')"
  15. class="button"
  16. >
  17. 更新降酸阈值
  18. </el-button>
  19. </el-card>
  20. <!-- 反酸阈值 -->
  21. <el-card class="threshold-card">
  22. <h3>反酸阈值</h3>
  23. <p><strong>当前阈值:</strong> {{ currentThresholdReflux }}</p>
  24. <el-input
  25. v-model="newThresholdReflux"
  26. placeholder="请输入新的反酸阈值"
  27. class="input"
  28. ></el-input>
  29. <el-button
  30. type="success"
  31. @click="updateThreshold('reflux')"
  32. class="button"
  33. >
  34. 更新反酸阈值
  35. </el-button>
  36. </el-card>
  37. </div>
  38. </template>
  39. <script>
  40. import axios from 'axios';
  41. export default {
  42. data() {
  43. return {
  44. // 当前阈值
  45. currentThresholdReduce: null,
  46. currentThresholdReflux: null,
  47. // 新增阈值输入框绑定值
  48. newThresholdReduce: '',
  49. newThresholdReflux: ''
  50. };
  51. },
  52. methods: {
  53. /**
  54. * 获取当前阈值信息
  55. */
  56. fetchThresholds() {
  57. axios.get('https://127.0.0.1:5000/get-threshold')
  58. .then(response => {
  59. const { reduce, reflux } = response.data;
  60. this.currentThresholdReduce = reduce.current_threshold;
  61. this.currentThresholdReflux = reflux.current_threshold;
  62. })
  63. .catch(error => {
  64. console.error("获取阈值失败:", error);
  65. this.$message.error('无法加载阈值,请稍后再试');
  66. });
  67. },
  68. /**
  69. * 更新阈值
  70. * @param {string} dataType - 数据类型 ('reduce' 或 'reflux')
  71. */
  72. updateThreshold(dataType) {
  73. let thresholdValue, targetVariable;
  74. if (dataType === 'reduce') {
  75. thresholdValue = parseFloat(this.newThresholdReduce);
  76. targetVariable = 'currentThresholdReduce';
  77. } else if (dataType === 'reflux') {
  78. thresholdValue = parseFloat(this.newThresholdReflux);
  79. targetVariable = 'currentThresholdReflux';
  80. }
  81. if (isNaN(thresholdValue) || thresholdValue <= 0) {
  82. this.$message.error('请输入有效的正数');
  83. return;
  84. }
  85. axios.post('https://127.0.0.1:5000/update-threshold', {
  86. threshold: thresholdValue,
  87. data_type: dataType
  88. })
  89. .then(response => {
  90. if (response.data.success) {
  91. this[targetVariable] = thresholdValue; // 动态更新当前阈值
  92. this.$message.success(response.data.message);
  93. } else {
  94. this.$message.error(response.data.error);
  95. }
  96. })
  97. .catch(error => {
  98. console.error("更新阈值失败:", error);
  99. this.$message.error('更新阈值时发生错误');
  100. });
  101. }
  102. },
  103. mounted() {
  104. // 页面加载时获取当前阈值
  105. this.fetchThresholds();
  106. }
  107. };
  108. </script>
  109. <style scoped>
  110. /* 容器样式 */
  111. .container {
  112. display: flex;
  113. justify-content: space-around;
  114. gap: 20px;
  115. }
  116. /* 卡片样式 */
  117. .threshold-card {
  118. flex: 1;
  119. max-width: 400px;
  120. min-width: 300px;
  121. margin: 0 auto;
  122. padding: 16px;
  123. }
  124. /* 输入框和按钮样式 */
  125. .input {
  126. width: 100%;
  127. margin-top: 10px;
  128. }
  129. .button {
  130. width: 100%;
  131. margin-top: 10px;
  132. }
  133. </style>