<template> <div class="dataClassify"> <div class="top"> <el-form ref="ruleForm" inline :model="form"> <el-form-item label="分类名称:" prop="typeName"> <el-input v-model="form.typeName" placeholder="请输入分类名称" /> </el-form-item> <el-form-item> <el-button type="primary" icon="Search" @click="search"> 查询</el-button> <el-button icon="Refresh" @click="resetQuery">重置</el-button> </el-form-item> </el-form> <el-row class="mb8"> <el-button type="primary" plain icon="Plus" @click="openDialog({}, 'add')">新增</el-button> </el-row> </div> <el-table :data="tableData" v-loading="loading" :max-height="600" row-key="id"> <!-- <el-table-column type="index" width="55" label="序号" /> --> <el-table-column label="分类名称" prop="typeName" show-overflow-tooltip /> <el-table-column label="分类编号" prop="typeCode" show-overflow-tooltip /> <el-table-column label="分类描述" prop="remark" show-overflow-tooltip /> <el-table-column label="创建时间" prop="createTime" show-overflow-tooltip /> <el-table-column label="创建人" prop="createBy" show-overflow-tooltip /> <el-table-column label="文档数" prop="fileNum" show-overflow-tooltip /> <el-table-column label="操作" show-overflow-tooltip width="220"> <template #default="{ row }"> <el-button type="primary" link @click="openDialog(row, 'view')">查看</el-button> <el-button type="primary" link @click="openDialog(row, 'add')">新增</el-button> <el-button type="primary" link @click="openDialog(row, 'edit')">修改</el-button> <el-button type="danger" link @click="del(row)">删除</el-button> </template> </el-table-column> </el-table> <el-dialog v-model="visible" :title="`${opts.text}分类`" :close-on-click-modal="false" width="30%" :before-close="close" class="dialog"> <operate v-if="visible" ref="operateRef" :cur-row="curRow" :opts="opts" @close="close"></operate> <template #footer v-if="opts.type !== 'view'"> <div class="dialog-footer"> <el-button type="primary" @click="submit">保存</el-button> <el-button @click="close">取消</el-button> </div> </template> </el-dialog> </div> </template> <script setup> import { reactive, ref, onMounted, shallowRef } from 'vue'; import { optTextMap } from '@/utils/map'; import operate from './operate.vue'; import { documentTypeTree, documentTypeDel } from '@/api/document/dataClassify'; const { proxy } = getCurrentInstance(); const form = reactive({ typeName: '', }); const tableData = ref([]); const loading = ref(false); const visible = ref(false); const curRow = shallowRef({}); const opts = reactive({ type: '', text: '', }); const getTableList = async () => { loading.value = true; try { const res = await documentTypeTree(form); loading.value = false; if (res?.code !== 200) return; tableData.value = res.data; } catch (error) { loading.value = false; } }; const search = () => { getTableList(); }; const resetQuery = () => { proxy.$refs.ruleForm.resetFields(); search(); }; const openDialog = (data, type) => { visible.value = true; opts.type = type; opts.text = optTextMap.get(type); curRow.value = data; }; const close = result => { if (result?.type === 'add') { search(); } else if (result?.type === 'edit') { getTableList(); } visible.value = false; opts.type = ''; opts.text = ''; curRow.value = {}; }; const del = row => { proxy.$modal .confirm('是否确认删除?') .then(async () => { const res = await documentTypeDel(row.id); if (res?.code !== 200) return; getTableList(); }) .catch(() => {}); }; const submit = () => { proxy.$refs.operateRef.submit(); }; onMounted(() => { getTableList(); }); </script> <style lang="scss" scoped> .dataClassify { padding: 20px; height: 90vh; overflow-y: hidden; .top { margin-bottom: 15px; } } :deep(.dialog) { .el-dialog__body { padding-bottom: 20px !important; } .el-dialog__footer { padding-top: 0 !important; } } </style>