提交 a851e776 编写于 作者: B baiy 提交者: ninecents

hash 优化

上级 36a955e1
<template>
<div style="position: relative;">
<slot></slot>
<div class="right-bottom">
<slot name="extra">
<Button v-if="text" type="primary" size="small" @click="buttonClick">{{ text }}</Button>
</slot>
</div>
</div>
</template>
<script>
export default {
name: 'inputBlock',
props: {
text: {
type: String,
default: ""
}
},
methods: {
buttonClick() {
this.$emit('on-default-right-bottom-click');
}
}
};
</script>
<style scoped>
.right-bottom {
position: absolute;
bottom: 4px;
right: 4px;
}
</style>
...@@ -3,6 +3,7 @@ import ViewUI from 'view-design' ...@@ -3,6 +3,7 @@ import ViewUI from 'view-design'
import './statics/theme.less' import './statics/theme.less'
import router from './tool.router' import router from './tool.router'
import optionBlock from './components/optionBlock' import optionBlock from './components/optionBlock'
import inputBlock from './components/inputBlock'
import {plugin as modelPlugin} from './tool/model' import {plugin as modelPlugin} from './tool/model'
import cache from './tool/cache' import cache from './tool/cache'
import setting from './tool/setting' import setting from './tool/setting'
...@@ -21,6 +22,7 @@ const run = () => { ...@@ -21,6 +22,7 @@ const run = () => {
Vue.use(ViewUI) Vue.use(ViewUI)
Vue.use(modelPlugin) Vue.use(modelPlugin)
Vue.component('option-block', optionBlock); Vue.component('option-block', optionBlock);
Vue.component('input-block', inputBlock);
new Vue({ new Vue({
i18n, i18n,
......
...@@ -12,12 +12,10 @@ export const copy = (data,successCallback)=>{ ...@@ -12,12 +12,10 @@ export const copy = (data,successCallback)=>{
} }
export const paste = ()=>{ export const paste = ()=>{
document.querySelector( document.querySelector('#clipboard').innerHTML = '<textarea id="clipboard-text"></textarea>'
'#clipboard').innerHTML = '<textarea id="clipboard-text"></textarea>'
document.querySelector('#clipboard-text').select() document.querySelector('#clipboard-text').select()
document.execCommand('paste') document.execCommand('paste')
let r = document.querySelector('#clipboard-text').value || let r = document.querySelector('#clipboard-text').value || document.querySelector('#clipboard-text').innerHTML
document.querySelector('#clipboard-text').innerHTML
document.querySelector('#clipboard').innerHTML = '' document.querySelector('#clipboard').innerHTML = ''
return r ? r : '' return r ? r : ''
} }
......
<template> <template>
<div> <div id="tool-hash">
<Input v-model="current.input" :rows="7" type="textarea" placeholder="内容"></Input> <Row :gutter="10">
<option-block> <Col span="8">
<FormItem> <input-block text="内容">
<ButtonGroup> <Input v-model="current.input" :rows="18" type="textarea" placeholder="内容"></Input>
<Button type="primary" @click="handle(v)" v-for="v in type" :key="v">{{ v }}</Button> <Checkbox slot="extra" v-model="current.isUppercase">大写字母</Checkbox>
</ButtonGroup> </input-block>
</FormItem> </Col>
<FormItem> <Col span="16">
<Checkbox v-model="current.isUppercase">大写字母</Checkbox> <input-block style="margin-bottom: 6px" :text="type" v-for="type in types" :key="type" @on-default-right-bottom-click="()=>copy(type)">
</FormItem> <Input :value="result(type)" :placeholder="type" :rows="3" type="textarea"></Input>
</option-block> </input-block>
<Input v-model="current.output" :rows="7" type="textarea" placeholder="结果"></Input> </Col>
</Row>
</div> </div>
</template> </template>
<script> <script>
import crypto from "crypto-js" import crypto from "crypto-js"
const sm = require('sm-crypto');
export default { export default {
created() { created() {
this.current = Object.assign(this.current, this.$getToolData("input")) this.current = Object.assign(this.current, this.$getToolData("input"))
}, },
methods: { computed: {
handle(v) { md5() {
if (this.current.input) { if (!this.current.input) {
switch (v) { return "";
case "md5": }
this.current.output = crypto.MD5(this.current.input).toString(); let result = crypto.MD5(this.current.input).toString();
break; return this.current.isUppercase ? result.toUpperCase() : result;
case "sha1": },
this.current.output = crypto.SHA1(this.current.input).toString(); sha1() {
break; if (!this.current.input) {
case "sha256": return "";
this.current.output = crypto.SHA256(this.current.input).toString(); }
break; let result = crypto.SHA1(this.current.input).toString();
case "sha512": return this.current.isUppercase ? result.toUpperCase() : result;
this.current.output = crypto.SHA512(this.current.input).toString(); },
break; sha256() {
case "sm3": if (!this.current.input) {
this.current.output = require('sm-crypto').sm3(this.current.input); return "";
break; }
default: let result = crypto.SHA256(this.current.input).toString();
return; return this.current.isUppercase ? result.toUpperCase() : result;
} },
if (this.current.isUppercase) { sha512() {
this.current.output = this.current.output.toUpperCase() if (!this.current.input) {
} return "";
this.current.operation = v; }
this.$clipboardCopy(this.current.output); let result = crypto.SHA512(this.current.input).toString();
return this.current.isUppercase ? result.toUpperCase() : result;
},
sm3() {
if (!this.current.input) {
return "";
}
let result = sm.sm3(this.current.input);
return this.current.isUppercase ? result.toUpperCase() : result;
},
},
watch: {
current: {
handler() {
this.$saveToolData(this.current); this.$saveToolData(this.current);
},
deep: true
}
},
methods:{
result(type){
return this[type]
},
copy(type){
if (this[type]){
this.$clipboardCopy(this[type])
} }
} }
}, },
...@@ -57,11 +83,9 @@ export default { ...@@ -57,11 +83,9 @@ export default {
current: { current: {
input: "", input: "",
isUppercase: false, isUppercase: false,
output: "",
operation: ""
}, },
type: ['md5', 'sha1', 'sha256', 'sha512', "sm3"] types: ['md5', 'sha1', 'sha256', 'sha512', "sm3"]
} }
}, },
} }
</script> </script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册