feat:添加打印模板管理模块
parent
ad79342616
commit
f3be54dd9f
@ -0,0 +1,33 @@
|
||||
import request from '@/config/axios'
|
||||
|
||||
export interface PrintTemplateVO {
|
||||
id: number
|
||||
templateCode: string
|
||||
templateName: string
|
||||
templateType: number
|
||||
templateJson: string
|
||||
remark: string
|
||||
isEnable: boolean
|
||||
createTime: string
|
||||
}
|
||||
|
||||
export const PrintTemplateApi = {
|
||||
getPrintTemplatePage: async (params: any) => {
|
||||
return await request.get({ url: `/mes/print-template/page`, params })
|
||||
},
|
||||
getPrintTemplate: async (id: number) => {
|
||||
return await request.get({ url: `/mes/print-template/get?id=` + id })
|
||||
},
|
||||
createPrintTemplate: async (data: PrintTemplateVO) => {
|
||||
return await request.post({ url: `/mes/print-template/create`, data })
|
||||
},
|
||||
updatePrintTemplate: async (data: PrintTemplateVO) => {
|
||||
return await request.put({ url: `/mes/print-template/update`, data })
|
||||
},
|
||||
deletePrintTemplate: async (id: number) => {
|
||||
return await request.delete({ url: `/mes/print-template/delete?id=` + id })
|
||||
},
|
||||
exportPrintTemplate: async (params) => {
|
||||
return await request.download({ url: `/mes/print-template/export-excel`, params })
|
||||
},
|
||||
}
|
||||
@ -0,0 +1,125 @@
|
||||
<template>
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px" v-loading="formLoading">
|
||||
<el-form-item prop="templateCode">
|
||||
<template #label>
|
||||
<span>
|
||||
{{ t('TemplateManagement.PrintTemplate.templateCode') }}
|
||||
<el-tooltip :content="t('TemplateManagement.PrintTemplate.templateCodeTooltip')" placement="top">
|
||||
<Icon icon="ep:question-filled" />
|
||||
</el-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<el-row :gutter="10" style="width: 100%;">
|
||||
<el-col :xs="24" :sm="18" :md="16" :lg="14" :xl="12">
|
||||
<el-input v-model="formData.templateCode" :placeholder="t('TemplateManagement.PrintTemplate.placeholderTemplateCode')" :disabled="formData.isAutoCode || formType === 'update'" />
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="6" :md="4" :lg="3" :xl="2">
|
||||
<el-switch v-model="formData.isAutoCode" :disabled="formType === 'update'" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('TemplateManagement.PrintTemplate.templateName')" prop="templateName">
|
||||
<el-input v-model="formData.templateName" :placeholder="t('TemplateManagement.PrintTemplate.placeholderTemplateName')" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('TemplateManagement.PrintTemplate.templateType')" prop="templateType">
|
||||
<el-select v-model="formData.templateType" :placeholder="t('TemplateManagement.PrintTemplate.placeholderTemplateType')" class="!w-full">
|
||||
<el-option v-for="dict in getIntDictOptions('print_template_type')" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('TemplateManagement.PrintTemplate.isEnable')" prop="isEnable">
|
||||
<el-switch v-model="formData.isEnable" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('TemplateManagement.PrintTemplate.remark')" prop="remark">
|
||||
<el-input v-model="formData.remark" :placeholder="t('TemplateManagement.PrintTemplate.placeholderRemark')" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">{{ t('common.ok') }}</el-button>
|
||||
<el-button @click="dialogVisible = false">{{ t('common.cancel') }}</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { PrintTemplateApi, PrintTemplateVO } from '@/api/mes/printtemplate'
|
||||
import { getIntDictOptions } from '@/utils/dict'
|
||||
|
||||
defineOptions({ name: 'PrintTemplateForm' })
|
||||
|
||||
const { t } = useI18n()
|
||||
const message = useMessage()
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const formLoading = ref(false)
|
||||
const formType = ref('')
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
templateCode: undefined,
|
||||
isAutoCode: true,
|
||||
templateName: undefined,
|
||||
templateType: undefined,
|
||||
remark: undefined,
|
||||
isEnable: true,
|
||||
})
|
||||
const formRules = computed(() => ({
|
||||
templateCode: formData.value.isAutoCode ? [] : [{ required: true, message: t('TemplateManagement.PrintTemplate.validatorCodeRequired'), trigger: 'blur' }],
|
||||
templateName: [{ required: true, message: t('TemplateManagement.PrintTemplate.validatorNameRequired'), trigger: 'blur' }],
|
||||
templateType: [{ required: true, message: t('TemplateManagement.PrintTemplate.validatorTypeRequired'), trigger: 'change' }],
|
||||
}))
|
||||
const formRef = ref()
|
||||
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await PrintTemplateApi.getPrintTemplate(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open })
|
||||
|
||||
const emit = defineEmits(['success'])
|
||||
const submitForm = async () => {
|
||||
await formRef.value.validate()
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as PrintTemplateVO
|
||||
const { isAutoCode, ...submitData } = data as any
|
||||
if (isAutoCode) {
|
||||
delete submitData.templateCode
|
||||
}
|
||||
if (formType.value === 'create') {
|
||||
await PrintTemplateApi.createPrintTemplate(submitData)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await PrintTemplateApi.updatePrintTemplate(submitData)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
templateCode: undefined,
|
||||
isAutoCode: true,
|
||||
templateName: undefined,
|
||||
templateType: undefined,
|
||||
remark: undefined,
|
||||
isEnable: true,
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" min-label-width="68px">
|
||||
<el-form-item :label="t('TemplateManagement.PrintTemplate.templateCode')" prop="templateCode">
|
||||
<el-input v-model="queryParams.templateCode"
|
||||
:placeholder="t('TemplateManagement.PrintTemplate.placeholderTemplateCode')" clearable
|
||||
@keyup.enter="handleQuery" class="!w-240px" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('TemplateManagement.PrintTemplate.templateName')" prop="templateName">
|
||||
<el-input v-model="queryParams.templateName"
|
||||
:placeholder="t('TemplateManagement.PrintTemplate.placeholderTemplateName')" clearable
|
||||
@keyup.enter="handleQuery" class="!w-240px" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery">
|
||||
<Icon icon="ep:search" class="mr-5px" /> {{ t('common.query') }}
|
||||
</el-button>
|
||||
<el-button @click="resetQuery">
|
||||
<Icon icon="ep:refresh" class="mr-5px" /> {{ t('common.reset') }}
|
||||
</el-button>
|
||||
<el-button type="primary" plain @click="openForm('create')">
|
||||
<Icon icon="ep:plus" class="mr-5px" /> {{ t('action.add') }}
|
||||
</el-button>
|
||||
<el-button type="success" plain @click="handleExport" :loading="exportLoading">
|
||||
<Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" row-key="id"
|
||||
@selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" fixed="left" reserve-selection />
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.templateCode')" align="center" prop="templateCode"
|
||||
sortable />
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.templateName')" align="center" prop="templateName"
|
||||
sortable />
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.templateType')" align="center" prop="templateType"
|
||||
sortable>
|
||||
<template #default="scope">
|
||||
<dict-tag type="print_template_type" :value="scope.row.templateType" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.isEnable')" align="center" prop="isEnable" sortable>
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.isEnable ? 'success' : 'danger'">
|
||||
{{ scope.row.isEnable ? t('TemplateManagement.PrintTemplate.enabled') :
|
||||
t('TemplateManagement.PrintTemplate.disabled') }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.templateJson')" align="center" prop="templateJson"
|
||||
min-width="200px" :show-overflow-tooltip="true" />
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.remark')" align="center" prop="remark" />
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.createTime')" align="center" prop="createTime"
|
||||
:formatter="dateFormatter" width="180px" sortable />
|
||||
<el-table-column :label="t('TemplateManagement.PrintTemplate.operate')" align="center" min-width="160px">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" @click="openForm('update', scope.row.id)">
|
||||
{{ t('action.edit') }}
|
||||
</el-button>
|
||||
<el-button link type="warning" @click="openDesigner(scope.row)">
|
||||
{{ t('TemplateManagement.PrintTemplate.design') }}
|
||||
</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(scope.row.id)">
|
||||
{{ t('action.del') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList" />
|
||||
</ContentWrap>
|
||||
|
||||
<PrintTemplateForm ref="formRef" @success="getList" />
|
||||
<PrintTemplateDesigner ref="designerRef" @success="getList" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import { PrintTemplateApi, PrintTemplateVO } from '@/api/mes/printtemplate'
|
||||
import { DictTag } from '@/components/DictTag'
|
||||
import PrintTemplateForm from './PrintTemplateForm.vue'
|
||||
import PrintTemplateDesigner from './PrintTemplateDesigner.vue'
|
||||
|
||||
defineOptions({ name: 'PrintTemplate' })
|
||||
|
||||
const message = useMessage()
|
||||
const { t } = useI18n()
|
||||
|
||||
const loading = ref(true)
|
||||
const list = ref<PrintTemplateVO[]>([])
|
||||
const total = ref(0)
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
templateCode: undefined,
|
||||
templateName: undefined,
|
||||
})
|
||||
const queryFormRef = ref()
|
||||
const exportLoading = ref(false)
|
||||
const selectedIds = ref<number[]>([])
|
||||
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await PrintTemplateApi.getPrintTemplatePage(queryParams)
|
||||
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 formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
const designerRef = ref()
|
||||
const openDesigner = (row: any) => {
|
||||
designerRef.value.open(row)
|
||||
}
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await message.delConfirm()
|
||||
await PrintTemplateApi.deletePrintTemplate(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
await getList()
|
||||
} catch { }
|
||||
}
|
||||
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
await message.exportConfirm()
|
||||
exportLoading.value = true
|
||||
const params = {
|
||||
...queryParams,
|
||||
ids: selectedIds.value.length ? selectedIds.value.join(',') : undefined,
|
||||
}
|
||||
const data = await PrintTemplateApi.exportPrintTemplate(params)
|
||||
download.excel(data, t('TemplateManagement.PrintTemplate.exportFilename'))
|
||||
} catch {
|
||||
} finally {
|
||||
exportLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectionChange = (rows: any[]) => {
|
||||
selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? []
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in New Issue