base64.vue 1.6 KB
Newer Older
B
baiy 已提交
1
<template>
B
baiy 已提交
2 3 4
    <div>
        <Input v-model="current.input" :rows="7" type="textarea" placeholder="内容"></Input>
        <option-block>
B
baiy 已提交
5 6
            <FormItem>
                <ButtonGroup>
B
baiy 已提交
7 8
                    <Button type="primary" @click="handle('encode')">编码</Button>
                    <Button type="primary" @click="handle('decode')">解密</Button>
B
baiy 已提交
9 10
                </ButtonGroup>
            </FormItem>
B
baiy 已提交
11
            <FormItem>
B
baiy 已提交
12
                <Checkbox v-model="current.isUriSafe">Url Safe</Checkbox>
B
baiy 已提交
13
            </FormItem>
B
baiy 已提交
14
        </option-block>
B
baiy 已提交
15 16
        <Input v-model="current.output" :rows="7" type="textarea" placeholder="结果"></Input>
    </div>
B
baiy 已提交
17 18
</template>
<script>
B
baiy 已提交
19 20
import { Base64 } from 'js-base64'

B
baiy 已提交
21
export default {
B
baiy 已提交
22 23
    created () {
        this.current = Object.assign(this.current, this.$getToolData('input'))
B
baiy 已提交
24 25
    },
    methods: {
B
baiy 已提交
26
        handle (v) {
B
baiy 已提交
27
            if (this.current.input) {
B
baiy 已提交
28 29 30 31 32
                if (v === "encode"){
                    this.current.output = Base64.encode(this.current.input,this.current.isUriSafe)
                }
                else{
                    this.current.output = Base64.decode(this.current.input)
B
baiy 已提交
33
                }
B
baiy 已提交
34
                this.current.operation = v
B
baiy 已提交
35
                this.$clipboardCopy(this.current.output)
B
baiy 已提交
36
                this.$saveToolData(this.current)
B
baiy 已提交
37 38
            }
        },
B
baiy 已提交
39
    },
B
baiy 已提交
40
    data () {
B
baiy 已提交
41 42 43 44 45 46 47 48 49 50
        return {
            current: {
                input: '',
                output: '',
                operation: '',
                isUriSafe: false,
            },
        }
    },
}
B
baiy 已提交
51
</script>