rightAngle45.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.dibian" placeholder="请输入底边"/>
  10. </u-form-item>
  11. <u-form-item label="边高(cm)" label-width="160">
  12. <u-input type="digit" v-model="formData.biangao" placeholder="请输入边高"/>
  13. </u-form-item>
  14. <u-form-item label="长(cm)" label-width="160">
  15. <u-input type="digit" v-model="formData.length" 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>{{item.value}}{{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="qiwan top">{{rules.qiwan.value?rules.qiwan.value:'**'}}{{rules.qiwan.unit}}</text>
  33. <text class="xiebian top">{{rules.xiebian.value?rules.xiebian.value:'**'}}{{rules.xiebian.unit}}</text>
  34. <text class="slice1 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  35. <text class="slice2 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</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: 'rightAngle45',
  50. mathImgs: mathImgs,
  51. formData: {
  52. dibian: '',
  53. biangao: '',
  54. length: '',
  55. },
  56. // 用来验证 输入
  57. rules: {
  58. xiebian: {name:'斜边', value:'',unit:'cm',show: true},
  59. slice: {name:'切口', value:'',unit:'cm',show: true,isHalf: true},
  60. qiwan: {name:'起弯', value:'',unit:'cm',show: false},
  61. }
  62. }
  63. },
  64. methods: {
  65. handleBigImage(){
  66. uni.previewImage({
  67. urls: [mathImgs[this.name].big],
  68. });
  69. },
  70. handelCalc(){
  71. this.initRules();
  72. /**
  73. * 1、 斜边=边高×1.414
  74. * 2、 切口=边高×0.828
  75. */
  76. this.formData.dibian = parseFloat(this.formData.dibian)
  77. this.formData.biangao = parseFloat(this.formData.biangao)
  78. if(this.formData.dibian && this.formData.biangao){
  79. this.rules.xiebian.value = this.formData.dibian * 1.414;
  80. this.rules.slice.value = this.formData.biangao * 0.828
  81. }else{
  82. this.$u.toast('请输入两个参数');
  83. }
  84. // 计算起弯 长-边高-底边
  85. if(this.formData.length){
  86. this.rules.qiwan.value = this.formData.length - this.formData.biangao - this.formData.dibian
  87. }
  88. this.roundRules();
  89. this.$u.toast("请参考计算示意图")
  90. },
  91. roundRules(){
  92. for (const itemKey in this.rules) {
  93. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  94. }
  95. },
  96. initRules(){
  97. for (const itemKey in this.rules) {
  98. this.rules[itemKey].value = "";
  99. }
  100. },
  101. handleClear() {
  102. this.initRules();
  103. this.formData = {
  104. dibian: '',
  105. biangao: '',
  106. length: '',
  107. };
  108. }
  109. },
  110. computed:{
  111. showResult(){
  112. let validate = [];
  113. for (const itemKey in this.rules) {
  114. validate.push(this.rules[itemKey].value);
  115. }
  116. return this.$util.checkArrayNotNullNumber(validate,2)
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. @import "@/static/css/math.scss";
  123. .qiwan{
  124. left: 100rpx;
  125. }
  126. .xiebian{
  127. left: 320rpx;
  128. }
  129. .slice1{
  130. left: 210rpx;
  131. }
  132. .slice2{
  133. left: 430rpx;
  134. }
  135. </style>