闫增涛
2024-07-04 1a6896dd660024b4ca2605a809f0f285f19929f0
计算器插件
1个文件已修改
1个文件已添加
252 ■■■■■ 已修改文件
src/views/components/calculator.vue 247 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/readerPages/webHome.vue 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/components/calculator.vue
New file
@@ -0,0 +1,247 @@
<template>
  <div class="calculator">
    <button @click="changeModeEvent" class="toggle-button">
      <p v-if="changeMode">基础计算器 &nbsp; &nbsp; &#9864;</p>
      <p v-else>科学计算器 &nbsp; &nbsp; &#9862;</p>
    </button>
    <div class="results">
      <input class="input" v-model="current" />
    </div>
    <div class="mode" v-if="changeMode">
      <button class="button" @click="press">7</button>
      <button class="button" @click="press">8</button>
      <button class="button" @click="press">9</button>
      <button class="button" @click="press">*</button>
      <button class="button" @click="press">&#60;=</button>
      <button class="button" @click="press">C</button>
      <button class="button" @click="press">4</button>
      <button class="button" @click="press($event)">5</button>
      <button class="button" @click="press">6</button>
      <button class="button" @click="press">/</button>
      <button class="button" @click="press">(</button>
      <button class="button" @click="press">)</button>
      <button class="button" @click="press">1</button>
      <button class="button" @click="press">2</button>
      <button class="button" @click="press">3</button>
      <button class="button" @click="press">-</button>
      <button class="button" @click="press">x ²</button>
      <button class="button" @click="press">±</button>
      <button class="button" @click="press">0</button>
      <button class="button" @click="press">.</button>
      <button class="button" @click="press">%</button>
      <button class="button" @click="press">+</button>
      <button class="button equal-sign" @click="press">=</button>
    </div>
    <div class="mode" v-else>
      <button class="button" @click="press">sin</button>
      <button class="button" @click="press">cos</button>
      <button class="button" @click="press">tan</button>
      <button class="button" @click="press">x^</button>
      <button class="button" @click="press">&#60;=</button>
      <button class="button" @click="press">C</button>
      <button class="button" @click="press">log</button>
      <button class="button" @click="press">ln</button>
      <button class="button" @click="press">e</button>
      <button class="button" @click="press">∘</button>
      <button class="button" @click="press">rad</button>
      <button class="button" @click="press">√</button>
      <button class="button" @click="press">7</button>
      <button class="button" @click="press">8</button>
      <button class="button" @click="press">9</button>
      <button class="button" @click="press">/</button>
      <button class="button" @click="press">x ²</button>
      <button class="button" @click="press">x !</button>
      <button class="button" @click="press">4</button>
      <button class="button" @click="press">5</button>
      <button class="button" @click="press">6</button>
      <button class="button" @click="press">*</button>
      <button class="button" @click="press">(</button>
      <button class="button" @click="press">)</button>
      <button class="button" @click="press">1</button>
      <button class="button" @click="press">2</button>
      <button class="button" @click="press">3</button>
      <button class="button" @click="press">-</button>
      <button class="button" @click="press">%</button>
      <button class="button" @click="press">±</button>
      <button class="button" @click="press">0</button>
      <button class="button" @click="press">.</button>
      <button class="button" @click="press">&#x003C0;</button>
      <button class="button" @click="press">+</button>
      <button class="button equal-sign" @click="press">=</button>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const current = ref<any>('')
const changeMode = ref(true)
const press = (event) => {
  var key = event.target.textContent
  if (
    key != '=' &&
    key != 'C' &&
    key != '*' &&
    key != '/' &&
    key != '√' &&
    key != 'x ²' &&
    key != '%' &&
    key != '<=' &&
    key != '±' &&
    key != 'sin' &&
    key != 'cos' &&
    key != 'tan' &&
    key != 'log' &&
    key != 'ln' &&
    key != 'x^' &&
    key != 'x !' &&
    key != 'π' &&
    key != 'e' &&
    key != 'rad' &&
    key != '∘'
  ) {
    current.value += key
  } else if (key === '=') {
    if (current.value.indexOf('^') > -1) {
      var base = current.value.slice(0, current.value.indexOf('^'))
      var exponent = current.value.slice(current.value.indexOf('^') + 1)
      current.value = eval('Math.pow(' + base + ',' + exponent + ')')
    } else {
      current.value = eval(current.value)
    }
  } else if (key === 'C') {
    current.value = ''
  } else if (key === '*') {
    current.value += '*'
  } else if (key === '/') {
    current.value += '/'
  } else if (key === '+') {
    current.value += '+'
  } else if (key === '-') {
    current.value += '-'
  } else if (key === '±') {
    if (current.value.charAt(0) === '-') {
      current.value = current.value.slice(1)
    } else {
      current.value = '-' + current.value
    }
  } else if (key === '<=') {
    current.value = current.value.substring(0, current.value.length - 1)
  } else if (key === '%') {
    current.value = current.value / 100
  } else if (key === 'π') {
    current.value = current.value * Math.PI
  } else if (key === 'x ²') {
    current.value = eval(current.value * current.value)
  } else if (key === '√') {
    current.value = Math.sqrt(current.value)
  } else if (key === 'sin') {
    current.value = Math.sin(current.value)
  } else if (key === 'cos') {
    current.value = Math.cos(current.value)
  } else if (key === 'tan') {
    current.value = Math.tan(current.value)
  } else if (key === 'log') {
    current.value = Math.log10(current.value)
  } else if (key === 'ln') {
    current.value = Math.log(current.value)
  } else if (key === 'x^') {
    current.value += '^'
  } else if (key === 'x !') {
    var number = 1
    if (current.value === 0) {
      current.value = '1'
    } else if (current.value < 0) {
      current.value = NaN
    } else {
      var _number = 1
      for (var i = current.value; i > 0; i--) {
        _number *= i
      }
      current.value = _number
    }
  } else if (key === 'e') {
    current.value = Math.exp(current.value)
  } else if (key === 'rad') {
    current.value = current.value * (Math.PI / 180)
  } else if (key === '∘') {
    current.value = current.value * (180 / Math.PI)
  }
}
const changeModeEvent = () => {
  changeMode.value = !changeMode.value
}
</script>
<style lang="less" scoped>
.calculator {
  width: 440px;
  padding: 20px;
  border-radius: 5px;
  margin: 20px auto;
  font-size: 16px;
  background-color: #333333;
}
.input {
  width: 420px;
  height: 50px;
  border-radius: 0px;
  border: 1px solid black;
  background-color: #333333;
  color: #d9d9d9;
  padding: 0 5px 0 5px;
  margin: 0 0px 10px 0px;
  font-size: 30px;
}
.input:focus,
.input:active {
  border-color: #03a9f4;
  box-shadow: 0 0 4px #03A9F4;
  outline: none 0;
}
.button {
  margin: 3px;
  width: 63px;
  border: 1px solid #0d0d0d;
  height: 30px;
  border-radius: 4px;
  color: #d9d9d9;
  background-color: #1a1a1a;
  cursor: pointer;
  outline: none;
}
.mode {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
}
.equal-sign {
  background-color: green;
  width: 133px;
}
.toggle-button {
  border: none;
  background-color: #333333;
  cursor: pointer;
  outline: none;
  font-size: 1rem;
  color: #fff;
  text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.35);
  margin-bottom: 10px;
}
p {
  margin-top: 0;
}
button::-moz-focus-inner {
  border-color: transparent;
}
</style>
src/views/readerPages/webHome.vue
@@ -1247,8 +1247,8 @@
    :infoType="examinationData.infoType"
  />
  <!-- 计算器 -->
   <el-dialog title="计算器" align-center v-model="calculatorVisble" width="40%">
   <el-dialog title="计算器" align-center v-model="calculatorVisble" width="550" style="height:548px">
    <calculator />
   </el-dialog>
</template>
@@ -1259,6 +1259,7 @@
import { useRouter, useRoute } from 'vue-router'
import useClipboard from 'vue-clipboard3'
import examination from '../examination/index.vue'
import calculator from '../components/calculator.vue'
const { toClipboard } = useClipboard()
const MG: any = inject('MG')
const toolClass = inject('toolClass')