作者 xudada

海关智慧定时任务管理功能

@@ -36,6 +36,13 @@ module.exports = { @@ -36,6 +36,13 @@ module.exports = {
36 '^/api/static': '/static', //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可 36 '^/api/static': '/static', //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
37 } 37 }
38 }, 38 },
  39 + '/api/task':{
  40 + target: 'http://192.168.1.7:8010',//设置你调用的接口域名和端口号 别忘了加http
  41 + changeOrigin: false,
  42 + pathRewrite: {
  43 + '^/api/task/': '/', //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
  44 + }
  45 + },
39 '/api':{ 46 '/api':{
40 target: 'http://192.168.1.63:12343',//设置你调用的接口域名和端口号 别忘了加http 47 target: 'http://192.168.1.63:12343',//设置你调用的接口域名和端口号 别忘了加http
41 // target: 'http://192.168.1.189:12343',//设置你调用的接口域名和端口号 别忘了加http 48 // target: 'http://192.168.1.189:12343',//设置你调用的接口域名和端口号 别忘了加http
  1 +import http from '../http.js'
  2 +
  3 +const API_URL = 'task';
  4 +
  5 +const api = {
  6 + // 任务管理接口
  7 + getAllTasks() {
  8 + return http.get(`${API_URL}/tasks`);
  9 + },
  10 + createTask(data) {
  11 + return http.post(`${API_URL}/tasks`, data);
  12 + },
  13 + updateTask(id, data) {
  14 + return http.post(`${API_URL}/tasks/${id}`, data);
  15 + },
  16 + deleteTask(id) {
  17 + return http.post(`${API_URL}/tasks/delete/${id}`);
  18 + },
  19 + executeTask(id) {
  20 + return http.post(`${API_URL}/tasks/execute/${id}`);
  21 + },
  22 + batchExecute(ids) {
  23 + return http.post(`${API_URL}/tasks/batch-execute`, { ids });
  24 + },
  25 + getExecuteTasks() {
  26 + return http.get(`${API_URL}/tasks/execute/list`);
  27 + },
  28 +
  29 + // 执行历史接口
  30 + getExecutionHistory(taskId) {
  31 + return http.get(`${API_URL}/api/task-execution-history/${taskId}`);
  32 + },
  33 + saveExecutionHistory(data) {
  34 + return http.post(`${API_URL}/api/task-execution-history`, data);
  35 + }
  36 +};
  37 +
  38 +export default api;
@@ -714,6 +714,17 @@ let routes = [ @@ -714,6 +714,17 @@ let routes = [
714 { path: '/page6', component: Page6, name: '综合楼空调站' }, 714 { path: '/page6', component: Page6, name: '综合楼空调站' },
715 ] 715 ]
716 }, 716 },
  717 + {
  718 + path: '/tasks',
  719 + component: () => import('./views/HomeNew.vue'),
  720 + name: '动态任务管理',
  721 + iconCls: 'el-icon-setting',
  722 + leaf: false,
  723 + children: [
  724 + { path: '/task_manage', component: () => import('@/views/task/index.vue'), name: '用户管理' },
  725 + { path: '/task_management', component: () => import('./views/task/components/TaskManagement'), name: '任务管理' },
  726 + ]
  727 + },
717 728
718 { 729 {
719 path: '*', 730 path: '*',
  1 +<template>
  2 + <el-dialog :title="'任务历史记录'" :visible.sync="visible">
  3 + <el-table :data="history">
  4 + <el-table-column prop="executedAt" label="执行时间"></el-table-column>
  5 + <el-table-column prop="status" label="状态"></el-table-column>
  6 + <el-table-column prop="result" label="执行结果"></el-table-column>
  7 + </el-table>
  8 + <span slot="footer">
  9 + <el-button @click="visible = false">关闭</el-button>
  10 + </span>
  11 + </el-dialog>
  12 +</template>
  13 +
  14 +<script>
  15 +import api from '../../../api/task/index';
  16 +
  17 +export default {
  18 + props: ['taskId', 'visible'],
  19 + data() {
  20 + return {
  21 + history: []
  22 + };
  23 + },
  24 + watch: {
  25 + taskId: async function(newVal) {
  26 + if (newVal) {
  27 + try {
  28 + const res = await api.getExecutionHistory(newVal);
  29 + this.history = res.data.data;
  30 + } catch (e) {
  31 + this.$message.error('加载历史记录失败');
  32 + }
  33 + }
  34 + }
  35 + }
  36 +};
  37 +</script>
  1 +<template>
  2 + <div class="task-management">
  3 + <el-card class="box-card">
  4 + <!-- 搜索栏 -->
  5 + <el-form :inline="true" class="demo-form-inline">
  6 + <el-form-item label="任务名称">
  7 + <el-input v-model="search.name" placeholder="任务名称"></el-input>
  8 + </el-form-item>
  9 + <el-button type="primary" @click="fetchTasks">搜索</el-button>
  10 + <el-button type="success" @click="showCreateForm">新建任务</el-button>
  11 + </el-form>
  12 +
  13 + <!-- 任务列表 -->
  14 + <el-table
  15 + :data="tasksTableData"
  16 + border
  17 + style="width: 100%"
  18 + @selection-change="handleSelectionChange">
  19 + <el-table-column
  20 + type="selection"
  21 + width="55">
  22 + </el-table-column>
  23 + <el-table-column prop="name" label="任务名称"></el-table-column>
  24 + <el-table-column prop="cronExpression" label="Cron表达式"></el-table-column>
  25 + <el-table-column prop="query" label="状态">
  26 + <template slot-scope="scope">
  27 + {{ scope.row.query || '待执行' }}
  28 + </template>
  29 + </el-table-column>
  30 + <el-table-column label="操作" width="250">
  31 + <template slot-scope="scope">
  32 + <el-button size="mini" @click="showEditorm(scope.$index, scope.row)">编辑</el-button>
  33 + <el-popconfirm
  34 + confirm-button-text="好的"
  35 + cancel-button-text="不用了"
  36 + icon="el-icon-info"
  37 + icon-color="red"
  38 + title="确定删除该商品吗?"
  39 + @confirm="handleDelete(scope.$index, scope.row)"
  40 + >
  41 + <el-button
  42 + type="danger"
  43 + slot="reference"
  44 + >删除</el-button>
  45 + </el-popconfirm>
  46 + <el-button size="mini" type="primary" @click="showHistory(scope.row.id)">历史记录</el-button>
  47 + </template>
  48 + </el-table-column>
  49 + </el-table>
  50 +
  51 + <!-- 分页 -->
  52 + <el-pagination
  53 + layout="prev, pager, next"
  54 + :total="total"
  55 + @current-change="handlePageChange">
  56 + </el-pagination>
  57 +
  58 + <!-- 新建/编辑弹窗 -->
  59 + <el-dialog :title="dialogMap[dialogStatus]" :visible.sync="dialogVisible" width="40%">
  60 + <el-form :model="from" label-width="100px">
  61 + <el-form-item label="任务名称">
  62 + <el-input v-model="from.name"></el-input>
  63 + </el-form-item>
  64 + <el-form-item label="Cron表达式">
  65 + <el-input v-model="from.cronExpression"></el-input>
  66 + </el-form-item>
  67 + <el-form-item label="查询密钥">
  68 + <el-input v-model="from.apiKey"></el-input>
  69 + </el-form-item>
  70 + <el-form-item label="查询类别">
  71 + <el-input v-model="from.categoryId"></el-input>
  72 + </el-form-item>
  73 + <el-form-item label="查询内容">
  74 + <el-input type="textarea" v-model="from.inputs"></el-input>
  75 + </el-form-item>
  76 + <!-- 其他字段... -->
  77 + </el-form>
  78 + <span slot="footer">
  79 + <el-button @click="dialogVisible = false">取消</el-button>
  80 +<el-button type="primary" @click="dialogStatus==='create'?outerVisible_add():outerVisible_edit()">保存</el-button>
  81 +</span>
  82 + </el-dialog>
  83 +
  84 + <!-- 历史记录弹窗 -->
  85 + <task-history
  86 + :visible="historyVisible"
  87 + :task-id="currentTaskId"
  88 + @close="historyVisible = false">
  89 + </task-history>
  90 + </el-card>
  91 + </div>
  92 +</template>
  93 +
  94 +<script>
  95 + import TaskHistory from './TaskHistory.vue';
  96 + import api from '../../../api/task/index';
  97 +
  98 + export default {
  99 + components: {TaskHistory},
  100 + data() {
  101 + return {
  102 + from:{
  103 + id: undefined,
  104 + name: "",
  105 + cronExpression: "",
  106 + query: "",
  107 + inputs: "",
  108 + username: "",
  109 + conversationId: "",
  110 + apiKey: "",
  111 + responseMode: "",
  112 + createdAt: "",
  113 + updatedAt:"",
  114 + categoryId: 0
  115 + },
  116 + tasksTableData: [],
  117 + search: {name: ''},
  118 + dialogVisible: false,
  119 + dialogTitle: '新建任务',
  120 + currentTask: {},
  121 + currentTaskId: 0,
  122 + historyVisible: false,
  123 + selectedTasks: [],
  124 + total:0,
  125 + dialogStatus:'create',
  126 + dialogMap:{
  127 + update: '编辑',
  128 + create: '添加'
  129 + },
  130 + };
  131 + },
  132 + methods: {
  133 + async outerVisible_add(){
  134 + try {
  135 + const res = await api.createTask(this.from);
  136 + if(res.data.code=='200'){
  137 + this.$message.success('任务新增成功');
  138 + }else{
  139 + this.$message.success('任务新增失败');
  140 + }
  141 + this.dialogVisible=false;
  142 + this.fetchTasks();
  143 + } catch (e) {
  144 + this.$message.error('新增任务失败');
  145 + }
  146 + },
  147 + async outerVisible_edit(){
  148 + try {
  149 + const res = await api.updateTask(this.from.id,this.from);
  150 + if(res.data.code=='200'){
  151 + this.$message.success('任务更新成功');
  152 + }else{
  153 + this.$message.success('任务更新失败');
  154 + }
  155 + this.dialogVisible=false;
  156 + this.fetchTasks();
  157 + } catch (e) {
  158 + this.$message.error('任务更新失败');
  159 + }
  160 + },
  161 + handlePageChange(){},
  162 + showCreateForm(){
  163 + this.dialogStatus='create';
  164 + this.dialogVisible=true;
  165 + },
  166 + handleSelectionChange(){},
  167 + async showHistory(id){
  168 + this.currentTaskId=id;
  169 + this.historyVisible=true;
  170 + },
  171 + async handleDelete(index,row){
  172 + const res = await api.deleteTask(row.id);
  173 + if(res.data.code=='200'){
  174 + this.$message.success('任务删除成功');
  175 + }else{
  176 + this.$message.success('任务删除失败');
  177 + }
  178 + this.fetchTasks();
  179 + },
  180 + showEditForm(index,row){
  181 + console.log(row)
  182 + this.dialogStatus='update';
  183 + this.from=row;
  184 + this.dialogVisible=true;
  185 + },
  186 + async fetchTasks() {
  187 + try {
  188 + const res = await api.getAllTasks();
  189 + this.tasksTableData = res.data.data;
  190 + } catch (e) {
  191 + this.$message.error('加载任务失败');
  192 + }
  193 + },
  194 + // 其他方法...
  195 + },
  196 + created() {
  197 + this.fetchTasks();
  198 + }
  199 + };
  200 +</script>
  1 +<template>
  2 + <div id="app">
  3 + <el-container>
  4 + <el-header>任务管理系统</el-header>
  5 + <el-main>
  6 + <el-tabs v-model="activeTab">
  7 + <el-tab-pane label="任务管理" name="tasks">
  8 + <task-management></task-management>
  9 + </el-tab-pane>
  10 + <el-tab-pane label="执行历史" name="history">
  11 + <task-history-list></task-history-list>
  12 + </el-tab-pane>
  13 + </el-tabs>
  14 + </el-main>
  15 + </el-container>
  16 + </div>
  17 +</template>
  18 +
  19 +<script>
  20 +import TaskManagement from './components/TaskManagement.vue';
  21 +import TaskHistoryList from './components/TaskHistory.vue';
  22 +
  23 +export default {
  24 + components: {
  25 + TaskManagement,
  26 + TaskHistoryList
  27 + }
  28 +};
  29 +</script>