This commit is contained in:
饶秋霖 2024-12-01 23:08:29 +08:00
parent 83523284c4
commit 49edf73cc4
2 changed files with 299 additions and 0 deletions

44
api/system/departments.js Normal file
View File

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询部门列表
export function listDepartments(query) {
return request({
url: '/system/departments/list',
method: 'get',
params: query
})
}
// 查询部门详细
export function getDepartments(id) {
return request({
url: '/system/departments/' + id,
method: 'get'
})
}
// 新增部门
export function addDepartments(data) {
return request({
url: '/system/departments',
method: 'post',
data: data
})
}
// 修改部门
export function updateDepartments(data) {
return request({
url: '/system/departments',
method: 'put',
data: data
})
}
// 删除部门
export function delDepartments(id) {
return request({
url: '/system/departments/' + id,
method: 'delete'
})
}

View File

@ -0,0 +1,255 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="科室" prop="department">
<el-input
v-model="queryParams.department"
placeholder="请输入科室"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="人数" prop="number">
<el-input
v-model="queryParams.number"
placeholder="请输入人数"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="图片" prop="picture">
<el-input
v-model="queryParams.picture"
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>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
@click="handleAdd"
v-hasPermi="['system:departments:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:departments:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:departments:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['system:departments:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="departmentsList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="id" align="center" prop="id" />
<el-table-column label="科室" align="center" prop="department" />
<el-table-column label="人数" align="center" prop="number" />
<el-table-column label="图片" align="center" prop="picture" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:departments:edit']">修改</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:departments:remove']">删除</el-button>
</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-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="departmentsRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="科室" prop="department">
<el-input v-model="form.department" placeholder="请输入科室" />
</el-form-item>
<el-form-item label="人数" prop="number">
<el-input v-model="form.number" placeholder="请输入人数" />
</el-form-item>
<el-form-item label="图片" prop="picture">
<el-input v-model="form.picture" 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>
<script setup name="Departments">
import { listDepartments, getDepartments, delDepartments, addDepartments, updateDepartments } from "@/api/system/departments";
const { proxy } = getCurrentInstance();
const departmentsList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
department: null,
number: null,
picture: null
},
rules: {
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询部门列表 */
function getList() {
loading.value = true;
listDepartments(queryParams.value).then(response => {
departmentsList.value = response.rows;
total.value = response.total;
loading.value = false;
});
}
//
function cancel() {
open.value = false;
reset();
}
//
function reset() {
form.value = {
id: null,
department: null,
number: null,
picture: null
};
proxy.resetForm("departmentsRef");
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
//
function handleSelectionChange(selection) {
ids.value = selection.map(item => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
reset();
open.value = true;
title.value = "添加部门";
}
/** 修改按钮操作 */
function handleUpdate(row) {
reset();
const _id = row.id || ids.value
getDepartments(_id).then(response => {
form.value = response.data;
open.value = true;
title.value = "修改部门";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["departmentsRef"].validate(valid => {
if (valid) {
if (form.value.id != null) {
updateDepartments(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
});
} else {
addDepartments(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
const _ids = row.id || ids.value;
proxy.$modal.confirm('是否确认删除部门编号为"' + _ids + '"的数据项?').then(function() {
return delDepartments(_ids);
}).then(() => {
getList();
proxy.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
/** 导出按钮操作 */
function handleExport() {
proxy.download('system/departments/export', {
...queryParams.value
}, `departments_${new Date().getTime()}.xlsx`)
}
getList();
</script>