normal.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.height" :placeholder="heightInput.placeholder" :disabled="heightInput.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.dibian" :placeholder="dibianInput.placeholder" :disabled="dibianInput.disabled"/>
  16. </u-form-item>
  17. <u-form-item label="斜边(cm)" label-width="160">
  18. <u-input type="digit" v-model="formData.xiebian" :placeholder="xiebianInput.placeholder" :disabled="xiebianInput.disabled"/>
  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.length" placeholder="选填"/>
  25. </u-form-item>
  26. </view>
  27. <view class="btn-group main-left cross-center">
  28. <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
  29. <u-button :ripple="true" @click="handleClear">清空</u-button>
  30. </view>
  31. </view>
  32. <div class="footer">
  33. <view class="result dir-top-wrap cross-center" v-if="showResult">
  34. <view v-for="item in rules" v-if="item.value && item.show">
  35. <text>{{item.name}}=</text>{{item.value}}{{item.unit}}
  36. <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
  37. </view>
  38. </view>
  39. <view class="title">计算图</view>
  40. <view class="calc-img">
  41. <text class="qiwan top">{{rules.qiwan.value?rules.qiwan.value:'**'}}{{rules.qiwan.unit}}</text>
  42. <text class="xiebian top">{{rules.xiebian.value?rules.xiebian.value:'**'}}{{rules.xiebian.unit}}</text>
  43. <text class="slice1 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  44. <text class="slice2 bottom">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  45. <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
  46. </view>
  47. <view class="title">切割图</view>
  48. <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
  49. </div>
  50. </view>
  51. </template>
  52. <script>
  53. import mathImgs from "@/core/math-imgs"
  54. // 万能公式
  55. export default {
  56. data() {
  57. return {
  58. name: 'normal',
  59. mathImgs: mathImgs,
  60. formData: {
  61. height: '',
  62. angle: '',
  63. dibian: '',
  64. xiebian: '',
  65. biangao: '',
  66. lenght: '',
  67. },
  68. // 用来验证 输入
  69. rules: {
  70. height: {name:'高', value:'',unit:'cm',show: true},
  71. angle:{name:'角度', value:'',unit:'°',show: true},
  72. dibian: {name:'底边', value:'',unit:'cm',show: true},
  73. xiebian:{name:'斜边', value:'',unit:'cm',show: true},
  74. slice:{name:'切口', value:'',unit:'cm',show: true,isHalf: true},
  75. qiwan:{name:'起弯', value:'',unit:'cm',show: false},
  76. }
  77. }
  78. },
  79. methods: {
  80. handleBigImage(){
  81. uni.previewImage({
  82. urls: [mathImgs[this.name].big],
  83. });
  84. },
  85. handelCalc(){
  86. if( this.formData.angle && this.formData.angle > 90){
  87. this.$u.toast('角度不能大于90');
  88. return
  89. }
  90. this.initRules();
  91. /*1:已知高、角度:底边=高÷tan角度° 斜边=高÷sin角度°*/
  92. if(this.formData.height && this.formData.angle){
  93. this.rules.dibian.value = this.formData.height/this.$util.tan(this.formData.angle);
  94. this.rules.xiebian.value = this.formData.height/this.$util.sin(this.formData.angle);
  95. }
  96. /* 2:已知高、底边:tan角度°=高÷底边 斜边²=高²+底边²*/
  97. if(this.formData.height && this.formData.dibian){
  98. this.rules.angle.value = this.$util.atan(this.formData.height/this.formData.dibian);
  99. this.rules.xiebian.value = Math.sqrt(Math.pow(this.formData.height,2) + Math.pow(this.formData.dibian,2));
  100. }
  101. /* 3:已知角度、底边:高=底边×tan角度° 斜边=底边÷cos角度°*/
  102. if(this.formData.angle && this.formData.dibian){
  103. this.rules.height.value = this.formData.dibian*this.$util.tan(this.formData.angle);
  104. this.rules.xiebian.value = this.formData.dibian/this.$util.cos(this.formData.angle);
  105. }
  106. /* 4:已知角度、斜边:高=斜边×sin角度° 底边=斜边×cos角度°*/
  107. if(this.formData.angle && this.formData.xiebian){
  108. this.rules.height.value = this.formData.xiebian/this.$util.sin(this.formData.angle);
  109. this.rules.dibian.value = this.formData.xiebian/this.$util.cos(this.formData.angle);
  110. }
  111. /* 5:已知底边、斜边:高²=斜边²-底边² cos角度°=底边÷斜边*/
  112. if(this.formData.dibian && this.formData.xiebian){
  113. this.rules.height.value = Math.sqrt(Math.pow(this.formData.xiebian,2) - Math.pow(this.formData.dibian,2));
  114. this.rules.angle.value = this.$util.acos(this.formData.dibian/this.formData.xiebian);
  115. }
  116. /*选填(输入边高计算出切口):1、 切口=边高×tan(角度°÷2)×2 2、 起弯=长-底边*/
  117. if(this.formData.biangao){
  118. let angle = this.rules.angle.value ? this.rules.angle.value : this.formData.angle
  119. this.rules.slice.value = this.formData.biangao * this.$util.tan(angle / 2) * 2;
  120. }
  121. if(this.formData.length){
  122. let dibian = this.formData.dibian ? this.formData.dibian : this.rules.dibian.value
  123. this.rules.qiwan.value = this.formData.length - dibian;
  124. }
  125. this.roundRules();
  126. this.$u.toast("请参考计算示意图")
  127. },
  128. roundRules(){
  129. for (const itemKey in this.rules) {
  130. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  131. }
  132. },
  133. initRules(){
  134. for (const itemKey in this.rules) {
  135. this.rules[itemKey].value = "";
  136. }
  137. },
  138. getInputItem(item){
  139. let validate = [];
  140. for (const itemKey in this.rules) {
  141. if(item !== itemKey && typeof this.formData[itemKey] !== "undefined")
  142. validate.push(this.formData[itemKey]);
  143. }
  144. let placeholder = `请输入${this.rules[item].name}`;
  145. let disabled = false;
  146. if(this.$util.checkArrayNotNullNumber(validate)){
  147. disabled = true;
  148. placeholder = '无需输入';
  149. }
  150. return {placeholder: placeholder,disabled:disabled};
  151. },
  152. handleClear() {
  153. this.initRules();
  154. this.formData = {
  155. height: '',
  156. angle: '',
  157. dibian: '',
  158. xiebian: '',
  159. biangao: '',
  160. lenght: '',
  161. };
  162. }
  163. },
  164. computed:{
  165. heightInput(){
  166. return this.getInputItem('height')
  167. },
  168. angleInput(){
  169. return this.getInputItem('angle')
  170. },
  171. dibianInput(){
  172. return this.getInputItem('dibian')
  173. },
  174. xiebianInput(){
  175. return this.getInputItem('xiebian')
  176. },
  177. showResult(){
  178. let validate = [];
  179. for (const itemKey in this.rules) {
  180. validate.push(this.rules[itemKey].value);
  181. }
  182. return this.$util.checkArrayNotNullNumber(validate)
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. @import "@/static/css/math.scss";
  189. .qiwan{
  190. left: 100rpx;
  191. }
  192. .xiebian{
  193. left: 300rpx;
  194. }
  195. .slice1{
  196. left: 210rpx;
  197. }
  198. .slice2{
  199. left: 430rpx;
  200. }
  201. </style>