duochengzhijiao.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. <u-input type="number" v-model="formData.angle" placeholder="请输入角度"/>
  10. </u-form-item>
  11. <u-form-item label="层间距(cm)" label-width="180">
  12. <u-input type="number" v-model="formData.cengjianju" placeholder="请输入层间距"/>
  13. </u-form-item>
  14. <u-form-item label="已测量层数" label-width="180">
  15. <text @click="cengShow = true" class="select">{{cengTxt}}</text>
  16. <u-select v-model="cengShow" :list="cengList" @confirm="handleSelectCeng"></u-select>
  17. </u-form-item>
  18. <u-form-item label="斜边(cm)" label-width="180">
  19. <u-input type="number" v-model="formData.xiebian" 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. <u-form-item label="起弯(cm)" label-width="180">
  25. <u-input type="number" v-model="formData.qiwan" placeholder="选填"/>
  26. </u-form-item>
  27. </view>
  28. <view class="btn-group main-left cross-center">
  29. <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
  30. <u-button :ripple="true" @click="handleClear">清空</u-button>
  31. </view>
  32. </view>
  33. <div class="footer">
  34. <view class="result dir-top-wrap cross-center" v-if="showResult">
  35. <view v-for="item in rules" v-if="item.value && item.show">
  36. <text>{{item.name}}=</text>{{item.value}}{{item.unit}}
  37. <text v-if="item.isHalf">{{$util.round(item.value/2,2)}}{{item.unit}}</text>
  38. </view>
  39. </view>
  40. <view class="title">计算图</view>
  41. <view class="calc-img">
  42. <text class="diyiceng">{{rules.diyiceng.value?rules.diyiceng.value:'**'}}{{rules.diyiceng.unit}}</text>
  43. <text class="diyicengqiwan">{{rules.diyicengqiwan.value?rules.diyicengqiwan.value:'**'}}{{rules.diyicengqiwan.unit}}</text>
  44. <text class="slice1">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  45. <text class="slice2">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  46. <text class="dierceng">{{rules.dierceng.value?rules.dierceng.value:'**'}}{{rules.dierceng.unit}}</text>
  47. <text class="diercengqiwan">{{rules.diercengqiwan.value?rules.diercengqiwan.value:'**'}}{{rules.diercengqiwan.unit}}</text>
  48. <text class="slice3">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  49. <text class="slice4">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  50. <text class="disanceng">{{rules.disanceng.value?rules.disanceng.value:'**'}}{{rules.disanceng.unit}}</text>
  51. <text class="disancengqiwan">{{rules.disancengqiwan.value?rules.disancengqiwan.value:'**'}}{{rules.disancengqiwan.unit}}</text>
  52. <text class="slice5">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  53. <text class="slice6">{{rules.slice.value?rules.slice.value:'**'}}{{rules.slice.unit}}</text>
  54. <text class="cengjianju1">{{formData.cengjianju?formData.cengjianju:'**'}}cm</text>
  55. <text class="cengjianju2">{{formData.cengjianju?formData.cengjianju:'**'}}cm</text>
  56. <u-image width="100%" height="600rpx" :src="mathImgs[name].calc" mode="widthFix"></u-image>
  57. </view>
  58. <view class="title">切割图</view>
  59. <u-image width="100%" height="600rpx" :src="mathImgs[name].slice" mode="widthFix"></u-image>
  60. </div>
  61. </view>
  62. </template>
  63. <script>
  64. import mathImgs from "@/core/math-imgs"
  65. // 万能公式
  66. export default {
  67. data() {
  68. return {
  69. name: 'duochengzhijiao',
  70. mathImgs: mathImgs,
  71. formData: {
  72. angle: '',
  73. cengjianju: '',
  74. ceng: '1',
  75. xiebian: '',
  76. biangao: '',
  77. qiwan: '',
  78. },
  79. // 用来验证 输入
  80. rules: {
  81. diyiceng: {name:'第一层斜边', value:'',unit:'cm',show: true},
  82. dierceng:{name:'第二层斜边', value:'',unit:'cm',show: true},
  83. disanceng: {name:'第三层斜边', value:'',unit:'cm',show: true},
  84. diyicengqiwan: {name:'第一层起弯', value:'',unit:'cm',show: true},
  85. diercengqiwan:{name:'第二层起弯', value:'',unit:'cm',show: true},
  86. disancengqiwan: {name:'第三层起弯', value:'',unit:'cm',show: true},
  87. slice:{name:'切口', value:'',unit:'cm',show: true,isHalf:true},
  88. },
  89. cengShow: false,
  90. cengList: [
  91. {value: '1',label: '第一层'},
  92. {value: '2',label: '第二层'},
  93. {value: '3',label: '第三层'},
  94. ],
  95. cengTxt: "第一层",
  96. }
  97. },
  98. methods: {
  99. handleBigImage(){
  100. uni.previewImage({
  101. urls: [mathImgs[this.name].big],
  102. });
  103. },
  104. handelCalc(){
  105. if(!this.formData.angle){
  106. this.$u.toast('请输入角度');
  107. return
  108. }
  109. if( this.formData.angle && this.formData.angle >= 90){
  110. this.$u.toast('角度不能大于和等于90');
  111. return
  112. }
  113. if(!this.formData.cengjianju){
  114. this.$u.toast('请输入层间距');
  115. return
  116. }
  117. if(!this.formData.xiebian){
  118. this.$u.toast('请输入斜边');
  119. return
  120. }
  121. if(!this.formData.biangao){
  122. this.$u.toast('请输入边高');
  123. return
  124. }
  125. this.initRules();
  126. /**
  127. * 1、 已知第一层:
  128. * 第二层斜边=斜边-(边高+层间距)×tan(角度°÷2)×2
  129. * 第三层斜边=斜边-(边高+层间距)×tan(角度°÷2)×4
  130. * 切口 = 边高×tan(角度°÷2)×2
  131. */
  132. this.formData.angle = parseFloat(this.formData.angle);
  133. this.formData.cengjianju = parseFloat(this.formData.cengjianju);
  134. this.formData.biangao = parseFloat(this.formData.biangao);
  135. this.formData.xiebian = parseFloat(this.formData.xiebian);
  136. this.formData.ceng = parseFloat(this.formData.ceng);
  137. this.formData.cengjianju = parseFloat(this.formData.cengjianju);
  138. this.formData.qiwan = parseFloat(this.formData.qiwan);
  139. if(this.formData.ceng === 1){
  140. this.rules.diyiceng.value = this.formData.xiebian
  141. this.rules.diyicengqiwan.value = this.formData.qiwan
  142. this.rules.diyiceng.show = false;
  143. this.rules.diyicengqiwan.show = false;
  144. this.rules.dierceng.value = this.formData.xiebian - (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 2;
  145. this.rules.disanceng.value = this.formData.xiebian - (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 4;
  146. /**
  147. * 1、 已知第一层起弯:
  148. * 第二层起弯 = 起弯-(边高+层间距)×tan(角度°÷2)
  149. * 第三层起弯 = 起弯-(边高+层间距)×tan(角度°÷2)×2
  150. */
  151. if(this.formData.qiwan){
  152. this.rules.diercengqiwan.value = this.formData.qiwan - (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2);
  153. this.rules.disancengqiwan.value = this.formData.qiwan - (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 2;
  154. }
  155. }
  156. /**
  157. * 2、 已知第二层:
  158. * 第一层斜边=斜边+(边高+层间距)×tan(角度°÷2)×2
  159. * 第三层斜边=斜边-(边高+层间距)×tan(角度°÷2)×2
  160. * 切口 = 边高×tan(角度°÷2)×2
  161. */
  162. if(this.formData.ceng === 2){
  163. this.rules.dierceng.value = this.formData.xiebian
  164. this.rules.diercengqiwan.value = this.formData.qiwan
  165. this.rules.dierceng.show = false;
  166. this.rules.diercengqiwan.show = false;
  167. this.rules.diyiceng.value = this.formData.xiebian + (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 2;
  168. this.rules.disanceng.value = this.formData.xiebian - (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 2;
  169. /**
  170. * 1、 已知第二层起弯
  171. * 第一层起弯 = 起弯+(边高+层间数)×tan(角度°÷2)
  172. * 第三层起弯 = 起弯-(边高+层间数)×tan(角度°÷2)
  173. */
  174. if(this.formData.qiwan){
  175. this.rules.diyicengqiwan.value = this.formData.qiwan + (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2);
  176. this.rules.disancengqiwan.value = this.formData.qiwan - (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2);
  177. }
  178. }
  179. /**
  180. * 3、 已知第三层:
  181. * 第一层斜边=斜边+(边高+层间距)×tan(角度°÷2)×4
  182. * 第二层斜边=斜边+(边高+层间距)×tan(角度°÷2)×2
  183. * 切口 = 边高×tan(角度°÷2)×2
  184. */
  185. if(this.formData.ceng === 3){
  186. this.rules.disanceng.value = this.formData.xiebian
  187. this.rules.disancengqiwan.value = this.formData.qiwan
  188. this.rules.disanceng.show = false;
  189. this.rules.disancengqiwan.show = false;
  190. this.rules.diyiceng.value = this.formData.xiebian + (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 4;
  191. this.rules.dierceng.value = this.formData.xiebian + (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 2;
  192. /**
  193. * 3、 已知第三层起弯:
  194. * 第一层起弯 = 起弯+(边高+层间数)×tan(角度°÷2)×4
  195. * 第二层起弯 = 起弯+(边高+层间数)×tan(角度°÷2)×2
  196. */
  197. if(this.formData.qiwan){
  198. this.rules.diyicengqiwan.value = this.formData.qiwan + (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 4
  199. this.rules.diercengqiwan.value = this.formData.qiwan + (this.formData.biangao + this.formData.cengjianju) * this.$util.tan(this.formData.angle / 2) * 2;
  200. }
  201. }
  202. this.rules.slice.value = this.formData.biangao * this.$util.tan(this.formData.angle / 2) * 2;
  203. this.roundRules();
  204. this.$u.toast("请参考计算示意图")
  205. },
  206. roundRules(){
  207. for (const itemKey in this.rules) {
  208. this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
  209. }
  210. },
  211. initRules(){
  212. for (const itemKey in this.rules) {
  213. this.rules[itemKey].value = "";
  214. this.rules[itemKey].show = true;
  215. }
  216. },
  217. handleSelectCeng(e){
  218. this.formData.ceng = e[0].value;
  219. this.cengTxt = e[0].label;
  220. },
  221. handleClear() {
  222. this.initRules();
  223. this.formData = {
  224. angle: '',
  225. cengjianju: '',
  226. ceng: '1',
  227. xiebian: '',
  228. biangao: '',
  229. qiwan: '',
  230. };
  231. }
  232. },
  233. computed:{
  234. showResult(){
  235. let validate = [];
  236. for (const itemKey in this.rules) {
  237. validate.push(this.rules[itemKey].value);
  238. }
  239. return this.$util.checkArrayNotNullNumber(validate)
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="scss" scoped>
  245. @import "@/static/css/math.scss";
  246. .diyiceng{
  247. left: 150rpx;
  248. }
  249. .diyicengqiwan{
  250. left: 320rpx;
  251. }
  252. .slice1{
  253. top: 170rpx;
  254. left: 240rpx;
  255. }
  256. .slice2{
  257. top: 170rpx;
  258. left: 445rpx;
  259. }
  260. .dierceng{
  261. top: 190rpx;
  262. left: 170rpx;
  263. }
  264. .diercengqiwan{
  265. top: 190rpx;
  266. left: 340rpx;
  267. }
  268. .slice3{
  269. top: 350rpx;
  270. left: 260rpx;
  271. }
  272. .slice4{
  273. top: 350rpx;
  274. left: 445rpx;
  275. }
  276. .disanceng{
  277. top: 360rpx;
  278. left: 170rpx;
  279. }
  280. .disancengqiwan{
  281. top: 360rpx;
  282. left: 340rpx;
  283. }
  284. .slice5{
  285. top: 520rpx;
  286. left: 280rpx;
  287. }
  288. .slice6{
  289. top: 520rpx;
  290. left: 445rpx;
  291. }
  292. .cengjianju1{
  293. top: 200rpx;
  294. }
  295. .cengjianju2{
  296. top: 370rpx;
  297. }
  298. </style>