Browse Source

添加阈值获取

DIng 2 months ago
parent
commit
5706b37025
4 changed files with 119 additions and 152 deletions
  1. 1 1
      shoping/Model Selection/Model Selection.wxml
  2. 63 42
      shoping/thres/thres.js
  3. 28 49
      shoping/thres/thres.wxml
  4. 27 60
      shoping/thres/thres.wxss

+ 1 - 1
shoping/Model Selection/Model Selection.wxml

@@ -13,7 +13,7 @@
       <view class="col select-col">选择</view>
       <view class="col">模型ID</view>
       <view class="col">模型类型</view>
-      <view class="col">综合评分</view>
+      <view class="col">R^2评分</view>
       <view class="col">MAE</view>
       <view class="col">RMSE</view>
     </view>

+ 63 - 42
shoping/thres/thres.js

@@ -1,55 +1,76 @@
+// pages/threshold/threshold.js
 Page({
   data: {
-    countOptions: ['25', '40', '60'], // 条数阈值选项
-    percentageOptions: ['25', '40', '60'], // 百分比阈值选项
-
-    selectedCountIndex: 0, // 条数默认选择
-    selectedPercentageIndex: 0, // 百分比默认选择
-
-    countThresh: 25, // 当前条数阈值
-    percentageThresh: 25, // 当前百分比阈值
+    threshold: null,     // 初始化为null
+    newThreshold: null,
+    loading: true       // 添加加载状态
   },
 
-  // 条数选择框变化
-  onCountPickerChange(e) {
-    const selectedValue = this.data.countOptions[e.detail.value];
-    this.setData({
-      selectedCountIndex: e.detail.value,
-      countThresh: selectedValue, // 更新到输入框
-    });
+  onLoad() {
+    this.getThreshold();
   },
 
-  // 百分比选择框变化
-  onPercentagePickerChange(e) {
-    const selectedValue = this.data.percentageOptions[e.detail.value];
-    this.setData({
-      selectedPercentageIndex: e.detail.value,
-      percentageThresh: selectedValue, // 更新到输入框
+  // 获取当前阈值(优化版)
+  getThreshold() {
+    this.setData({ loading: true });
+    wx.request({
+      url: 'https://soilgd.com:5000/get-threshold',
+      success: (res) => {
+        if (res.statusCode === 200 && res.data && typeof res.data.current_threshold === 'number') {
+          this.setData({
+            threshold: res.data.current_threshold,
+          });
+        } else {
+          wx.showToast({ title: '数据格式错误', icon: 'error' });
+          console.error('Invalid response:', res);
+        }
+      },
+      fail: (err) => {
+        wx.showToast({ title: '请求失败', icon: 'error' });
+        console.error('API Error:', err);
+      },
+      complete: () => {
+        this.setData({ loading: false });
+      }
     });
   },
 
-  // 更新条数阈值输入框
-  updateCountThreshold(e) {
-    this.setData({
-      countThresh: e.detail.value, // 允许手动输入
-    });
+  // 输入框改变事件(添加校验)
+  onInput(e) {
+    const value = Number(e.detail.value);
+    if (!isNaN(value)) {
+      this.setData({
+        newThreshold: value
+      });
+    }
   },
 
-  // 更新百分比阈值输入框
-  updatePercentageThreshold(e) {
-    this.setData({
-      percentageThresh: e.detail.value, // 允许手动输入
-    });
-  },
+  // 提交更新阈值(优化版)
+  updateThreshold() {
+    if (this.data.newThreshold === null || isNaN(this.data.newThreshold)) {
+      wx.showToast({ title: '请输入有效数字', icon: 'error' });
+      return;
+    }
 
-  // 保存设置
-  saveSettings() {
-    wx.showToast({
-      title: '保存成功',
-      icon: 'success',
+    wx.showLoading({ title: '更新中...' });
+    wx.request({
+      url: 'https://soilgd.com:5000/update-threshold',
+      method: 'POST',
+      data: { threshold: this.data.newThreshold },
+      success: (res) => {
+        if (res.statusCode === 200) {
+          wx.showToast({ title: '更新成功' });
+          this.setData({ threshold: this.data.newThreshold });
+        } else {
+          wx.showToast({ title: '更新失败', icon: 'error' });
+        }
+      },
+      fail: (err) => {
+        wx.showToast({ title: '网络错误', icon: 'error' });
+      },
+      complete: () => {
+        wx.hideLoading();
+      }
     });
-
-    console.log('条数阈值:', this.data.countThresh);
-    console.log('百分比阈值:', this.data.percentageThresh);
-  },
-});
+  }
+});

+ 28 - 49
shoping/thres/thres.wxml

@@ -1,53 +1,32 @@
-<view class="green-box">
-  <text class="title-en">降酸模型</text>
-</view>
-
+<!-- pages/threshold/threshold.wxml -->
 <view class="container">
-  <view class="row">
-    <!-- 条数阈值 -->
-    <view class="input-group">
-      <text class="label">条数阈值:</text>
-      <picker mode="selector" range="{{countOptions}}" value="{{selectedCountIndex}}" bindchange="onCountPickerChange">
-        <text class="picker-text">{{countOptions[selectedCountIndex]}} 条</text>
-      </picker>
-      <input type="number" value="{{countThresh}}" bindinput="updateCountThreshold" class="input" />
-    </view>
-
-    <!-- 百分比阈值 -->
-    <view class="input-group">
-      <text class="label">百分比阈值:</text>
-      <picker mode="selector" range="{{percentageOptions}}" value="{{selectedPercentageIndex}}" bindchange="onPercentagePickerChange">
-        <text class="picker-text">{{percentageOptions[selectedPercentageIndex]}}%</text>
-      </picker>
-      <input type="number" value="{{percentageThresh}}" bindinput="updatePercentageThreshold" class="input" />
-    </view>
-  </view>
-  <button class="save-btn" bindtap="saveSettings">保存</button>
-</view>
-
-<view class="green-box">
-  <text class="title-en">反酸模型</text>
-</view>
-
-<view class="container">
-  <view class="row">
-    <!-- 条数阈值 -->
-    <view class="input-group">
-      <text class="label">条数阈值:</text>
-      <picker mode="selector" range="{{countOptions}}" value="{{selectedCountIndex}}" bindchange="onCountPickerChange">
-        <text class="picker-text">{{countOptions[selectedCountIndex]}} 条</text>
-      </picker>
-      <input type="number" value="{{countThresh}}" bindinput="updateCountThreshold" class="input" />
-    </view>
+  <view class="card">
+    <text class="title">当前阈值</text>
+    
+    <block wx:if="{{threshold !== null}}">
+      <text class="value">{{threshold}}</text>
+    </block>
+    <block wx:else>
+      <text class="value">--</text>
+    </block>
 
-    <!-- 百分比阈值 -->
-    <view class="input-group">
-      <text class="label">百分比阈值:</text>
-      <picker mode="selector" range="{{percentageOptions}}" value="{{selectedPercentageIndex}}" bindchange="onPercentagePickerChange">
-        <text class="picker-text">{{percentageOptions[selectedPercentageIndex]}}%</text>
-      </picker>
-      <input type="number" value="{{percentageThresh}}" bindinput="updatePercentageThreshold" class="input" />
+    <view class="input-area">
+      <input 
+        type="number" 
+        value="{{newThreshold}}" 
+        bindinput="onInput" 
+        placeholder="请输入新阈值"
+        class="input"
+        disabled="{{loading}}"
+      />
+      <button 
+        type="primary" 
+        bindtap="updateThreshold" 
+        class="button"
+        disabled="{{loading}}"
+      >
+        {{loading ? '加载中...' : '更新阈值'}}
+      </button>
     </view>
   </view>
-  <button class="save-btn" bindtap="saveSettings">保存</button>
-</view>
+</view>

+ 27 - 60
shoping/thres/thres.wxss

@@ -1,75 +1,42 @@
-/* 页面整体背景 */
-.green-box {
-  background-color: #4caf50; /* 绿色背景 */
-  padding: 10px 20px;  /* 减小上下内边距,控制高度 */
-  text-align: center;
-  display: flex;
-  flex-direction: column; /* 设置垂直方向布局 */
-  justify-content: center;
-  align-items: center;
-  max-height: 100rpx; /* 限制最大高度 */
-  max-width: calc(100% - 10px); /* 宽度最大100%,两边各留5px */
-  margin-left: 15px;  /* 左边留5px */
-  margin-right: 15px; /* 右边留5px */
-  box-sizing: border-box; /* 确保 padding 和 margin 不影响宽度计算 */
-}
-
-.title-en {
-  font-size: 16px;
-  color: #fff;
-  display: block;
-}
-
+/* pages/threshold/threshold.wxss */
 .container {
-  margin: 20rpx;
-  padding: 10rpx;
+  padding: 20rpx;
 }
 
-.row {
-  display: flex;
-  justify-content: space-between;
-  align-items: center;
-  margin-bottom: 20rpx;
+.card {
+  background-color: #fff;
+  border-radius: 16rpx;
+  padding: 40rpx;
+  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.1);
 }
 
-.input-group {
-  display: flex;
-  align-items: center;
-  flex: 1;
-  margin-right: 20rpx;
+.title {
+  font-size: 32rpx;
+  color: #666;
+  display: block;
+  margin-bottom: 20rpx;
 }
 
-.label {
-  font-size: 30rpx;
-  color: #333;
-  margin-right: 10rpx;
+.value {
+  font-size: 48rpx;
+  color: #007bff;
+  font-weight: bold;
+  display: block;
+  margin-bottom: 40rpx;
 }
 
-.picker-text {
-  font-size: 28rpx;
-  color: #007acc; /* 选择框的文字颜色 */
-  margin-right: 10rpx;
+.input-area {
+  margin-top: 40rpx;
 }
 
 .input {
-  width: 200rpx;
-  padding: 7rpx;
-  font-size: 28rpx;
-  border: 1px solid #ccc;
+  border: 2rpx solid #eee;
   border-radius: 8rpx;
-  color: #333;
+  padding: 20rpx;
+  margin-bottom: 30rpx;
 }
 
-.save-btn {
-  width: 50%;
-  padding: 5rpx;
-  background-color: #e6f7ff; /* 保存按钮的背景颜色 */
-  color: #303030;
-  border-radius: 10rpx;
-  font-size: 32rpx;
-  text-align: center;
-}
-
-.countOptions {
-  font-weight: 400;
-}
+.button {
+  width: 100%;
+  border-radius: 8rpx;
+}