block.vue 4.2 KB
Newer Older
B
baiy 已提交
1 2
<template>
    <div>
B
baiy 已提交
3 4
        <div>
            <CellGroup @on-click="open">
B
baiy 已提交
5 6 7
                <Cell :title="$t('main_common_tool')" name="setting"/>
                <Cell v-if="is_chromium || is_firefox" :title="$t('main_keyboard_setting')" name="shortcuts"/>
                <Cell :title="$t('main_display_mode')">
B
baiy 已提交
8
                    <Select v-model="display_mode" slot="extra" transfer>
B
baiy 已提交
9 10 11 12 13 14
                        <Option v-for="item in display_mode_list" :value="item" :key="item">{{ $t('main_display_mode_'+item)}}</Option>
                    </Select>
                </Cell>
                <Cell :title="$t('main_setting_language')">
                    <Select v-model="locale" slot="extra" transfer>
                        <Option v-for="item in locales" :value="item.code" :key="item.code">{{ item.name }}</Option>
B
baiy 已提交
15 16
                    </Select>
                </Cell>
B
baiy 已提交
17 18
            </CellGroup>
            <CellGroup>
B
baiy 已提交
19
                <Cell :title="$t('main_copy_results_to_clipboard')">
B
baiy 已提交
20 21
                    <i-switch v-model="auto_save_copy" slot="extra"/>
                </Cell>
B
baiy 已提交
22
                <Cell :title="$t('main_read_content_from_clipboard')">
B
baiy 已提交
23 24
                    <i-switch v-model="auto_read_copy" slot="extra"/>
                </Cell>
B
baiy 已提交
25
                <Cell :title="$t('main_read_clipboard_content_trim')">
26 27
                    <i-switch v-model="auto_read_copy_filter" slot="extra"/>
                </Cell>
B
baiy 已提交
28 29
            </CellGroup>
        </div>
B
baiy 已提交
30 31
        <Drawer :title="$t('main_common_tool_setting')" placement="left" v-model="commonShow" :width="100">
            <setting-common v-if="commonShow"></setting-common>
B
baiy 已提交
32
        </Drawer>
B
baiy 已提交
33 34 35 36
    </div>
</template>

<script>
B
baiy 已提交
37
import {isChromium, isFirefox, isUtools, openUrl, setDisplayMode} from '../../helper'
B
baiy 已提交
38
import {LOCALE_LISTS, setCurrentLocale} from '../../i18n'
B
baiy 已提交
39
import setting from '../../tool/setting'
B
baiy 已提交
40
import common from "./common"
B
baiy 已提交
41
export default {
B
baiy 已提交
42
    components: {
B
baiy 已提交
43
        "setting-common": common
B
baiy 已提交
44
    },
45
    data() {
B
baiy 已提交
46
        return {
B
baiy 已提交
47
            commonShow: false,
B
baiy 已提交
48 49
            auto_save_copy: true,
            auto_read_copy: true,
B
baiy 已提交
50
            display_mode: "light",
51
            auto_read_copy_filter: false,
52
            is_chromium: isChromium,
53
            is_utools: isUtools,
B
baiy 已提交
54
            is_firefox: isFirefox,
B
baiy 已提交
55 56 57
            display_mode_list: ["light","dark","auto"],
            locales: LOCALE_LISTS,
            locale: "",
B
baiy 已提交
58 59
        }
    },
B
baiy 已提交
60 61
    watch: {
        display_mode(value) {
B
baiy 已提交
62
            setDisplayMode(value)
B
baiy 已提交
63 64 65
        },
        locale(value) {
            setCurrentLocale(value)
B
baiy 已提交
66 67
        }
    },
68
    created() {
B
baiy 已提交
69 70
        this.auto_save_copy = setting.autoSaveCopy()
        this.auto_read_copy = setting.autoReadCopy()
71
        this.auto_read_copy_filter = setting.autoReadCopyFilter()
B
baiy 已提交
72
        this.display_mode = setting.displayMode()
B
baiy 已提交
73
        this.locale = setting.locale()
B
baiy 已提交
74
    },
75
    beforeDestroy() {
B
baiy 已提交
76 77
        setting.autoSaveCopy(this.auto_save_copy)
        setting.autoReadCopy(this.auto_read_copy)
78
        setting.autoReadCopyFilter(this.auto_read_copy_filter)
B
baiy 已提交
79
        setting.displayMode(this.display_mode)
B
baiy 已提交
80
        setting.locale(this.locale)
B
baiy 已提交
81 82
    },
    methods: {
83
        open(name) {
B
baiy 已提交
84 85
            switch (name) {
                case 'shortcuts':
B
baiy 已提交
86 87
                    if (this.is_firefox) {
                        return this.$Notice.success({
B
baiy 已提交
88
                            title: this.$t('main_keyboard_firefox_1'),
B
baiy 已提交
89 90
                            render: h => {
                                return h('span', [
B
baiy 已提交
91
                                    this.$t('main_keyboard_firefox_2'),
B
baiy 已提交
92 93 94 95 96
                                    h('a', {
                                        attrs: {
                                            href: 'https://jingyan.baidu.com/article/3ea51489f1d0a713e61bbaff.html',
                                            target: '_blank'
                                        }
B
baiy 已提交
97
                                    }, this.$t('main_keyboard_firefox_3')),
B
baiy 已提交
98 99 100 101
                                ])
                            }
                        });
                    }
B
baiy 已提交
102
                    openUrl('chrome://extensions/shortcuts')
B
baiy 已提交
103 104
                    break
                case 'setting':
B
baiy 已提交
105
                    this.commonShow = true
B
baiy 已提交
106 107
                    break
            }
108
        }
B
baiy 已提交
109 110
    },
}
B
baiy 已提交
111
</script>