Commit e4d9cb82 authored by Facius's avatar Facius

feat: 计算器修改

parent aa0f436a
Pipeline #2757 canceled with stages
......@@ -14,7 +14,7 @@
<!-- 小程序使用请改成 :key="ix" -->
<view class="calculator-button-left-aview dot-view" v-for="(item, ix) in calculatorButBList" :key="ix">
<view class="calculator-button-left-a2 dot-view"></view>
<view class="calculator-button-left-a dot-view" @tap="numTapB(item)">
<view class="calculator-button-left-a dot-view" @tap="numTapA(item)">
<text class="calculator-button-left-a1">{{ item }}</text>
</view>
</view>
......@@ -78,8 +78,9 @@ export default {
},
methods: {
handleClickSure() {
console.log('-----sure-----', this.sureText)
this.$emit('sure', this.sureText);
var text = (Math.trunc(this.sureText * 100) / 100).toFixed(2)
console.log('-----sure-----', this.sureText, text)
this.$emit('sure', text);
},
textChange(text) {
console.log('top:', '|'+this.topText+'|')
......@@ -134,43 +135,63 @@ export default {
// 1-9输入判断
numTapA(item) {
// this.showSure = false
if (this.bottomText.length == 1 && this.bottomText == 0) {
if (this.bottomText.length == 1 && this.bottomText == 0 && !this.topText && item == 0) {
return;
}
if (this.bottomText.length == 1 && this.bottomText == 0 && !this.topText) {
this.bottomText = '';
}
if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') {
this.bottomText = '';
}
this.bottomText += item;
var text = this.bottomText
var array = this.bottomText.split('.')
console.log('----()-----', array, array.length, array[array.length - 1],array[array.length - 1].length)
if (array.length > 1 && array[array.length - 1].length >= 2) { // bottomText超过两个小数点不处理
return
}
var text = this.bottomText + item
if (this.topText) {
let numList = ['7', '8', '9', '4', '5', '6', '1', '2', '3', '0', '.'];
let lastT = this.topText.slice(-1);
if (numList.includes(lastT)) {
var arr = this.topText.split(' ')
var a = arr[arr.length - 1].split('.')
if (a.length > 1 && a[a.length - 1].length + this.bottomText.length >= 2) { // topText和bottomText超过两个小数点不处理
return
}
this.bottomText = text
text = String(this.topText) + String(this.bottomText)
} else {
this.bottomText = text
text = this.topText + ' ' + this.bottomText
}
} else {
this.bottomText = text
}
// else {
// this.showSure = true
// }
this.textChange(text)
},
// 0,00输入判断
numTapB(item) {
if (this.bottomText.length == 1 && this.bottomText == 0) {
return;
}
if (item == '00' && this.bottomText == '') {
return;
}
if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') {
this.bottomText = '';
}
this.bottomText += item;
this.textChange(this.bottomText)
},
// numTapB(item) {
// if (this.bottomText.length == 1 && this.bottomText == 0) {
// return;
// }
// // if (item == '00' && this.bottomText == '') {
// // return;
// // }
// if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') {
// this.bottomText = '';
// }
// this.bottomText += item;
// this.textChange(this.bottomText)
// },
// .输入判断
numTapC() {
// this.showSure = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment