normal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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>{{$util.round(item.value,2)}}{{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. if(this.formData.xiebian){
  92. this.rules.xiebian.value = this.formData.xiebian;
  93. this.rules.xiebian.show = false;
  94. }
  95. /*1:已知高、角度:底边=高÷tan角度° 斜边=高÷sin角度°*/
  96. if(this.formData.height && this.formData.angle){
  97. this.rules.dibian.value = this.formData.height/this.$util.tan(this.formData.angle);
  98. this.rules.xiebian.value = this.formData.height/this.$util.sin(this.formData.angle);
  99. }
  100. /* 2:已知高、底边:tan角度°=高÷底边 斜边²=高²+底边²*/
  101. if(this.formData.height && this.formData.dibian){
  102. this.rules.angle.value = this.$util.atan(this.formData.height/this.formData.dibian);
  103. this.rules.xiebian.value = Math.sqrt(Math.pow(this.formData.height,2) + Math.pow(this.formData.dibian,2));
  104. }
  105. /* 3:已知角度、底边:高=底边×tan角度° 斜边=底边÷cos角度°*/
  106. if(this.formData.angle && this.formData.dibian){
  107. this.rules.height.value = this.formData.dibian*this.$util.tan(this.formData.angle);
  108. this.rules.xiebian.value = this.formData.dibian/this.$util.cos(this.formData.angle);
  109. }
  110. /* 4:已知角度、斜边:高=斜边×sin角度° 底边=斜边×cos角度°*/
  111. if(this.formData.angle && this.formData.xiebian){
  112. this.rules.height.value = this.formData.xiebian/this.$util.sin(this.formData.angle);
  113. this.rules.dibian.value = this.formData.xiebian/this.$util.cos(this.formData.angle);
  114. }
  115. /* 5:已知底边、斜边:高²=斜边²-底边² cos角度°=底边÷斜边*/
  116. if(this.formData.dibian && this.formData.xiebian){
  117. this.rules.height.value = Math.sqrt(Math.pow(this.formData.xiebian,2) - Math.pow(this.formData.dibian,2));
  118. this.rules.angle.value = this.$util.acos(this.formData.dibian/this.formData.xiebian);
  119. }
  120. /* 6:已知高、斜边:底边²=斜边²-高² cos角度°=底边÷斜边*/
  121. if(this.formData.height && this.formData.xiebian){
  122. this.rules.dibian.value = Math.sqrt(Math.pow(this.formData.xiebian,2) - Math.pow(this.formData.height,2));
  123. this.rules.angle.value = this.$util.acos(this.rules.dibian.value/this.formData.xiebian);
  124. }
  125. /*选填(输入边高计算出切口):1、 切口=边高×tan(角度°÷2)×2 2、 起弯=长-底边*/
  126. if(this.formData.biangao){
  127. let angle = this.rules.angle.value ? this.rules.angle.value : this.formData.angle
  128. this.rules.slice.value = this.formData.biangao * this.$util.tan(angle / 2) * 2;
  129. }
  130. if(this.formData.length){
  131. let dibian = this.formData.dibian ? this.formData.dibian : this.rules.dibian.value
  132. this.rules.qiwan.value = this.formData.length - dibian;
  133. }
  134. console.log('-->data',this.rules)
  135. this.roundRules();
  136. this.$u.toast("请参考计算示意图")
  137. },
  138. roundRules(){
  139. for (const itemKey in this.rules) {
  140. //this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  141. }
  142. },
  143. initRules(){
  144. for (const itemKey in this.rules) {
  145. this.rules[itemKey].value = "";
  146. }
  147. },
  148. getInputItem(item){
  149. let validate = [];
  150. for (const itemKey in this.rules) {
  151. if(item !== itemKey && typeof this.formData[itemKey] !== "undefined")
  152. validate.push(this.formData[itemKey]);
  153. }
  154. let placeholder = `请输入${this.rules[item].name}`;
  155. let disabled = false;
  156. if(this.$util.checkArrayNotNullNumber(validate)){
  157. disabled = true;
  158. placeholder = '无需输入';
  159. }
  160. return {placeholder: placeholder,disabled:disabled};
  161. },
  162. handleClear() {
  163. this.initRules();
  164. this.formData = {
  165. height: '',
  166. angle: '',
  167. dibian: '',
  168. xiebian: '',
  169. biangao: '',
  170. lenght: '',
  171. };
  172. }
  173. },
  174. computed:{
  175. heightInput(){
  176. return this.getInputItem('height')
  177. },
  178. angleInput(){
  179. return this.getInputItem('angle')
  180. },
  181. dibianInput(){
  182. return this.getInputItem('dibian')
  183. },
  184. xiebianInput(){
  185. return this.getInputItem('xiebian')
  186. },
  187. showResult(){
  188. let validate = [];
  189. for (const itemKey in this.rules) {
  190. validate.push(this.rules[itemKey].value);
  191. }
  192. return this.$util.checkArrayNotNullNumber(validate)
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. @import "@/static/css/math.scss";
  199. .qiwan{
  200. left: 100rpx;
  201. }
  202. .xiebian{
  203. left: 300rpx;
  204. }
  205. .slice1{
  206. left: 210rpx;
  207. }
  208. .slice2{
  209. left: 430rpx;
  210. }
  211. </style>