text.vue 12.7 KB
Newer Older
B
baiy 已提交
1 2
<template>
    <div>
B
baiy 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
        <input-block right="15px" bottom="10px">
            <heightResize :append="['.page-option-block']">
                <autoHeightTextarea  v-model="current.content" :placeholder="$t('text_input')"></autoHeightTextarea>
            </heightResize>
            <template slot="extra">
                <Button type="dashed" @click="statShow = true" size="small">
                    {{ $t('text_stat_show',[stat.word_length,stat.byte_utf8_length,stat.byte_gbk_length]) }}
                    <Icon type="ios-more" />
                </Button>
            </template>
        </input-block>
        <option-block class="page-option-block">
            <FormItem v-if="current.original.length > 0">
                <Button type="default" :size="buttonSize"
                        @click="[current.content,current.original]=[current.original,current.content]">
                    {{ $t('text_resume') }}
                </Button>
            </FormItem>
            <FormItem>
                <Dropdown @on-click="(item)=>handle(item)" transfer>
                    <Button :size="buttonSize" type="primary">
                        {{ $t('text_case_conversion') }}
                        <Icon type="ios-arrow-down"></Icon>
B
baiy 已提交
26
                    </Button>
B
baiy 已提交
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
                    <DropdownMenu slot="list">
                        <DropdownItem name="upper">{{ $t('text_upper_all') }}</DropdownItem>
                        <DropdownItem name="lower">{{ $t('text_lower_all') }}</DropdownItem>
                        <DropdownItem name="upperLineStart">{{ $t('text_upper_line_start') }}</DropdownItem>
                        <DropdownItem name="lowerLineStart">{{ $t('text_lower_line_start') }}</DropdownItem>
                        <DropdownItem name="upperStart">{{ $t('text_upper_word_start') }}</DropdownItem>
                        <DropdownItem name="lowerStart">{{ $t('text_lower_word_start') }}</DropdownItem>
                    </DropdownMenu>
                </Dropdown>
            </FormItem>
            <FormItem>
                <Dropdown @on-click="(item)=>handle('replacePunctuation',item)" transfer>
                    <Button :size="buttonSize" type="primary">
                        {{ $t('text_punctuation') }}
                        <Icon type="ios-arrow-down"></Icon>
                    </Button>
                    <DropdownMenu slot="list">
                        <DropdownItem name="en">{{ $t('text_cn') }} -> {{ $t('text_en') }}</DropdownItem>
                        <DropdownItem name="zh">{{ $t('text_en') }} -> {{ $t('text_cn') }}</DropdownItem>
                    </DropdownMenu>
                </Dropdown>
            </FormItem>
            <FormItem>
                <Dropdown @on-click="(item)=>handle('zhTran',item)" transfer>
                    <Button :size="buttonSize" type="primary">
                        {{ $t('text_simplified_traditional') }}
                        <Icon type="ios-arrow-down"></Icon>
                    </Button>
                    <DropdownMenu slot="list">
                        <DropdownItem name="simplified">{{ $t('text_simplified') }} -> {{ $t('text_traditional') }}</DropdownItem>
                        <DropdownItem name="traditional">{{ $t('text_traditional') }} -> {{ $t('text_simplified') }}</DropdownItem>
                    </DropdownMenu>
                </Dropdown>
            </FormItem>
            <FormItem>
                <Button :size="buttonSize" type="primary" @click="replace.show = true">{{ $t('text_replace') }}</Button>
            </FormItem>
            <FormItem>
                <Button :size="buttonSize" type="primary" @click="handle('lineRemoveRepeat')">
                    {{ $t('text_line_remove_duplicate') }}
                </Button>
            </FormItem>
            <FormItem>
                <Dropdown @on-click="(item)=>handle(item)" transfer>
                    <Button :size="buttonSize" type="primary">
                        {{ $t('text_line_number') }}
                        <Icon type="ios-arrow-down"></Icon>
                    </Button>
                    <DropdownMenu slot="list">
                        <DropdownItem name="addLineIndex">{{ $t('text_line_number_add') }}</DropdownItem>
                        <DropdownItem name="removeLineIndex">{{ $t('text_line_number_remove') }}</DropdownItem>
                    </DropdownMenu>
                </Dropdown>
            </FormItem>
            <FormItem>
                <Dropdown @on-click="(item)=>handle('lineSort',item)" transfer>
                    <Button :size="buttonSize" type="primary">
                        {{ $t('text_line_sort') }}
                        <Icon type="ios-arrow-down"></Icon>
                    </Button>
                    <DropdownMenu slot="list">
                        <DropdownItem name="asc">{{ $t('text_line_sort_asc') }}</DropdownItem>
                        <DropdownItem name="desc">{{ $t('text_line_sort_desc') }}</DropdownItem>
                    </DropdownMenu>
                </Dropdown>
            </FormItem>
            <FormItem>
                <Dropdown @on-click="(item)=>handle(item)" transfer>
                    <Button :size="buttonSize" type="primary">
                        {{ $t('text_filter') }}
                        <Icon type="ios-arrow-down"></Icon>
                    </Button>
                    <DropdownMenu slot="list">
                        <DropdownItem name="lineTrim">{{ $t('text_filter_trim') }}</DropdownItem>
                        <DropdownItem name="filterBlankLine">{{ $t('text_filter_blank_line') }}</DropdownItem>
                        <DropdownItem name="filterAllBr">{{ $t('text_filter_all_br') }}</DropdownItem>
                    </DropdownMenu>
                </Dropdown>
            </FormItem>
P
pc-ls 已提交
106 107 108 109 110 111
            <FormItem>
                <Button :size="buttonSize" type="primary" @click="handleStringEscape()">
                    {{ $t('stringEscape') }}
                    <!-- <Icon type="ios-arrow-down"></Icon> -->
                </Button>
            </FormItem>
B
baiy 已提交
112 113 114 115 116 117 118 119 120 121
        </option-block>
        <Modal v-model="statShow" :styles="{top: '20px'}" width="700" footer-hide>
            <Tabs value="stat">
                <TabPane :label="$t('text_stat')" name="stat">
                    <Table :columns="statColumns" stripe border size="small" :data="statTable" />
                </TabPane>
                <TabPane :label="$t('text_stat_explain')" name="explain">
                    <Table :columns="statExplain.columns" border stripe size="small" :data="statExplain.data"/>
                </TabPane>
            </Tabs>
B
baiy 已提交
122
        </Modal>
B
baiy 已提交
123
        <Modal v-model="replace.show" width="600" :title="$t('text_replace')">
B
baiy 已提交
124 125 126
            <Form label-position="top">
                <Row :gutter="16">
                    <Col span="12">
B
baiy 已提交
127 128 129 130 131 132 133 134
                        <FormItem :label="$t('text_replace_search')">
                            <input-block>
                                <Input v-model="replace.search" :rows="6" type="textarea"></Input>
                                <template slot="extra">
                                    <Checkbox v-model="replace.regular">{{ $t('text_replace_regular') }}
                                    </Checkbox>
                                </template>
                            </input-block>
B
baiy 已提交
135 136 137
                        </FormItem>
                    </Col>
                    <Col span="12">
B
baiy 已提交
138
                        <FormItem :label="$t('text_replace_replace')">
B
baiy 已提交
139 140 141 142 143
                            <Input v-model="replace.replace" :rows="6" type="textarea"></Input>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
B
baiy 已提交
144
            <Alert v-if="!replace.regular">{{ $t('text_replace_explain') }}</Alert>
B
baiy 已提交
145
            <div slot="footer">
B
baiy 已提交
146 147
                <Button type="text" @click="replace.show = false">{{ $t('text_cancel') }}</Button>
                <Button type="primary" @click="replaceRun()">{{ $t('text_submit') }}</Button>
B
baiy 已提交
148 149 150 151 152 153
            </div>
        </Modal>
    </div>
</template>
<script>
import TextHandle from './library/text'
B
baiy 已提交
154 155
import autoHeightTextarea from "./components/autoHeightTextarea";
import heightResize from "./components/heightResize";
B
baiy 已提交
156 157

export default {
B
baiy 已提交
158 159 160 161
    components:{
        autoHeightTextarea,
        heightResize
    },
B
baiy 已提交
162
    created() {
B
baiy 已提交
163
        this.$initToolData('content')
B
baiy 已提交
164 165
    },
    computed: {
B
baiy 已提交
166 167 168 169
        stat(){
            return TextHandle(this.current.content).stat()
        },
        statTable() {
B
baiy 已提交
170 171
            let stat = TextHandle(this.current.content).stat();
            return [
B
baiy 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
                {
                    name1: this.$t('text_string_length'), value1: stat.string_length,
                    name2: this.$t('text_byte_length'), value2: `${stat.byte_utf8_length} / ${stat.byte_gbk_length}`
                },
                {
                    name1: this.$t('text_word_length'), value1: stat.word_length,
                    name2: this.$t('text_line_length'), value2: stat.line_length
                },
                {
                    name1: this.$t('text_zh_length'), value1: `${stat.zh_word} / ${stat.zh_punctuation}`,
                    name2: this.$t('text_en_length'), value2: `${stat.en_string} / ${stat.en_word} / ${stat.en_punctuation}`
                },
                {
                    name1: this.$t('text_int_length'), value1: `${stat.int_string} / ${stat.int_word}`,
                    name2: '-', value2: '-'
                },
B
baiy 已提交
188 189 190 191 192 193 194 195 196 197
            ]
        }
    },
    methods: {
        handle(method, ...parameter) {
            try {
                let result = TextHandle(this.current.content)[method](...parameter)
                this.current.original = this.current.content;
                this.current.content = result;
                this.$saveToolData(this.current);
B
baiy 已提交
198
                this.$Message.success(this.$t('text_ok').toString())
B
baiy 已提交
199
            } catch (e) {
B
baiy 已提交
200
                this.$Message.error(this.$t('text_error',[e.message]).toString())
B
baiy 已提交
201 202 203
            }
        },
        replaceRun() {
B
baiy 已提交
204 205 206 207 208 209
            if (this.replace.regular){
                this.handle('regularReplace', this.replace.search, this.replace.replace)
            }
            else{
                this.handle('replace', this.replace.search.split(/\r?\n/), this.replace.replace.split(/\r?\n/))
            }
B
baiy 已提交
210
            this.replace.show = false
P
pc-ls 已提交
211 212 213 214
        },
        handleStringEscape() {
            console.log(this.current.content);
            this.current.content = this.current.content.replace(/\\/g, `\\\\`);
B
baiy 已提交
215 216 217 218 219 220 221
        }
    },
    data() {
        return {
            replace: {
                show: false,
                search: "",
B
baiy 已提交
222 223
                replace: "",
                regular: false
B
baiy 已提交
224 225 226 227 228
            },
            current: {
                content: "",
                original: "",
            },
B
baiy 已提交
229
            statShow:false,
B
baiy 已提交
230 231 232
            statExplain: {
                columns: [
                    {
B
baiy 已提交
233
                        title: this.$t('text_item'),
B
baiy 已提交
234
                        key: 'name',
B
baiy 已提交
235
                        width: 200
B
baiy 已提交
236 237
                    },
                    {
B
baiy 已提交
238
                        title: this.$t('text_explain'),
B
baiy 已提交
239 240 241 242
                        key: 'explain',
                    },
                ],
                data: [
B
baiy 已提交
243 244 245 246 247 248 249
                    {name: this.$t('text_explain_byte_length_utf8_name'), explain: this.$t('text_explain_byte_length_utf8_info')},
                    {name: this.$t('text_explain_byte_length_gbk_name'), explain: this.$t('text_explain_byte_length_gbk_info')},
                    {name: this.$t('text_explain_string_length_name'), explain: this.$t('text_explain_string_length_info')},
                    {name: this.$t('text_explain_word_length_name'), explain: this.$t('text_explain_word_length_info')},
                    {name: this.$t('text_explain_int_length_name'), explain: this.$t('text_explain_int_length_info')},
                    {name: this.$t('text_explain_int_word_length_name'), explain: this.$t('text_explain_int_word_length_info')},
                    {name: this.$t('text_explain_blank_line_length_name'), explain: this.$t('text_explain_blank_line_length_info')},
B
baiy 已提交
250 251 252 253
                ]
            },
            statColumns: [
                {
B
baiy 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266
                    title: this.$t('text_item'),
                    key: 'name1',
                    width: 200
                },
                {
                    title: this.$t('text_value'),
                    key: 'value1',
                    align: "right"
                },
                {
                    title: this.$t('text_item'),
                    key: 'name2',
                    width: 200
B
baiy 已提交
267 268
                },
                {
B
baiy 已提交
269 270
                    title: this.$t('text_value'),
                    key: 'value2',
B
baiy 已提交
271 272 273 274 275 276 277 278 279
                    align: "right"
                },
            ],
            buttonSize: "small",
        }
    },
}
</script>
<style>
B
baiy 已提交
280
.ctool-stat-block .ivu-modal-body {
B
baiy 已提交
281 282
    padding: 0;
}
B
baiy 已提交
283
</style>