打卡定位

This commit is contained in:
2026-09-24 11:41:39 +08:00
parent bef7f00970
commit 403f7e835f
3 changed files with 65 additions and 24 deletions
+29
View File
@@ -92,6 +92,35 @@ export function pad2(n) {
return String(n).padStart(2, '0')
}
/** 弹性:9:009:30 上班,18:0018:30 下班。早于 9:00、晚于 18:30 的分钟计入调休。 */
export function flexCreditMinutes(inTime, outTime) {
const inn = hmMinutes(inTime)
const out = hmMinutes(outTime)
let extra = 0
if (inn != null && inn < 9 * 60) extra += 9 * 60 - inn
if (out != null && out > 18 * 60 + 30) extra += out - (18 * 60 + 30)
return extra
}
export function flexCreditText(minutes) {
const n = Math.max(0, Math.round(Number(minutes) || 0))
if (!n) return '0 分钟'
const h = Math.floor(n / 60)
const m = n % 60
if (h && m) return h + ' 小时 ' + m + ' 分钟'
if (h) return h + ' 小时'
return m + ' 分钟'
}
function hmMinutes(value) {
const m = String(value || '').match(/(\d{1,2}):(\d{2})/)
if (!m) return null
const h = Number(m[1])
const min = Number(m[2])
if (h > 23 || min > 59) return null
return h * 60 + min
}
export function clockText(date) {
const d = date || new Date()
return `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`
+25 -20
View File
@@ -867,32 +867,37 @@ export const store = {
this.emit()
},
punch() {
_locate() {
let type = 'gcj02'
// #ifdef H5
type = 'wgs84'
// #endif
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'gcj02',
isHighAccuracy: true,
success: async (pos) => {
try {
const rec = await api.oaPost('/profile/attendance/punch', {
source: 'mobile',
latitude: pos.latitude,
longitude: pos.longitude,
accuracyM: pos.accuracy
}, this.token)
await this.refreshAttendance()
resolve((rec && rec.title) || '打卡成功')
} catch (e) {
reject(e)
}
},
fail() {
reject(new Error('需要定位权限才能打卡'))
}
type,
isHighAccuracy: false,
timeout: 8000,
success: resolve,
fail: reject
})
})
},
async punch() {
const body = { source: 'mobile' }
try {
const pos = await this._locate()
body.latitude = pos.latitude
body.longitude = pos.longitude
body.accuracyM = pos.accuracy
} catch (_) {
// 桌面浏览器经常没有定位;坐标缺省时仍提交,由服务端决定是否允许
}
const rec = await api.oaPost('/profile/attendance/punch', body, this.token)
await this.refreshAttendance()
return (rec && rec.title) || '打卡成功'
},
async audit(no, action, comment) {
await api.oaPost(`/workflow/requests/${no}/audit`, { action, comment }, this.token)
await this.refreshWorkbench()