361 lines
11 KiB
HTML
361 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<!-- <script src="https://cdn.tailwindcss.com"></script> -->
|
|
<link rel="stylesheet" href="../lib/css/modern-normalize.css" />
|
|
|
|
<!-- element-plus style -->
|
|
<link rel="stylesheet" href="../lib/css/element-plus-index.css" />
|
|
|
|
<style>
|
|
.app-container {
|
|
padding: 20px;
|
|
}
|
|
</style>
|
|
<title>组织管理</title>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<div class="app-container">
|
|
<el-form
|
|
:model="queryParams"
|
|
ref="queryFormRef"
|
|
v-show="showSearch"
|
|
:inline="true"
|
|
>
|
|
<el-form-item label="部门名称" prop="name">
|
|
<el-input
|
|
v-model="queryParams.name"
|
|
placeholder="请输入部门名称"
|
|
clearable
|
|
size="default"
|
|
style="width: 240px"
|
|
@keyup.enter.native="handleQuery"
|
|
/>
|
|
</el-form-item>
|
|
|
|
<el-form-item label="状态" prop="status">
|
|
<el-select v-model="queryParams.status" placeholder="请选择状态">
|
|
<el-option label="启用" :value="1"></el-option>
|
|
<el-option label="禁用" :value="0"></el-option>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button
|
|
type="primary"
|
|
icon="search"
|
|
size="default"
|
|
@click="handleQuery"
|
|
>搜索</el-button
|
|
>
|
|
<el-button icon="Refresh" size="default" @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"
|
|
size="default"
|
|
@click="handleAdd"
|
|
>新增</el-button
|
|
>
|
|
<el-button type="warning" plain size="default" @click="handleAdd"
|
|
>修改</el-button
|
|
>
|
|
<el-button type="danger" plain size="default" @click="handleAdd"
|
|
>删除</el-button
|
|
>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-table v-loading="loading" :data="dataList" style="width: 100%">
|
|
<el-table-column type="selection" width="55"></el-table-column>
|
|
<el-table-column
|
|
label="部门名称"
|
|
prop="name"
|
|
align="center"
|
|
></el-table-column>
|
|
|
|
<el-table-column
|
|
label="排序"
|
|
prop="sort"
|
|
align="center"
|
|
></el-table-column>
|
|
<el-table-column label="状态" prop="status" align="center">
|
|
<template #default="{row}">
|
|
<el-switch
|
|
v-model="row.status"
|
|
style="
|
|
--el-switch-on-color: #13ce66;
|
|
--el-switch-off-color: #ff4949;
|
|
"
|
|
:active-value="1"
|
|
:inactive-value="0"
|
|
@change="switchStatus(row)"
|
|
></el-switch>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
label="创建时间"
|
|
prop="createTime"
|
|
align="center"
|
|
></el-table-column>
|
|
|
|
<el-table-column label="操作" align="center">
|
|
<template #default="{row}">
|
|
<el-link
|
|
type="primary"
|
|
icon="Edit"
|
|
size="small"
|
|
@click="handleEdit(row.id)"
|
|
>编辑</el-link
|
|
>
|
|
<el-link
|
|
type="danger"
|
|
icon="Delete"
|
|
size="small"
|
|
@click="handleDelete(row.id)"
|
|
>删除</el-link
|
|
>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
<el-pagination
|
|
v-model:currentPage="queryParams.page"
|
|
v-model:page-size="queryParams.limit"
|
|
background
|
|
:page-sizes="[10, 20, 30, 50]"
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
:total="total"
|
|
@size-change="handleSizeChange"
|
|
@current-change="handleCurrentChange"
|
|
></el-pagination>
|
|
<el-dialog title="查看" v-model="showEditDialog" width="500px">
|
|
<el-form
|
|
ref="formRef"
|
|
:model="form"
|
|
:rules="rules"
|
|
label-width="100px"
|
|
>
|
|
<el-form-item label="部门名称:" prop="name">
|
|
<el-input v-model="form.name" />
|
|
</el-form-item>
|
|
<el-form-item label="排序:" prop="sort">
|
|
<el-input-number v-model="form.sort" :min="0" />
|
|
</el-form-item>
|
|
<el-form-item label="状态:" prop="status">
|
|
<el-switch
|
|
v-model="form.status"
|
|
style="
|
|
--el-switch-on-color: #13ce66;
|
|
--el-switch-off-color: #ff4949;
|
|
"
|
|
:active-value="1"
|
|
:inactive-value="0"
|
|
></el-switch>
|
|
</el-form-item>
|
|
</el-form>
|
|
<div slot="footer" class="dialog-footer">
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
<el-button @click="cancel">取 消</el-button>
|
|
</div>
|
|
</el-dialog>
|
|
</div>
|
|
</div>
|
|
<script src="../lib/js/vue.global.js"></script>
|
|
<script src="../lib/js/element-plus.full.js"></script>
|
|
<script src="../lib/js/element-plus-zh-cn.js"></script>
|
|
<!-- element-plus icon -->
|
|
<script src="../lib/js/element-plus-icon-vue.js"></script>
|
|
<script src="../lib/js/lodash.js"></script>
|
|
<script src="../lib/js/axios.min.js"></script>
|
|
<script type="module">
|
|
const { createApp, ref, reactive, toRefs } = Vue;
|
|
const { ElMessage, ElMessageBox } = ElementPlus;
|
|
import {
|
|
getOrganizational,
|
|
deleteOrganizational,
|
|
} from "/common/js/api/organizational.js";
|
|
|
|
const app = createApp({
|
|
setup() {
|
|
const data = reactive({
|
|
queryParams: {
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
},
|
|
form: {},
|
|
rules: {
|
|
name: [{ required: true, trigger: "blur", message: "角色必填" }],
|
|
sort: [{ required: true, trigger: "blur", message: "姓名必填" }],
|
|
status: [
|
|
{ required: true, trigger: "blur", message: "性别必选" },
|
|
],
|
|
createTime: [
|
|
{ required: true, trigger: "blur", message: "省份证号必填" },
|
|
],
|
|
},
|
|
});
|
|
|
|
const { queryParams, form, rules } = toRefs(data);
|
|
const dataList = ref([]);
|
|
const showSearch = ref(true);
|
|
const showEditDialog = ref(false);
|
|
const loading = ref(false);
|
|
const formRef = ref();
|
|
const total = ref(0);
|
|
const genderDict = reactive({
|
|
0: "男",
|
|
1: "女",
|
|
});
|
|
// 取消按钮
|
|
const cancel = () => {
|
|
showEditDialog.value = false;
|
|
reset();
|
|
};
|
|
// 表单重置
|
|
const reset = () => {
|
|
form.value = {};
|
|
if (formRef.value) {
|
|
formRef.value.resetFields();
|
|
}
|
|
};
|
|
const handleQuery = () => {
|
|
queryParams.value.pageNum = 1;
|
|
getList();
|
|
};
|
|
|
|
const resetQuery = () => {
|
|
queryParams.value = {
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
};
|
|
getList();
|
|
};
|
|
const handleDelete = async (id) => {
|
|
ElMessageBox.confirm(`是否删除id为${id}的项?`, "删除", {
|
|
confirmButtonText: "确认",
|
|
cancelButtonText: "取消",
|
|
type: "warning",
|
|
}).then(async () => {
|
|
try {
|
|
await deleteOrganizational(id);
|
|
ElMessage.success("删除成功");
|
|
getList();
|
|
} catch (error) {
|
|
console.log(error);
|
|
ElMessage.error("删除失败");
|
|
}
|
|
});
|
|
};
|
|
const handleAdd = async () => {
|
|
reset();
|
|
showEditDialog.value = true;
|
|
};
|
|
const handleEdit = async (id) => {
|
|
reset();
|
|
const resp = await axios.get(
|
|
`http://localhost:8000/organizational/${id}`
|
|
);
|
|
form.value = resp.data.data;
|
|
showEditDialog.value = true;
|
|
};
|
|
const submitForm = async () => {
|
|
await formRef.value.validate();
|
|
if (form.value.id) {
|
|
fetch(`http://localhost:8000/organizational/${form.value.id}`, {
|
|
method: "PUT",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(form.value),
|
|
})
|
|
.then((resp) => resp.json())
|
|
.then(() => {
|
|
cancel();
|
|
getList();
|
|
});
|
|
} else {
|
|
fetch(`http://localhost:8000/organizational`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(form.value),
|
|
})
|
|
.then((resp) => resp.json())
|
|
.then(() => {
|
|
cancel();
|
|
getList();
|
|
ElMessage.success("新增成功");
|
|
});
|
|
}
|
|
};
|
|
const getList = async () => {
|
|
const resp = await getOrganizational(queryParams.value);
|
|
dataList.value = resp.data.rows;
|
|
total.value = resp.data.total;
|
|
};
|
|
const handleSizeChange = () => {};
|
|
const handleCurrentChange = (value) => {
|
|
queryParams.value.pageNum = value;
|
|
getList();
|
|
};
|
|
const switchStatus = async (row) => {
|
|
const orgData = _.cloneDeep(row);
|
|
console.log(orgData.status);
|
|
try {
|
|
await axios.put(
|
|
`http://localhost:8000/organizational/${orgData.id}`,
|
|
orgData
|
|
);
|
|
getList();
|
|
console.log("更改状态成功");
|
|
} catch (error) {
|
|
getList();
|
|
console.log("更改状态失败");
|
|
}
|
|
};
|
|
getList();
|
|
return {
|
|
cancel,
|
|
reset,
|
|
queryParams,
|
|
dataList,
|
|
showSearch,
|
|
loading,
|
|
form,
|
|
rules,
|
|
submitForm,
|
|
handleQuery,
|
|
resetQuery,
|
|
handleDelete,
|
|
handleAdd,
|
|
showEditDialog,
|
|
formRef,
|
|
handleEdit,
|
|
genderDict,
|
|
total,
|
|
handleSizeChange,
|
|
handleCurrentChange,
|
|
switchStatus,
|
|
};
|
|
},
|
|
});
|
|
app.use(ElementPlus, { locale: ElementPlusLocaleZhCn });
|
|
// 注册所有图标
|
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
app.component(key, component);
|
|
}
|
|
app.mount("#app");
|
|
</script>
|
|
</body>
|
|
</html>
|