anyangle.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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="number" v-model="formData.leftxiebian" placeholder="请输入左斜边"/>
  14. </u-form-item>
  15. <u-form-item label="右斜边(cm)" label-width="180">
  16. <u-input type="number" v-model="formData.rightxiebian" placeholder="请输入右斜边"/>
  17. </u-form-item>
  18. <u-form-item label="底边(cm)" label-width="180">
  19. <u-input type="number" v-model="formData.dibian" placeholder="请输入底边"/>
  20. </u-form-item>
  21. <u-form-item label="边高(cm)" label-width="180">
  22. <u-input type="number" 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. this.rules.left.value = this.$util.acos(left)
  115. this.rules.right.value = this.$util.acos(right)
  116. this.rules.top.value = top = 180 - this.rules.left.value - this.rules.right.value
  117. if(biangao){
  118. if(this.formData.angle === '1'){ // 顶角
  119. slice = biangao * this.$util.tan(this.rules.top.value/2)*2
  120. }else if(this.formData.angle === '2'){ // 左底角
  121. slice = biangao * this.$util.tan(this.rules.left.value/2)*2
  122. }else{
  123. slice = biangao * this.$util.tan(this.rules.right.value/2)*2
  124. }
  125. }
  126. this.rules.slice.value = slice
  127. this.roundRules();
  128. },
  129. roundRules(){
  130. for (const itemKey in this.rules) {
  131. //this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  132. }
  133. },
  134. initRules(){
  135. for (const itemKey in this.rules) {
  136. this.rules[itemKey].value = "";
  137. }
  138. },
  139. handleSelectAngle(e){
  140. this.formData.angle = e[0].value;
  141. this.angleTxt = e[0].label;
  142. this.handelCalc()
  143. },
  144. handleClear() {
  145. this.initRules();
  146. this.formData = {
  147. leftxiebian: '',
  148. rightxiebian: '',
  149. dibian: '',
  150. biangao: '',
  151. angle: '2'
  152. };
  153. }
  154. },
  155. computed:{
  156. showResult(){
  157. let validate = [];
  158. for (const itemKey in this.rules) {
  159. validate.push(this.rules[itemKey].value);
  160. }
  161. return this.$util.checkArrayNotNullNumber(validate,1)
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. @import "@/static/css/math.scss";
  168. </style>