日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線(xiàn)咨詢(xún)客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

如何利用PHP和Vue搭建員工考勤的簽到地點(diǎn)設(shè)置功能

近年來(lái),隨著科技的發(fā)展和社會(huì)的進(jìn)步,越來(lái)越多的企事業(yè)單位開(kāi)始采用電子化的方式進(jìn)行員工考勤管理。而其中的一個(gè)重要環(huán)節(jié)就是員工簽到地點(diǎn)的設(shè)置。在這篇文章中,我們將介紹如何利用PHP和Vue搭建一個(gè)員工考勤的簽到地點(diǎn)設(shè)置功能,并提供具體的代碼示例。

一、準(zhǔn)備工作

在開(kāi)始之前,我們需要先準(zhǔn)備好所需的開(kāi)發(fā)環(huán)境。我們需要一個(gè)服務(wù)器,可以使用Apache或Nginx搭建。同時(shí),我們還需要安裝PHP和MySQL作為后端的開(kāi)發(fā)語(yǔ)言和數(shù)據(jù)庫(kù)。另外,我們還需要安裝Node.js和Vue.js作為前端的開(kāi)發(fā)工具。

二、創(chuàng)建數(shù)據(jù)庫(kù)

首先,我們需要?jiǎng)?chuàng)建一個(gè)數(shù)據(jù)庫(kù)來(lái)存儲(chǔ)員工的相關(guān)信息和簽到地點(diǎn)??梢允褂肗avicat或phpMyAdmin等工具創(chuàng)建一個(gè)名為”attendance”的數(shù)據(jù)庫(kù),并在其中創(chuàng)建兩張表,分別是”employees”和”locations”。

employees表的結(jié)構(gòu)如下:

CREATE TABLE employees (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(50) NOT NULL,
  job_title VARCHAR(50) NOT NULL,
  department VARCHAR(50) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

登錄后復(fù)制

locations表的結(jié)構(gòu)如下:

CREATE TABLE locations (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(50) NOT NULL,
  address VARCHAR(100) NOT NULL,
  latitude DECIMAL(10, 6) NOT NULL,
  longitude DECIMAL(10, 6) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

登錄后復(fù)制

三、后端開(kāi)發(fā)

    創(chuàng)建一個(gè)api.php文件,用于處理前端發(fā)送的請(qǐng)求并與數(shù)據(jù)庫(kù)進(jìn)行交互。
<?php
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];

// 處理GET請(qǐng)求,查詢(xún)數(shù)據(jù)庫(kù)中的員工和簽到地點(diǎn)信息
if ($method === 'GET') {
  $action = $_GET['action'];
  
  // 查詢(xún)員工信息
  if ($action === 'employees') {
    // 連接數(shù)據(jù)庫(kù)
    $conn = new mysqli('localhost', 'root', '', 'attendance');
    mysqli_set_charset($conn, "utf8");
    
    // 查詢(xún)數(shù)據(jù)庫(kù)中的員工信息
    $result = $conn->query('SELECT * FROM employees');
    $employees = $result->fetch_all(MYSQLI_ASSOC);
    
    // 返回員工信息
    echo json_encode($employees);
    
    // 關(guān)閉數(shù)據(jù)庫(kù)連接
    $conn->close();
  }
  
  // 查詢(xún)簽到地點(diǎn)信息
  else if ($action === 'locations') {
    // 連接數(shù)據(jù)庫(kù)
    $conn = new mysqli('localhost', 'root', '', 'attendance');
    mysqli_set_charset($conn, "utf8");
    
    // 查詢(xún)數(shù)據(jù)庫(kù)中的簽到地點(diǎn)信息
    $result = $conn->query('SELECT * FROM locations');
    $locations = $result->fetch_all(MYSQLI_ASSOC);
    
    // 返回簽到地點(diǎn)信息
    echo json_encode($locations);
    
    // 關(guān)閉數(shù)據(jù)庫(kù)連接
    $conn->close();
  }
}

// 處理POST請(qǐng)求,添加員工和簽到地點(diǎn)信息到數(shù)據(jù)庫(kù)
else if ($method === 'POST') {
  $data = json_decode(file_get_contents('php://input'), true);
  $action = $data['action'];

  // 添加員工信息
  if ($action === 'addEmployee') {
    // 連接數(shù)據(jù)庫(kù)
    $conn = new mysqli('localhost', 'root', '', 'attendance');
    mysqli_set_charset($conn, "utf8");
    
    // 添加員工信息到數(shù)據(jù)庫(kù)
    $name = $data['name'];
    $job_title = $data['job_title'];
    $department = $data['department'];
    $conn->query("INSERT INTO employees (name, job_title, department) VALUES ('$name', '$job_title', '$department')");

    // 返回成功信息
    echo json_encode(['status' => 'success']);

    // 關(guān)閉數(shù)據(jù)庫(kù)連接
    $conn->close();
  }
  
  // 添加簽到地點(diǎn)信息
  else if ($action === 'addLocation') {
    // 連接數(shù)據(jù)庫(kù)
    $conn = new mysqli('localhost', 'root', '', 'attendance');
    mysqli_set_charset($conn, "utf8");

    // 添加簽到地點(diǎn)信息到數(shù)據(jù)庫(kù)
    $name = $data['name'];
    $address = $data['address'];
    $latitude = $data['latitude'];
    $longitude = $data['longitude'];
    $conn->query("INSERT INTO locations (name, address, latitude, longitude) VALUES ('$name', '$address', '$latitude', '$longitude')");

    // 返回成功信息
    echo json_encode(['status' => 'success']);

    // 關(guān)閉數(shù)據(jù)庫(kù)連接
    $conn->close();
  }
}
?>

登錄后復(fù)制

    啟動(dòng)服務(wù)器,并將api.php文件放置在服務(wù)器的根目錄下。

四、前端開(kāi)發(fā)

    創(chuàng)建一個(gè)index.html文件,用于顯示員工和簽到地點(diǎn)的信息,并提供添加員工和簽到地點(diǎn)的功能。
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>員工考勤簽到地點(diǎn)設(shè)置</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
  <div id="app">
    <h2>員工信息</h2>
    <table>
      <tr>
        <th>姓名</th>
        <th>職位</th>
        <th>部門(mén)</th>
      </tr>
      <tr v-for="employee in employees">
        <td>{{ employee.name }}</td>
        <td>{{ employee.job_title }}</td>
        <td>{{ employee.department }}</td>
      </tr>
    </table>

    <form @submit.prevent="addEmployee">
      <input type="text" v-model="newEmployee.name" placeholder="姓名" required>
      <input type="text" v-model="newEmployee.job_title" placeholder="職位" required>
      <input type="text" v-model="newEmployee.department" placeholder="部門(mén)" required>
      <button type="submit">添加員工</button>
    </form>

    <h2>簽到地點(diǎn)</h2>
    <table>
      <tr>
        <th>名稱(chēng)</th>
        <th>地址</th>
        <th>經(jīng)度</th>
        <th>緯度</th>
      </tr>
      <tr v-for="location in locations">
        <td>{{ location.name }}</td>
        <td>{{ location.address }}</td>
        <td>{{ location.latitude }}</td>
        <td>{{ location.longitude }}</td>
      </tr>
    </table>

    <form @submit.prevent="addLocation">
      <input type="text" v-model="newLocation.name" placeholder="名稱(chēng)" required>
      <input type="text" v-model="newLocation.address" placeholder="地址" required>
      <input type="text" v-model="newLocation.latitude" placeholder="經(jīng)度" required>
      <input type="text" v-model="newLocation.longitude" placeholder="緯度" required>
      <button type="submit">添加簽到地點(diǎn)</button>
    </form>
  </div>

  <script>
    new Vue({
      el: '#app',
      data: {
        employees: [],
        newEmployee: {
          name: '',
          job_title: '',
          department: ''
        },
        locations: [],
        newLocation: {
          name: '',
          address: '',
          latitude: '',
          longitude: ''
        }
      },
      methods: {
        addEmployee() {
          fetch('api.php', {
            method: 'POST',
            body: JSON.stringify({
              action: 'addEmployee',
              name: this.newEmployee.name,
              job_title: this.newEmployee.job_title,
              department: this.newEmployee.department
            })
          })
          .then(() => {
            this.employees.push(this.newEmployee);
            this.newEmployee = { name: '', job_title: '', department: '' };
          });
        },
        addLocation() {
          fetch('api.php', {
            method: 'POST',
            body: JSON.stringify({
              action: 'addLocation',
              name: this.newLocation.name,
              address: this.newLocation.address,
              latitude: this.newLocation.latitude,
              longitude: this.newLocation.longitude
            })
          })
          .then(() => {
            this.locations.push(this.newLocation);
            this.newLocation = { name: '', address: '', latitude: '', longitude: '' };
          });
        }
      },
      mounted() {
        fetch('api.php?action=employees')
          .then(response => response.json())
          .then(employees => {
            this.employees = employees;
          });

        fetch('api.php?action=locations')
          .then(response => response.json())
          .then(locations => {
            this.locations = locations;
          });
      }
    });
  </script>
</body>
</html>

登錄后復(fù)制

    將index.html文件也放置在服務(wù)器的根目錄下。

五、運(yùn)行項(xiàng)目

    啟動(dòng)Apache(或Nginx)和MySQL服務(wù)器。在瀏覽器中訪(fǎng)問(wèn)index.html文件,即可看到員工和簽到地點(diǎn)的信息,并可以添加新的員工和簽到地點(diǎn)。

通過(guò)以上步驟,我們成功地利用PHP和Vue搭建了員工考勤的簽到地點(diǎn)設(shè)置功能,并提供了具體的代碼示例,希望對(duì)您有所幫助。當(dāng)然,在實(shí)際應(yīng)用中,還需要根據(jù)具體的需求進(jìn)行進(jìn)一步的開(kāi)發(fā)和完善。

以上就是如何利用PHP和Vue搭建員工考勤的簽到地點(diǎn)設(shè)置功能的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!

分享到:
標(biāo)簽:員工 地點(diǎn) 搭建 簽到 考勤
用戶(hù)無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定