tool.vue 6.9 KB
Newer Older
B
baiy 已提交
1 2
<template>
    <div>
B
baiy 已提交
3 4
        <Menu mode="horizontal" theme="light" :active-name="currentCategory" @on-select="categorySelect"
              style="height: 45px;line-height: 45px;">
B
fix  
baiy 已提交
5
            <MenuItem :name="cat.name" v-for="(cat) in category" :key="cat.name">
B
baiy 已提交
6
                <Badge v-if="badgeCategoryIsShow(cat.name)" dot :offset="[15,-10]">
B
baiy 已提交
7
                    {{ cat.title }}
B
baiy 已提交
8 9
                </Badge>
                <template v-else>
B
baiy 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
                    {{ cat.title }}
                </template>
            </MenuItem>
            <MenuItem style="padding: 0 5px;float: right" name="_new">
                <Icon type="md-expand" :size="24"/>
            </MenuItem>
            <MenuItem style="padding: 0 5px;float: right" name="_feedback">
                <Icon type="md-help-circle" :size="24"/>
            </MenuItem>
            <MenuItem style="padding: 0 5px;float: right" name="_setting">
                <Icon type="md-settings" :size="24"/>
            </MenuItem>
            <MenuItem style="padding: 0 5px;float: right" name="_about">
                <Icon type="logo-github" :size="24"/>
            </MenuItem>
            <MenuItem style="padding: 0 5px;float: right" name="_history">
                <Badge v-if="historyLength>0" dot :offset="[10,-3]">
                    <Icon type="md-time" :size="24"/>
                </Badge>
                <template v-else>
                    <Icon type="md-time" :size="24"/>
B
baiy 已提交
31
                </template>
B
baiy 已提交
32
            </MenuItem>
B
baiy 已提交
33
        </Menu>
B
fix  
baiy 已提交
34
        <RadioGroup :value="currentTool" @on-change="toolSelect" style="margin: 10px 0 10px 20px;line-height: 30px;">
B
baiy 已提交
35
            <Radio :label="tool.name" v-for="(tool) in tools" :key="tool.name">
B
baiy 已提交
36
                <Badge v-if="badgeToolIsShow(tool.name)" dot :offset="[5,-5]">
B
baiy 已提交
37
                    {{ tool.title }}
B
baiy 已提交
38 39
                </Badge>
                <template v-else>
B
baiy 已提交
40
                    {{ tool.title }}
B
baiy 已提交
41
                </template>
B
baiy 已提交
42 43 44
            </Radio>
        </RadioGroup>
        <div>
B
baiy 已提交
45
            <router-view :key="$route.path + $route.query.t"/>
B
baiy 已提交
46
        </div>
B
baiy 已提交
47 48 49 50 51
        <Drawer :title="currentToolTitle+' - 历史记录'" v-model="historyShow" :width="100">
            <Table ref="historyTable" border :columns="historyColumns" :data="historyData" :height="historyTableHeight">
                <template slot-scope="{ row }" slot="_value">
                    <div>{{ historyValue(row.value) }}}</div>
                </template>
B
baiy 已提交
52
                <template slot-scope="{ index }" slot="_op">
B
baiy 已提交
53 54 55 56 57 58 59 60
                    <Button type="primary" size="small" @click="historyView(index)">查看</Button>
                    <Button type="primary" style="margin-left: 5px" @click="historyLoad(index)" size="small">加载</Button>
                </template>
            </Table>
            <div class="drawer-footer">
                <Button type="primary" @click="historyClear">清空历史记录</Button>
            </div>
        </Drawer>
B
baiy 已提交
61 62 63 64
    </div>
</template>

<script>
B
baiy 已提交
65 66 67 68 69
import config from './tool/config'
import model from './tool/model'
import historyFactory from './tool/history'
import {setLoadHistoryIndex} from './tool/history'
import { openTab } from './helper'
70

B
baiy 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
export default {
    data () {
        return {
            category: config.category,
            currentCategory: '',
            currentTool: '',
            historyData: [],
            historyShow: false,
            historyColumns: [
                {
                    title: '操作时间',
                    key: 'time',
                    width:180
                },
                {
                    title: '数据',
                    slot: '_value',
B
baiy 已提交
88
                    ellipsis:true,
B
baiy 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                },
                {
                    title: '操作',
                    slot: '_op',
                    width:150
                }
            ],
        }
    },
    computed: {
        tools () {
            return config.getToolByCategory(this.currentCategory)
        },
        historyLength(){
            return historyFactory(this.currentTool).length()
        },
        historyTableHeight() {
            // 设置表格高度
            return window.innerHeight - 140
B
baiy 已提交
108
        },
B
baiy 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        currentToolTitle(){
            return config.getToolTitle(this.currentTool)
        }
    },
    watch: {
        currentTool (name) {
            model.setCurrentTool(name)
            this.$router.push('/tool/' + name)
        },
    },
    created () {
        this.currentCategory = model.getCategoryHistory()
        this.currentTool = model.getToolHistory(this.currentCategory)
        this.$Message.config({
            top: 150,
        })
    },
    mounted () {},
    methods: {
        categorySelect (name) {
            switch (name) {
                case '_feedback':
                    openTab('https://github.com/baiy/Ctool/issues')
                    break
                case '_about':
                    openTab('https://github.com/baiy/Ctool')
                    break
                case '_setting':
                    openTab('/setting.html')
                    break
                case '_new':
                    openTab(window.location.href)
                    break
                case '_history':
                    this.history()
                    break
                default:
                    this.currentCategory = name
                    model.setCategoryHistory(name)
                    this.currentTool = model.getToolHistory(this.currentCategory)
                    break
B
baiy 已提交
150 151
            }
        },
B
baiy 已提交
152 153 154 155
        history () {
            let history = historyFactory(this.currentTool)
            if (history.length() < 1) {
                return this.$Message.error('暂无历史记录')
B
fix  
baiy 已提交
156
            }
B
baiy 已提交
157 158
            this.historyData = history.all()
            this.historyShow = true
B
baiy 已提交
159
        },
B
baiy 已提交
160 161
        historyValue (value) {
            return JSON.stringify(value)
B
baiy 已提交
162
        },
B
baiy 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
        historyView(index){
            console.log(historyFactory(this.currentTool).get(index))
        },
        historyClear(){
            historyFactory(this.currentTool).clear()
            this.historyShow = false;
        },
        historyLoad(index){
            setLoadHistoryIndex(index)
            this.historyShow = false;
            this.$router.push({
                path:this.$router.currentRoute.fullPath,
                query:{
                    t:Date.now(),
                },
            });
        },
        toolSelect (name) {
            model.setToolHistory(this.currentCategory, name)
            this.currentTool = name
        },
        badgeToolIsShow (tool) {
            return config.badgeToolIsShow(tool)
        },
        badgeCategoryIsShow (cat) {
            return config.badgeCategoryIsShow(cat)
B
baiy 已提交
189
        },
B
baiy 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    },
}
</script>
<style scoped>
.drawer-footer{
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    background: #fff;
}
</style>