santongwanHorizontal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.cibianheight" placeholder="请输入次底高"/>
  10. </u-form-item>
  11. <u-form-item label="次底宽(cm)" label-width="160">
  12. <u-input type="number" v-model="formData.cidilength" 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="cibianheight1">{{formData.cibianheight?$util.round(formData.cibianheight,2):'**'}}cm</text>
  29. <text class="cidilength">{{formData.cidilength?$util.round(formData.cidilength,2):'**'}}cm</text>
  30. <text class="cibianheight2">{{formData.cibianheight?$util.round(formData.cibianheight,2):'**'}}cm</text>
  31. <text class="cibianheight3">{{formData.cibianheight?$util.round(formData.cibianheight,2):'**'}}cm</text>
  32. <text class="slice1">{{rules.result.value?rules.result.value:'**'}}{{rules.result.unit}}</text>
  33. <text class="slice2">{{rules.result.value?rules.result.value:'**'}}{{rules.result.unit}}</text>
  34. <u-image width="100%" height="800rpx" :src="mathImgs[name].calc" mode="widthFix"></u-image>
  35. </view>
  36. <view class="title">切割图</view>
  37. <u-image width="100%" height="800rpx" :src="mathImgs[name].slice" mode="widthFix"></u-image>
  38. </div>
  39. </view>
  40. </template>
  41. <script>
  42. import mathImgs from "@/core/math-imgs"
  43. // 万能公式
  44. export default {
  45. data() {
  46. return {
  47. name: 'santongwanHorizontal',
  48. mathImgs: mathImgs,
  49. formData: {
  50. cibianheight: '',
  51. cidilength: '',
  52. },
  53. // 用来验证 输入
  54. rules: {
  55. result: {name:'', value:'',unit:'cm',show: true},
  56. }
  57. }
  58. },
  59. methods: {
  60. handleBigImage(){
  61. uni.previewImage({
  62. urls: [mathImgs[this.name].big],
  63. });
  64. },
  65. handelCalc(){
  66. let validate = [this.formData.cibianheight,this.formData.cidilength]
  67. if(!this.$util.checkArrayNotNullNumber(validate)){
  68. this.$u.toast('至少输入两个参数');
  69. return
  70. }
  71. this.initRules();
  72. /**
  73. 结果=次边高×1.414
  74. */
  75. this.rules.result.value = this.formData.cibianheight * 1.414
  76. this.roundRules();
  77. this.$u.toast("请参考计算示意图")
  78. },
  79. roundRules(){
  80. for (const itemKey in this.rules) {
  81. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  82. }
  83. },
  84. initRules(){
  85. for (const itemKey in this.rules) {
  86. this.rules[itemKey].value = "";
  87. }
  88. },
  89. handleClear() {
  90. this.initRules();
  91. this.formData = {
  92. cibianheight: '',
  93. cidilength: '',
  94. };
  95. }
  96. },
  97. computed:{
  98. showResult(){
  99. let validate = [];
  100. for (const itemKey in this.rules) {
  101. validate.push(this.rules[itemKey].value);
  102. }
  103. return this.$util.checkArrayNotNullNumber(validate,1)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. @import "@/static/css/math.scss";
  110. .cibianheight1{
  111. top: 210rpx;
  112. left: 10rpx;
  113. }
  114. .cidilength{
  115. top: 290rpx;
  116. left: 230rpx;
  117. }
  118. .cibianheight2{
  119. top: 290rpx;
  120. left: 340rpx;
  121. }
  122. .cibianheight3{
  123. top: 290rpx;
  124. left: 445rpx;
  125. }
  126. .slice1{
  127. top: 390rpx;
  128. left: 180rpx;
  129. }
  130. .slice2{
  131. top: 730rpx;
  132. left: 160rpx;
  133. }
  134. </style>