hexConvert.vue 3.8 KB
Newer Older
1 2 3 4 5 6
<template>
    <heightResize ignore :append="['.page-option-block']" @resize="resize">
        <autoHeightTextarea v-model="current.input" :height="inputHeight" :placeholder="$t('hexString_input')"/>
        <option-block class="page-option-block">
            <FormItem>
                <ButtonGroup>
P
pc-ls 已提交
7
                    <Button type="primary" @click="handle()">{{ $t('allMy_convert') }}</Button>
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
                    <!-- <Button type="primary" @click="handle('str')">Hex -> String</Button> -->
                </ButtonGroup>
            </FormItem>
            <FormItem>
                <Checkbox v-model="current.isUppercase">{{ $t('hexString_uppercase') }}</Checkbox>
            </FormItem>
        </option-block>
        <span>美化的内容&nbsp;&nbsp;&nbsp;&nbsp;</span><input class="input_width_100" type="text" v-model="current.output_beautiful">
        <br>
        <span>字符串格式&nbsp;&nbsp;&nbsp;&nbsp;</span><input class="input_width_100" type="text" v-model="current.output_str">
        <br>
        <span>字节数组格式:</span><input class="input_width_100" type="text" v-model="current.output_bytes">
        <autoHeightTextarea :value="current.output" :height="outputHeight" :placeholder="$t('hexString_output')"/>
    </heightResize>
</template>
<script>
import heightResize from "../tool/components/heightResize";
import autoHeightTextarea from "../tool/components/autoHeightTextarea";

export default {
    components: {
        heightResize,
        autoHeightTextarea
    },
    created() {
        this.$initToolData('input')
    },
    methods: {
        handle() {
            console.log('enter...')
            var bytes = ''
            if (this.current.input) {
                var lines = this.current.input.split('\n');
                lines.forEach(line => {
                    console.log(line)
                    var items = line.split('|')
                    if (items.length != 4) {
                        return
                    }

                    bytes += items[1]
                    // items.forEach(item => {
                    //     console.log(item)
                    // })
                })
            }
            console.log('leave...', bytes)
            this.current.output = bytes

            // 
            this.current.output_beautiful = bytes.replaceAll(':', '').replaceAll(' ', '')
            if (this.current.output_beautiful.length % 2 == 1) {
                alert('数据有误,请检查后再尝试')
                return;
            }

            var lst = []
            for (var i = 0; i < this.current.output_beautiful.length / 2; ++i) {
                lst.push(this.current.output_beautiful.slice(2*i, 2*i + 2))
            }
            this.current.output_str = ''
            lst.forEach(item => {
                this.current.output_str += '\\x' + item;
            })
            this.current.output_bytes = ''
            lst.forEach(item => {
                this.current.output_bytes += '0x' + item + ', ';
            })
        },
        resize(height) {
            this.inputHeight = Math.min(320, Math.ceil(height / 2))
            // this.outputHeight = height - this.inputHeight
            this.outputHeight = 180
        }
    },
    data() {
        return {
            current: {
                input: "",
                isUppercase: false,
                output_beautiful: "",       // 一行,全字节内容,美化的内容
                output_str: "",             // 字符串格式
                output_bytes: "",           // 字节数组格式
                output: "",
                operation: ""
            },
            inputHeight: 100,
            outputHeight: 100
        }
    },
}
</script>

<style scoped>
.input_width_100 {
    width: 80%;
    margin: 8px 0;
}
</style>