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