<template>
|
<div class="task-path-template-page art-full-height">
|
<ArtSearchBar
|
v-model="searchForm"
|
:items="searchItems"
|
:showExpand="true"
|
@search="handleSearch"
|
@reset="handleReset"
|
/>
|
|
<ElCard class="art-table-card">
|
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
<template #left>
|
<ElSpace wrap>
|
<ElButton v-auth="'add'" @click="showDialog('add')" v-ripple>新增模板</ElButton>
|
<ElButton
|
v-auth="'delete'"
|
type="danger"
|
:disabled="selectedRows.length === 0"
|
@click="handleBatchDelete"
|
v-ripple
|
>
|
批量删除
|
</ElButton>
|
<ListExportPrint
|
class="inline-flex"
|
:preview-visible="previewVisible"
|
@update:previewVisible="handlePreviewVisibleChange"
|
:report-title="reportTitle"
|
:selected-rows="selectedRows"
|
:query-params="reportQueryParams"
|
:columns="columns"
|
:preview-rows="previewRows"
|
:preview-meta="resolvedPreviewMeta"
|
:total="pagination.total"
|
:disabled="loading"
|
@export="handleExport"
|
@print="handlePrint"
|
/>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
|
<TaskPathTemplateDialog
|
v-model:visible="dialogVisible"
|
:dialog-type="dialogType"
|
:task-path-template-data="currentTaskPathTemplateData"
|
@submit="handleDialogSubmit"
|
/>
|
|
<TaskPathTemplateDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
/>
|
|
<TaskPathTemplateFlowDrawer
|
v-model:visible="flowDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, ref } from 'vue'
|
import { ElMessage } from 'element-plus'
|
import { useUserStore } from '@/store/modules/user'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useCrudPage } from '@/views/system/common/useCrudPage'
|
import { usePrintExportPage } from '@/views/system/common/usePrintExportPage'
|
import ListExportPrint from '@/components/biz/list-export-print/index.vue'
|
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import {
|
buildTaskPathTemplatePageQueryParams,
|
buildTaskPathTemplatePrintRows,
|
buildTaskPathTemplateReportMeta,
|
buildTaskPathTemplateSavePayload,
|
buildTaskPathTemplateSearchParams,
|
createTaskPathTemplateSearchState,
|
getTaskPathTemplatePaginationKey,
|
normalizeTaskPathTemplateListRow,
|
TASK_PATH_TEMPLATE_REPORT_STYLE,
|
TASK_PATH_TEMPLATE_REPORT_TITLE
|
} from './taskPathTemplatePage.helpers'
|
import {
|
fetchDeleteTaskPathTemplate,
|
fetchExportTaskPathTemplateReport,
|
fetchGetTaskPathTemplateDetail,
|
fetchGetTaskPathTemplateMany,
|
fetchSaveTaskPathTemplate,
|
fetchTaskPathTemplatePage,
|
fetchUpdateTaskPathTemplate
|
} from '@/api/task-path-template'
|
import TaskPathTemplateDialog from './modules/task-path-template-dialog.vue'
|
import TaskPathTemplateDetailDrawer from './modules/task-path-template-detail-drawer.vue'
|
import TaskPathTemplateFlowDrawer from './modules/task-path-template-flow-drawer.vue'
|
import { createTaskPathTemplateTableColumns } from './taskPathTemplateTable.columns'
|
|
defineOptions({ name: 'TaskPathTemplate' })
|
|
const { hasAuth } = useAuth()
|
const userStore = useUserStore()
|
|
const searchForm = ref(createTaskPathTemplateSearchState())
|
const detailDrawerVisible = ref(false)
|
const flowDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const reportTitle = TASK_PATH_TEMPLATE_REPORT_TITLE
|
const reportQueryParams = computed(() => buildTaskPathTemplateSearchParams(searchForm.value))
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入模板编码/名称/条件描述'
|
}
|
},
|
{
|
label: '模板编码',
|
key: 'templateCode',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入模板编码'
|
}
|
},
|
{
|
label: '模板名称',
|
key: 'templateName',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入模板名称'
|
}
|
},
|
{
|
label: '起点类型',
|
key: 'sourceType',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入起点类型'
|
}
|
},
|
{
|
label: '终点类型',
|
key: 'targetType',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入终点类型'
|
}
|
},
|
{
|
label: '版本号',
|
key: 'version',
|
type: 'number',
|
props: {
|
min: 1,
|
controlsPosition: 'right',
|
placeholder: '请输入版本号'
|
}
|
},
|
{
|
label: '当前版本',
|
key: 'isCurrent',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '当前版本', value: 1 },
|
{ label: '历史版本', value: 0 }
|
]
|
}
|
},
|
{
|
label: '优先级',
|
key: 'priority',
|
type: 'number',
|
props: {
|
min: 1,
|
controlsPosition: 'right',
|
placeholder: '请输入优先级'
|
}
|
},
|
{
|
label: '超时(分)',
|
key: 'timeoutMinutes',
|
type: 'number',
|
props: {
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入超时时间'
|
}
|
},
|
{
|
label: '步序长度',
|
key: 'stepSize',
|
type: 'number',
|
props: {
|
min: 1,
|
controlsPosition: 'right',
|
placeholder: '请输入步序长度'
|
}
|
},
|
{
|
label: '状态',
|
key: 'status',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '启用', value: 1 },
|
{ label: '禁用', value: 0 }
|
]
|
}
|
},
|
{
|
label: '生效时间',
|
key: 'effectiveTime',
|
type: 'datetime',
|
props: {
|
type: 'datetime',
|
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
format: 'YYYY-MM-DD HH:mm:ss',
|
placeholder: '请选择生效时间'
|
}
|
},
|
{
|
label: '失效时间',
|
key: 'expireTime',
|
type: 'datetime',
|
props: {
|
type: 'datetime',
|
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
format: 'YYYY-MM-DD HH:mm:ss',
|
placeholder: '请选择失效时间'
|
}
|
}
|
])
|
|
async function openDetail(row) {
|
flowDrawerVisible.value = false
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetTaskPathTemplateDetail(row.id), {}, {
|
timeoutMessage: '任务路径模板详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeTaskPathTemplateListRow(detail)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取任务路径模板详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openFlow(row) {
|
detailDrawerVisible.value = false
|
flowDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetTaskPathTemplateDetail(row.id), {}, {
|
timeoutMessage: '流程图数据加载超时,已停止等待'
|
})
|
detailData.value = normalizeTaskPathTemplateListRow(detail)
|
} catch (error) {
|
flowDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取流程图数据失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
const detail = await guardRequestWithMessage(fetchGetTaskPathTemplateDetail(row.id), {}, {
|
timeoutMessage: '任务路径模板详情加载超时,已停止等待'
|
})
|
showDialog('edit', detail)
|
} catch (error) {
|
ElMessage.error(error?.message || '获取任务路径模板详情失败')
|
}
|
}
|
|
const {
|
columns,
|
columnChecks,
|
data,
|
loading,
|
pagination,
|
getData,
|
replaceSearchParams,
|
resetSearchParams,
|
handleSizeChange,
|
handleCurrentChange,
|
refreshData,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
} = useTable({
|
core: {
|
apiFn: fetchTaskPathTemplatePage,
|
apiParams: buildTaskPathTemplatePageQueryParams(searchForm.value),
|
paginationKey: getTaskPathTemplatePaginationKey(),
|
columnsFactory: () =>
|
createTaskPathTemplateTableColumns({
|
handleView: openDetail,
|
handleFlow: openFlow,
|
handleEdit: hasAuth('update') ? openEditDialog : null,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null,
|
canEdit: hasAuth('update'),
|
canDelete: hasAuth('delete')
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeTaskPathTemplateListRow(item))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentTaskPathTemplateData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildTaskPathTemplateSavePayload({}),
|
buildEditModel: (record) => buildTaskPathTemplateSavePayload(record),
|
buildSavePayload: (formData) => buildTaskPathTemplateSavePayload(formData),
|
saveRequest: fetchSaveTaskPathTemplate,
|
updateRequest: fetchUpdateTaskPathTemplate,
|
deleteRequest: fetchDeleteTaskPathTemplate,
|
entityName: '任务路径模板',
|
resolveRecordLabel: (record) => record?.templateCode || record?.templateName || record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
const buildPreviewMeta = (rows) => {
|
const now = new Date()
|
return {
|
reportDate: now.toLocaleDateString('zh-CN'),
|
printedAt: now.toLocaleString('zh-CN', { hour12: false }),
|
operator: userStore.getUserInfo?.name || userStore.getUserInfo?.username || '',
|
count: rows.length,
|
reportStyle: { ...TASK_PATH_TEMPLATE_REPORT_STYLE }
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
|
return defaultResponseAdapter(await fetchGetTaskPathTemplateMany(payload.ids)).records
|
}
|
return defaultResponseAdapter(
|
await fetchTaskPathTemplatePage({
|
...reportQueryParams.value,
|
current: 1,
|
pageSize: Number(pagination.total) > 0 ? Number(pagination.total) : Number(payload?.pageSize) || 20
|
})
|
).records
|
}
|
|
const { previewVisible, previewRows, previewMeta, handlePreviewVisibleChange, handleExport, handlePrint } =
|
usePrintExportPage({
|
downloadFileName: 'task-path-template.xlsx',
|
requestExport: (payload) =>
|
fetchExportTaskPathTemplateReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildTaskPathTemplatePrintRows(records),
|
buildPreviewMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildTaskPathTemplateReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation: TASK_PATH_TEMPLATE_REPORT_STYLE.orientation
|
})
|
)
|
|
function handleSearch(params) {
|
replaceSearchParams(buildTaskPathTemplateSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createTaskPathTemplateSearchState())
|
resetSearchParams()
|
}
|
</script>
|