浏览代码

fix: 更新生产环境API地址,修改.gitignore以忽略新文件,优化考勤服务中的距离计算和状态处理,调整考勤打卡页面的状态显示逻辑,提升用户体验。

master
lizhuang 1周前
父节点
当前提交
b6ef9392d9
共有 5 个文件被更改,包括 47 次插入40 次删除
  1. 1
    1
      .env.production
  2. 1
    0
      .gitignore
  3. 1
    1
      src/router/index.js
  4. 36
    36
      src/utils/attendance/AttendanceService.js
  5. 8
    2
      src/views/m/checkin/index.vue

+ 1
- 1
.env.production 查看文件

VUE_APP_XXL_JOB_ADMIN = '/xxl-job-admin' VUE_APP_XXL_JOB_ADMIN = '/xxl-job-admin'


# 逐世管理系统/生产环境 # 逐世管理系统/生产环境
VUE_APP_BASE_API = '/prod-api'
VUE_APP_BASE_API = 'https://digital.sohomall.jp/prod-api'


# 积木报表 # 积木报表
VUE_APP_JMREPORT_URL = '/jmreport' VUE_APP_JMREPORT_URL = '/jmreport'

+ 1
- 0
.gitignore 查看文件



package-lock.json package-lock.json
yarn.lock yarn.lock
.cursorrules

+ 1
- 1
src/router/index.js 查看文件

{ {
path: '/m/checkin', path: '/m/checkin',
component: () => import('@/views/m/checkin'), component: () => import('@/views/m/checkin'),
hidden: true
meta: { title: '考勤打卡', icon: 'date' }
}, },
] ]



+ 36
- 36
src/utils/attendance/AttendanceService.js 查看文件

* @param {number} lng1 经度1 * @param {number} lng1 经度1
* @param {number} lat2 纬度2 * @param {number} lat2 纬度2
* @param {number} lng2 经度2 * @param {number} lng2 经度2
* @returns {number} 距离,单位为公里
* @returns {number} 距离,
*/ */
static calculateDistance(lat1, lng1, lat2, lng2) { static calculateDistance(lat1, lng1, lat2, lng2) {
const R = 6371 // 地球半径
const R = 6371000 // 地球半径,单位:米
const dLat = (lat2 - lat1) * (Math.PI / 180) const dLat = (lat2 - lat1) * (Math.PI / 180)
const dLng = (lng2 - lng1) * (Math.PI / 180) const dLng = (lng2 - lng1) * (Math.PI / 180)
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1 * (Math.PI / 180)) *
Math.cos(lat2 * (Math.PI / 180)) *
Math.sin(dLng / 2) * Math.sin(dLng / 2)

const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1 * (Math.PI / 180)) *
Math.cos(lat2 * (Math.PI / 180)) *
Math.sin(dLng / 2) *
Math.sin(dLng / 2)

const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
return R * c
return R * c // 返回单位:米
} }


/** /**
static isInAttendanceRange(userLocation, attendanceGroup) { static isInAttendanceRange(userLocation, attendanceGroup) {
const { latitude, longitude } = userLocation const { latitude, longitude } = userLocation
const { lat, lng, radius } = attendanceGroup const { lat, lng, radius } = attendanceGroup
if (!latitude || !longitude || !lat || !lng) { if (!latitude || !longitude || !lat || !lng) {
return false return false
} }
const distance = this.calculateDistance(latitude, longitude, lat, lng) const distance = this.calculateDistance(latitude, longitude, lat, lng)
return distance <= radius return distance <= radius
} }
static compareTimeWithSchedule(scheduleTime) { static compareTimeWithSchedule(scheduleTime) {
const now = new Date() const now = new Date()
const [scheduleHour, scheduleMinute] = scheduleTime.split(':').map(Number) const [scheduleHour, scheduleMinute] = scheduleTime.split(':').map(Number)
const currentMinutes = now.getHours() * 60 + now.getMinutes() const currentMinutes = now.getHours() * 60 + now.getMinutes()
const scheduleMinutes = scheduleHour * 60 + scheduleMinute const scheduleMinutes = scheduleHour * 60 + scheduleMinute
return Math.sign(currentMinutes - scheduleMinutes) return Math.sign(currentMinutes - scheduleMinutes)
} }


[PUNCH_STATUS.EARLY_OUT]: '早退打卡', [PUNCH_STATUS.EARLY_OUT]: '早退打卡',
[PUNCH_STATUS.UPDATE_OUT]: '更新打卡' [PUNCH_STATUS.UPDATE_OUT]: '更新打卡'
} }
return statusTexts[status] || '未打卡' return statusTexts[status] || '未打卡'
} }


*/ */
static buildPunchData(params) { static buildPunchData(params) {
const { type, userInfo, userLocation, remark } = params const { type, userInfo, userLocation, remark } = params
const statusMap = { const statusMap = {
morning: PUNCH_STATUS.CHECKED_IN, morning: PUNCH_STATUS.CHECKED_IN,
evening: PUNCH_STATUS.CHECKED_OUT, evening: PUNCH_STATUS.CHECKED_OUT,
morning_late: PUNCH_STATUS.LATE_IN, morning_late: PUNCH_STATUS.LATE_IN,
evening_early: PUNCH_STATUS.EARLY_OUT evening_early: PUNCH_STATUS.EARLY_OUT
} }
const isClockIn = type.includes('morning') const isClockIn = type.includes('morning')
const currentTime = this.formatDateTime(new Date()) const currentTime = this.formatDateTime(new Date())
return { return {
userId: userInfo.userId, userId: userInfo.userId,
userName: userInfo.nickName, userName: userInfo.nickName,
clockInStatus: PUNCH_STATUS.NOT_CHECKED, clockInStatus: PUNCH_STATUS.NOT_CHECKED,
clockOutStatus: PUNCH_STATUS.NOT_CHECKED clockOutStatus: PUNCH_STATUS.NOT_CHECKED
} }
records.forEach(record => {
if (record.checkInType === PUNCH_TYPE.CLOCK_IN) {
attendanceStatus.clockInTime = record.checkInTime
attendanceStatus.clockInStatus = parseInt(record.checkInStatus)
} else if (record.checkInType === PUNCH_TYPE.CLOCK_OUT) {
attendanceStatus.clockOutTime = record.checkInTime
attendanceStatus.clockOutStatus = parseInt(record.checkInStatus)
}

records.forEach((record) => {
attendanceStatus.clockInTime = record.clockIn
attendanceStatus.clockInStatus = parseInt(record.clockInStatus)
attendanceStatus.clockOutTime = record.clockOut
attendanceStatus.clockOutStatus = parseInt(record.clockOutStatus || 0)
}) })

return attendanceStatus return attendanceStatus
} }


*/ */
static async getAttendanceGroup(userId) { static async getAttendanceGroup(userId) {
const response = await queryAttendanceGroupByUserId({ userId }) const response = await queryAttendanceGroupByUserId({ userId })
if (response.code !== 200) { if (response.code !== 200) {
throw new Error(response.msg || '获取考勤组信息失败') throw new Error(response.msg || '获取考勤组信息失败')
} }
if (!response.data) { if (!response.data) {
throw new Error('未配置考勤组,请联系管理员') throw new Error('未配置考勤组,请联系管理员')
} }
return response.data return response.data
} }


*/ */
static async getTodayAttendance(userId) { static async getTodayAttendance(userId) {
const response = await getCurrentDayRecord({ userId }) const response = await getCurrentDayRecord({ userId })
if (response.code !== 200) { if (response.code !== 200) {
throw new Error(response.msg || '获取考勤状态失败') throw new Error(response.msg || '获取考勤状态失败')
} }
return response.data || [] return response.data || []
} }


* @returns {Promise<Object>} API响应 * @returns {Promise<Object>} API响应
*/ */
static async submitPunch(punchData) { static async submitPunch(punchData) {
const apiCall = punchData.checkInType === PUNCH_TYPE.CLOCK_IN ? checkIn : checkOut
const apiCall =
punchData.checkInType === PUNCH_TYPE.CLOCK_IN ? checkIn : checkOut
const response = await apiCall(punchData) const response = await apiCall(punchData)
if (response.code !== 200) { if (response.code !== 200) {
throw new Error(response.msg || '打卡失败') throw new Error(response.msg || '打卡失败')
} }
return response return response
} }
}
}

+ 8
- 2
src/views/m/checkin/index.vue 查看文件

punchButtonText() { punchButtonText() {
const { clockInStatus, clockOutStatus } = this.attendanceStatus const { clockInStatus, clockOutStatus } = this.attendanceStatus


if (clockInStatus === PUNCH_STATUS.NOT_CHECKED) {
console.log(this.attendanceStatus)

if (clockInStatus == PUNCH_STATUS.NOT_CHECKED) {
return '上班打卡' return '上班打卡'
} }
if (clockOutStatus === PUNCH_STATUS.NOT_CHECKED) {
if (
clockOutStatus == PUNCH_STATUS.NOT_CHECKED ||
clockOutStatus == PUNCH_STATUS.CHECKED_OUT ||
clockOutStatus == PUNCH_STATUS.LATE_IN
) {
return '下班打卡' return '下班打卡'
} }
return '已打卡' return '已打卡'

正在加载...
取消
保存