rightAngleHorizontal.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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="biangao1 top">{{formData.biangao?parseFloat(formData.biangao):'**'}}cm</text>
  29. <text class="biangao2 top">{{formData.biangao?parseFloat(formData.biangao):'**'}}cm</text>
  30. <text class="dikuan1 top">{{formData.dikuan?parseFloat(formData.dikuan):'**'}}cm</text>
  31. <text class="dikuan2 top">{{formData.dikuan?parseFloat(formData.dikuan):'**'}}cm</text>
  32. <text class="result bottom">{{rules.result.value?rules.result.value:'**'}}{{rules.result.unit}}</text>
  33. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  34. </view>
  35. <view class="title">切割图</view>
  36. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  37. </div>
  38. </view>
  39. </template>
  40. <script>
  41. import mathImgs from "@/core/math-imgs"
  42. // 万能公式
  43. export default {
  44. data() {
  45. return {
  46. name: 'rightAngleHorizontal',
  47. mathImgs: mathImgs,
  48. formData: {
  49. biangao: '',
  50. dikuan: '',
  51. },
  52. // 用来验证 输入
  53. rules: {
  54. result: {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. /*结果=边高×1.414*/
  67. if(this.formData.biangao && this.formData.dikuan){
  68. this.rules.result.value = this.formData.biangao * 1.414;
  69. }else{
  70. this.$u.toast('请输入两个参数');
  71. }
  72. this.roundRules();
  73. this.$u.toast("请参考计算示意图")
  74. },
  75. roundRules(){
  76. for (const itemKey in this.rules) {
  77. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  78. }
  79. },
  80. initRules(){
  81. for (const itemKey in this.rules) {
  82. this.rules[itemKey].value = "";
  83. }
  84. },
  85. handleClear() {
  86. this.initRules();
  87. this.formData = {
  88. biangao: '',
  89. dikuan: '',
  90. };
  91. }
  92. },
  93. computed:{
  94. showResult(){
  95. let validate = [];
  96. for (const itemKey in this.rules) {
  97. validate.push(this.rules[itemKey].value);
  98. }
  99. return this.$util.checkArrayNotNullNumber(validate,1)
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. @import "@/static/css/math.scss";
  106. .biangao1,.biangao2{
  107. top: -5rpx !important;
  108. }
  109. .biangao1{
  110. left: 200rpx;
  111. }
  112. .biangao2{
  113. left: 425rpx;
  114. }
  115. .dikuan1,.dikuan2{
  116. top: 50rpx !important;
  117. }
  118. .dikuan1{
  119. left: 280rpx;
  120. }
  121. .dikuan2{
  122. left: 355rpx;
  123. }
  124. .result{
  125. top: 250rpx !important;
  126. left: 200rpx;
  127. }
  128. </style>