123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <template>
- <view class="math-container">
- <view class="header">
- <u-image width="100%" height="300rpx" :src="mathImgs[name].big" mode="aspectFit" @click="handleBigImage"></u-image>
- </view>
- <view class="main dir-top-wrap cross-center">
- <view class="form">
- <u-form-item label="边高(cm)" label-width="160">
- <u-input type="digit" v-model="formData.biangao" placeholder="请输入边高"/>
- </u-form-item>
- <u-form-item label="底宽(cm)" label-width="160">
- <u-input type="digit" v-model="formData.dikuan" placeholder="请输入底宽"/>
- </u-form-item>
- </view>
- <view class="btn-group main-left cross-center">
- <u-button :ripple="true" @click="handelCalc" :custom-style="{backgroundColor: $u.color['mainBgColor'],color:'#ffffff',width: '260rpx',marginRight:'30rpx'}">计算</u-button>
- <u-button :ripple="true" @click="handleClear">清空</u-button>
- </view>
- </view>
- <div class="footer">
- <view class="result dir-top-wrap cross-center" v-if="showResult">
- <view v-for="item in rules" v-if="item.value && item.show">
- <text>{{item.name}}</text>{{item.value}}{{item.unit}}
- </view>
- </view>
- <view class="title">计算图</view>
- <view class="calc-img">
- <text class="biangao1 top">{{formData.biangao?parseFloat(formData.biangao):'**'}}cm</text>
- <text class="biangao2 top">{{formData.biangao?parseFloat(formData.biangao):'**'}}cm</text>
- <text class="dikuan1 top">{{formData.dikuan?parseFloat(formData.dikuan):'**'}}cm</text>
- <text class="dikuan2 top">{{formData.dikuan?parseFloat(formData.dikuan):'**'}}cm</text>
- <text class="result bottom">{{rules.result.value?rules.result.value:'**'}}{{rules.result.unit}}</text>
- <u-image width="100%" height="300rpx" :src="mathImgs[name].calc" mode="aspectFit"></u-image>
- </view>
- <view class="title">切割图</view>
- <u-image width="100%" height="300rpx" :src="mathImgs[name].slice" mode="aspectFit"></u-image>
- </div>
- </view>
- </template>
- <script>
- import mathImgs from "@/core/math-imgs"
- // 万能公式
- export default {
- data() {
- return {
- name: 'rightAngleHorizontal',
- mathImgs: mathImgs,
- formData: {
- biangao: '',
- dikuan: '',
- },
- // 用来验证 输入
- rules: {
- result: {name:'', value:'',unit:'cm',show: true},
- }
- }
- },
- methods: {
- handleBigImage(){
- uni.previewImage({
- urls: [mathImgs[this.name].big],
- });
- },
- handelCalc(){
- this.initRules();
- /*结果=边高×1.414*/
- if(this.formData.biangao && this.formData.dikuan){
- this.rules.result.value = this.formData.biangao * 1.414;
- }else{
- this.$u.toast('请输入两个参数');
- }
- this.roundRules();
- this.$u.toast("请参考计算示意图")
- },
- roundRules(){
- for (const itemKey in this.rules) {
- this.rules[itemKey].value = this.$util.round(this.rules[itemKey].value,2);
- }
- },
- initRules(){
- for (const itemKey in this.rules) {
- this.rules[itemKey].value = "";
- }
- },
- handleClear() {
- this.initRules();
- this.formData = {
- biangao: '',
- dikuan: '',
- };
- }
- },
- computed:{
- showResult(){
- let validate = [];
- for (const itemKey in this.rules) {
- validate.push(this.rules[itemKey].value);
- }
- return this.$util.checkArrayNotNullNumber(validate,1)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "@/static/css/math.scss";
- .biangao1,.biangao2{
- top: -5rpx !important;
- }
- .biangao1{
- left: 200rpx;
- }
- .biangao2{
- left: 425rpx;
- }
- .dikuan1,.dikuan2{
- top: 50rpx !important;
- }
- .dikuan1{
- left: 280rpx;
- }
- .dikuan2{
- left: 355rpx;
- }
- .result{
- top: 250rpx !important;
- left: 200rpx;
- }
- </style>
|