rightAngleVertical.vue 4.9 KB

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