index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <content-wrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="100px"
  10. >
  11. <el-form-item label="任务名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入任务名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="任务状态" prop="status">
  21. <el-select
  22. v-model="queryParams.status"
  23. placeholder="请选择任务状态"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getIntDictOptions(DICT_TYPE.INFRA_JOB_STATUS)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="dict.value"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="处理器的名字" prop="handlerName">
  36. <el-input
  37. v-model="queryParams.handlerName"
  38. placeholder="请输入处理器的名字"
  39. clearable
  40. @keyup.enter="handleQuery"
  41. class="!w-240px"
  42. />
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  46. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  47. <el-button
  48. type="primary"
  49. plain
  50. @click="openForm('create')"
  51. v-hasPermi="['infra:job:create']"
  52. >
  53. <Icon icon="ep:plus" class="mr-5px" /> 新增
  54. </el-button>
  55. <el-button
  56. type="success"
  57. plain
  58. @click="handleExport"
  59. :loading="exportLoading"
  60. v-hasPermi="['infra:job:export']"
  61. >
  62. <Icon icon="ep:download" class="mr-5px" /> 导出
  63. </el-button>
  64. <el-button type="info" plain @click="handleJobLog" v-hasPermi="['infra:job:query']">
  65. <Icon icon="ep:zoom-in" class="mr-5px" /> 执行日志
  66. </el-button>
  67. </el-form-item>
  68. </el-form>
  69. </content-wrap>
  70. <!-- 列表 -->
  71. <content-wrap>
  72. <el-table v-loading="loading" :data="list">
  73. <el-table-column label="任务编号" align="center" prop="id" />
  74. <el-table-column label="任务名称" align="center" prop="name" />
  75. <el-table-column label="任务状态" align="center" prop="status">
  76. <template #default="scope">
  77. <dict-tag :type="DICT_TYPE.INFRA_JOB_STATUS" :value="scope.row.status" />
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="处理器的名字" align="center" prop="handlerName" />
  81. <el-table-column label="处理器的参数" align="center" prop="handlerParam" />
  82. <el-table-column label="CRON 表达式" align="center" prop="cronExpression" />
  83. <el-table-column label="操作" align="center" width="200">
  84. <template #default="scope">
  85. <el-button
  86. type="primary"
  87. link
  88. @click="openForm('update', scope.row.id)"
  89. v-hasPermi="['infra:job:update']"
  90. >
  91. 修改
  92. </el-button>
  93. <el-button
  94. type="primary"
  95. link
  96. @click="handleChangeStatus(scope.row)"
  97. v-hasPermi="['infra:job:update']"
  98. >
  99. {{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}
  100. </el-button>
  101. <el-button
  102. type="danger"
  103. link
  104. @click="handleDelete(scope.row)"
  105. v-hasPermi="['infra:job:delete']"
  106. >
  107. 删除
  108. </el-button>
  109. <el-dropdown
  110. @command="(command) => handleCommand(command, scope.row)"
  111. v-hasPermi="['infra:job:trigger', 'infra:job:query']"
  112. >
  113. <el-button type="primary" link><Icon icon="ep:d-arrow-right" /> 更多</el-button>
  114. <template #dropdown>
  115. <el-dropdown-menu>
  116. <el-dropdown-item command="handleRun" v-if="checkPermi(['infra:job:trigger'])">
  117. 执行一次
  118. </el-dropdown-item>
  119. <el-dropdown-item command="handleView" v-if="checkPermi(['infra:job:query'])">
  120. 任务详细
  121. </el-dropdown-item>
  122. <el-dropdown-item command="handleJobLog" v-if="checkPermi(['infra:job:query'])">
  123. 调度日志
  124. </el-dropdown-item>
  125. </el-dropdown-menu>
  126. </template>
  127. </el-dropdown>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <!-- 分页组件 -->
  132. <Pagination
  133. :total="total"
  134. v-model:page="queryParams.pageNo"
  135. v-model:limit="queryParams.pageSize"
  136. @pagination="getList"
  137. />
  138. </content-wrap>
  139. <!-- 表单弹窗:添加/修改 -->
  140. <JobForm ref="formRef" @success="getList" />
  141. <!-- 表单弹窗:查看 -->
  142. <job-view ref="viewModalRef" @success="getList" />
  143. </template>
  144. <script setup lang="ts" name="Job">
  145. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  146. import { checkPermi } from '@/utils/permission'
  147. import JobForm from './JobForm.vue'
  148. import JobView from './view.vue'
  149. import download from '@/utils/download'
  150. import * as JobApi from '@/api/infra/job'
  151. import { InfraJobStatusEnum } from '@/utils/constants'
  152. const { t } = useI18n() // 国际化
  153. const message = useMessage() // 消息弹窗
  154. const { push } = useRouter() // 路由
  155. const loading = ref(true) // 列表的加载中
  156. const total = ref(0) // 列表的总页数
  157. const list = ref([]) // 列表的数据
  158. const queryParams = reactive({
  159. pageNo: 1,
  160. pageSize: 10,
  161. name: undefined,
  162. status: undefined,
  163. handlerName: undefined
  164. })
  165. const queryFormRef = ref() // 搜索的表单
  166. const exportLoading = ref(false) // 导出的加载中
  167. /** 查询参数列表 */
  168. const getList = async () => {
  169. loading.value = true
  170. try {
  171. const data = await JobApi.getJobPageApi(queryParams)
  172. list.value = data.list
  173. total.value = data.total
  174. } finally {
  175. loading.value = false
  176. }
  177. }
  178. /** 搜索按钮操作 */
  179. const handleQuery = () => {
  180. queryParams.pageNo = 1
  181. getList()
  182. }
  183. /** 重置按钮操作 */
  184. const resetQuery = () => {
  185. queryFormRef.value.resetFields()
  186. handleQuery()
  187. }
  188. /** 导出按钮操作 */
  189. const handleExport = async () => {
  190. try {
  191. // 导出的二次确认
  192. await message.exportConfirm()
  193. // 发起导出
  194. exportLoading.value = true
  195. const data = await JobApi.exportJobApi(queryParams)
  196. download.excel(data, '定时任务.xls')
  197. } catch {
  198. } finally {
  199. exportLoading.value = false
  200. }
  201. }
  202. /** 添加/修改操作 */
  203. const formRef = ref()
  204. const openForm = (type: string, id?: number) => {
  205. formRef.value.open(type, id)
  206. }
  207. /** 修改状态操作 */
  208. const handleChangeStatus = async (row: JobApi.JobVO) => {
  209. try {
  210. // 修改状态的二次确认
  211. const text = row.status === InfraJobStatusEnum.STOP ? '开启' : '关闭'
  212. await message.confirm(
  213. '确认要' + text + '定时任务编号为"' + row.id + '"的数据项?',
  214. t('common.reminder')
  215. )
  216. const status =
  217. row.status === InfraJobStatusEnum.STOP ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP
  218. await JobApi.updateJobStatusApi(row.id, status)
  219. message.success(text + '成功')
  220. // 刷新列表
  221. await getList()
  222. } catch {
  223. // 取消后,进行恢复按钮
  224. row.status =
  225. row.status === InfraJobStatusEnum.NORMAL ? InfraJobStatusEnum.STOP : InfraJobStatusEnum.NORMAL
  226. }
  227. }
  228. /** 删除按钮操作 */
  229. const handleDelete = async (id: number) => {
  230. try {
  231. // 删除的二次确认
  232. await message.delConfirm()
  233. // 发起删除
  234. await JobApi.deleteJobApi(id)
  235. message.success(t('common.delSuccess'))
  236. // 刷新列表
  237. await getList()
  238. } catch {}
  239. }
  240. /** '更多'操作按钮 */
  241. const handleCommand = (command, row) => {
  242. switch (command) {
  243. case 'handleRun':
  244. handleRun(row)
  245. break
  246. case 'handleView':
  247. handleView(row?.id)
  248. break
  249. case 'handleJobLog':
  250. handleJobLog(row?.id)
  251. break
  252. default:
  253. break
  254. }
  255. }
  256. /** 执行一次 */
  257. const handleRun = async (row: JobApi.JobVO) => {
  258. try {
  259. // 二次确认
  260. await message.confirm('确认要立即执行一次' + row.name + '?', t('common.reminder'))
  261. // 提交执行
  262. await JobApi.runJobApi(row.id)
  263. message.success('执行成功')
  264. // 刷新列表
  265. await getList()
  266. } catch {}
  267. }
  268. /** 查看操作 */
  269. const viewModalRef = ref()
  270. const handleView = (rowId?: number) => {
  271. viewModalRef.value.openForm(rowId)
  272. }
  273. // 执行日志
  274. const handleJobLog = (rowId?: number) => {
  275. if (rowId) {
  276. push('/job/job-log?id=' + rowId)
  277. } else {
  278. push('/job/job-log')
  279. }
  280. }
  281. /** 初始化 **/
  282. onMounted(() => {
  283. getList()
  284. })
  285. </script>