回退 'Pull Request !84 : 修改测试所提bug'

This commit is contained in:
芋道源码 2023-04-02 14:48:43 +00:00 committed by Gitee
parent e94eb757a2
commit c964ca78ee
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 991 additions and 729 deletions

3
.gitignore vendored
View File

@ -6,3 +6,6 @@ dist-ssr
/dist* /dist*
*-lock.* *-lock.*
pnpm-debug pnpm-debug
.idea
.history

View File

@ -133,24 +133,15 @@ const openModel = (title: string) => {
} }
/** 复制 **/ /** 复制 **/
const copy = async (text: string) => { const copy = async (text: string) => {
// const { copy, copied, isSupported } = useClipboard({ source: JSON.stringify(text) }) const { copy, copied, isSupported } = useClipboard({ source: text })
// if (!isSupported.value) { if (!isSupported) {
// message.error(t('common.copyError')) message.error(t('common.copyError'))
// } else { } else {
// await copy() await copy()
// if (unref(copied.value)) { if (unref(copied)) {
// message.success(t('common.copySuccess'))
// }
// }
let url = JSON.stringify(text)
let oInput = document.createElement('textarea')
oInput.value = url
document.body.appendChild(oInput)
oInput.select() // ;
// console.log(oInput.value)
document.execCommand('Copy') //
message.success(t('common.copySuccess')) message.success(t('common.copySuccess'))
oInput.remove() }
}
} }
// ========== ========== // ========== ==========
onMounted(() => { onMounted(() => {

View File

@ -77,24 +77,15 @@ const showTemplate = () => {
/** 复制 **/ /** 复制 **/
const copy = async (text: string) => { const copy = async (text: string) => {
// const { copy, copied, isSupported } = useClipboard({ source: JSON.stringify(text) }) const { copy, copied, isSupported } = useClipboard({ source: text })
// if (!isSupported.value) { if (!isSupported) {
// message.error(t('common.copyError')) message.error(t('common.copyError'))
// } else { } else {
// await copy() await copy()
// if (unref(copied.value)) { if (unref(copied)) {
// message.success(t('common.copySuccess'))
// }
// }
let url = JSON.stringify(text)
let oInput = document.createElement('textarea')
oInput.value = url
document.body.appendChild(oInput)
oInput.select() // ;
// console.log(oInput.value)
document.execCommand('Copy') //
message.success(t('common.copySuccess')) message.success(t('common.copySuccess'))
oInput.remove() }
}
} }
const makeTemplate = () => { const makeTemplate = () => {

View File

@ -130,11 +130,11 @@ const handleFiles = (datas: CodegenPreviewVO[]) => {
/** 复制 **/ /** 复制 **/
const copy = async (text: string) => { const copy = async (text: string) => {
const { copy, copied, isSupported } = useClipboard({ source: text }) const { copy, copied, isSupported } = useClipboard({ source: text })
if (!isSupported.value) { if (!isSupported) {
message.error(t('common.copyError')) message.error(t('common.copyError'))
} else { } else {
await copy() await copy()
if (unref(copied.value)) { if (unref(copied)) {
message.success(t('common.copySuccess')) message.success(t('common.copySuccess'))
} }
} }

View File

@ -6,8 +6,7 @@ export const rules = reactive({
category: [required], category: [required],
name: [required], name: [required],
key: [required], key: [required],
value: [required], value: [required]
visible: [{ required: true, message: '请选择是否可见', trigger: 'change' }]
}) })
// CrudSchema // CrudSchema

View File

@ -93,8 +93,8 @@ const message = useMessage() // 消息弹窗
// //
const [registerTable, { reload, deleteData, exportList }] = useXTable({ const [registerTable, { reload, deleteData, exportList }] = useXTable({
allSchemas: allSchemas, allSchemas: allSchemas,
getListApi: ConfigApi.getConfigPage, getListApi: ConfigApi.getConfigPageApi,
deleteApi: ConfigApi.deleteConfig, deleteApi: ConfigApi.deleteConfigApi,
exportListApi: ConfigApi.exportConfigApi exportListApi: ConfigApi.exportConfigApi
}) })
@ -127,6 +127,14 @@ const handleCreate = async () => {
}, },
2 2
) )
unref(formRef)?.addSchema(
{
field: 'value',
label: '参数键值',
component: 'Input'
},
3
)
} }
} }
@ -134,15 +142,17 @@ const handleCreate = async () => {
const handleUpdate = async (rowId: number) => { const handleUpdate = async (rowId: number) => {
setDialogTile('update') setDialogTile('update')
// //
const res = await ConfigApi.getConfig(rowId) const res = await ConfigApi.getConfigApi(rowId)
unref(formRef)?.delSchema('key') unref(formRef)?.delSchema('key')
unref(formRef)?.delSchema('value')
unref(formRef)?.setValues(res) unref(formRef)?.setValues(res)
} }
// //
const handleDetail = async (rowId: number) => { const handleDetail = async (rowId: number) => {
setDialogTile('detail') setDialogTile('detail')
const res = await ConfigApi.getConfig(rowId) const res = await ConfigApi.getConfigApi(rowId)
detailData.value = res detailData.value = res
} }
@ -157,10 +167,10 @@ const submitForm = async () => {
try { try {
const data = unref(formRef)?.formModel as ConfigApi.ConfigVO const data = unref(formRef)?.formModel as ConfigApi.ConfigVO
if (actionType.value === 'create') { if (actionType.value === 'create') {
await ConfigApi.createConfig(data) await ConfigApi.createConfigApi(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await ConfigApi.updateConfig(data) await ConfigApi.updateConfigApi(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
dialogVisible.value = false dialogVisible.value = false

View File

@ -59,7 +59,6 @@
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-success="handleFileSuccess" :on-success="handleFileSuccess"
:on-error="excelUploadError" :on-error="excelUploadError"
:on-change="handleFileChange"
:before-remove="beforeRemove" :before-remove="beforeRemove"
:auto-upload="false" :auto-upload="false"
accept=".jpg, .png, .gif" accept=".jpg, .png, .gif"
@ -84,7 +83,7 @@
</XModal> </XModal>
</template> </template>
<script setup lang="ts" name="FileList"> <script setup lang="ts" name="FileList">
import type { UploadInstance, UploadRawFile, UploadProps, UploadFile } from 'element-plus' import type { UploadInstance, UploadRawFile, UploadProps } from 'element-plus'
// import // import
import { allSchemas } from './fileList.data' import { allSchemas } from './fileList.data'
import * as FileApi from '@/api/infra/fileList' import * as FileApi from '@/api/infra/fileList'
@ -120,11 +119,9 @@ const beforeUpload = (file: UploadRawFile) => {
return isImg && isLt5M return isImg && isLt5M
} }
// //
const handleFileChange = (uploadFile: UploadFile): void => { // const handleFileChange = (uploadFile: UploadFile): void => {
// uploadRef.value.data.path = uploadFile.name // uploadRef.value.data.path = uploadFile.name
console.log(uploadFile, 'uploadFile') // }
uploadDisabled.value = false
}
// //
const submitFileForm = () => { const submitFileForm = () => {
uploadHeaders.value = { uploadHeaders.value = {
@ -151,12 +148,10 @@ const beforeRemove: UploadProps['beforeRemove'] = () => {
// //
const handleExceed = (): void => { const handleExceed = (): void => {
message.error('最多只能上传一个文件!') message.error('最多只能上传一个文件!')
uploadDisabled.value = false
} }
// //
const excelUploadError = (): void => { const excelUploadError = (): void => {
message.error('导入数据失败,请您重新上传!') message.error('导入数据失败,请您重新上传!')
uploadDisabled.value = false
} }
// //
@ -169,26 +164,14 @@ const handleDetail = (row: FileApi.FileVO) => {
// ========== ========== // ========== ==========
const handleCopy = async (text: string) => { const handleCopy = async (text: string) => {
let url = text const { copy, copied, isSupported } = useClipboard({ source: text })
let oInput = document.createElement('textarea') if (!isSupported) {
oInput.value = url message.error(t('common.copyError'))
document.body.appendChild(oInput) } else {
oInput.select() // ; await copy()
// console.log(oInput.value) if (unref(copied)) {
document.execCommand('Copy') //
message.success(t('common.copySuccess')) message.success(t('common.copySuccess'))
oInput.remove() }
// const { copy, copied, isSupported } = useClipboard({ source: text, read: true }) }
// console.log(copy, 'copycopycopy')
// console.log(copied, 'copiedcopiedcopied')
// console.log(isSupported, 'isSupportedisSupportedisSupported')
// if (!isSupported.value) {
// message.error(t('common.copyError'))
// } else {
// await copy()
// if (unref(copied.value)) {
// message.success(t('common.copySuccess'))
// }
// }
} }
</script> </script>

View File

@ -1,77 +1,179 @@
<template> <template>
<ContentWrap> <content-wrap>
<!-- 列表 --> <!-- 搜索栏 -->
<XTable @register="registerTable"> <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="120px">
<template #toolbar_buttons> <el-form-item label="处理器的名字" prop="handlerName">
<XButton <el-input
type="warning" v-model="queryParams.handlerName"
preIcon="ep:download" placeholder="请输入处理器的名字"
:title="t('action.export')" clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="开始执行时间" prop="beginTime">
<el-date-picker
clearable
v-model="queryParams.beginTime"
type="date"
value-format="YYYY-MM-DD"
placeholder="选择开始执行时间"
/>
</el-form-item>
<el-form-item label="结束执行时间" prop="endTime">
<el-date-picker
clearable
v-model="queryParams.endTime"
type="date"
value-format="YYYY-MM-DD"
placeholder="选择结束执行时间"
/>
</el-form-item>
<el-form-item label="任务状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.INFRA_JOB_LOG_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['infra:job:export']" v-hasPermi="['infra:job:export']"
@click="exportList('定时任务详情.xls')" >
/> <Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="list">
<el-table-column label="日志编号" align="center" prop="id" />
<el-table-column label="任务编号" align="center" prop="jobId" />
<el-table-column label="处理器的名字" align="center" prop="handlerName" />
<el-table-column label="处理器的参数" align="center" prop="handlerParam" />
<el-table-column label="第几次执行" align="center" prop="executeIndex" />
<el-table-column label="执行时间" align="center" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.beginTime) + ' ~ ' + parseTime(scope.row.endTime) }}</span>
</template> </template>
<template #beginTime_default="{ row }"> </el-table-column>
<span>{{ <el-table-column label="执行时长" align="center" prop="duration">
dayjs(row.beginTime).format('YYYY-MM-DD HH:mm:ss') + <template #default="scope">
' ~ ' + <span>{{ scope.row.duration + ' 毫秒' }}</span>
dayjs(row.endTime).format('YYYY-MM-DD HH:mm:ss')
}}</span>
</template> </template>
<template #duration_default="{ row }"> </el-table-column>
<span>{{ row.duration + ' 毫秒' }}</span> <el-table-column label="任务状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="scope.row.status" />
</template> </template>
<template #actionbtns_default="{ row }"> </el-table-column>
<XTextButton <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
preIcon="ep:view" <template #default="scope">
:title="t('action.detail')" <el-button
link
icon="el-icon-view"
@click="handleView(scope.row.id)"
:loading="exportLoading"
v-hasPermi="['infra:job:query']" v-hasPermi="['infra:job:query']"
@click="handleDetail(row)" >详细
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/> />
</content-wrap>
<!-- 表单弹窗查看 -->
<log-view ref="viewModalRef" @success="getList" />
</template> </template>
</XTable>
</ContentWrap>
<XModal v-model="dialogVisible" :title="dialogTitle">
<!-- 对话框(详情) -->
<Descriptions :schema="allSchemas.detailSchema" :data="detailData">
<template #retryInterval="{ row }">
<span>{{ row.retryInterval + '毫秒' }} </span>
</template>
<template #monitorTimeout="{ row }">
<span>{{ row.monitorTimeout > 0 ? row.monitorTimeout + ' 毫秒' : '未开启' }}</span>
</template>
</Descriptions>
<!-- 操作按钮 -->
<template #footer>
<XButton :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</template>
<script setup lang="ts" name="JobLog"> <script setup lang="ts" name="JobLog">
import dayjs from 'dayjs' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import download from '@/utils/download'
import LogView from './JobLogView.vue'
import * as JobLogApi from '@/api/infra/jobLog' import * as JobLogApi from '@/api/infra/jobLog'
import { allSchemas } from './jobLog.data' import { parseTime } from './utils'
const { t } = useI18n() // const message = useMessage() //
//
const [registerTable, { exportList }] = useXTable({ const loading = ref(true) //
allSchemas: allSchemas, const total = ref(0) //
getListApi: JobLogApi.getJobLogPageApi, const list = ref([]) //
exportListApi: JobLogApi.exportJobLogApi const queryParams = reactive({
pageNo: 1,
pageSize: 10,
handlerName: undefined,
beginTime: undefined,
endTime: undefined,
status: undefined
}) })
// ========== CRUD ========== const queryFormRef = ref() //
const dialogVisible = ref(false) // const exportLoading = ref(false) //
const dialogTitle = ref('') //
// ========== ========== /** 查询参数列表 */
const detailData = ref() // Ref const getList = async () => {
loading.value = true
// try {
const handleDetail = async (row: JobLogApi.JobLogVO) => { const data = await JobLogApi.getJobLogPageApi({
// ...queryParams,
const res = await JobLogApi.getJobLogApi(row.id) beginTime: queryParams.beginTime ? queryParams.beginTime + ' 00:00:00' : undefined,
detailData.value = res endTime: queryParams.endTime ? queryParams.endTime + ' 23:59:59' : undefined
dialogTitle.value = t('action.detail') })
dialogVisible.value = true list.value = data.list
total.value = data.total
} finally {
loading.value = false
} }
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 查看操作 */
const viewModalRef = ref()
const handleView = (rowId?: number) => {
viewModalRef.value.openModal(rowId)
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await JobLogApi.exportJobLogApi(queryParams)
download.excel(data, '定时任务执行日志.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script> </script>

View File

@ -0,0 +1,74 @@
<template>
<!-- 调度日志详细 -->
<Dialog title="调度日志详细" v-model="modelVisible" width="700px" append-to-body>
<el-form ref="form" :model="formData" label-width="120px" size="mini">
<el-row>
<el-col :span="12">
<el-form-item label="日志编号:">{{ formData.id }}</el-form-item>
<el-form-item label="任务编号:">{{ formData.jobId }}</el-form-item>
<el-form-item label="处理器的名字:">{{ formData.handlerName }}</el-form-item>
<el-form-item label="处理器的参数:">{{ formData.handlerParam }}</el-form-item>
<el-form-item label="第几次执行:">{{ formData.executeIndex }}</el-form-item>
<el-form-item label="执行时间:">{{
parseTime(formData.beginTime) + ' ~ ' + parseTime(formData.endTime)
}}</el-form-item>
<el-form-item label="执行时长:">{{ formData.duration + ' 毫秒' }}</el-form-item>
<el-form-item label="任务状态:">
<dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="formData.status" />
</el-form-item>
<el-form-item label="执行结果:">{{ formData.result }}</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="close"> </el-button>
</div>
</template>
</Dialog>
</template>
<script setup lang="ts" name="JobView">
import * as JobLogApi from '@/api/infra/jobLog'
import { DICT_TYPE } from '@/utils/dict'
import { parseTime } from './utils'
const emit = defineEmits(['success']) // success
const { t } = useI18n() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined,
jobId: undefined,
handlerParam: '',
handlerName: '',
executeIndex: '',
beginTime: undefined,
endTime: undefined,
duration: true,
result: '',
status: undefined
})
/** 打开弹窗 */
const openModal = async (id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.detail')
//
if (id) {
formLoading.value = true
try {
formData.value = await JobLogApi.getJobLogApi(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
const close = () => {
emit('success')
}
</script>

View File

@ -0,0 +1,172 @@
<template>
<!-- 添加或修改定时任务对话框 -->
<Dialog :title="modelTitle" v-model="modelVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="120px"
v-loading="formLoading"
>
<el-form-item label="任务名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入任务名称" />
</el-form-item>
<el-form-item label="处理器的名字" prop="handlerName">
<el-input
:readonly="formData.id !== undefined"
v-model="formData.handlerName"
placeholder="请输入处理器的名字"
/>
</el-form-item>
<el-form-item label="处理器的参数" prop="handlerParam">
<el-input v-model="formData.handlerParam" placeholder="请输入处理器的参数" />
</el-form-item>
<el-form-item label="CRON 表达式" prop="cronExpression">
<el-input v-model="formData.cronExpression" placeholder="请输入CRON 表达式">
<template #append>
<el-button type="primary" @click="handleShowCron">
生成表达式
<i class="el-icon-time el-icon--right"></i>
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item label="重试次数" prop="retryCount">
<el-input
v-model="formData.retryCount"
placeholder="请输入重试次数。设置为 0 时,不进行重试"
/>
</el-form-item>
<el-form-item label="重试间隔" prop="retryInterval">
<el-input
v-model="formData.retryInterval"
placeholder="请输入重试间隔,单位:毫秒。设置为 0 时,无需间隔"
/>
</el-form-item>
<el-form-item label="监控超时时间" prop="monitorTimeout">
<el-input v-model="formData.monitorTimeout" placeholder="请输入监控超时时间,单位:毫秒" />
</el-form-item>
</el-form>
<!-- 操作按钮 -->
<template #footer>
<!-- 按钮保存 -->
<div class="dialog-footer">
<el-button type="primary" @click="submitForm" :loading="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</div>
</template>
</Dialog>
<el-dialog
title="Cron表达式生成器"
v-model="openCron"
append-to-body
class="scrollbar"
destroy-on-close
>
<crontab @hide="openCron = false" @fill="crontabFill" :expression="expression" />
</el-dialog>
</template>
<script setup lang="ts" name="JobForm">
import * as JobApi from '@/api/infra/job'
const emit = defineEmits(['success', 'crontabFill']) // success
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const defaultFormData = {
id: undefined,
name: '',
status: 0,
handlerName: '',
handlerParam: '',
cronExpression: '',
retryCount: 0,
retryInterval: 0,
monitorTimeout: 0,
createTime: new Date()
}
const formData = ref({ ...defaultFormData })
// Cron
const openCron = ref(false)
//
const expression = ref('')
//
const formRules = reactive({
name: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
handlerName: [{ required: true, message: '处理器的名字不能为空', trigger: 'blur' }],
cronExpression: [{ required: true, message: 'CRON 表达式不能为空', trigger: 'blur' }],
retryCount: [{ required: true, message: '重试次数不能为空', trigger: 'blur' }],
retryInterval: [{ required: true, message: '重试间隔不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const openModal = async (type: string, id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await JobApi.getJobApi(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
/** cron表达式按钮操作 */
const handleShowCron = () => {
console.info(123333333333)
expression.value = formData.value.cronExpression
openCron.value = true
}
// cron
const crontabFill = (expression: string) => {
formData.value.cronExpression = expression
emit('crontabFill', expression)
}
//
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as unknown as JobApi.JobVO
if (formType.value === 'create') {
await JobApi.createJobApi(data)
message.success(t('common.createSuccess'))
} else {
await JobApi.updateJobApi(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
...defaultFormData
}
formRef.value?.resetFields()
}
</script>

View File

@ -1,243 +1,175 @@
<template> <template>
<ContentWrap> <content-wrap>
<!-- 列表 --> <!-- 搜索栏 -->
<XTable @register="registerTable"> <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
<template #toolbar_buttons> <el-form-item label="任务名称" prop="name">
<!-- 操作新增 --> <el-input
<XButton v-model="queryParams.name"
placeholder="请输入任务名称"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="任务状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.INFRA_JOB_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="处理器的名字" prop="handlerName">
<el-input
v-model="queryParams.handlerName"
placeholder="请输入处理器的名字"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary" type="primary"
preIcon="ep:zoom-in" plain
:title="t('action.add')" @click="openModal('create')"
v-hasPermi="['infra:job:create']" v-hasPermi="['infra:job:create']"
@click="handleCreate()" >
/> <Icon icon="ep:plus" class="mr-5px" /> 新增
<!-- 操作导出 --> </el-button>
<XButton <el-button
type="warning" type="success"
preIcon="ep:download" plain
:title="t('action.export')" @click="handleExport"
:loading="exportLoading"
v-hasPermi="['infra:job:export']" v-hasPermi="['infra:job:export']"
@click="exportList('定时任务.xls')" >
/> <Icon icon="ep:download" class="mr-5px" /> 导出
<XButton </el-button>
type="info"
preIcon="ep:zoom-in" <el-button type="info" plain @click="handleJobLog" v-hasPermi="['infra:job:query']">
title="执行日志" <Icon icon="ep:zoom-in" class="mr-5px" /> 执行日志
v-hasPermi="['infra:job:query']" </el-button>
@click="handleJobLog()" </el-form-item>
/> </el-form>
</template>
<template #actionbtns_default="{ row }"> <el-table v-loading="loading" :data="list">
<!-- 操作修改 --> <el-table-column label="任务编号" align="center" prop="id" />
<XTextButton <el-table-column label="任务名称" align="center" prop="name" />
preIcon="ep:edit" <el-table-column label="任务状态" align="center" prop="status">
:title="t('action.edit')" <template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_JOB_STATUS" :value="scope.row.status" />
</template> </el-table-column
>>
<el-table-column label="处理器的名字" align="center" prop="handlerName" />
<el-table-column label="处理器的参数" align="center" prop="handlerParam" />
<el-table-column label="CRON 表达式" align="center" prop="cronExpression" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
link
icon="el-icon-edit"
@click="openModal('update', scope.row.id)"
v-hasPermi="['infra:job:update']" v-hasPermi="['infra:job:update']"
@click="handleUpdate(row.id)" >修改</el-button
/> >
<XTextButton <el-button
preIcon="ep:edit" link
:title="row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停'" icon="el-icon-check"
@click="handleChangeStatus(scope.row)"
v-hasPermi="['infra:job:update']" v-hasPermi="['infra:job:update']"
@click="handleChangeStatus(row)" >{{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}</el-button
/> >
<!-- 操作删除 --> <el-button
<XTextButton link
preIcon="ep:delete" icon="el-icon-delete"
:title="t('action.del')" @click="handleDelete(scope.row)"
v-hasPermi="['infra:job:delete']" v-hasPermi="['infra:job:delete']"
@click="deleteData(row.id)" >删除</el-button
/> >
<el-dropdown class="p-0.5" v-hasPermi="['infra:job:trigger', 'infra:job:query']"> <el-dropdown
<XTextButton :title="t('action.more')" postIcon="ep:arrow-down" /> class="mt-1"
:teleported="true"
@command="(command) => handleCommand(command, scope.row)"
v-hasPermi="['infra:job:trigger', 'infra:job:query']"
>
<el-button link icon="el-icon-d-arrow-right">更多</el-button>
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item> <el-dropdown-item command="handleRun" v-if="hasPermi(['infra:job:trigger'])">
<!-- 操作执行 --> 执行一次
<XTextButton
preIcon="ep:view"
title="执行一次"
v-hasPermi="['infra:job:trigger']"
@click="handleRun(row)"
/>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item command="handleView" v-if="hasPermi(['infra:job:query'])">
<!-- 操作详情 --> 任务详细
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['infra:job:query']"
@click="handleDetail(row.id)"
/>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item command="handleJobLog" v-if="hasPermi(['infra:job:query'])">
<!-- 操作日志 --> 调度日志
<XTextButton
preIcon="ep:view"
title="调度日志"
v-hasPermi="['infra:job:query']"
@click="handleJobLog(row.id)"
/>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
</el-dropdown> </el-dropdown>
</template> </template>
</XTable> </el-table-column>
</ContentWrap> </el-table>
<XModal v-model="dialogVisible" :title="dialogTitle"> <!-- 分页组件 -->
<!-- 对话框(添加 / 修改) --> <pagination
<Form v-show="total > 0"
v-if="['create', 'update'].includes(actionType)" :total="total"
:schema="allSchemas.formSchema" v-model:page="queryParams.pageNo"
:rules="rules" v-model:limit="queryParams.pageSize"
ref="formRef" @pagination="getList"
>
<template #cronExpression="form">
<Crontab v-model="form['cronExpression']" :shortcuts="shortcuts" />
</template>
</Form>
<!-- 对话框(详情) -->
<Descriptions
v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema"
:data="detailData"
>
<template #retryInterval="{ row }">
<span>{{ row.retryInterval + '毫秒' }} </span>
</template>
<template #monitorTimeout="{ row }">
<span>{{ row.monitorTimeout > 0 ? row.monitorTimeout + ' 毫秒' : '未开启' }}</span>
</template>
<template #nextTimes>
<span>{{ Array.from(nextTimes, (x) => parseTime(x)).join('; ') }}</span>
</template>
</Descriptions>
<!-- 操作按钮 -->
<template #footer>
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitForm()"
/> />
<!-- 按钮关闭 --> </content-wrap>
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template> <!-- 表单弹窗添加/修改 -->
</XModal> <job-form ref="modalRef" @success="getList" />
<!-- 表单弹窗查看 -->
<job-view ref="viewModalRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="Job"> <script setup lang="ts" name="Job">
import type { FormExpose } from '@/components/Form' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import JobForm from './form.vue'
import JobView from './view.vue'
import download from '@/utils/download'
import * as JobApi from '@/api/infra/job' import * as JobApi from '@/api/infra/job'
import { rules, allSchemas } from './job.data'
import { InfraJobStatusEnum } from '@/utils/constants' import { InfraJobStatusEnum } from '@/utils/constants'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const { push } = useRouter() const { push } = useRouter()
// const loading = ref(true) //
const [registerTable, { reload, deleteData, exportList }] = useXTable({ const total = ref(0) //
allSchemas: allSchemas, const list = ref([]) //
getListApi: JobApi.getJobPageApi, const queryParams = reactive({
deleteApi: JobApi.deleteJobApi, pageNo: 1,
exportListApi: JobApi.exportJobApi pageSize: 10,
name: undefined,
status: undefined,
handlerName: undefined
}) })
const queryFormRef = ref() //
const exportLoading = ref(false) //
// ========== CRUD ========== /** 查询参数列表 */
const actionLoading = ref(false) // const getList = async () => {
const actionType = ref('') // loading.value = true
const dialogVisible = ref(false) // try {
const dialogTitle = ref('edit') // const data = await JobApi.getJobPageApi(queryParams)
const formRef = ref<FormExpose>() // Ref list.value = data.list
const detailData = ref() // Ref total.value = data.total
const nextTimes = ref([]) } finally {
const shortcuts = ref([ loading.value = false
{
text: '每天8点和12点 (自定义追加)',
value: '0 0 8,12 * * ?'
} }
])
//
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
//
const handleCreate = () => {
setDialogTile('create')
}
//
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await JobApi.getJobApi(rowId)
unref(formRef)?.setValues(res)
}
//
const handleDetail = async (rowId: number) => {
//
const res = await JobApi.getJobApi(rowId)
detailData.value = res
//
const jobNextTime = await JobApi.getJobNextTimesApi(rowId)
nextTimes.value = jobNextTime
setDialogTile('detail')
}
const parseTime = (time) => {
if (!time) {
return null
}
const format = '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time
.replace(new RegExp(/-/gm), '/')
.replace('T', ' ')
.replace(new RegExp(/\.[\d]{3}/gm), '')
}
if (typeof time === 'number' && time.toString().length === 10) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
} }
const handleChangeStatus = async (row: JobApi.JobVO) => { const handleChangeStatus = async (row: JobApi.JobVO) => {
const text = row.status === InfraJobStatusEnum.STOP ? '开启' : '关闭' const text = row.status === InfraJobStatusEnum.STOP ? '开启' : '关闭'
const status = const status =
row.status === InfraJobStatusEnum.STOP ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP row.status === InfraJobStatusEnum.STOP ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP
message message
@ -249,7 +181,7 @@ const handleChangeStatus = async (row: JobApi.JobVO) => {
: InfraJobStatusEnum.STOP : InfraJobStatusEnum.STOP
await JobApi.updateJobStatusApi(row.id, status) await JobApi.updateJobStatusApi(row.id, status)
message.success(text + '成功') message.success(text + '成功')
await reload() await getList()
}) })
.catch(() => { .catch(() => {
row.status = row.status =
@ -258,6 +190,43 @@ const handleChangeStatus = async (row: JobApi.JobVO) => {
: InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.NORMAL
}) })
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const modalRef = ref()
const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await JobApi.deleteJobApi(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 查看操作 */
const viewModalRef = ref()
const handleView = (rowId?: number) => {
viewModalRef.value.openModal(rowId)
}
// //
const handleJobLog = (rowId?: number) => { const handleJobLog = (rowId?: number) => {
if (rowId) { if (rowId) {
@ -271,32 +240,61 @@ const handleRun = (row: JobApi.JobVO) => {
message.confirm('确认要立即执行一次' + row.name + '?', t('common.reminder')).then(async () => { message.confirm('确认要立即执行一次' + row.name + '?', t('common.reminder')).then(async () => {
await JobApi.runJobApi(row.id) await JobApi.runJobApi(row.id)
message.success('执行成功') message.success('执行成功')
await reload() await getList()
}) })
} }
//
const submitForm = async () => { /** '更多'操作按钮 */
const elForm = unref(formRef)?.getElFormRef() const handleCommand = (command, row) => {
if (!elForm) return switch (command) {
elForm.validate(async (valid) => { case 'handleRun':
if (valid) { handleRun(row)
actionLoading.value = true break
// case 'handleView':
handleView(row?.id)
break
case 'handleJobLog':
handleJobLog(row?.id)
break
default:
break
}
}
/** 导出按钮操作 */
const handleExport = async () => {
try { try {
const data = unref(formRef)?.formModel as JobApi.JobVO //
if (actionType.value === 'create') { await message.exportConfirm()
await JobApi.createJobApi(data) //
message.success(t('common.createSuccess')) exportLoading.value = true
} else { const data = await JobApi.exportJobApi(queryParams)
await JobApi.updateJobApi(data) download.excel(data, '定时任务.xls')
message.success(t('common.updateSuccess')) } catch {
}
dialogVisible.value = false
} finally { } finally {
actionLoading.value = false exportLoading.value = false
await reload()
} }
} }
// dropdown v-hasPermiwaringv-if
const hasPermi = (permiKeys: string[]) => {
const { wsCache } = useCache()
const all_permission = '*:*:*'
const permissions = wsCache.get(CACHE_KEY.USER).permissions
if (permiKeys && permiKeys instanceof Array && permiKeys.length > 0) {
const permissionFlag = permiKeys
const hasPermissions = permissions.some((permission: string) => {
return all_permission === permission || permissionFlag.includes(permission)
}) })
return hasPermissions
} }
return false
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script> </script>

View File

@ -1,70 +0,0 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
export const rules = reactive({
name: [required],
handlerName: [required],
cronExpression: [required],
retryCount: [required],
retryInterval: [required]
})
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'id',
primaryTitle: '任务编号',
action: true,
actionWidth: '280px',
columns: [
{
title: '任务名称',
field: 'name',
isSearch: true
},
{
title: t('common.status'),
field: 'status',
dictType: DICT_TYPE.INFRA_JOB_STATUS,
dictClass: 'number',
isForm: false,
isSearch: true
},
{
title: '处理器的名字',
field: 'handlerName',
isSearch: true
},
{
title: '处理器的参数',
field: 'handlerParam',
isTable: false
},
{
title: 'CRON 表达式',
field: 'cronExpression'
},
{
title: '后续执行时间',
field: 'nextTimes',
isTable: false,
isForm: false
},
{
title: '重试次数',
field: 'retryCount',
isTable: false
},
{
title: '重试间隔',
field: 'retryInterval',
isTable: false
},
{
title: '监控超时时间',
field: 'monitorTimeout',
isTable: false
}
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)

View File

@ -1,76 +0,0 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
// 国际化
const { t } = useI18n()
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'id',
primaryTitle: '日志编号',
action: true,
columns: [
{
title: '任务编号',
field: 'jobId',
isSearch: true
},
{
title: '处理器的名字',
field: 'handlerName',
isSearch: true
},
{
title: '处理器的参数',
field: 'handlerParam'
},
{
title: '第几次执行',
field: 'executeIndex'
},
{
title: '开始执行时间',
field: 'beginTime',
formatter: 'formatDate',
table: {
slots: {
default: 'beginTime_default'
}
},
search: {
show: true,
itemRender: {
name: 'XDataPicker'
}
}
},
{
title: '结束执行时间',
field: 'endTime',
formatter: 'formatDate',
isTable: false,
search: {
show: true,
itemRender: {
name: 'XDataPicker'
}
}
},
{
title: '执行时长',
field: 'duration',
table: {
slots: {
default: 'duration_default'
}
}
},
{
title: t('common.status'),
field: 'status',
dictType: DICT_TYPE.INFRA_JOB_LOG_STATUS,
dictClass: 'number',
isSearch: true
}
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)

View File

@ -0,0 +1,44 @@
export const parseTime = (time) => {
if (!time) {
return null
}
const format = '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time
.replace(new RegExp(/-/gm), '/')
.replace('T', ' ')
.replace(new RegExp(/\.[\d]{3}/gm), '')
}
if (typeof time === 'number' && time.toString().length === 10) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}

View File

@ -0,0 +1,89 @@
<template>
<!-- 任务详细 -->
<Dialog title="任务详细" v-model="modelVisible" width="700px" append-to-body>
<el-form ref="formRef" :model="formData" label-width="200px">
<el-row>
<el-col :span="24">
<el-form-item label="任务编号:">{{ formData.id }}</el-form-item>
<el-form-item label="任务名称:">{{ formData.name }}</el-form-item>
<el-form-item label="任务名称:">
<dict-tag :type="DICT_TYPE.INFRA_JOB_STATUS" :value="formData.status" />
</el-form-item>
<el-form-item label="处理器的名字:">{{ formData.handlerName }}</el-form-item>
<el-form-item label="处理器的参数:">{{ formData.handlerParam }}</el-form-item>
<el-form-item label="cron表达式">{{ formData.cronExpression }}</el-form-item>
<el-form-item label="重试次数:">{{ formData.retryCount }}</el-form-item>
<el-form-item label="重试间隔:">{{ formData.retryInterval + ' 毫秒' }}</el-form-item>
<el-form-item label="监控超时时间:">{{
formData.monitorTimeout > 0 ? formData.monitorTimeout + ' 毫秒' : '未开启'
}}</el-form-item>
<el-form-item label="后续执行时间:">
<el-timeline class="pt-3">
<el-timeline-item
v-for="(activity, index) in nextTimes"
:key="index"
:timestamp="parseTime(activity)"
>
{{ index + 1 }}
</el-timeline-item>
</el-timeline>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="close"> </el-button>
</div>
</template>
</Dialog>
</template>
<script setup lang="ts" name="JobView">
import * as JobApi from '@/api/infra/job'
import { parseTime } from './utils'
import { DICT_TYPE } from '@/utils/dict'
const emit = defineEmits(['success']) // success
const { t } = useI18n() //
const formRef = ref() // Ref
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined,
name: '',
handlerParam: '',
handlerName: '',
cronExpression: '',
retryCount: true,
retryInterval: '',
monitorTimeout: 0,
status: 0
})
const nextTimes = ref([])
/** 打开弹窗 */
const openModal = async (id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.detail')
//
if (id) {
formLoading.value = true
try {
formData.value = await JobApi.getJobApi(id)
//
nextTimes.value = await JobApi.getJobNextTimesApi(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
const close = () => {
modelVisible.value = false
emit('success')
}
</script>

View File

@ -1,148 +1,159 @@
<template> <template>
<ContentWrap> <content-wrap>
<!-- 列表 --> <!-- 搜索工作栏 -->
<XTable @register="registerTable"> <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
<!-- 操作新增 --> <el-form-item label="公告标题" prop="title">
<template #toolbar_buttons> <el-input
<XButton v-model="queryParams.title"
placeholder="请输入公告标题"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="公告状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择公告状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)"
:label="dict.label"
:value="parseInt(dict.value)"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary" type="primary"
preIcon="ep:zoom-in" @click="openModal('create')"
:title="t('action.add')"
v-hasPermi="['system:notice:create']" v-hasPermi="['system:notice:create']"
@click="handleCreate()"
/>
</template>
<template #actionbtns_default="{ row }">
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:notice:update']"
@click="handleUpdate(row.id)"
/>
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['system:notice:query']"
@click="handleDetail(row.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['system:notice:delete']"
@click="deleteData(row.id)"
/>
</template>
</XTable>
</ContentWrap>
<!-- 弹窗 -->
<XModal id="noticeModel" v-model="dialogVisible" :title="dialogTitle">
<!-- 对话框(添加 / 修改) -->
<Form
ref="formRef"
v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema"
:rules="rules"
/>
<!-- 对话框(详情) -->
<Descriptions
v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema"
:data="detailData"
> >
<template #content="{ row }"> <Icon icon="ep:plus" class="mr-5px" /> 新增
<Editor :model-value="row.content" :readonly="true" /> </el-button>
</el-form-item>
</el-form>
<!-- 列表 -->
<el-table v-loading="loading" :data="list" align="center">
<el-table-column label="公告编号" align="center" prop="id" />
<el-table-column label="公告标题" align="center" prop="title" />
<el-table-column label="公告类型" align="center" prop="type">
<template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="scope.row.type" />
</template> </template>
</Descriptions> </el-table-column>
<template #footer> <el-table-column label="状态" align="center" prop="status">
<!-- 按钮保存 --> <template #default="scope">
<XButton <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
v-if="['create', 'update'].includes(actionType)" </template>
type="primary" </el-table-column>
:title="t('action.save')" <el-table-column
:loading="actionLoading" label="创建时间"
@click="submitForm()" align="center"
prop="createTime"
width="180"
:formatter="dateFormatter"
/> />
<!-- 按钮关闭 --> <el-table-column label="操作" align="center">
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" /> <template #default="scope">
<el-button
link
type="primary"
@click="openModal('update', scope.row.id)"
v-hasPermi="['system:notice:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['system:notice:delete']"
>
删除
</el-button>
</template> </template>
</XModal> </el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</content-wrap>
<!-- 表单弹窗添加/修改 -->
<notice-form ref="modalRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="Notice"> <script setup lang="tsx">
import type { FormExpose } from '@/components/Form' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
// import import { dateFormatter } from '@/utils/formatTime'
import * as NoticeApi from '@/api/system/notice' import * as NoticeApi from '@/api/system/notice'
import { rules, allSchemas } from './notice.data' import { DictTag } from '@/components/DictTag'
import NoticeForm from './form.vue'
const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
// const { t } = useI18n() //
const [registerTable, { reload, deleteData }] = useXTable({
allSchemas: allSchemas, const loading = ref(true) //
getListApi: NoticeApi.getNoticePageApi, const total = ref(0) //
deleteApi: NoticeApi.deleteNoticeApi const list = ref([]) //
const queryParams = reactive({
title: '',
type: undefined,
status: undefined,
pageNo: 1,
pageSize: 100
}) })
// const queryFormRef = ref() //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const actionType = ref('') //
const actionLoading = ref(false) // Loading
const formRef = ref<FormExpose>() // Ref
const detailData = ref() // Ref
// /** 查询公告列表 */
const setDialogTile = (type: string) => { const getList = async () => {
dialogTitle.value = t('action.' + type) loading.value = true
actionType.value = type
dialogVisible.value = true
}
//
const handleCreate = () => {
setDialogTile('create')
}
//
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await NoticeApi.getNoticeApi(rowId)
unref(formRef)?.setValues(res)
}
//
const handleDetail = async (rowId: number) => {
setDialogTile('detail')
//
const res = await NoticeApi.getNoticeApi(rowId)
detailData.value = res
}
// /
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true
//
try { try {
const data = unref(formRef)?.formModel as NoticeApi.NoticeVO const data = await NoticeApi.getNoticePage(queryParams)
if (actionType.value === 'create') {
await NoticeApi.createNoticeApi(data) list.value = data.list
message.success(t('common.createSuccess')) total.value = data.total
} else {
await NoticeApi.updateNoticeApi(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally { } finally {
actionLoading.value = false loading.value = false
await reload()
} }
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const modalRef = ref()
const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await NoticeApi.deleteNotice(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 初始化 **/
onMounted(() => {
getList()
}) })
}
</script> </script>

View File

@ -1,59 +0,0 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
export const rules = reactive({
title: [required],
type: [required]
})
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'seq',
action: true,
columns: [
{
title: '公告标题',
field: 'title',
isSearch: true
},
{
title: '公告类型',
field: 'type',
dictType: DICT_TYPE.SYSTEM_NOTICE_TYPE,
dictClass: 'number'
},
{
title: t('common.status'),
field: 'status',
dictType: DICT_TYPE.COMMON_STATUS,
dictClass: 'number',
isSearch: true
},
{
title: '公告内容',
field: 'content',
table: {
type: 'html'
},
form: {
component: 'Editor',
colProps: {
span: 24
},
componentProps: {
valueHtml: ''
}
},
isTable: false
},
{
title: t('common.createTime'),
field: 'createTime',
formatter: 'formatDate',
isForm: false
}
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)

View File

@ -28,7 +28,7 @@ export const rules = reactive({
} }
], ],
status: [required], status: [required],
postIds: [required], postIds: [{ required: true, message: '请选择岗位', trigger: ['blur', 'change'] }],
mobile: [ mobile: [
required, required,
{ {
@ -86,6 +86,11 @@ const crudSchemas = reactive<VxeCrudSchema>({
field: 'deptId', field: 'deptId',
isTable: false isTable: false
}, },
{
title: '岗位',
field: 'postIds',
isTable: false
},
{ {
title: t('common.status'), title: t('common.status'),
field: 'status', field: 'status',
@ -98,11 +103,6 @@ const crudSchemas = reactive<VxeCrudSchema>({
} }
} }
}, },
{
title: '岗位',
field: 'postIds',
isTable: false
},
{ {
title: '最后登录时间', title: '最后登录时间',
field: 'loginDate', field: 'loginDate',