<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<script type="module" src="./main.js"></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
index.html
global.css
main.js
App.vue
HelloBicool.vue
package.json
现在支持上传本地图片了!
body {
background-color: #fefefe;
}
import { createApp } from 'vue'
import './global.css'
import App from './App.vue'
createApp(App).mount('#app')
<script setup>
import HelloBicool from './HelloBicool.vue'
import { ref } from "vue"
</script>
<template>
<div class="container">
<HelloBicool />
</div>
</template>
<style lang="scss" scoped>
$bg: #f0f2f5;
.container {
background: $bg;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.logo {
height: 40px;
width: 40px;
margin-top: 20px;
}
</style>
<script setup>
import { ref, computed } from 'vue'
// 文本
const txtStr = ref('')
// 十六进制
const hexVal = ref('')
// 通过文本自动计算十六进制的方法
function changeStrToHex(str) {
const arr = str?.split('')
const mapArr = arr?.map(item => {
// 获取当前项的 askII码
const askIICode = item.charCodeAt(0)
// 转为16进制并且转为大写
return askIICode.toString(16)?.toUpperCase()
})
return mapArr?.join(' ')
}
// 通过十六进制自动计算文本的方法
function changeHexToStr(hex) {
const arr = hex?.replace(/\s/g, '')?.match(/.{2}/g)
const mapArr = arr?.map(item => {
// 16进制转10进制
const naturalNum = parseInt(item, 16)
// 10进制转为askII码
return String.fromCharCode(naturalNum)
})
return mapArr?.join('')
}
const result = computed(() => {
let val = hexVal.value?.replace(/[^\dABCDEFabcdef]/g, '')
const group = val?.match(/.{2}/g)
const group16 = group?.map(item => `0X${item}`)
const res = group16?.reduce((acc, cur) => {
return `${acc}` ^ `${cur}`
})
let xor = res?.toString(16)?.toUpperCase()
console.log(xor)
if (xor?.startsWith('0X')) {
xor = xor.slice(2)
}
return xor
})
// 文本输入的 input 事件
function txtInput() {
hexVal.value = changeStrToHex(txtStr.value)
}
// 十六进制输入的 input 事件
function hexInput() {
txtStr.value = changeHexToStr(hexVal.value)
}
</script>
<template>
<p>请输入文本:</p>
<textarea
tabIndex="0"
spellcheck="false"
v-model="txtStr"
placeholder="请输入文本"
@input="txtInput"
/>
<br />
<p>请输入十六进制数:</p>
<textarea
tabIndex="1"
spellcheck="false"
v-model="hexVal"
placeholder="十六进制,不区分大小写"
@input="hexInput"
/>
<br />
Xor结果:{{ result }}
</template>
<style lang="scss" scoped>
h1 {
color: #333;
text-align: center;
}
textarea {
height: 90px;
line-height: 30px;
max-width: 500px;
width: 90%;
outline: none;
padding: 5px 10px;
font-family: "微软雅黑"
}
p {
color: #666;
text-align: center;
}
</style>
{
"dependencies": {
"vue": "3.5.13"
}
}
预览