<!-- CNAS文件 --> <script lang="ts" setup> import { Delete } from '@element-plus/icons-vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import addDialog from './addDialog.vue' import type { fileListType, fileResType, fileSearchType } from '@/views/measure/file/file-interface' import { deleteApi, listPageApi, updateApi } from '@/api/measure/file' import { getDictByCode } from '@/api/system/dict' import { exportExcel } from '@/utils/exportXlsx' import { uploadApi } from '@/api/system/notice' const searchQuery = reactive<fileSearchType>({ fileNo: '', // 编号 fileName: '', // 名称 publishTime: '', // 发布时间 fileCode: '', // 文件号 effectiveTime: '', // 实施时间 effectiveStatus: '', // 实施状态 limit: 10, offset: 1, fileType: '', // 类型 }) // 查询参数 const loadingTable = ref<boolean>(false) // 表格loading const total = ref<number>(0) // 数据总条数 const columns = ref([ { text: '名称', value: 'fileName', align: 'center' }, { text: '编号', value: 'fileNo', align: 'center' }, { text: '文件号', value: 'fileCode', align: 'center' }, { text: '类别', value: 'fileType', align: 'center' }, { text: '发布时间', value: 'publishTime', align: 'center' }, { text: '实施时间', value: 'effectiveTime', align: 'center' }, { text: '实施状态', value: 'effectiveStatus', align: 'center' }, ]) // 表格 const printObj = ref({ id: 'print', // 需要打印元素的id popTitle: 'CNAS文件', // 打印配置页上方的标题 extraHead: '', // 最上方的头部文字,附加在head标签上的额外标签,使用逗号分割 preview: false, // 是否启动预览模式,默认是false previewBeforeOpenCallback() { console.log('正在加载预览窗口!') }, // 预览窗口打开之前的callback previewOpenCallback() { console.log('已经加载完预览窗口,预览打开了!') }, // 预览窗口打开时的callback beforeOpenCallback() { console.log('开始打印之前!') }, // 开始打印之前的callback openCallback() { console.log('执行打印了!') }, // 调用打印时的callback closeCallback() { console.log('关闭了打印工具!') }, // 关闭打印的callback(无法区分确认or取消) clickMounted() { console.log('点击v-print绑定的按钮了!') }, // url: 'http://localhost:8080/', // 打印指定的URL,确保同源策略相同 // asyncUrl (reslove) { // setTimeout(() => { // reslove('http://localhost:8080/') // }, 2000) // }, standard: '', extarCss: '', }) const list = ref([]) // 表格数据 const addRef = ref() // 添加/编辑/详情/组件 // 获取类型 const fileTypeList = ref<fileResType[]>([]) const getType = async () => { const res = await getDictByCode('fileType') fileTypeList.value = res.data searchQuery.fileType = res.data.filter((item: fileResType) => item.name === 'CNAS文件')[0].value } const effectiveStatusSelect = ref<fileResType[]>([]) // 获取实施状态 const getStatus = () => { getDictByCode('effectiveStatus').then((res) => { if (res.code === 200) { effectiveStatusSelect.value = res.data } }) } // 获取数据列表 const getList = () => { loadingTable.value = true listPageApi(searchQuery).then((res) => { if (res.code === 200) { list.value = res.data.rows total.value = res.data.total } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.limit = val.size } if (val && val.page) { searchQuery.offset = val.page } getList() } // 详情 const detail = (row: fileListType) => { addRef.value.initDialog({ ...row, fileType: searchQuery.fileType, fileTypeName: 'CNAS文件', title: '详情', }) } // 下载(单个) const exportSelf = (row: fileListType) => { exportExcel({ json: [row].map((item: fileListType, index: number) => ({ index: index + 1, fileName: item.fileName, fileNo: item.fileNo, fileCode: item.fileCode, fileType: item.fileType, publishTime: item.publishTime, effectiveTime: item.effectiveTime, effectiveStatus: item.effectiveStatus })), name: 'CNAS文件', titleArr: ['序号', '名称', '编号', '文件号', '类别', '发布时间', '实施时间', '实施状态'], sheetName: 'sheet1', }) } // 废止 const abolish = (row: fileListType) => { ElMessageBox.confirm( `确认废止${row.fileName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { updateApi({ id: row.id as string }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '操作成功', }) getList() } }) }) } // 删除 const remove = (row: fileListType) => { ElMessageBox.confirm( `确认删除${row.fileName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { deleteApi({ id: row.id as string }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '删除成功', }) getList() } }) }) } // 搜索 const search = () => { getList() } // 重置 const reset = () => { searchQuery.fileNo = '' searchQuery.fileName = '' searchQuery.fileCode = '' searchQuery.publishTime = '' searchQuery.effectiveTime = '' searchQuery.effectiveStatus = '' getList() } // 模板下载 const templateDownload = () => { } // 新增 const add = () => { addRef.value.initDialog({ fileType: searchQuery.fileType, title: '新增', fileTypeName: 'CNAS文件', }) } // 导出 const exportExcelBtn = () => { const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(255, 255, 255, 0.8)', }) listPageApi({ ...searchQuery, limit: 9999999, offset: 1 }).then((res) => { if (res.code === 200) { if (res.data.rows.length) { exportExcel({ json: res.data.rows.map((item: fileListType, index: number) => ({ index: index + 1, fileName: item.fileName, fileNo: item.fileNo, fileCode: item.fileCode, fileType: item.fileType, publishTime: item.publishTime, effectiveTime: item.effectiveTime, effectiveStatus: item.effectiveStatus })), name: 'CNAS文件', titleArr: ['序号', '名称', '编号', '文件号', '类别', '发布时间', '实施时间', '实施状态'], sheetName: 'sheet1', }) } else { ElMessage({ type: 'warning', message: '暂无数据', }) } } loading.close() }).catch((_) => { loading.close() }) } // 打印 const print = () => { } const fileRef = ref() // 文件上传input const onFileChange = (event: any) => { // 原生上传图片 // console.log(event.target.files) // if (event.target.files[0].type === 'application/pdf') { if (event.target.files?.length !== 0) { // 创建formdata对象 const fd = new FormData() fd.append('multipartFile', event.target.files[0]) uploadApi(fd).then((res) => { if (res.code === 200) { ElMessage.success('上传成功') } else { ElMessage.error(res.message) } }) } // } // else { // ElMessage.error('请上传pdf格式') // } } // 批量导入 const batchImport = () => { fileRef.value.click() } onMounted(() => { getStatus() getType().then((_) => { getList() }) }) </script> <template> <!-- 布局 --> <app-container> <!-- 筛选条件 --> <search-area @search="search"> <search-item> <el-input v-model="searchQuery.fileNo" placeholder="编号" clearable class="w-50 m-2 normal-input" /> </search-item> <search-item> <el-input v-model="searchQuery.fileName" placeholder="名称" clearable class="w-50 m-2 normal-input" /> </search-item> <search-item> <el-input v-model="searchQuery.fileCode" placeholder="文件号" clearable class="w-50 m-2 normal-input" /> </search-item> <search-item> <el-select v-model="searchQuery.fileType" class="m-2 normal-select" placeholder="类别"> <el-option v-for="item in fileTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-date-picker v-model="searchQuery.publishTime" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" placeholder="发布时间" class="normal-date" style="width: 130px;" /> </search-item> <search-item> <el-date-picker v-model="searchQuery.effectiveTime" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" placeholder="实施时间" class="normal-date" style="width: 130px;" /> </search-item> <search-item> <el-select v-model="searchQuery.effectiveStatus" class="m-2 normal-select" placeholder="实施状态"> <el-option v-for="item in effectiveStatusSelect" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <template #btns> <el-button class="filter-item" type="info" :icon="Delete" :style="{ marginTop: '-10px' }" @click="reset"> 重置 </el-button> </template> </search-area> <table-container> <!-- 表头区域 --> <template #btns-right> <input v-show="false" ref="fileRef" type="file" multiple @change="onFileChange"> <el-button type="primary" @click="batchImport"> 批量导入 </el-button> <el-button type="primary" @click="templateDownload"> 模板下载 </el-button> <el-button type="primary" @click="add"> 新建 </el-button> <el-button type="primary" @click="exportExcelBtn"> 导出 </el-button> <el-button v-print="printObj" type="primary" @click="print"> 打印 </el-button> </template> <!-- 表格区域 --> <normal-table id="print" :data="list" :total="total" :columns="columns as any" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" @change="changePage" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" align="center" width="250"> <template #default="{ row }"> <el-button @click="detail(row)"> 查看 </el-button> <el-button @click="exportSelf(row)"> 下载 </el-button> <el-button @click="abolish(row)"> 废止 </el-button> <el-button @click="remove(row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> <add-dialog ref="addRef" @reset-data="getList" /> </app-container> </template> <style lang="scss" scoped> .normal-input { width: 130px !important; } .normal-date { width: 130px !important; } .normal-select { width: 130px !important; } :deep(.el-table__header) { background-color: #bbb; } </style>