uphill.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="math-container">
  3. <view class="header">
  4. <u-image width="100%" height="300rpx" :src="mathImgs[name].big" mode="aspectFit" @click="handleBigImage"></u-image>
  5. </view>
  6. <view class="main dir-top-wrap cross-center">
  7. <view class="form">
  8. <u-form-item label="高(cm)" label-width="160">
  9. <u-input type="digit" v-model="formData.height" placeholder="请输入高"/>
  10. </u-form-item>
  11. <u-form-item label="角度(°)" label-width="160">
  12. <u-input type="digit" v-model="formData.angle" placeholder="请输入角度"/>
  13. </u-form-item>
  14. <u-form-item label="边高(cm)" label-width="160">
  15. <u-input type="digit" v-model="formData.biangao" placeholder="请输入边高"/>
  16. </u-form-item>
  17. <u-form-item label="长(cm)" label-width="160">
  18. <u-input type="digit" v-model="formData.length" placeholder="选填"/>
  19. </u-form-item>
  20. </view>
  21. <view class="btn-group main-left cross-center">
  22. <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
  23. <u-button :ripple="true" @click="handleClear">清空</u-button>
  24. </view>
  25. </view>
  26. <div class="footer">
  27. <view class="result dir-top-wrap cross-center" v-if="showResult">
  28. <view v-for="item in rules" v-if="item.value && item.show">
  29. <text>{{item.name}}=</text>{{item.value}}{{item.unit}}
  30. <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
  31. </view>
  32. </view>
  33. <view class="title">计算图</view>
  34. <view class="calc-img">
  35. <text class="qiwan top">{{rules.qiwan.value?rules.qiwan.value:'**'}}{{rules.qiwan.unit}}</text>
  36. <text class="xiebian top">{{rules.xiebian.value?rules.xiebian.value:'**'}}{{rules.xiebian.unit}}</text>
  37. <text class="slice1 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  38. <text class="slice2 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  39. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  40. </view>
  41. <view class="title">切割图</view>
  42. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  43. </div>
  44. </view>
  45. </template>
  46. <script>
  47. import mathImgs from "@/core/math-imgs"
  48. // 万能公式
  49. export default {
  50. data() {
  51. return {
  52. name: 'uphill',
  53. mathImgs: mathImgs,
  54. formData: {
  55. height: '',
  56. angle: '',
  57. biangao: '',
  58. lenght: '',
  59. },
  60. // 用来验证 输入
  61. rules: {
  62. xiebian:{name:'斜边', value:'',unit:'cm',show: true},
  63. qiwan:{name:'起弯', value:'',unit:'cm',show: true},
  64. slice:{name:'切口', value:'',unit:'cm',show: true,isHalf:true},
  65. }
  66. }
  67. },
  68. methods: {
  69. handleBigImage(){
  70. uni.previewImage({
  71. urls: [mathImgs[this.name].big],
  72. });
  73. },
  74. handelCalc(){
  75. this.initRules();
  76. if( this.formData.angle && this.formData.angle > 90){
  77. this.$u.toast('角度不能大于90');
  78. return
  79. }
  80. /**
  81. * 1、斜边=高×csc角度°
  82. 2、切口=边高×tan(角度°÷2)×2
  83. */
  84. if(this.formData.height && this.formData.angle && this.formData.biangao){
  85. this.rules.xiebian.value = this.formData.height * this.$util.csc(this.formData.angle);
  86. this.rules.slice.value = this.formData.biangao * this.$util.tan(this.formData.angle / 2) * 2;
  87. }else{
  88. this.$u.toast('请输入三个参数');
  89. return;
  90. }
  91. // 1、 起弯=长 -(高×cot角度°)
  92. if(this.formData.length){
  93. this.rules.qiwan.value = this.formData.length - (this.formData.height * this.$util.cot(this.formData.angle))
  94. }
  95. this.roundRules();
  96. this.$u.toast("请参考计算示意图")
  97. },
  98. roundRules(){
  99. for (const itemKey in this.rules) {
  100. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  101. }
  102. },
  103. initRules(){
  104. for (const itemKey in this.rules) {
  105. this.rules[itemKey].value = "";
  106. }
  107. },
  108. handleClear() {
  109. this.initRules();
  110. this.formData = {
  111. height: '',
  112. angle: '',
  113. biangao: '',
  114. lenght: '',
  115. };
  116. }
  117. },
  118. computed:{
  119. showResult(){
  120. let validate = [];
  121. for (const itemKey in this.rules) {
  122. validate.push(this.rules[itemKey].value);
  123. }
  124. return this.$util.checkArrayNotNullNumber(validate)
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. @import "@/static/css/math.scss";
  131. .qiwan{
  132. left: 120rpx;
  133. }
  134. .xiebian{
  135. left: 300rpx;
  136. }
  137. .slice1{
  138. left: 210rpx;
  139. }
  140. .slice2{
  141. left: 430rpx;
  142. }
  143. </style>