baoliangwan.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.leftHeight" placeholder="请输入左侧高"/>
  10. </u-form-item>
  11. <u-form-item label="右高(cm)" label-width="160">
  12. <u-input type="digit" v-model="formData.rightHeight" placeholder="请输入右侧高"/>
  13. </u-form-item>
  14. <u-form-item label="左角度(°)" label-width="160">
  15. <u-input type="digit" v-model="formData.leftAngle" placeholder="请输入左角度"/>
  16. </u-form-item>
  17. <u-form-item label="右角度(°)" label-width="160">
  18. <u-input type="digit" v-model="formData.rightAngle" placeholder="请输入右角度"/>
  19. </u-form-item>
  20. <u-form-item label="边高(cm)" label-width="160">
  21. <u-input type="digit" v-model="formData.biangao" placeholder="请输入边高"/>
  22. </u-form-item>
  23. <u-form-item label="柱宽(cm)" label-width="160">
  24. <u-input type="digit" v-model="formData.zhukuan" placeholder="请输入柱宽"/>
  25. </u-form-item>
  26. <u-form-item label="长(cm)" label-width="160">
  27. <u-input type="digit" v-model="formData.length" placeholder="选填"/>
  28. </u-form-item>
  29. </view>
  30. <view class="btn-group main-left cross-center">
  31. <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
  32. <u-button :ripple="true" @click="handleClear">清空</u-button>
  33. </view>
  34. </view>
  35. <div class="footer">
  36. <view class="result dir-top-wrap cross-center" v-if="showResult">
  37. <view v-for="item in rules" v-if="item.value && item.show">
  38. <text>{{item.name}}=</text>{{item.value}}{{item.unit}}
  39. <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
  40. </view>
  41. </view>
  42. <view class="title">计算图</view>
  43. <view class="calc-img">
  44. <text class="qiwan top">{{rules.qiwan.value?rules.qiwan.value:'**'}}{{rules.qiwan.unit}}</text>
  45. <text class="leftxiebian top">{{rules.leftxiebian.value?rules.leftxiebian.value:'**'}}{{rules.leftxiebian.unit}}</text>
  46. <text class="rightxiebian top">{{rules.rightxiebian.value?rules.rightxiebian.value:'**'}}{{rules.rightxiebian.unit}}</text>
  47. <text class="leftxiekou1 bottom">{{rules.leftxiekou.value?rules.leftxiekou.value:'**'}}{{rules.leftxiekou.unit}}</text>
  48. <text class="leftxiekou2 bottom">{{rules.leftxiekou.value?rules.leftxiekou.value:'**'}}{{rules.leftxiekou.unit}}</text>
  49. <text class="zhukuan">{{formData.zhukuan?$util.round(formData.zhukuan,2):'**'}}cm</text>
  50. <text class="rightxiekou1 bottom">{{rules.rightxiekou.value?rules.rightxiekou.value:'**'}}{{rules.rightxiekou.unit}}</text>
  51. <text class="rightxiekou2 bottom">{{rules.rightxiekou.value?rules.rightxiekou.value:'**'}}{{rules.rightxiekou.unit}}</text>
  52. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  53. </view>
  54. <view class="title">切割图</view>
  55. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  56. </div>
  57. </view>
  58. </template>
  59. <script>
  60. import mathImgs from "@/core/math-imgs"
  61. // 万能公式
  62. export default {
  63. data() {
  64. return {
  65. name: 'baoliangwan',
  66. mathImgs: mathImgs,
  67. formData: {
  68. leftHeight: '',
  69. rightHeight: '',
  70. leftAngle: '',
  71. rightAngle: '',
  72. biangao: '',
  73. zhukuan: '',
  74. lenght: '',
  75. },
  76. // 用来验证 输入
  77. rules: {
  78. leftxiebian: {name:'左斜边', value:'',unit:'cm',show: true},
  79. leftxiekou:{name:'左切口', value:'',unit:'cm',show: true,isHalf:true},
  80. rightxiebian: {name:'右斜边', value:'',unit:'cm',show: true},
  81. rightxiekou:{name:'右切口', value:'',unit:'cm',show: true,isHalf:true},
  82. qiwan:{name:'起弯', value:'',unit:'cm',show: false},
  83. }
  84. }
  85. },
  86. methods: {
  87. handleBigImage(){
  88. uni.previewImage({
  89. urls: [mathImgs[this.name].big],
  90. });
  91. },
  92. handelCalc(){
  93. if(!this.formData.leftHeight || !this.formData.rightHeight || !this.formData.leftAngle || !this.formData.rightAngle
  94. || !this.formData.biangao || !this.formData.zhukuan ){
  95. this.$u.toast('请填写全部参数');
  96. return
  97. }
  98. if( this.formData.leftAngle > 90 || this.formData.rightHeight > 90){
  99. this.$u.toast('角度不能大于90');
  100. return
  101. }
  102. this.initRules();
  103. /**
  104. * 5、 左斜边=左高×csc左角度°
  105. 6、 左切口=边高×tan(左角度°÷2)×2
  106. 7、 右斜边=右高×csc右角度°
  107. 8、 右切口=边高×tan(右角度°÷2)×2
  108. */
  109. this.rules.leftxiebian.value = this.formData.leftHeight * this.$util.csc(this.formData.leftAngle)
  110. this.rules.leftxiekou.value = this.formData.biangao * this.$util.tan(this.formData.leftAngle / 2) * 2
  111. this.rules.rightxiebian.value = this.formData.rightHeight * this.$util.csc(this.formData.rightAngle)
  112. this.rules.rightxiekou.value = this.formData.biangao * this.$util.tan(this.formData.rightAngle / 2) * 2
  113. // 1、 起弯=长-左高×cot左角度°
  114. if(this.formData.length){
  115. this.rules.qiwan.value = this.formData.length - this.formData.leftHeight * this.$util.cot(this.formData.leftAngle)
  116. }
  117. this.roundRules();
  118. this.$u.toast("请参考计算示意图")
  119. },
  120. roundRules(){
  121. for (const itemKey in this.rules) {
  122. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  123. }
  124. },
  125. initRules(){
  126. for (const itemKey in this.rules) {
  127. this.rules[itemKey].value = "";
  128. }
  129. },
  130. handleClear() {
  131. this.initRules();
  132. this.formData = {
  133. leftHeight: '',
  134. rightHeight: '',
  135. leftAngle: '',
  136. rightAngle: '',
  137. biangao: '',
  138. zhukuan: '',
  139. lenght: '',
  140. };
  141. }
  142. },
  143. computed:{
  144. showResult(){
  145. let validate = [];
  146. for (const itemKey in this.rules) {
  147. validate.push(this.rules[itemKey].value);
  148. }
  149. return this.$util.checkArrayNotNullNumber(validate)
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. @import "@/static/css/math.scss";
  156. .qiwan{
  157. left: 80rpx;
  158. }
  159. .leftxiebian{
  160. left: 200rpx;
  161. }
  162. .rightxiebian{
  163. left: 440rpx;
  164. }
  165. .leftxiekou1{
  166. left: 160rpx;
  167. }
  168. .leftxiekou2{
  169. left: 260rpx;
  170. }
  171. .zhukuan{
  172. top: 200rpx;
  173. left: 320rpx;
  174. }
  175. .rightxiekou1{
  176. left: 380rpx;
  177. }
  178. .rightxiekou2{
  179. left: 490rpx;
  180. }
  181. </style>