angle.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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="底边(cm)" label-width="160">
  12. <u-input type="digit" v-model="formData.dibian" 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. </view>
  18. <view class="btn-group main-left cross-center">
  19. <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
  20. <u-button :ripple="true" @click="handleClear">清空</u-button>
  21. </view>
  22. </view>
  23. <div class="footer">
  24. <view class="result dir-top-wrap cross-center" v-if="showResult">
  25. <view v-for="item in rules" v-if="item.value && item.show">
  26. <text>{{item.name}}=</text>{{$util.round(item.value,2)}}{{item.unit}}
  27. <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
  28. </view>
  29. </view>
  30. <view class="title">计算图</view>
  31. <view class="calc-img">
  32. <text class="height">{{formData.height?parseFloat(formData.height):'**'}}cm</text>
  33. <text class="xiebian">{{rules.xiebian.value?$util.round(rules.xiebian.value,2):'**'}}{{rules.xiebian.unit}}</text>
  34. <text class="angle">{{rules.angle.value?$util.round(rules.angle.value,2):'**'}}{{rules.angle.unit}}</text>
  35. <text class="dibian">{{formData.dibian?parseFloat(formData.dibian):'**'}}cm</text>
  36. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  37. </view>
  38. <view class="title">切割图</view>
  39. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  40. </div>
  41. </view>
  42. </template>
  43. <script>
  44. import mathImgs from "@/core/math-imgs"
  45. // 万能公式
  46. export default {
  47. data() {
  48. return {
  49. name: 'angle',
  50. mathImgs: mathImgs,
  51. formData: {
  52. height: '',
  53. dibian: '',
  54. biangao: '',
  55. },
  56. // 用来验证 输入
  57. rules: {
  58. xiebian:{name:'斜边', value:'',unit:'cm',show: true},
  59. angle: {name:'角度', value:'',unit:'°',show: true},
  60. slice:{name:'切口', value:'',unit:'cm',show: true,isHalf: true},
  61. }
  62. }
  63. },
  64. methods: {
  65. handleBigImage(){
  66. uni.previewImage({
  67. urls: [mathImgs[this.name].big],
  68. });
  69. },
  70. handelCalc(){
  71. this.initRules();
  72. /*1:斜边²=高²+底边²*/
  73. /*2、tan角度°=高÷底边*/
  74. if(this.formData.height && this.formData.dibian){
  75. this.rules.xiebian.value = Math.sqrt(Math.pow(this.formData.height,2) + Math.pow(this.formData.dibian,2));
  76. this.rules.angle.value = this.$util.atan(this.formData.height / this.formData.dibian);
  77. }
  78. /*1、 切口=边高×tan(角度°÷2)×2*/
  79. if(this.formData.biangao){
  80. this.rules.slice.value = this.formData.biangao * this.$util.tan(this.rules.angle.value / 2) * 2;
  81. }
  82. this.roundRules();
  83. this.$u.toast("请参考计算示意图")
  84. },
  85. roundRules(){
  86. for (const itemKey in this.rules) {
  87. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  88. }
  89. },
  90. initRules(){
  91. for (const itemKey in this.rules) {
  92. this.rules[itemKey].value = "";
  93. }
  94. },
  95. handleClear() {
  96. this.initRules();
  97. this.formData = {
  98. height: '',
  99. dibian: '',
  100. biangao: '',
  101. };
  102. }
  103. },
  104. computed:{
  105. showResult(){
  106. let validate = [];
  107. for (const itemKey in this.rules) {
  108. validate.push(this.rules[itemKey].value);
  109. }
  110. return this.$util.checkArrayNotNullNumber(validate,1)
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. @import "@/static/css/math.scss";
  117. .height{
  118. top: 210rpx;
  119. left: 410rpx;
  120. }
  121. .xiebian{
  122. left: 320rpx;
  123. top: 180rpx;
  124. }
  125. .angle{
  126. left: 320rpx;
  127. top: 246rpx;
  128. }
  129. .dibian{
  130. left: 350rpx;
  131. top: 280rpx;
  132. }
  133. </style>