1.leave_form.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>请假申请单</title> <!-- 引入样式 --> <link rel="stylesheet" type="text/css" href="/assets/element-plus/index.css"> <!-- 引入组件库 --> <script src="/assets/vue/vue.global.js"></script> <script src="/assets/element-plus/index.full.js"></script> <script src="/assets/element-plus/locale/zh-cn.js"></script> <script src="/assets/axios/axios.js"></script> <style> .el-form { border: 1px solid #DCDFE6; width: 600px; margin: 180px auto; padding: 35px 35px 15px 35px; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; box-shadow: 0 0 25px #909399; } </style> </head> <body> <div id="app"> <el-form ref="leaveForm" :model="form" :rules="rules" label-width="80px"> <el-descriptions title="请假申请单" :column="1" border> <el-descriptions-item label="部门">{{department.departmentName}}</el-descriptions-item> <el-descriptions-item label="申请人">{{employee.name}}[{{employee.title}}] </el-descriptions-item> <el-descriptions-item label="请假类型"> <el-select v-model="form.formType" style="width: 100%"> <el-option label="事假" value="1"></el-option> <el-option label="病假" value="2"></el-option> <el-option label="工伤假" value="3"></el-option> <el-option label="婚嫁" value="4"></el-option> <el-option label="产假" value="5"></el-option> <el-option label="丧假" value="6"></el-option> </el-select> </el-descriptions-item> <el-descriptions-item label="请假时间"> <el-form-item prop="timeRange" label-width="0px"> <div class="block"> <el-date-picker v-model="form.timeRange" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker> </div> </el-form-item> </el-descriptions-item> <el-descriptions-item label="请假原因"> <el-form-item prop="reason" label-width="0px"> <el-input type="text" placeholder="请输入请假原因" v-model="form.reason"/> </el-form-item> </el-descriptions-item> </el-descriptions> <div style="text-align: center;padding-top: 30px"> <el-button type="primary" >立即申请</el-button> </div> </el-form> </div> <script> var Main = { data() { return { employee:{}, department:{}, form: { formType: "1", timeRange: "", startTime: "", endTime: "", reason: "", eid: "", }, // 表单验证,需要在 el-form-item 元素中增加 prop 属性 rules: { timeRange: [ {required: true, message: '请选择请假时间', trigger: 'blur'} ], reason: [ {required: true, message: '请填写请假原因', trigger: 'blur'} ] } } } ,mounted(){ const objApp = this; axios.get("/api/user_info?uid=" + sessionStorage.uid + "&eid=" + sessionStorage.eid) .then(function(response){ console.info(response); objApp.employee = response.data.data.employee; objApp.department = response.data.data.department; }) } }; ElementPlus.locale(ElementPlus.lang.zhCn); const app = Vue.createApp(Main); app.use(ElementPlus, ElementPlus.lang.zhCn); app.mount("#app"); </script> </body> </html>
2.部门表
2.1 实体类com.imooc.oa.entity
package com.imooc.oa.entity; public class Department { private Long departmentId; private String departmentName; public Long getDepartmentId() { return departmentId; } public void setDepartmentId(Long departmentId) { this.departmentId = departmentId; } public String getDepartmentName() { return departmentName; } public void setDepartmentName(String departmentName) { this.departmentName = departmentName; } }
2.2 开发mapper(com.imooc.oa.mapper.DepartmentMapper)
package com.imooc.oa.mapper; import com.imooc.oa.entity.Department; public interface DepartmentMapper { public Department selectById(Long departmentId); }
2.3 mappers/department.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace与包名类名一致--> <mapper namespace="com.imooc.oa.mapper.DepartmentMapper"> <select id="selectById" parameterType="Long" resultType="com.imooc.oa.entity.Department"> select * from adm_department where department_id = #{value} </select> </mapper>
2.4 在mybatis-config.xml中注册
<mapper resource="mappers/department.xml"/>
2.5 com.imooc.oa.service.DepartmentService
package com.imooc.oa.service; import com.imooc.oa.entity.Department; import com.imooc.oa.mapper.DepartmentMapper; import com.imooc.oa.utils.MybatisUtils; public class DepartmentService { public Department selectById(Long departmentId){ return (Department)MybatisUtils.executeQuery(sqlSession -> sqlSession.getMapper(DepartmentMapper.class).selectById(departmentId)); } }
2.6 修改com.imooc.oa.controller.UserInfoServlet
package com.imooc.oa.controller; import com.imooc.oa.entity.Department; import com.imooc.oa.entity.Employee; import com.imooc.oa.entity.Node; import com.imooc.oa.service.DepartmentService; import com.imooc.oa.service.EmployeeService; import com.imooc.oa.service.RbacService; import com.imooc.oa.utils.ResponseUtils; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @WebServlet("/api/user_info") public class UserInfoServlet extends HttpServlet { private RbacService rbacService = new RbacService(); private EmployeeService employeeService = new EmployeeService(); private DepartmentService departmentService = new DepartmentService(); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uid = request.getParameter("uid"); String eid = request.getParameter("eid"); List<Node> nodes = rbacService.selectNodeByUserId(Long.parseLong(uid)); List<Map> treeList = new ArrayList<>(); Map module = null; for(Node node : nodes){ if(node.getNodeType() == 1){ module = new LinkedHashMap(); module.put("node", node); module.put("children", new ArrayList()); treeList.add(module); }else if(node.getNodeType() == 2){ List children = (List)module.get("children"); children.add(node); } } Employee employee = employeeService.selectById(Long.parseLong(eid)); Department department = departmentService.selectById(employee.getDepartmentId()); String json = new ResponseUtils() .put("nodeList", treeList).put("employee",employee).put("department",department).toJsonString(); response.setContentType("application/json;charset=utf-8"); response.getWriter().println(json); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
标签:请假,oa,021,department,import,com,public,imooc,View From: https://www.cnblogs.com/LLL0617/p/16991132.html