


How to combine PHP and Vue to implement the check-in and check-out function for employee attendance
How to combine PHP and Vue to implement the sign-in and sign-out function of employee attendance
Employee attendance is an essential management link for every enterprise, and sign-in and sign-out can be effective Keep track of employee work and attendance. This article will introduce how to combine PHP and Vue to implement the check-in and check-out function of employee attendance, and provide specific code examples.
1. Technology selection
To realize the check-in and check-out function of employee attendance, we choose PHP as the back-end development language and Vue as the front-end development framework. PHP can handle the background logic, and Vue can be responsible for the front-end display. The two work together to quickly implement functions.
2. Database design
First, we need to design a database to store employee attendance information. The following is a simple design example of an employee attendance table:
Employee attendance table (attendance)
- id: Attendance record ID (primary key)
- employee_id: Employee ID
- sign_in_time: Sign-in time
- sign_out_time: Sign-out time
3. Back-end implementation
- Create a PHP file , named attendance.php, and introduce the database connection file.
<?php include 'db_connect.php';
- Implement employee sign-in function.
// 接收从前台传来的员工ID $employee_id = $_POST['employee_id']; // 获取当前时间 $sign_in_time = date('Y-m-d H:i:s'); // 将签到信息插入到数据库 $sql = "INSERT INTO attendance (employee_id, sign_in_time) VALUES ('$employee_id', '$sign_in_time')"; $result = mysqli_query($conn, $sql); if ($result) { echo "签到成功"; } else { echo "签到失败"; }
- Implement employee sign-out function.
// 接收从前台传来的员工ID $employee_id = $_POST['employee_id']; // 获取当前时间 $sign_out_time = date('Y-m-d H:i:s'); // 更新签退时间 $sql = "UPDATE attendance SET sign_out_time = '$sign_out_time' WHERE employee_id = '$employee_id'"; $result = mysqli_query($conn, $sql); if ($result) { echo "签退成功"; } else { echo "签退失败"; }
4. Front-end implementation
- In the front-end project, use the Vue framework to create an employee attendance page, where you can choose to sign in or out.
<template> <div> <h2 id="员工考勤">员工考勤</h2> <select v-model="employeeId"> <option v-for="employee in employees" :key="employee.id" :value="employee.id">{{ employee.name }}</option> </select> <button @click="signIn">签到</button> <button @click="signOut">签退</button> <p>{{ message }}</p> </div> </template> <script> export default { data() { return { employeeId: '', employees: [], message: '' } }, mounted() { // 获取员工列表 // 可以通过接口请求后台获取员工列表,这里直接模拟数据 this.employees = [ { id: 1, name: '张三' }, { id: 2, name: '李四' }, { id: 3, name: '王五' } ] }, methods: { signIn() { // 向后台发送签到请求 fetch('attendance.php', { method: 'POST', body: JSON.stringify({ employee_id: this.employeeId }) }) .then(response => response.text()) .then(data => { this.message = data }) }, signOut() { // 向后台发送签退请求 fetch('attendance.php', { method: 'POST', body: JSON.stringify({ employee_id: this.employeeId }) }) .then(response => response.text()) .then(data => { this.message = data }) } } } </script>
- Use Vue CLI for packaging and generate static files for background introduction.
5. Summary
By combining PHP and Vue, we can quickly implement the sign-in and sign-out function for employee attendance. PHP is responsible for processing the background logic, and Vue is responsible for the front-end display and sends requests to the background through the interface. The above is a simple example, you can expand and optimize it according to actual needs. To sum up, we can use PHP and Vue to implement the check-in and check-out function of employee attendance.
The above is the detailed content of How to combine PHP and Vue to implement the check-in and check-out function for employee attendance. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

There are three ways to refer to JS files in Vue.js: directly specify the path using the <script> tag;; dynamic import using the mounted() lifecycle hook; and importing through the Vuex state management library.

The watch option in Vue.js allows developers to listen for changes in specific data. When the data changes, watch triggers a callback function to perform update views or other tasks. Its configuration options include immediate, which specifies whether to execute a callback immediately, and deep, which specifies whether to recursively listen to changes to objects or arrays.

You can add a function to the Vue button by binding the button in the HTML template to a method. Define the method and write function logic in the Vue instance.

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

Vue.js has four methods to return to the previous page: $router.go(-1)$router.back() uses <router-link to="/" component window.history.back(), and the method selection depends on the scene.

In Vue.js, lazy loading allows components or resources to be loaded dynamically as needed, reducing initial page loading time and improving performance. The specific implementation method includes using <keep-alive> and <component is> components. It should be noted that lazy loading can cause FOUC (splash screen) issues and should be used only for components that need lazy loading to avoid unnecessary performance overhead.

There are three common methods for Vue.js to traverse arrays and objects: the v-for directive is used to traverse each element and render templates; the v-bind directive can be used with v-for to dynamically set attribute values for each element; and the .map method can convert array elements into new arrays.
