thres.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div>
  3. <!-- 显示当前阈值 -->
  4. <p>当前阈值: {{ currentThreshold }}</p>
  5. <!-- 显示默认阈值 -->
  6. <p>默认阈值: {{ defaultThreshold }}</p>
  7. <!-- 输入框和按钮用于设置新阈值 -->
  8. <el-input v-model="newThreshold" placeholder="请输入新阈值"></el-input>
  9. <el-button type="primary" @click="updateThreshold">更新阈值</el-button>
  10. </div>
  11. </template>
  12. <script>
  13. import axios from 'axios';
  14. export default {
  15. data() {
  16. return {
  17. currentThreshold: null,
  18. defaultThreshold: null,
  19. newThreshold: '' // 新增阈值输入框的绑定值
  20. };
  21. },
  22. methods: {
  23. // 获取阈值信息
  24. fetchThresholds() {
  25. axios.get('https://127.0.0.1:5000/get-threshold')
  26. .then(response => {
  27. this.currentThreshold = response.data.current_threshold;
  28. this.defaultThreshold = response.data.default_threshold;
  29. })
  30. .catch(error => {
  31. console.error("获取阈值失败:", error);
  32. });
  33. },
  34. // 更新阈值
  35. updateThreshold() {
  36. const thresholdValue = parseFloat(this.newThreshold); // 将输入转换为浮点数
  37. if (isNaN(thresholdValue) || thresholdValue <= 0) {
  38. this.$message.error('请输入有效的正数');
  39. return;
  40. }
  41. axios.post('https://127.0.0.1:5000/update-threshold', { threshold: thresholdValue })
  42. .then(response => {
  43. if (response.data.success) {
  44. this.currentThreshold = thresholdValue; // 更新当前阈值显示
  45. this.$message.success(response.data.message);
  46. } else {
  47. this.$message.error(response.data.error);
  48. }
  49. })
  50. .catch(error => {
  51. console.error("更新阈值失败:", error);
  52. this.$message.error('更新阈值时发生错误');
  53. });
  54. }
  55. },
  56. mounted() {
  57. // 页面加载时获取阈值
  58. this.fetchThresholds();
  59. }
  60. }
  61. </script>
  62. <style scoped>
  63. /* 添加一些样式让页面看起来更好 */
  64. .el-input {
  65. margin-top: 10px;
  66. }
  67. .el-button {
  68. margin-top: 10px;
  69. }
  70. </style>