| | |
| | | <script setup lang="ts"> |
| | | import type { VbenFormProps } from '@vben/common-ui'; |
| | | import type { Recordable } from '@vben/types'; |
| | | <template> |
| | | <div class="app-container"> |
| | | <div class="search" v-show="showSearch"> |
| | | <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> |
| | | <el-form-item label="分类名称" prop="categoryName"> |
| | | <el-input v-model="queryParams.categoryName" placeholder="请输入分类名称" clearable @keyup.enter="handleQuery" /> |
| | | </el-form-item> |
| | | <el-form-item label="分类编码" prop="code"> |
| | | <el-input v-model="queryParams.code" placeholder="请输入分类编码" clearable @keyup.enter="handleQuery" /> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button> |
| | | <el-button icon="Refresh" @click="resetQuery">重置</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </div> |
| | | <el-card shadow="never"> |
| | | <template #header> |
| | | <el-row :gutter="10" class="mb8"> |
| | | <el-col :span="1.5"> |
| | | <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['workflow:category:add']">新增</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['workflow:category:edit']"> |
| | | 修改 |
| | | </el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['workflow:category:remove']"> |
| | | 删除 |
| | | </el-button> |
| | | </el-col> |
| | | <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> |
| | | </el-row> |
| | | </template> |
| | | |
| | | import type { VxeGridProps } from '#/adapter/vxe-table'; |
| | | <el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange"> |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <el-table-column label="分类编号" align="center" prop="categoryId" v-if="true" /> |
| | | <el-table-column label="分类名称" align="center" prop="categoryName" /> |
| | | <el-table-column label="分类编码" align="center" prop="code" /> |
| | | <el-table-column label="备注" align="center" prop="remark" /> |
| | | <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width"> |
| | | <template #default="scope"> |
| | | <el-tooltip content="修改" placement="top"> |
| | | <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['workflow:category:edit']"></el-button> |
| | | </el-tooltip> |
| | | <el-tooltip content="删除" placement="top"> |
| | | <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['workflow:category:remove']"></el-button> |
| | | </el-tooltip> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" /> |
| | | </el-card> |
| | | |
| | | import { nextTick } from 'vue'; |
| | | <!-- 添加或修改参数配置对话框 --> |
| | | <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body> |
| | | <el-form ref="categoryFormRef" :model="form" :rules="rules" label-width="80px"> |
| | | <el-form-item label="分类名称" prop="categoryName"> |
| | | <el-input v-model="form.categoryName" placeholder="请输入分类名称" /> |
| | | </el-form-item> |
| | | <el-form-item label="分类编码" prop="code"> |
| | | <el-input v-model="form.code" placeholder="请输入分类编码" /> |
| | | </el-form-item> |
| | | <el-form-item label="备注" prop="remark"> |
| | | <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" @click="submitForm">确 定</el-button> |
| | | <el-button @click="cancel">取 消</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | import { Page, useVbenModal } from '@vben/common-ui'; |
| | | import { getVxePopupContainer } from '@vben/utils'; |
| | | <script setup name="Category" > |
| | | import { listCategory, getCategory, delCategory, addCategory, updateCategory } from "#/api/workflow/category"; |
| | | |
| | | import { Popconfirm, Space } from 'ant-design-vue'; |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | import { useVbenVxeGrid } from '#/adapter/vxe-table'; |
| | | import { categoryList, categoryRemove } from '#/api/workflow/category'; |
| | | const categoryList = ref([]); |
| | | const loading = ref(true); |
| | | const showSearch = ref(true); |
| | | const ids = ref([]); |
| | | const single = ref(true); |
| | | const multiple = ref(true); |
| | | const total = ref(0); |
| | | |
| | | import categoryModal from './category-modal.vue'; |
| | | import { columns, querySchema } from './data'; |
| | | |
| | | const formOptions: VbenFormProps = { |
| | | commonConfig: { |
| | | labelWidth: 80, |
| | | componentProps: { |
| | | allowClear: true, |
| | | }, |
| | | const queryFormRef = ref(); |
| | | const categoryFormRef = ref(); |
| | | const dialog = reactive({ |
| | | visible: false, |
| | | title: '' |
| | | }); |
| | | const initFormData = { |
| | | categoryId: undefined, |
| | | categoryName: '', |
| | | code: '', |
| | | remark: '' |
| | | } |
| | | const data = reactive({ |
| | | form: {...initFormData}, |
| | | queryParams: { |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | categoryName: '', |
| | | code: '' |
| | | }, |
| | | schema: querySchema(), |
| | | wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4', |
| | | }; |
| | | |
| | | const gridOptions: VxeGridProps = { |
| | | columns, |
| | | height: 'auto', |
| | | keepSource: true, |
| | | pagerConfig: { |
| | | enabled: false, |
| | | }, |
| | | proxyConfig: { |
| | | ajax: { |
| | | query: async (_, formValues = {}) => { |
| | | const resp = await categoryList({ |
| | | ...formValues, |
| | | }); |
| | | return { rows: resp }; |
| | | }, |
| | | // 默认请求接口后展开全部 不需要可以删除这段 |
| | | querySuccess: () => { |
| | | nextTick(() => { |
| | | expandAll(); |
| | | }); |
| | | }, |
| | | }, |
| | | }, |
| | | /** |
| | | * 虚拟滚动 默认关闭 |
| | | */ |
| | | scrollY: { |
| | | enabled: false, |
| | | gt: 0, |
| | | }, |
| | | rowConfig: { |
| | | keyField: 'categoryId', |
| | | }, |
| | | treeConfig: { |
| | | parentField: 'parentId', |
| | | rowField: 'categoryId', |
| | | transform: true, |
| | | }, |
| | | // 表格全局唯一表示 保存列配置需要用到 |
| | | id: 'workflow-category-index', |
| | | }; |
| | | |
| | | const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions }); |
| | | const [CategoryModal, modalApi] = useVbenModal({ |
| | | connectedComponent: categoryModal, |
| | | rules: { |
| | | categoryName: [{ required: true, message: "分类名称不能为空", trigger: "blur" }], |
| | | code: [{ required: true, message: "分类编码不能为空", trigger: "blur" }] |
| | | } |
| | | }); |
| | | |
| | | function handleAdd(row?: Recordable<any>) { |
| | | modalApi.setData({ parentId: row?.categoryId }); |
| | | modalApi.open(); |
| | | const { queryParams, form, rules } = toRefs(data); |
| | | |
| | | /** 查询参数列表 */ |
| | | const getList = async () => { |
| | | loading.value = true; |
| | | const res = await listCategory(queryParams.value); |
| | | categoryList.value = res.rows; |
| | | total.value = res.total; |
| | | loading.value = false; |
| | | } |
| | | /** 取消按钮 */ |
| | | const cancel = () => { |
| | | reset(); |
| | | dialog.visible = false; |
| | | } |
| | | /** 表单重置 */ |
| | | const reset = () => { |
| | | form.value = {...initFormData}; |
| | | categoryFormRef.value.resetFields(); |
| | | } |
| | | /** 搜索按钮操作 */ |
| | | const handleQuery = () => { |
| | | queryParams.value.pageNum = 1; |
| | | getList(); |
| | | } |
| | | /** 重置按钮操作 */ |
| | | const resetQuery = () => { |
| | | queryFormRef.value.resetFields(); |
| | | handleQuery(); |
| | | } |
| | | /** 多选框选中数据 */ |
| | | const handleSelectionChange = (selection) => { |
| | | ids.value = selection.map(item => item.categoryId); |
| | | single.value = selection.length != 1; |
| | | multiple.value = !selection.length; |
| | | } |
| | | /** 新增按钮操作 */ |
| | | const handleAdd = () => { |
| | | dialog.visible = true; |
| | | dialog.title = "添加参数"; |
| | | nextTick(() => { |
| | | reset(); |
| | | }) |
| | | } |
| | | /** 修改按钮操作 */ |
| | | const handleUpdate = (row) => { |
| | | dialog.visible = true; |
| | | dialog.title = "修改参数"; |
| | | const categoryId = row?.categoryId || ids.value[0]; |
| | | nextTick(async () => { |
| | | reset(); |
| | | const res = await getCategory(categoryId); |
| | | form.value = res.data; |
| | | }) |
| | | } |
| | | /** 提交按钮 */ |
| | | const submitForm = () => { |
| | | categoryFormRef.value.validate(async (valid) => { |
| | | if (valid) { |
| | | form.value.categoryId ? await updateCategory(form.value) : await addCategory(form.value); |
| | | proxy?.$modal.msgSuccess("操作成功"); |
| | | dialog.visible = false; |
| | | getList(); |
| | | } |
| | | }); |
| | | } |
| | | /** 删除按钮操作 */ |
| | | const handleDelete = async (row) => { |
| | | const categoryIds = row?.categoryId || ids.value; |
| | | await proxy?.$modal.confirm('是否确认删除参数编号为"' + categoryIds + '"的数据项?'); |
| | | await delCategory(categoryIds); |
| | | getList(); |
| | | proxy?.$modal.msgSuccess("删除成功"); |
| | | } |
| | | /** 导出按钮操作 */ |
| | | const handleExport = () => { |
| | | proxy?.download("workflow/category/export", { |
| | | ...queryParams.value |
| | | }, `category_${new Date().getTime()}.xlsx`); |
| | | } |
| | | |
| | | async function handleEdit(row: Recordable<any>) { |
| | | modalApi.setData({ id: row.categoryId }); |
| | | modalApi.open(); |
| | | } |
| | | |
| | | async function handleDelete(row: Recordable<any>) { |
| | | await categoryRemove(row.categoryId); |
| | | await tableApi.query(); |
| | | } |
| | | |
| | | function expandAll() { |
| | | tableApi.grid?.setAllTreeExpand(true); |
| | | } |
| | | |
| | | function collapseAll() { |
| | | tableApi.grid?.setAllTreeExpand(false); |
| | | } |
| | | onMounted(() => { |
| | | getList(); |
| | | }) |
| | | </script> |
| | | |
| | | <template> |
| | | <Page :auto-content-height="true"> |
| | | <BasicTable table-title="流程分类列表"> |
| | | <template #toolbar-tools> |
| | | <Space> |
| | | <a-button @click="collapseAll"> |
| | | {{ $t('pages.common.collapse') }} |
| | | </a-button> |
| | | <a-button @click="expandAll"> |
| | | {{ $t('pages.common.expand') }} |
| | | </a-button> |
| | | <a-button |
| | | type="primary" |
| | | v-access:code="['workflow:category:add']" |
| | | @click="handleAdd" |
| | | > |
| | | {{ $t('pages.common.add') }} |
| | | </a-button> |
| | | </Space> |
| | | </template> |
| | | <template #action="{ row }"> |
| | | <Space> |
| | | <ghost-button |
| | | v-access:code="['workflow:category:edit']" |
| | | @click.stop="handleEdit(row)" |
| | | > |
| | | {{ $t('pages.common.edit') }} |
| | | </ghost-button> |
| | | <ghost-button |
| | | class="btn-success" |
| | | v-access:code="['workflow:category:edit']" |
| | | @click.stop="handleAdd(row)" |
| | | > |
| | | {{ $t('pages.common.add') }} |
| | | </ghost-button> |
| | | <Popconfirm |
| | | :get-popup-container="getVxePopupContainer" |
| | | placement="left" |
| | | title="确认删除?" |
| | | @confirm="handleDelete(row)" |
| | | > |
| | | <ghost-button |
| | | danger |
| | | v-access:code="['workflow:category:remove']" |
| | | @click.stop="" |
| | | > |
| | | {{ $t('pages.common.delete') }} |
| | | </ghost-button> |
| | | </Popconfirm> |
| | | </Space> |
| | | </template> |
| | | </BasicTable> |
| | | <CategoryModal @reload="tableApi.query()" /> |
| | | </Page> |
| | | </template> |