anyangle.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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="请选择角度" label-width="180">
  9. <text @click="angleShow = true" class="select">{{angleTxt}}</text>
  10. <u-select v-model="angleShow" :list="angleList" @confirm="handleSelectAngle"></u-select>
  11. </u-form-item>
  12. <u-form-item label="左斜边(cm)" label-width="180">
  13. <u-input type="digit" v-model="formData.leftxiebian" placeholder="请输入左斜边"/>
  14. </u-form-item>
  15. <u-form-item label="右斜边(cm)" label-width="180">
  16. <u-input type="digit" v-model="formData.rightxiebian" placeholder="请输入右斜边"/>
  17. </u-form-item>
  18. <u-form-item label="底边(cm)" label-width="180">
  19. <u-input type="digit" v-model="formData.dibian" placeholder="请输入底边"/>
  20. </u-form-item>
  21. <u-form-item label="边高(cm)" label-width="180">
  22. <u-input type="digit" v-model="formData.biangao" placeholder="选填"/>
  23. </u-form-item>
  24. </view>
  25. <view class="btn-group main-left cross-center">
  26. <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
  27. <u-button :ripple="true" @click="handleClear">清空</u-button>
  28. </view>
  29. </view>
  30. <div class="footer">
  31. <view class="result dir-top-wrap cross-center" v-if="showResult">
  32. <view v-for="item in rules" v-if="item.value && item.show">
  33. <text>{{item.name}}=</text>{{$util.round(item.value,2)}}{{item.unit}}
  34. <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
  35. </view>
  36. </view>
  37. </div>
  38. </view>
  39. </template>
  40. <script>
  41. import mathImgs from "@/core/math-imgs"
  42. // 万能公式
  43. export default {
  44. data() {
  45. return {
  46. name: 'anyangle',
  47. mathImgs: mathImgs,
  48. formData: {
  49. leftxiebian: '',
  50. rightxiebian: '',
  51. dibian: '',
  52. biangao: '',
  53. angle: '1'
  54. },
  55. // 用来验证 输入
  56. rules: {
  57. left:{name:'左底角', value:'',unit:'°',show: true},
  58. right: {name:'右底角', value:'',unit:'°',show: true},
  59. top:{name:'顶角', value:'',unit:'°',show: true},
  60. slice:{name:'切口', value:'',unit:'cm',show: true,isHalf:true},
  61. },
  62. angleShow: false,
  63. angleList: [
  64. {value: '1',label: '顶角'},
  65. {value: '2',label: '左底角'},
  66. {value: '3',label: '右底角'},
  67. ],
  68. angleTxt: "顶角",
  69. }
  70. },
  71. methods: {
  72. handleBigImage(){
  73. uni.previewImage({
  74. urls: [mathImgs[this.name].big],
  75. });
  76. },
  77. handelCalc(){
  78. if(!this.formData.leftxiebian){
  79. this.$u.toast('请输入左斜边');
  80. return
  81. }
  82. if(!this.formData.rightxiebian){
  83. this.$u.toast('请输入右斜边');
  84. return
  85. }
  86. if(!this.formData.dibian){
  87. this.$u.toast('请输入底边');
  88. return
  89. }
  90. this.initRules();
  91. /**
  92. * 1、 已知左斜边(a)、右斜边(b)、底边(c),求左底度(A)、右底度(B)、顶角 (C)
  93. * 左底角:cosA=(b²+c²-a²)÷(2bc) 当A>90°时,A=|180°-A|
  94. 右底度:cosB=(a²+c²-b²)÷(2ac) 当B>90°时,A=|180°-B|
  95. 顶角:cosC =(a²+b²-c²)÷(2ab) 当C>90°时,A=|180°-C|
  96. 2、 ①已知顶角:切口=边高×cosec顶角°
  97. ②已知左底角:切口=边高×cosec左底角°
  98. ③已知右底角:切口=边高×cosec右底角°
  99. */
  100. let left = 0;
  101. let right = 0;
  102. let top = 0;
  103. let a = this.formData.leftxiebian;
  104. let b = this.formData.rightxiebian;
  105. let c = this.formData.dibian;
  106. let slice = 0;
  107. let biangao = this.formData.biangao;
  108. if(!this.$util.checkTriangle(a, b, c)){
  109. this.$u.toast('两边之后要大于第三边');
  110. return;
  111. }
  112. left = (Math.pow(a,2) + Math.pow(c,2) - Math.pow(b,2)) / (2 * a * c)
  113. right = (Math.pow(b,2) + Math.pow(c,2) - Math.pow(a,2)) / (2 * b * c)
  114. top = (Math.pow(a,2) + Math.pow(b,2) - Math.pow(c,2)) / (2 * a * b)
  115. this.rules.left.value = this.$util.acos(left)
  116. this.rules.right.value = this.$util.acos(right)
  117. this.rules.top.value = this.$util.acos(top)
  118. /* if(this.rules.left.value > 90){
  119. this.rules.left.value = Math.abs(180 - this.rules.left.value)
  120. }else if(this.rules.right.value > 90){
  121. this.rules.left.value = Math.abs(180 - this.rules.right.value)
  122. }else if(this.rules.top.value > 90){
  123. this.rules.left.value = Math.abs(180 - this.rules.top.value)
  124. }*/
  125. this.rules.left.value = this.rules.left.value > 90 ? Math.abs(180 - this.rules.left.value) : this.rules.left.value;
  126. this.rules.right.value = this.rules.right.value > 90 ? Math.abs(180 - this.rules.right.value) : this.rules.right.value;
  127. this.rules.top.value = this.rules.top.value > 90 ? Math.abs(180 - this.rules.top.value) : this.rules.top.value;
  128. if(biangao){
  129. if(this.formData.angle === '1'){ // 顶角
  130. slice = biangao * this.$util.tan(this.rules.top.value/2)*2
  131. }else if(this.formData.angle === '2'){ // 左底角
  132. slice = biangao * this.$util.tan(this.rules.left.value/2)*2
  133. }else{
  134. slice = biangao * this.$util.tan(this.rules.right.value/2)*2
  135. }
  136. }
  137. this.rules.slice.value = slice
  138. this.roundRules();
  139. },
  140. roundRules(){
  141. for (const itemKey in this.rules) {
  142. //this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  143. }
  144. },
  145. initRules(){
  146. for (const itemKey in this.rules) {
  147. this.rules[itemKey].value = "";
  148. }
  149. },
  150. handleSelectAngle(e){
  151. this.formData.angle = e[0].value;
  152. this.angleTxt = e[0].label;
  153. this.handelCalc()
  154. },
  155. handleClear() {
  156. this.initRules();
  157. this.formData = {
  158. leftxiebian: '',
  159. rightxiebian: '',
  160. dibian: '',
  161. biangao: '',
  162. angle: '2'
  163. };
  164. }
  165. },
  166. computed:{
  167. showResult(){
  168. let validate = [];
  169. for (const itemKey in this.rules) {
  170. validate.push(this.rules[itemKey].value);
  171. }
  172. return this.$util.checkArrayNotNullNumber(validate,1)
  173. },
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. @import "@/static/css/math.scss";
  179. </style>