text.vue 12.3 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 106 107 108 109 110 111 112 113 114 115
                    <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>
        </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 已提交
116
        </Modal>
B
baiy 已提交
117
        <Modal v-model="replace.show" width="400" :title="$t('text_replace')">
B
baiy 已提交
118 119 120
            <Form label-position="top">
                <Row :gutter="16">
                    <Col span="12">
B
baiy 已提交
121 122 123 124 125 126 127 128
                        <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 已提交
129 130 131
                        </FormItem>
                    </Col>
                    <Col span="12">
B
baiy 已提交
132
                        <FormItem :label="$t('text_replace_replace')">
B
baiy 已提交
133 134 135 136 137
                            <Input v-model="replace.replace" :rows="6" type="textarea"></Input>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
B
baiy 已提交
138
            <Alert v-if="!replace.regular">{{ $t('text_replace_explain') }}</Alert>
B
baiy 已提交
139
            <div slot="footer">
B
baiy 已提交
140 141
                <Button type="text" @click="replace.show = false">{{ $t('text_cancel') }}</Button>
                <Button type="primary" @click="replaceRun()">{{ $t('text_submit') }}</Button>
B
baiy 已提交
142 143 144 145 146 147
            </div>
        </Modal>
    </div>
</template>
<script>
import TextHandle from './library/text'
B
baiy 已提交
148 149
import autoHeightTextarea from "./components/autoHeightTextarea";
import heightResize from "./components/heightResize";
B
baiy 已提交
150 151

export default {
B
baiy 已提交
152 153 154 155
    components:{
        autoHeightTextarea,
        heightResize
    },
B
baiy 已提交
156
    created() {
B
baiy 已提交
157
        this.$initToolData('content')
B
baiy 已提交
158 159
    },
    computed: {
B
baiy 已提交
160 161 162 163
        stat(){
            return TextHandle(this.current.content).stat()
        },
        statTable() {
B
baiy 已提交
164 165
            let stat = TextHandle(this.current.content).stat();
            return [
B
baiy 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
                {
                    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 已提交
182 183 184 185 186 187 188 189 190 191
            ]
        }
    },
    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 已提交
192
                this.$Message.success(this.$t('text_ok').toString())
B
baiy 已提交
193
            } catch (e) {
B
baiy 已提交
194
                this.$Message.error(this.$t('text_error',[e.message]).toString())
B
baiy 已提交
195 196 197
            }
        },
        replaceRun() {
B
baiy 已提交
198 199 200 201 202 203
            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 已提交
204 205 206 207 208 209 210 211
            this.replace.show = false
        }
    },
    data() {
        return {
            replace: {
                show: false,
                search: "",
B
baiy 已提交
212 213
                replace: "",
                regular: false
B
baiy 已提交
214 215 216 217 218
            },
            current: {
                content: "",
                original: "",
            },
B
baiy 已提交
219
            statShow:false,
B
baiy 已提交
220 221 222
            statExplain: {
                columns: [
                    {
B
baiy 已提交
223
                        title: this.$t('text_item'),
B
baiy 已提交
224
                        key: 'name',
B
baiy 已提交
225
                        width: 200
B
baiy 已提交
226 227
                    },
                    {
B
baiy 已提交
228
                        title: this.$t('text_explain'),
B
baiy 已提交
229 230 231 232
                        key: 'explain',
                    },
                ],
                data: [
B
baiy 已提交
233 234 235 236 237 238 239
                    {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 已提交
240 241 242 243
                ]
            },
            statColumns: [
                {
B
baiy 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256
                    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 已提交
257 258
                },
                {
B
baiy 已提交
259 260
                    title: this.$t('text_value'),
                    key: 'value2',
B
baiy 已提交
261 262 263 264 265 266 267 268 269
                    align: "right"
                },
            ],
            buttonSize: "small",
        }
    },
}
</script>
<style>
B
baiy 已提交
270
.ctool-stat-block .ivu-modal-body {
B
baiy 已提交
271 272
    padding: 0;
}
B
baiy 已提交
273
</style>