rightAngle30.vue 5.8 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="number" v-model="formData.dibian" placeholder="请输入底边"/>
  10. </u-form-item>
  11. <u-form-item label="边高(cm)" label-width="160">
  12. <u-input type="number" v-model="formData.biangao" placeholder="请输入边高"/>
  13. </u-form-item>
  14. <u-form-item label="长(cm)" label-width="160">
  15. <u-input type="number" 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="xiebian1 top">{{rules.xiebian.value?rules.xiebian.value:'**'}}{{rules.xiebian.unit}}</text>
  34. <text class="xiebian2 top">{{rules.xiebian.value?rules.xiebian.value:'**'}}{{rules.xiebian.unit}}</text>
  35. <text class="slice1 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  36. <text class="slice2 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  37. <text class="slice3 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  38. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  39. </view>
  40. <view class="title">切割图</view>
  41. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  42. </div>
  43. </view>
  44. </template>
  45. <script>
  46. import mathImgs from "@/core/math-imgs"
  47. // 万能公式
  48. export default {
  49. data() {
  50. return {
  51. name: 'rightAngle30',
  52. mathImgs: mathImgs,
  53. formData: {
  54. dibian: '',
  55. biangao: '',
  56. length: '',
  57. },
  58. // 用来验证 输入
  59. rules: {
  60. xiebian: {name:'斜边', value:'',unit:'cm',show: true},
  61. slice: {name:'切口', value:'',unit:'cm',show: true,isHalf: true},
  62. qiwan: {name:'起弯', value:'',unit:'cm',show: false},
  63. }
  64. }
  65. },
  66. methods: {
  67. handleBigImage(){
  68. uni.previewImage({
  69. urls: [mathImgs[this.name].big],
  70. });
  71. },
  72. handelCalc(){
  73. this.initRules();
  74. /**
  75. 1、斜边=边高×0.732
  76. 2、切口=边高×0.536
  77. */
  78. this.formData.dibian = parseFloat(this.formData.dibian)
  79. this.formData.biangao = parseFloat(this.formData.biangao)
  80. if(this.formData.dibian && this.formData.biangao){
  81. this.rules.xiebian.value = this.formData.dibian * 0.732;
  82. this.rules.slice.value = this.formData.biangao * 0.536
  83. }else{
  84. this.$u.toast('请输入两个参数');
  85. }
  86. // 计算起弯 长-边高-底边
  87. if(this.formData.length){
  88. this.rules.qiwan.value = this.formData.length - this.formData.biangao - this.formData.dibian
  89. }
  90. this.roundRules();
  91. this.$u.toast("请参考计算示意图")
  92. },
  93. roundRules(){
  94. for (const itemKey in this.rules) {
  95. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  96. }
  97. },
  98. initRules(){
  99. for (const itemKey in this.rules) {
  100. this.rules[itemKey].value = "";
  101. }
  102. },
  103. handleClear() {
  104. this.initRules();
  105. this.formData = {
  106. dibian: '',
  107. biangao: '',
  108. length: '',
  109. };
  110. }
  111. },
  112. computed:{
  113. showResult(){
  114. let validate = [];
  115. for (const itemKey in this.rules) {
  116. validate.push(this.rules[itemKey].value);
  117. }
  118. return this.$util.checkArrayNotNullNumber(validate,2)
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. @import "@/static/css/math.scss";
  125. .qiwan{
  126. left: 80rpx;
  127. }
  128. .xiebian1{
  129. left: 240rpx;
  130. }
  131. .xiebian2{
  132. left: 390rpx;
  133. }
  134. .slice1{
  135. left: 160rpx;
  136. }
  137. .slice2{
  138. left: 320rpx;
  139. }
  140. .slice3{
  141. left: 490rpx;
  142. }
  143. </style>