|
|
@ -6,9 +6,7 @@
|
|
|
|
<OperatorButton v-for="op in operators" :key="op.operator" :operator="op.operator" @click="appendOperator(op.operator)" />
|
|
|
|
<OperatorButton v-for="op in operators" :key="op.operator" :operator="op.operator" @click="appendOperator(op.operator)" />
|
|
|
|
<button @click="appendDecimal('.')">.</button>
|
|
|
|
<button @click="appendDecimal('.')">.</button>
|
|
|
|
<button @click="calculate">=</button>
|
|
|
|
<button @click="calculate">=</button>
|
|
|
|
<button @click="deleteLastChar">del</button>
|
|
|
|
|
|
|
|
<button class="ac-button" @click="clearDisplay">AC</button>
|
|
|
|
<button class="ac-button" @click="clearDisplay">AC</button>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
@ -31,8 +29,6 @@ const operators = [
|
|
|
|
{ operator: '%' },
|
|
|
|
{ operator: '%' },
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const appendNumber = (number) => {
|
|
|
|
const appendNumber = (number) => {
|
|
|
|
if (displayValue.value === '0' || displayValue.value === '表达式错误') {
|
|
|
|
if (displayValue.value === '0' || displayValue.value === '表达式错误') {
|
|
|
|
displayValue.value = number;
|
|
|
|
displayValue.value = number;
|
|
|
@ -51,16 +47,6 @@ const appendOperator = (op) => {
|
|
|
|
|
|
|
|
|
|
|
|
const calculate = () => {
|
|
|
|
const calculate = () => {
|
|
|
|
displayValue.value = eval(displayValue.value);
|
|
|
|
displayValue.value = eval(displayValue.value);
|
|
|
|
try {
|
|
|
|
|
|
|
|
const result = Function('"use strict"; return (' + displayValue.value + ')')();
|
|
|
|
|
|
|
|
if (!isFinite(result)) {
|
|
|
|
|
|
|
|
displayValue.value = '错误';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
displayValue.value = result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
displayValue.value = '错误';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const clearDisplay = () => {
|
|
|
|
const clearDisplay = () => {
|
|
|
@ -69,12 +55,6 @@ const clearDisplay = () => {
|
|
|
|
secondNumber.value = null;
|
|
|
|
secondNumber.value = null;
|
|
|
|
operator.value = null;
|
|
|
|
operator.value = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const deleteLastChar = () => {
|
|
|
|
|
|
|
|
if (displayValue.value.length > 0) {
|
|
|
|
|
|
|
|
displayValue.value = displayValue.value.slice(0, -1); // 删除最后一个字符
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
<style scoped>
|
|
|
|