Commit e4d9cb82 authored by Facius's avatar Facius

feat: 计算器修改

parent aa0f436a
Pipeline #2757 canceled with stages
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<!-- 小程序使用请改成 :key="ix" --> <!-- 小程序使用请改成 :key="ix" -->
<view class="calculator-button-left-aview dot-view" v-for="(item, ix) in calculatorButBList" :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-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> <text class="calculator-button-left-a1">{{ item }}</text>
</view> </view>
</view> </view>
...@@ -78,8 +78,9 @@ export default { ...@@ -78,8 +78,9 @@ export default {
}, },
methods: { methods: {
handleClickSure() { handleClickSure() {
console.log('-----sure-----', this.sureText) var text = (Math.trunc(this.sureText * 100) / 100).toFixed(2)
this.$emit('sure', this.sureText); console.log('-----sure-----', this.sureText, text)
this.$emit('sure', text);
}, },
textChange(text) { textChange(text) {
console.log('top:', '|'+this.topText+'|') console.log('top:', '|'+this.topText+'|')
...@@ -134,43 +135,63 @@ export default { ...@@ -134,43 +135,63 @@ export default {
// 1-9输入判断 // 1-9输入判断
numTapA(item) { numTapA(item) {
// this.showSure = false // this.showSure = false
if (this.bottomText.length == 1 && this.bottomText == 0 && !this.topText && item == 0) {
if (this.bottomText.length == 1 && this.bottomText == 0) {
return; return;
} }
if (this.bottomText.length == 1 && this.bottomText == 0 && !this.topText) {
this.bottomText = '';
}
if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') { if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') {
this.bottomText = ''; this.bottomText = '';
} }
this.bottomText += item; var array = this.bottomText.split('.')
var text = this.bottomText 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) { if (this.topText) {
let numList = ['7', '8', '9', '4', '5', '6', '1', '2', '3', '0', '.']; let numList = ['7', '8', '9', '4', '5', '6', '1', '2', '3', '0', '.'];
let lastT = this.topText.slice(-1); let lastT = this.topText.slice(-1);
if (numList.includes(lastT)) { 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) text = String(this.topText) + String(this.bottomText)
} else { } else {
this.bottomText = text
text = this.topText + ' ' + this.bottomText text = this.topText + ' ' + this.bottomText
} }
} else {
this.bottomText = text
} }
// else { // else {
// this.showSure = true // this.showSure = true
// } // }
this.textChange(text) this.textChange(text)
}, },
// 0,00输入判断 // 0,00输入判断
numTapB(item) { // numTapB(item) {
if (this.bottomText.length == 1 && this.bottomText == 0) { // if (this.bottomText.length == 1 && this.bottomText == 0) {
return; // return;
} // }
if (item == '00' && this.bottomText == '') { // // if (item == '00' && this.bottomText == '') {
return; // // return;
} // // }
if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') { // if (this.bottomText == 'Infinity' || this.bottomText == 'NaN') {
this.bottomText = ''; // this.bottomText = '';
} // }
this.bottomText += item;
this.textChange(this.bottomText) // this.bottomText += item;
}, // this.textChange(this.bottomText)
// },
// .输入判断 // .输入判断
numTapC() { numTapC() {
// this.showSure = false // 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