slice.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.biangao" :placeholder="biangaoInput.placeholder" :disabled="biangaoInput.disabled"/>
  10. </u-form-item>
  11. <u-form-item label="角度(°)" label-width="160">
  12. <u-input type="digit" v-model="formData.angle" :placeholder="angleInput.placeholder" :disabled="angleInput.disabled"/>
  13. </u-form-item>
  14. <u-form-item label="切口(cm)" label-width="160">
  15. <u-input type="digit" v-model="formData.slice" :placeholder="sliceInput.placeholder" :disabled="sliceInput.disabled"/>
  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>{{$util.round(item.value,2)}}{{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="slice1">{{rules.slice.value?$util.round(rules.slice.value/2,2):'**'}}{{rules.slice.unit}}</text>
  33. <text class="slice2">{{rules.slice.value?$util.round(rules.slice.value/2,2):'**'}}{{rules.slice.unit}}</text>
  34. <text class="slice3 bottom">{{rules.slice.value?$util.round(rules.slice.value,2):'**'}}{{rules.slice.unit}}</text>
  35. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  36. </view>
  37. <view class="title">切割图</view>
  38. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  39. </div>
  40. </view>
  41. </template>
  42. <script>
  43. import mathImgs from "@/core/math-imgs"
  44. // 万能公式
  45. export default {
  46. data() {
  47. return {
  48. name: 'slice',
  49. mathImgs: mathImgs,
  50. formData: {
  51. biangao: '',
  52. angle: '',
  53. slice: '',
  54. },
  55. // 用来验证 输入
  56. rules: {
  57. biangao: {name:'边高', value:'',unit:'cm',show: true},
  58. angle:{name:'角度', value:'',unit:'°',show: true},
  59. slice:{name:'切口', value:'',unit:'cm',show: true,isHalf: true},
  60. }
  61. }
  62. },
  63. methods: {
  64. handleBigImage(){
  65. uni.previewImage({
  66. urls: [mathImgs[this.name].big],
  67. });
  68. },
  69. handelCalc(){
  70. if( this.formData.angle && this.formData.angle > 90){
  71. this.$u.toast('角度不能大于90');
  72. return
  73. }
  74. this.initRules();
  75. /*1、 已知边高、角度:切口=边高×tan(角度°÷2)×2*/
  76. if(this.formData.biangao && this.formData.angle){
  77. this.rules.slice.value = this.formData.biangao * this.$util.tan(this.formData.angle / 2) * 2
  78. }
  79. /*2、 已知边高、切口:tan(角度°÷2)=切口÷(边高×2)*/
  80. if(this.formData.biangao && this.formData.slice){
  81. this.rules.angle.value = this.$util.atan(this.formData.slice / (this.formData.biangao * 2)) * 2
  82. }
  83. /*3、 已知角度、切口:边高=切口÷{tan(角度°÷2)×2}×2*/
  84. if(this.formData.angle && this.formData.slice){
  85. this.rules.biangao.value = this.formData.slice * this.$util.tan(this.formData.angle / 2) * 2
  86. }
  87. this.roundRules();
  88. this.$u.toast("请参考计算示意图")
  89. },
  90. roundRules(){
  91. for (const itemKey in this.rules) {
  92. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  93. }
  94. },
  95. initRules(){
  96. for (const itemKey in this.rules) {
  97. this.rules[itemKey].value = "";
  98. }
  99. },
  100. getInputItem(item){
  101. let validate = [];
  102. for (const itemKey in this.rules) {
  103. if(item !== itemKey && typeof this.formData[itemKey] !== "undefined")
  104. validate.push(this.formData[itemKey]);
  105. }
  106. let placeholder = `请输入${this.rules[item].name}`;
  107. let disabled = false;
  108. if(this.$util.checkArrayNotNullNumber(validate)){
  109. disabled = true;
  110. placeholder = '无需输入';
  111. }
  112. return {placeholder: placeholder,disabled:disabled};
  113. },
  114. handleClear() {
  115. this.initRules();
  116. this.formData = {
  117. biangao: '',
  118. angle: '',
  119. slice: '',
  120. };
  121. }
  122. },
  123. computed:{
  124. angleInput(){
  125. return this.getInputItem('angle')
  126. },
  127. sliceInput(){
  128. return this.getInputItem('slice')
  129. },
  130. biangaoInput(){
  131. return this.getInputItem('biangao')
  132. },
  133. showResult(){
  134. let validate = [];
  135. for (const itemKey in this.rules) {
  136. validate.push(this.rules[itemKey].value);
  137. }
  138. return this.$util.checkArrayNotNullNumber(validate,1)
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. @import "@/static/css/math.scss";
  145. .slice1,.slice2{
  146. top: -15rpx;
  147. }
  148. .slice1{
  149. left: 270rpx;
  150. }
  151. .slice2{
  152. left: 360rpx;
  153. }
  154. .slice3{
  155. top: 280rpx !important;
  156. left: 320rpx;
  157. }
  158. </style>