!84 修改测试所提bug

Merge pull request !84 from 周建/master
This commit is contained in:
芋道源码 2023-04-01 14:45:06 +00:00 committed by Gitee
commit e94eb757a2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 730 additions and 992 deletions

3
.gitignore vendored
View File

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

View File

@ -133,15 +133,24 @@ const openModel = (title: string) => {
} }
/** 复制 **/ /** 复制 **/
const copy = async (text: string) => { const copy = async (text: string) => {
const { copy, copied, isSupported } = useClipboard({ source: text }) // const { copy, copied, isSupported } = useClipboard({ source: JSON.stringify(text) })
if (!isSupported) { // if (!isSupported.value) {
message.error(t('common.copyError')) // message.error(t('common.copyError'))
} else { // } else {
await copy() // await copy()
if (unref(copied)) { // if (unref(copied.value)) {
// 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,15 +77,24 @@ const showTemplate = () => {
/** 复制 **/ /** 复制 **/
const copy = async (text: string) => { const copy = async (text: string) => {
const { copy, copied, isSupported } = useClipboard({ source: text }) // const { copy, copied, isSupported } = useClipboard({ source: JSON.stringify(text) })
if (!isSupported) { // if (!isSupported.value) {
message.error(t('common.copyError')) // message.error(t('common.copyError'))
} else { // } else {
await copy() // await copy()
if (unref(copied)) { // if (unref(copied.value)) {
// 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) { if (!isSupported.value) {
message.error(t('common.copyError')) message.error(t('common.copyError'))
} else { } else {
await copy() await copy()
if (unref(copied)) { if (unref(copied.value)) {
message.success(t('common.copySuccess')) message.success(t('common.copySuccess'))
} }
} }

View File

@ -6,7 +6,8 @@ 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.getConfigPageApi, getListApi: ConfigApi.getConfigPage,
deleteApi: ConfigApi.deleteConfigApi, deleteApi: ConfigApi.deleteConfig,
exportListApi: ConfigApi.exportConfigApi exportListApi: ConfigApi.exportConfigApi
}) })
@ -127,14 +127,6 @@ const handleCreate = async () => {
}, },
2 2
) )
unref(formRef)?.addSchema(
{
field: 'value',
label: '参数键值',
component: 'Input'
},
3
)
} }
} }
@ -142,17 +134,15 @@ const handleCreate = async () => {
const handleUpdate = async (rowId: number) => { const handleUpdate = async (rowId: number) => {
setDialogTile('update') setDialogTile('update')
// //
const res = await ConfigApi.getConfigApi(rowId) const res = await ConfigApi.getConfig(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.getConfigApi(rowId) const res = await ConfigApi.getConfig(rowId)
detailData.value = res detailData.value = res
} }
@ -167,10 +157,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.createConfigApi(data) await ConfigApi.createConfig(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await ConfigApi.updateConfigApi(data) await ConfigApi.updateConfig(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
dialogVisible.value = false dialogVisible.value = false

View File

@ -59,6 +59,7 @@
: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"
@ -83,7 +84,7 @@
</XModal> </XModal>
</template> </template>
<script setup lang="ts" name="FileList"> <script setup lang="ts" name="FileList">
import type { UploadInstance, UploadRawFile, UploadProps } from 'element-plus' import type { UploadInstance, UploadRawFile, UploadProps, UploadFile } 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'
@ -119,9 +120,11 @@ 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 = {
@ -148,10 +151,12 @@ 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
} }
// //
@ -164,14 +169,26 @@ const handleDetail = (row: FileApi.FileVO) => {
// ========== ========== // ========== ==========
const handleCopy = async (text: string) => { const handleCopy = async (text: string) => {
const { copy, copied, isSupported } = useClipboard({ source: text }) let url = text
if (!isSupported) { let oInput = document.createElement('textarea')
message.error(t('common.copyError')) oInput.value = url
} else { document.body.appendChild(oInput)
await copy() oInput.select() // ;
if (unref(copied)) { // console.log(oInput.value)
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,179 +1,77 @@
<template> <template>
<content-wrap> <ContentWrap>
<!-- 搜索栏 --> <!-- 列表 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="120px"> <XTable @register="registerTable">
<el-form-item label="处理器的名字" prop="handlerName"> <template #toolbar_buttons>
<el-input <XButton
v-model="queryParams.handlerName" type="warning"
placeholder="请输入处理器的名字" preIcon="ep:download"
clearable :title="t('action.export')"
@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>
</el-table-column>
<el-table-column label="执行时长" align="center" prop="duration">
<template #default="scope">
<span>{{ scope.row.duration + ' 毫秒' }}</span>
</template>
</el-table-column>
<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>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
link
icon="el-icon-view"
@click="handleView(scope.row.id)"
:loading="exportLoading"
v-hasPermi="['infra:job:query']"
>详细
</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>
<template #beginTime_default="{ row }">
<span>{{
dayjs(row.beginTime).format('YYYY-MM-DD HH:mm:ss') +
' ~ ' +
dayjs(row.endTime).format('YYYY-MM-DD HH:mm:ss')
}}</span>
</template>
<template #duration_default="{ row }">
<span>{{ row.duration + ' 毫秒' }}</span>
</template>
<template #actionbtns_default="{ row }">
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['infra:job:query']"
@click="handleDetail(row)"
/>
</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 { DICT_TYPE, getDictOptions } from '@/utils/dict' import dayjs from 'dayjs'
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 { parseTime } from './utils' import { allSchemas } from './jobLog.data'
const message = useMessage() // const { t } = useI18n() //
//
const loading = ref(true) // const [registerTable, { exportList }] = useXTable({
const total = ref(0) // allSchemas: allSchemas,
const list = ref([]) // getListApi: JobLogApi.getJobLogPageApi,
const queryParams = reactive({ exportListApi: JobLogApi.exportJobLogApi
pageNo: 1,
pageSize: 10,
handlerName: undefined,
beginTime: undefined,
endTime: undefined,
status: undefined
}) })
const queryFormRef = ref() // // ========== CRUD ==========
const exportLoading = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('') //
/** 查询参数列表 */ // ========== ==========
const getList = async () => { const detailData = ref() // Ref
loading.value = true
try {
const data = await JobLogApi.getJobLogPageApi({
...queryParams,
beginTime: queryParams.beginTime ? queryParams.beginTime + ' 00:00:00' : undefined,
endTime: queryParams.endTime ? queryParams.endTime + ' 23:59:59' : undefined
})
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */ //
const handleQuery = () => { const handleDetail = async (row: JobLogApi.JobLogVO) => {
queryParams.pageNo = 1 //
getList() const res = await JobLogApi.getJobLogApi(row.id)
detailData.value = res
dialogTitle.value = t('action.detail')
dialogVisible.value = true
} }
/** 重置按钮操作 */
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

@ -1,74 +0,0 @@
<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

@ -1,172 +0,0 @@
<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,175 +1,243 @@
<template> <template>
<content-wrap> <ContentWrap>
<!-- 搜索栏 --> <!-- 列表 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px"> <XTable @register="registerTable">
<el-form-item label="任务名称" prop="name"> <template #toolbar_buttons>
<el-input <!-- 操作新增 -->
v-model="queryParams.name" <XButton
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"
plain preIcon="ep:zoom-in"
@click="openModal('create')" :title="t('action.add')"
v-hasPermi="['infra:job:create']" v-hasPermi="['infra:job:create']"
> @click="handleCreate()"
<Icon icon="ep:plus" class="mr-5px" /> 新增 />
</el-button> <!-- 操作导出 -->
<el-button <XButton
type="success" type="warning"
plain preIcon="ep:download"
@click="handleExport" :title="t('action.export')"
:loading="exportLoading"
v-hasPermi="['infra:job:export']" v-hasPermi="['infra:job:export']"
> @click="exportList('定时任务.xls')"
<Icon icon="ep:download" class="mr-5px" /> 导出 />
</el-button> <XButton
type="info"
<el-button type="info" plain @click="handleJobLog" v-hasPermi="['infra:job:query']"> preIcon="ep:zoom-in"
<Icon icon="ep:zoom-in" class="mr-5px" /> 执行日志 title="执行日志"
</el-button> v-hasPermi="['infra:job:query']"
</el-form-item> @click="handleJobLog()"
</el-form> />
</template>
<el-table v-loading="loading" :data="list"> <template #actionbtns_default="{ row }">
<el-table-column label="任务编号" align="center" prop="id" /> <!-- 操作修改 -->
<el-table-column label="任务名称" align="center" prop="name" /> <XTextButton
<el-table-column label="任务状态" align="center" prop="status"> preIcon="ep:edit"
<template #default="scope"> :title="t('action.edit')"
<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']"
>修改</el-button @click="handleUpdate(row.id)"
> />
<el-button <XTextButton
link preIcon="ep:edit"
icon="el-icon-check" :title="row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停'"
@click="handleChangeStatus(scope.row)"
v-hasPermi="['infra:job:update']" v-hasPermi="['infra:job:update']"
>{{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}</el-button @click="handleChangeStatus(row)"
> />
<el-button <!-- 操作删除 -->
link <XTextButton
icon="el-icon-delete" preIcon="ep:delete"
@click="handleDelete(scope.row)" :title="t('action.del')"
v-hasPermi="['infra:job:delete']" v-hasPermi="['infra:job:delete']"
>删除</el-button @click="deleteData(row.id)"
> />
<el-dropdown <el-dropdown class="p-0.5" v-hasPermi="['infra:job:trigger', 'infra:job:query']">
class="mt-1" <XTextButton :title="t('action.more')" postIcon="ep:arrow-down" />
: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 command="handleRun" v-if="hasPermi(['infra:job:trigger'])"> <el-dropdown-item>
执行一次 <!-- 操作执行 -->
<XTextButton
preIcon="ep:view"
title="执行一次"
v-hasPermi="['infra:job:trigger']"
@click="handleRun(row)"
/>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item command="handleView" v-if="hasPermi(['infra:job:query'])"> <el-dropdown-item>
任务详细 <!-- 操作详情 -->
<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 command="handleJobLog" v-if="hasPermi(['infra:job:query'])"> <el-dropdown-item>
调度日志 <!-- 操作日志 -->
<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>
</el-table-column> </XTable>
</el-table> </ContentWrap>
<!-- 分页组件 --> <XModal v-model="dialogVisible" :title="dialogTitle">
<pagination <!-- 对话框(添加 / 修改) -->
v-show="total > 0" <Form
:total="total" v-if="['create', 'update'].includes(actionType)"
v-model:page="queryParams.pageNo" :schema="allSchemas.formSchema"
v-model:limit="queryParams.pageSize" :rules="rules"
@pagination="getList" ref="formRef"
/> >
</content-wrap> <template #cronExpression="form">
<Crontab v-model="form['cronExpression']" :shortcuts="shortcuts" />
<!-- 表单弹窗添加/修改 --> </template>
<job-form ref="modalRef" @success="getList" /> </Form>
<!-- 表单弹窗查看 --> <!-- 对话框(详情) -->
<job-view ref="viewModalRef" @success="getList" /> <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()"
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</template> </template>
<script setup lang="ts" name="Job"> <script setup lang="ts" name="Job">
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import type { FormExpose } from '@/components/Form'
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 total = ref(0) // const [registerTable, { reload, deleteData, exportList }] = useXTable({
const list = ref([]) // allSchemas: allSchemas,
const queryParams = reactive({ getListApi: JobApi.getJobPageApi,
pageNo: 1, deleteApi: JobApi.deleteJobApi,
pageSize: 10, exportListApi: JobApi.exportJobApi
name: undefined,
status: undefined,
handlerName: undefined
}) })
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询参数列表 */ // ========== CRUD ==========
const getList = async () => { const actionLoading = ref(false) //
loading.value = true const actionType = ref('') //
try { const dialogVisible = ref(false) //
const data = await JobApi.getJobPageApi(queryParams) const dialogTitle = ref('edit') //
list.value = data.list const formRef = ref<FormExpose>() // Ref
total.value = data.total const detailData = ref() // Ref
} finally { const nextTimes = ref([])
loading.value = false const shortcuts = ref([
{
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
@ -181,7 +249,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 getList() await reload()
}) })
.catch(() => { .catch(() => {
row.status = row.status =
@ -190,43 +258,6 @@ 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) {
@ -240,61 +271,32 @@ 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 getList() await reload()
}) })
} }
//
/** '更多'操作按钮 */ const submitForm = async () => {
const handleCommand = (command, row) => { const elForm = unref(formRef)?.getElFormRef()
switch (command) { if (!elForm) return
case 'handleRun': elForm.validate(async (valid) => {
handleRun(row) if (valid) {
break actionLoading.value = true
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
await message.exportConfirm() if (actionType.value === 'create') {
// await JobApi.createJobApi(data)
exportLoading.value = true message.success(t('common.createSuccess'))
const data = await JobApi.exportJobApi(queryParams) } else {
download.excel(data, '定时任务.xls') await JobApi.updateJobApi(data)
} catch { message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally { } finally {
exportLoading.value = false actionLoading.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

@ -0,0 +1,70 @@
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

@ -0,0 +1,76 @@
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

@ -1,44 +0,0 @@
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

@ -1,89 +0,0 @@
<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,159 +1,148 @@
<template> <template>
<content-wrap> <ContentWrap>
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
<el-form-item label="公告标题" prop="title">
<el-input
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"
@click="openModal('create')"
v-hasPermi="['system:notice:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
</el-form-item>
</el-form>
<!-- 列表 --> <!-- 列表 -->
<el-table v-loading="loading" :data="list" align="center"> <XTable @register="registerTable">
<el-table-column label="公告编号" align="center" prop="id" /> <!-- 操作新增 -->
<el-table-column label="公告标题" align="center" prop="title" /> <template #toolbar_buttons>
<el-table-column label="公告类型" align="center" prop="type"> <XButton
<template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary" type="primary"
@click="openModal('update', scope.row.id)" preIcon="ep:zoom-in"
v-hasPermi="['system:notice:update']" :title="t('action.add')"
> v-hasPermi="['system:notice:create']"
编辑 @click="handleCreate()"
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['system:notice:delete']"
>
删除
</el-button>
</template>
</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="tsx"> <template #actionbtns_default="{ row }">
import { DICT_TYPE, getDictOptions } from '@/utils/dict' <!-- 操作修改 -->
import { dateFormatter } from '@/utils/formatTime' <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 }">
<Editor :model-value="row.content" :readonly="true" />
</template>
</Descriptions>
<template #footer>
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitForm()"
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</template>
<script setup lang="ts" name="Notice">
import type { FormExpose } from '@/components/Form'
// import
import * as NoticeApi from '@/api/system/notice' import * as NoticeApi from '@/api/system/notice'
import { DictTag } from '@/components/DictTag' import { rules, allSchemas } from './notice.data'
import NoticeForm from './form.vue'
const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() //
const loading = ref(true) // //
const total = ref(0) // const [registerTable, { reload, deleteData }] = useXTable({
const list = ref([]) // allSchemas: allSchemas,
const queryParams = reactive({ getListApi: NoticeApi.getNoticePageApi,
title: '', deleteApi: NoticeApi.deleteNoticeApi
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 getList = async () => { const setDialogTile = (type: string) => {
loading.value = true 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 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 = await NoticeApi.getNoticePage(queryParams) const data = unref(formRef)?.formModel as NoticeApi.NoticeVO
if (actionType.value === 'create') {
list.value = data.list await NoticeApi.createNoticeApi(data)
total.value = data.total message.success(t('common.createSuccess'))
} else {
await NoticeApi.updateNoticeApi(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally { } finally {
loading.value = false actionLoading.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

@ -0,0 +1,59 @@
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: true, message: '请选择岗位', trigger: ['blur', 'change'] }], postIds: [required],
mobile: [ mobile: [
required, required,
{ {
@ -86,11 +86,6 @@ 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',
@ -103,6 +98,11 @@ const crudSchemas = reactive<VxeCrudSchema>({
} }
} }
}, },
{
title: '岗位',
field: 'postIds',
isTable: false
},
{ {
title: '最后登录时间', title: '最后登录时间',
field: 'loginDate', field: 'loginDate',