How to generate employee attendance exception record report through PHP and Vue
Introduction: With the development of enterprises and the increase in the number of employees, managing employee attendance has become more and more important. getting more and more complex. In order to facilitate managers to quickly understand employees' attendance status, it is crucial to generate employee attendance exception record reports. This article will introduce how to use PHP and Vue to implement this function, and provide specific code examples.
1. Preparation work
Before starting, we need to prepare the following work:
2. Build the backend interface
In "api.php", connect to the database and write SQL statements to query attendance data. For example, assuming we have an employee table "employees" and an attendance record table "attendance", we can use the following SQL statement to query all attendance exception records:
SELECT employees.name, attendance.date, attendance.reason FROM employees INNER JOIN attendance ON employees.id = attendance.employee_id WHERE attendance.status = '异常'
Convert the query results into JSON format and output to the front-end page. For example,
$result = $db->query($sql); $data = array(); while ($row = $result->fetch_assoc()) { $data[] = $row; } echo json_encode($data);
3. Create a Vue component
Create a Vue component, name it "AttendanceReport", and introduce it into the page.
<template> <div> <h1>员工考勤异常记录报告</h1> <table> <thead> <tr> <th>员工姓名</th> <th>考勤日期</th> <th>异常原因</th> </tr> </thead> <tbody> <tr v-for="record in records" :key="record.id"> <td>{{ record.name }}</td> <td>{{ record.date }}</td> <td>{{ record.reason }}</td> </tr> </tbody> </table> </div> </template> <script> export default { data() { return { records: [] }; }, mounted() { this.fetchRecords(); }, methods: { fetchRecords() { // 使用Axios发送GET请求到后台接口 axios.get('/api.php') .then(response => { this.records = response.data; }) .catch(error => { console.error(error); }); } } }; </script>
4. Start the project
Conclusion:
Through the combination of PHP and Vue, we can quickly generate employee attendance exception record reports. PHP provides a backend interface for querying data in the database and outputs it to the front end in JSON format. As a front-end framework, Vue is responsible for displaying and processing data. Developers only need to follow the above steps to build an environment and write code to implement functions and improve work efficiency.
Appendix: Complete code example
api.php
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "attendance"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检测连接是否成功 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } $sql = "SELECT employees.name, attendance.date, attendance.reason FROM employees INNER JOIN attendance ON employees.id = attendance.employee_id WHERE attendance.status = '异常'"; $result = $conn->query($sql); $data = array(); while ($row = $result->fetch_assoc()) { $data[] = $row; } echo json_encode($data); $conn->close(); ?>
App.vue
<template> <div> <attendance-report></attendance-report> </div> </template> <script> import AttendanceReport from './components/AttendanceReport.vue'; export default { components: { AttendanceReport } }; </script>
main.js
import Vue from 'vue'; import App from './App.vue'; new Vue({ render: h => h(App) }).$mount('#app');
The above is how to use PHP and Specific steps and code examples for generating employee attendance exception record reports with Vue. Using this method, managers can quickly view employee attendance exceptions and improve work efficiency and accuracy. Hope this article helps you!
The above is the detailed content of How to generate employee attendance exception record report through PHP and Vue. For more information, please follow other related articles on the PHP Chinese website!