wujianwei
2025-09-10 de448cb8a94591b85a99816d741480bf4c227879
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<template>
  <basicContainer>
    <avue-crud
        :option="option"
        :table-loading="pageF.loading"
        :data="tableData"
        :page="page"
        :permission="permissionList"
        :before-open="beforeOpen"
        v-model="form"
        ref="crudRef"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @row-del="rowDel"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @on-load="onLoad"
    >
      <template #menu-left>
        <el-button
            type="success"
            icon="Edit"
            :disabled="pageF.single"
            v-hasPermi="['system:job:edit']"
            @click="handleUpdate">修改
        </el-button>
        <el-button
            type="danger"
            icon="Delete"
            :disabled="pageF.multiple"
            @click="handleDelete"
            v-hasPermi="['system:job:remove']"
        >删除
        </el-button>
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['system:job:export']"
        >导出
        </el-button>
        <el-button
            type="info"
            plain
            icon="Operation"
            @click="handleJobLog(undefined)"
            v-hasPermi="['monitor:job:query']"
        >日志</el-button>
      </template>
      <template #menu="scope">
        <div v-hasPermi="['monitor:job:changeStatus','monitor:job:query']" style="display: inline-block;line-height: 1;vertical-align: middle;">
          <el-dropdown size="small" @command="(command:any) => handleCommand(command, scope.row)" >
            <el-link size="small" type="primary" :underline="false" icon="el-icon-d-arrow-right">更多</el-link>
            <template #dropdown>
              <el-dropdown-menu slot="dropdown">
                <div  v-hasPermi="['monitor:job:changeStatus']">
                  <el-dropdown-item command="handleRun" icon="CaretRight"
                  >执行一次</el-dropdown-item>
                </div>
                <div  v-hasPermi="['monitor:job:query']">
                  <el-dropdown-item command="handleJobLog" icon="Operation"
                  >调度日志</el-dropdown-item>
                </div>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </template>
 
      <template #status="scope">
        <el-switch
            v-model="scope.row.status"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
        ></el-switch>
      </template>
    </avue-crud>
  </basicContainer>
</template>
 
<script setup name="job" lang="ts">
import {JobI, addJob, delJob, exportJob, getJob, listJob, updateJob, runJob, changeJobStatus} from "@/api/monitor/job";
import useCurrentInstance from "@/utils/useCurrentInstance";
import {computed, reactive, ref, toRefs} from "vue";
import {PagesInterface, PageQueryInterface} from "@/utils/globalInterface";
import {usePagePlus} from "@/hooks/usePagePlus";
import {hasPermission} from "@/utils/permissionUtils";
import {useRouter} from "vue-router";
 
 
const {proxy} = useCurrentInstance();
const crudRef = ref();
const router = useRouter();
 
const permissionList = computed(() => {
  return {
    addBtn: hasPermission(["system:job:add"]),
    delBtn: hasPermission(["system:job:remove"]),
    editBtn: hasPermission(["system:job:edit"]),
    viewBtn: hasPermission(["system:job:query"]),
  }
})
 
const data = reactive({
  form: <JobI>{},
  queryParams: <JobI & PageQueryInterface>{},
  page: <PagesInterface>{
    pageSize: 10,
    total: 0,
    currentPage: 1,
  },
  selectionList: [],
})
const {queryParams, form, page, selectionList} = toRefs(data);
 
 
const {
  tableData, pageF, rowSave, rowUpdate, rowDel, beforeOpen, searchChange,
  searchReset, selectionChange, onLoad, currentChange, sizeChange, handleDelete, handleExport, handleUpdate
} = usePagePlus({
  form: form,
  queryParams: queryParams,
  idKey: 'jobId',
  page: page.value,
  getListApi: listJob,
  getDetailApi: getJob,
  exportApi: exportJob,
  deleteApi: delJob,
  addApi: addJob,
  updateApi: updateJob,
  handleUpdateFunc: () => {
    crudRef.value.rowEdit(selectionList.value[0]);
  },
  handleSelectionChangeFunc: (selection: any) => {
    selectionList.value = selection;
  }
})
 
const option = ref({
  rowKey: 'jobId',
  labelWidth:120,
  viewBtn:false,
  column: {
    jobId: {
      label: '任务编号', width: 100,  display: false
    },
    jobName: {
      label: '任务名称',search:true,
      rules: [
        {
          required: true,
          message: "任务名称不能为空", trigger: "blur"
        }
      ],
    },
    jobGroup: {
      label: '任务组名', dicUrl: '/system/dict/data/type/sys_job_group', type: "select",value: 'DEFAULT',search:true,
    },
    invokeTarget: {
      label: '调用方法', hide: true, span: 24,
      type: 'textarea', minRows: 3, maxRows: 5,
      rules: [
        {
          required: true,
          message: "调用目标字符串不能为空", trigger: "blur"
        }
      ],
    },
    cronExpression: {
      label: 'cron表达式', span: 24,
      rules: [
        {
          required: true,
          message: "cron执行表达式不能为空", trigger: "blur"
        }
      ],
    },
    misfirePolicy: {
      label: '执行策略', hide: true, type: 'radio', button: true,value: '1',
      dicData: [
        {dictLabel: '立即执行', dictValue: '1'},
        {dictLabel: '执行一次', dictValue: '2'},
        {dictLabel: '放弃执行', dictValue: '3'},
      ]
    },
    concurrent: {
      label: '是否并发', hide: true, type: 'radio', button: true,value: '0',
      dicData: [
        {dictLabel: '允许', dictValue: '0'},
        {dictLabel: '禁止', dictValue: '1'},
      ]
    },
    status: {
      label: '状态',value: '0',search:true,
      type: 'radio', dicUrl: '/system/dict/data/type/sys_job_status',
    },
    createBy: {
      label: '创建者', addDisplay: false, editDisplay: false,
    },
    createTime: {
      label: '创建时间', addDisplay: false, editDisplay: false,span:24
    },
  }
})
const handleCommand = (command:string,row:JobI)=>{
  switch (command) {
    case "handleRun":
      handleRun(row);
      break;
    case "handleJobLog":
      handleJobLog(row);
      break;
    default:
      break;
  }
}
//执行一次
function handleRun(row:JobI) {
  proxy.$modal.confirm('确认要立即执行一次"' + row.jobName + '"任务吗?').then(function () {
    return runJob({jobId:row.jobId, jobGroup:row.jobGroup});
  }).then(() => {
    proxy.$modal.msgSuccess("执行成功");
  })
}
/**
 * 任务日志列表查询
 */
function handleJobLog(row?:JobI){
  const jobId = row?.jobId || 0;
  router.push({path: "/monitor/job-log/index",query:{jobId:jobId,jobName:row?.jobName,jobGroup: row?.jobGroup}})
}
function handleStatusChange(row:any) {
  if(!row.jobName){return;}
  let text = row.status === "0"? "启用":"停用";
  proxy.$modal.confirm(`确认要"${text}""${row.jobName}"任务吗?`).
  then(()=>{
    return  changeJobStatus({jobId:row.jobId,status:row.status})
  }).then(() => {
    proxy.$modal.msgSuccess(`${text}成功`);
  }).catch(()=>{
    row.status = row.status === "0"?"1":"0"
  })
}
 
 
</script>