-
Notifications
You must be signed in to change notification settings - Fork 702
/
Copy pathencoding.vue
71 lines (69 loc) · 2.09 KB
/
encoding.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
<div class="encoding">
<nya-container title="文本在线编码解码">
<nya-input v-model="content" class="mb-15" fullwidth rows="5" type="textarea" autofocus autocomplete="off" label="待处理的内容" placeholder="请输入要处理的内容" />
<br>
<nya-select v-model="encodingType" class="mb-15" fullwidth :items="list" label="选择编码方式" />
<br>
<button
type="button"
class="nya-btn mr-15"
@click="encoding"
>
编码
</button>
<button
type="button"
class="nya-btn mr-15"
@click="decoding"
>
解码
</button>
</nya-container>
<nya-container v-show="result" title="转换成功">
<pre>{{ result }}</pre>
</nya-container>
</div>
</template>
<script>
import coreValuesEncoder from '~/utils/core-values-encoder.js';
export default {
name: 'Crypto',
head() {
return this.$store.state.currentTool.head;
},
data() {
return {
list: {
Base64: 'Base64',
coreValuesEncoder: '社会主义核心价值观'
},
encodingType: 'Base64', //加密方式
content: '', //要处理的内容
result: '' //输出的结果
};
},
methods: {
encoding() {
this.result = this[this.encodingType](true);
},
decoding() {
this.result = this[this.encodingType](false);
},
Base64(type) {
if (type) {
return Buffer.from(this.content).toString('base64');
} else {
return Buffer.from(this.content, 'base64').toString();
}
},
coreValuesEncoder(type) {
if (type) {
return coreValuesEncoder.encode(this.content);
} else {
return coreValuesEncoder.decode(this.content);
}
}
}
};
</script>