Bläddra i källkod

fix(controller): 万能公式

xiansin 3 år sedan
förälder
incheckning
f769238c8e
2 ändrade filer med 13 tillägg och 3 borttagningar
  1. 1 1
      core/util.js
  2. 12 2
      pages/formula/normal.vue

+ 1 - 1
core/util.js

xqd
@@ -75,7 +75,7 @@ const round = (number,percent) => {
     number = parseFloat(number).toFixed(percent)
     let flag = number < 0 ? '-' : '';
     let arr = number.toString().split(".");
-    arr[1] = arr[1].padEnd(percent + 1,'0')
+    arr[1] = arr[1].padEnd(percent,'0')
     return flag+arr.join(".");
 }
 

+ 12 - 2
pages/formula/normal.vue

xqd xqd xqd xqd
@@ -32,7 +32,7 @@
         <div class="footer">
             <view class="result dir-top-wrap cross-center" v-if="showResult">
                 <view v-for="item in rules" v-if="item.value && item.show">
-                    <text>{{item.name}}=</text>{{item.value}}{{item.unit}}
+                    <text>{{item.name}}=</text>{{$util.round(item.value,2)}}{{item.unit}}
                     <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
                 </view>
             </view>
@@ -90,6 +90,10 @@
                     return
                 }
                 this.initRules();
+                if(this.formData.xiebian){
+                    this.rules.xiebian.value = this.formData.xiebian;
+                    this.rules.xiebian.show = false;
+                }
                 /*1:已知高、角度:底边=高÷tan角度°		斜边=高÷sin角度°*/
                 if(this.formData.height && this.formData.angle){
                     this.rules.dibian.value = this.formData.height/this.$util.tan(this.formData.angle);
@@ -115,6 +119,11 @@
                     this.rules.height.value = Math.sqrt(Math.pow(this.formData.xiebian,2) - Math.pow(this.formData.dibian,2));
                     this.rules.angle.value = this.$util.acos(this.formData.dibian/this.formData.xiebian);
                 }
+                /* 6:已知高、斜边:底边²=斜边²-高²			cos角度°=底边÷斜边*/
+                if(this.formData.height && this.formData.xiebian){
+                    this.rules.dibian.value = Math.sqrt(Math.pow(this.formData.xiebian,2) - Math.pow(this.formData.height,2));
+                    this.rules.angle.value = this.$util.acos(this.rules.dibian.value/this.formData.xiebian);
+                }
                 /*选填(输入边高计算出切口):1、 切口=边高×tan(角度°÷2)×2 2、 起弯=长-底边*/
                 if(this.formData.biangao){
                     let angle = this.rules.angle.value ? this.rules.angle.value : this.formData.angle
@@ -124,12 +133,13 @@
                     let dibian = this.formData.dibian ? this.formData.dibian : this.rules.dibian.value
                     this.rules.qiwan.value = this.formData.length - dibian;
                 }
+                console.log('-->data',this.rules)
                 this.roundRules();
                 this.$u.toast("请参考计算示意图")
             },
             roundRules(){
                 for (const itemKey in this.rules) {
-                    this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
+                    //this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
                 }
             },
             initRules(){