gaoshp
2024-06-03 6f1ac1da6b6cba5c74f2fb6be82f7e472c4116ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!--
 * @Descripttion: 系统计划任务配置
 * @version: 1.2
 * @Author: sakuya
 * @Date: 2021年7月7日09:28:32
 * @LastEditors: sakuya
 * @LastEditTime: 2021年7月10日20:56:47
-->
 
<template>
    <el-main>
        <el-row :gutter="15">
            <el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24" v-for="item in list" :key="item.id">
                <el-card class="task task-item" shadow="hover">
                    <h2>{{item.title}}</h2>
                    <ul>
                        <li>
                            <h4>执行类</h4>
                            <p>{{item.handler}}</p>
                        </li>
                        <li>
                            <h4>定时规则</h4>
                            <p>{{item.cron}}</p>
                        </li>
                    </ul>
                    <div class="bottom">
                        <div class="state">
                            <el-tag v-if="item.state=='1'" size="small">准备就绪</el-tag>
                            <el-tag v-if="item.state=='-1'" size="small" type="info">停用</el-tag>
                        </div>
                        <div class="handler">
                            <el-popconfirm title="确定立即执行吗?" @confirm="run(item)">
                                <template #reference>
                                    <el-button type="primary" icon="el-icon-caret-right" circle></el-button>
                                </template>
                            </el-popconfirm>
                            <el-dropdown trigger="click">
                                <el-button type="primary" icon="el-icon-more" circle plain></el-button>
                                <template #dropdown>
                                    <el-dropdown-menu>
                                        <el-dropdown-item @click="edit(item)">编辑</el-dropdown-item>
                                        <el-dropdown-item @click="logs(item)">日志</el-dropdown-item>
                                        <el-dropdown-item @click="del(item)" divided>删除</el-dropdown-item>
                                    </el-dropdown-menu>
                                </template>
                            </el-dropdown>
                        </div>
                    </div>
                </el-card>
            </el-col>
            <el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24">
                <el-card class="task task-add" shadow="never" @click="add">
                    <el-icon><el-icon-plus /></el-icon>
                    <p>添加计划任务</p>
                </el-card>
            </el-col>
        </el-row>
    </el-main>
 
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
 
    <el-drawer title="计划任务日志" v-model="dialog.logsVisible" :size="600" direction="rtl" destroy-on-close>
        <logs></logs>
    </el-drawer>
</template>
 
<script>
    import saveDialog from './save'
    import logs from './logs'
 
    export default {
        name: 'task',
        components: {
            saveDialog,
            logs
        },
        provide() {
            return {
                list: this.list
            }
        },
        data() {
            return {
                dialog: {
                    save: false,
                    logsVisible: false
                },
                list: [
                    {
                        id: "1",
                        title: "清理服务器缓存",
                        handler: "cleanUpCacheHandler",
                        cron: "59 59 23 * * ? *",
                        state: "1"
                    },
                    {
                        id: "2",
                        title: "自动审核",
                        handler: "automaticAuditHandler",
                        cron: "0 0 * * * ? *",
                        state: "1"
                    },
                    {
                        id: "3",
                        title: "清理未实名用户",
                        handler: "deleteUserHandler",
                        cron: "0 0 0 * * ? *",
                        state: "-1"
                    }
                ]
            }
        },
        mounted() {
 
        },
        methods: {
            add(){
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open()
                })
            },
            edit(task){
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open('edit').setData(task)
                })
            },
            del(task){
                this.$confirm(`确认删除 ${task.title} 计划任务吗?`,'提示', {
                    type: 'warning',
                    confirmButtonText: '删除',
                    confirmButtonClass: 'el-button--danger'
                }).then(() => {
                    this.list.splice(this.list.findIndex(item => item.id === task.id), 1)
                }).catch(() => {
                    //取消
                })
            },
            logs(){
                this.dialog.logsVisible = true
            },
            run(task){
                this.$message.success(`已成功执行计划任务:${task.title}`)
            },
            //本地更新数据
            handleSuccess(data, mode){
                if(mode=='add'){
                    data.id = new Date().getTime()
                    this.list.push(data)
                }else if(mode=='edit'){
                    this.list.filter(item => item.id===data.id ).forEach(item => {
                        Object.assign(item, data)
                    })
                }
            }
        }
    }
</script>
 
<style scoped>
    .task {height: 210px;}
    .task-item h2 {font-size: 15px;color: #3c4a54;padding-bottom:15px;}
    .task-item li {list-style-type:none;margin-bottom: 10px;}
    .task-item li h4 {font-size: 12px;font-weight: normal;color: #999;}
    .task-item li p {margin-top: 5px;}
    .task-item .bottom {border-top: 1px solid #EBEEF5;text-align: right;padding-top:10px;display: flex;justify-content: space-between;align-items: center;}
 
    .task-add {display: flex;flex-direction: column;align-items: center;justify-content: center;text-align: center;cursor: pointer;color: #999;}
    .task-add:hover {color: #409EFF;}
    .task-add i {font-size: 30px;}
    .task-add p {font-size: 12px;margin-top: 20px;}
    
    .dark .task-item .bottom {border-color: var(--el-border-color-light);}
</style>