zhangwencui
3 小时以前 aef408c91928a8dfeb28a3f48190ead32aeb45d1
非HTTPS,获取位置功能暂时隐藏
已修改2个文件
92 ■■■■ 文件已修改
src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/personnelManagement/attendanceCheckin/index.vue 86 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue
@@ -43,13 +43,13 @@
        <div class="map-container">
          <div class="map-header"
               style="margin-bottom: 10px">
            <el-button @click="getCurrentLocation">
            <!-- <el-button @click="getCurrentLocation">
              <el-icon>
                <Position />
              </el-icon>
              当前位置
            </el-button>
            <span style="margin-left: 10px; color: #909399;font-size: 12px;">点击地图选择位置</span>
            </el-button> -->
            <!-- <span style="margin-left: 10px; color: #909399;font-size: 12px;">点击地图选择位置</span> -->
          </div>
          <div id="map-container"
               class="map"
src/views/personnelManagement/attendanceCheckin/index.vue
@@ -1,7 +1,7 @@
<template>
  <div class="app-container">
    <!-- 员工打卡区 -->
    <el-card shadow="never"
    <!-- <el-card shadow="never"
             class="mb16">
      <div class="attendance-header">
        <div>
@@ -58,7 +58,7 @@
          </el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
    </el-card> -->
    <div class="attendance-operation">
      <!-- 查询条件(管理员考勤日报) -->
      <el-form :model="searchForm"
@@ -159,7 +159,7 @@
                         label="备注"
                         show-overflow-tooltip />
      </el-table>
      <pagination :total="total"
      <pagination :total="page.total"
                  layout="total, sizes, prev, pager, next, jumper"
                  :page="page.current"
                  :limit="page.size"
@@ -302,7 +302,7 @@
    findPersonalAttendanceRecords({ ...page, ...searchForm })
      .then(res => {
        tableData.value = res.data.records;
        page.value.total = res.data.total;
        page.total = res.data.total;
      })
      .finally(() => {
        tableLoading.value = false;
@@ -311,9 +311,9 @@
  // 查询今日打卡信息
  const fetchTodayData = () => {
    findTodayPersonalAttendanceRecord({}).then(res => {
      todayRecord.value = res.data;
    });
    // findTodayPersonalAttendanceRecord({}).then(res => {
    //   todayRecord.value = res.data;
    // });
  };
  const paginationChange = pagination => {
@@ -345,20 +345,67 @@
  // 获取当前位置
  const getCurrentLocation = () => {
    return new Promise((resolve, reject) => {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(
          position => {
            const { longitude, latitude } = position.coords;
            resolve({ longitude, latitude });
          },
          error => {
            console.log("获取位置失败:", error);
            reject(error);
          }
        );
      } else {
      if (!navigator.geolocation) {
        reject(new Error("浏览器不支持地理定位"));
        return;
      }
      // 检查是否使用HTTPS
      const isSecureContext =
        window.isSecureContext || window.location.protocol === "https:";
      console.log(
        "当前协议:",
        window.location.protocol,
        "是否安全上下文:",
        isSecureContext
      );
      if (!isSecureContext) {
        console.warn("当前不是HTTPS协议,地理位置API可能受限");
      }
      navigator.geolocation.getCurrentPosition(
        position => {
          const { longitude, latitude } = position.coords;
          console.log("获取位置成功:", longitude, latitude);
          resolve({ longitude, latitude });
        },
        error => {
          console.log("获取位置失败:", error);
          let errorMessage = "获取位置失败";
          // 根据错误类型提供更具体的提示
          switch (error.code) {
            case error.PERMISSION_DENIED:
              errorMessage =
                "用户拒绝了位置权限请求,请在浏览器设置中允许位置访问";
              break;
            case error.POSITION_UNAVAILABLE:
              errorMessage = "位置信息不可用,请检查设备定位功能";
              break;
            case error.TIMEOUT:
              errorMessage = "获取位置超时,请重试";
              break;
            case error.UNKNOWN_ERROR:
              errorMessage = "获取位置时发生未知错误";
              break;
            default:
              errorMessage = `获取位置失败: ${error.message}`;
          }
          // 检查是否是HTTPS问题
          if (error.code === error.PERMISSION_DENIED && !isSecureContext) {
            errorMessage += "(注意:生产环境需要使用HTTPS协议才能获取位置)";
          }
          reject(new Error(errorMessage));
        },
        {
          enableHighAccuracy: true,
          timeout: 10000,
          maximumAge: 0,
        }
      );
    });
  };
@@ -366,6 +413,7 @@
  const handleCheckInOut = () => {
    getCurrentLocation()
      .then(location => {
        console.log("位置成功");
        createPersonalAttendanceRecord(location).then(res => {
          fetchData();
          fetchTodayData();