YNUtdPlatform/pages/realName/workAttendance/clock/index.vue

573 lines
15 KiB
Vue
Raw Normal View History

<template>
<view class="page">
<u-navbar class="u-navbar" title="考勤打卡" placeholder @leftClick="leftClick" leftIconColor="#fff" bgColor="#00337A" :titleStyle="{ color: '#FFF', fontSize: '32rpx' }"/>
<scroll-view class="content" scroll-y="true">
<view class="view-box">
<!-- <view class="title-view">
基本信息
</view> -->
<view class="view-item">{{proName}}</view>
<view class="view-item">
<view>{{longitude}},{{latitude}}</view>
<!-- <view class="button-box">复制</view> -->
</view>
<view class="view-item">{{timeStr}}</view>
<!-- <view class="view-item">
<view>上班0</view>
<view style="margin-left: 40rpx;">下班0</view>
<view class="button-box">打卡记录</view>
</view> -->
<view class="view-item">
<view>上班</view>
<view>{{isToWork}}</view>
</view>
<view class="view-item">
<view>下班</view>
<view>{{isOffWork}}</view>
</view>
<view class="view-item">
<view>打卡点</view>
<view @click="goMap" style="display: flex;align-items: center;">
<text>{{rangeName}}</text>
<image src="../../../../static/realName/nav.png" style="width:40rpx;height: 40rpx;margin-left: 20rpx;"></image>
</view>
<view class="button-box" style="margin-left: 60rpx;" @click="goWorkLocation">上传打卡点</view>
</view>
<view class="view-item">
<view>无法打卡请点击查询准入信息</view>
<view class="button-box" @click="goDayPlan">准入信息查询</view>
</view>
</view>
<view class="view-box">
<view class="title-view">
上班打卡
</view>
<view class="img-box" @click="handleAttendance(1)">
<view class="img-item upload-btn">
<image class="img" src="../../../../static/realName/tianjia-img.png" mode=""></image>
</view>
<view style="font-size: 28rpx;font-weight: bold;color: #757575;margin-top: 20rpx;" v-if="isShow">已进入考勤范围</view>
</view>
<view class="title-view">
下班打卡
</view>
<view class="img-box" @click="handleAttendance(2)">
<view class="img-item upload-btn">
<image class="img" src="../../../../static/realName/tianjia-img.png" mode=""></image>
</view>
<view style="font-size: 28rpx;font-weight: bold;color: #757575;margin-top: 20rpx;" v-if="isShow">已进入考勤范围</view>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
import { pathToBase64, base64ToPath } from 'image-tools';
import config from '@/config'
export default {
data() {
return {
userId:uni.getStorageSync('realNameUser').userId,
userName:uni.getStorageSync('realNameUser').userName,
idNumber:uni.getStorageSync('realNameUser').idNumber,
proId:uni.getStorageSync('realNameUser').proId,
teamId:uni.getStorageSync('realNameUser').teamId,
isShow:false,
teamList:[],//打卡点列表
proName:"",
rangeName:"",
longitude:"",
latitude:"",
timeStr:"",
userData:{},
isToWork:"",
isOffWork:"",
type:1,//1上班2下班
faceData:{},
photoPath:'',
attendanceImgUrl:'',
}
},
onLoad(option) {
this.getPro()
this.getWork()
this.getLocation();//获取定位
this.Time();//定时器
this.getTeamList()
},
onShow() {
},
methods: {
// 获取工程名称
getPro(){
let param={
id:this.proId,
subId:-1
}
uni.request({
url: config.realAppUrl + '/offLine/getPro',
method: 'post',
data: param,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: uni.getStorageSync('realNameToken')
},
success: res => {
res = res.data;
if(res.code==200){
console.log(res)
this.proName = res.data[0].abbreviation||"";
}
},
fail: err => {
console.log(err)
}
})
},
//获取打卡时间
getWork(){
let param={
idNumber:this.idNumber
}
uni.request({
url: config.realAppUrl + '/BasePerson/downloadWorkPerson',
method: 'post',
data: param,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: uni.getStorageSync('realNameToken')
},
success: res => {
res = res.data;
if(res.code==200){
console.log(res)
this.userData=res.data[0]
if(res.data[0].isToWork!="0"){
this.isToWork=res.data[0].isToWork;
}
if(res.data[0].isOffWork!="0"){
this.isOffWork=res.data[0].isOffWork;
}
}
},
fail: err => {
console.log(err)
}
})
},
// 获取打卡点列表
getTeamList(){
let param={
teamId:this.teamId
}
2024-11-06 09:07:29 +08:00
console.log(param)
uni.request({
url: config.realAppUrl + '/offLine/getSubTeam',
method: 'post',
data: param,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: uni.getStorageSync('realNameToken')
},
success: res => {
2024-11-06 09:07:29 +08:00
console.log(res)
res = res.data;
if(res.code==200){
console.log(res)
this.teamList=res.data;
if(this.teamList.length>0){
this.teamList.forEach((item,index)=>{
let distance=this.getDistance(this.latitude,this.longitude,item.lat,item.lon)
// console.log(distance)
item.distance=distance;
})
this.teamList.sort((a, b) => { return a.distance - b.distance; });
this.rangeName=this.teamList[0].rangeName;
}
}
},
fail: err => {
console.log(err)
}
})
},
// 定时器
Time() {
setTimeout(()=>{
this.getLocation();//获取定位
},2000)
this.timme = setInterval(() => {
this.timeStr=this.timeFormat(null,'yyyy-mm-dd hh:MM:ss')
}, 1000);
2024-12-06 15:48:41 +08:00
},
//获取定位
getLocation(){
uni.getLocation({
2024-12-06 15:48:41 +08:00
type: "wgs84", //默认为 wgs84 返回 gps 坐标
isHighAccuracy: true, // 开启高精度定位
success: e => {
this.longitude=e.longitude;
this.latitude=e.latitude;
if(this.teamList.length>0){
this.teamList.forEach((item,index)=>{
let distance=this.getDistance(this.latitude,this.longitude,item.lat,item.lon)
item.distance=distance;
})
}
var index = this.teamList.findIndex(item => {return item.distance < 6})
console.log(index)
if(index>-1){//存在-在考勤范围内
this.isShow=true;
}else{
this.isShow=false;
}
},fail:e=>{
}
});
},
//查看地图
goMap(){
let arr=this.teamList;
uni.navigateTo({
url: `/pages/realName/workAttendance/clock/bMap?teamList=${JSON.stringify(arr)}`
})
},
//上传打卡点
goWorkLocation(){
let obj={
longitude:117.150204,
latitude:31.877608
}
uni.navigateTo({
url: `/pages/realName/workAttendance/clock/workLocation?workData=${JSON.stringify(obj)}`
})
},
//计算距离
getDistance(lat1, lon1, lat2, lon2) {
const R = 6371; // 地球半径,单位为千米
const toRadians = (degree) => degree * Math.PI / 180; // 角度转弧度
const deltaLat = toRadians(lat2 - lat1); // 纬度差
const deltaLon = toRadians(lon2 - lon1); // 经度差
const a = Math.sin(deltaLat / 2) ** 2 +
Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) *
Math.sin(deltaLon / 2) ** 2;
const c = 2 * Math.asin(Math.sqrt(a));
const distance = R * c; // 距离,单位为千米
2024-12-06 15:48:41 +08:00
return distance.toFixed(2)-1;
},
//打卡
handleAttendance(type){
this.type=type;
this.getLocation()//重新获取定位
var index = this.teamList.findIndex(item => {return item.distance < 6})
if(index<0){//存在-在考勤范围内
uni.$u.toast('不在考勤范围内!');
}else if(this.type==2&&this.userData.isToWork==0){
uni.$u.toast('还未打上班卡!');
}else if(this.type==1&&this.userData.isToWork!=0){
uni.$u.toast('已打过上班卡!');
}else if(this.type==2&&this.userData.isOffWork!=0){
uni.$u.toast('已打过下班卡!');
}else if(this.userData.lightStatus==0&&this.userData.attDayNum>7){
uni.$u.toast('红灯人员只能打7天卡');
}else if(this.userData.isFurloughPerson==1){
uni.$u.toast('暂退人员无法打卡!');
}else if(this.userData.workerType==0){
uni.$u.toast('临时人员无法在当前页面打卡!');
}else{
this.distinguish()//打开人脸识别
}
},
//人脸识别采集
distinguish(){
console.log('人脸识别采集')
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['camera'],
success: res => {
2024-09-29 10:19:21 +08:00
console.log('?? ~ res-拍照:', res)
this.imgToBase64(res.tempFilePaths[0]).then(base64 => {
// console.log(base64)
//上传考勤图片
uni.uploadFile({
url: config.realFileUrl+`file/upload`, //服务器地址
fileType:"image",//ZFB必填,不然报错
filePath: res.tempFilePaths[0],//这个就是我们上面拍照返回或者先中照片返回的数组
name: "imgFile",
formData: {
photoType:'attendance',
},
success: (uploadFileRes) => {
console.log(uploadFileRes)
if(uploadFileRes.statusCode==200){
this.photoPath=JSON.parse(uploadFileRes.data).data.url;
}else{
uni.$u.toast('上传失败');
}
},
fail: err => {
uni.$u.toast('上传失败');
console.log(err)
}
});
//人脸验证
uni.uploadFile({
url: config.realFileUrl+'file/getFaceRecognition', //服务器地址
fileType:"image",//ZFB必填,不然报错
filePath: res.tempFilePaths[0],//这个就是我们上面拍照返回或者先中照片返回的数组
formData: {
file:base64,
photoType:'face',
},
success: (uploadFileRes) => {
console.log(uploadFileRes)
if(uploadFileRes.statusCode==200){
uploadFileRes=JSON.parse(uploadFileRes.data)
console.log(uploadFileRes)
if(uploadFileRes.code==200){
if(uploadFileRes.data.face){
this.faceData=JSON.parse(uploadFileRes.data.personData)
console.log(this.faceData)
if(this.faceData){
// if(this.faceData.idNumber==this.idNumber){//人脸身份证号与登录身份证号相同
this.idNumber=this.faceData.idNumber;
2024-11-06 09:07:29 +08:00
this.userName=this.faceData.name;
this.proId=this.faceData.proId;
// uni.$u.toast('人脸认证成功!');
this.uploadAttendance()
// }else{
// uni.$u.toast('不是本人!');
// }
}else{
uni.$u.toast('识别失败');
}
}else{
uni.$u.toast(uploadFileRes.msg);
}
}else{
uni.$u.toast(uploadFileRes.msg);
}
}else{
uni.$u.toast('识别失败');
}
},
fail: err => {
uni.$u.toast('识别失败');
console.log(err)
}
});
})
},
fail: err => {
2024-09-29 10:19:21 +08:00
console.log('?? ~ err:', err)
}
})
},
//打卡接口
uploadAttendance(){
let param={
"name": this.userName,
"idNumber": this.idNumber,
"proId": this.proId,
"imei": this.idNumber,
"userId": this.userId,
"currentDay": this.timeFormat(null,'yyyy-mm-dd'),
"addTime": this.timeFormat(null,'yyyy-mm-dd hh:MM:ss'),
"photoPath": this.photoPath,
"uploadType": this.type,
"lon": this.longitude,
"lat": this.latitude,
}
console.log(param)
uni.request({
url: config.realAppUrl + '/BasePerson/uploadFaceAttendance',
method: 'post',
data: param,
header: {
'Content-Type': 'application/json',
Authorization: uni.getStorageSync('realNameToken')
},
success: res => {
console.log(res)
res = res.data;
if(res.code==200){
uni.$u.toast('打卡成功!');
}else{
uni.$u.toast('打卡失败!');
}
},
fail: err => {
uni.$u.toast('打卡失败!');
console.log(err)
}
})
},
goDayPlan(){//准入信息查询
uni.navigateTo({
url: `/pages/realName/workbench/dayPlan/index`
})
},
leftClick() {
console.log('返回')
uni.navigateBack({
delta: 1 // 返回
});
},
imgToBase64(data) {
return new Promise((resolve, reject) => {
pathToBase64(data)
.then(base64 => {
resolve(base64)
})
.catch(error => {
console.error(error)
reject(error)
})
})
},
timeFormat(dateTime = null, formatStr = 'yyyy-mm-dd') {
let date
// 若传入时间为假值,则取当前时间
if (!dateTime) {
date = new Date()
}
// 若为unix秒时间戳则转为毫秒时间戳逻辑有点奇怪但不敢改以保证历史兼容
else if (/^\d{10}$/.test(dateTime?.toString().trim())) {
date = new Date(dateTime * 1000)
}
// 若用户传入字符串格式时间戳new Date无法解析需做兼容
else if (typeof dateTime === 'string' && /^\d+$/.test(dateTime.trim())) {
date = new Date(Number(dateTime))
}
// 处理平台性差异在Safari/Webkit中new Date仅支持/作为分割符的字符串时间
// 处理 '2022-07-10 01:02:03',跳过 '2022-07-10T01:02:03'
else if (typeof dateTime === 'string' && dateTime.includes('-') && !dateTime.includes('T')) {
date = new Date(dateTime.replace(/-/g, '/'))
}
// 其他都认为符合 RFC 2822 规范
else {
date = new Date(dateTime)
}
const timeSource = {
'y': date.getFullYear().toString(), // 年
'm': (date.getMonth() + 1).toString().padStart(2, '0'), // 月
'd': date.getDate().toString().padStart(2, '0'), // 日
'h': date.getHours().toString().padStart(2, '0'), // 时
'M': date.getMinutes().toString().padStart(2, '0'), // 分
's': date.getSeconds().toString().padStart(2, '0') // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
}
for (const key in timeSource) {
const [ret] = new RegExp(`${key}+`).exec(formatStr) || []
if (ret) {
// 年可能只需展示两位
const beginIndex = key === 'y' && ret.length === 2 ? 2 : 0
formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex))
}
}
return formatStr
},
},
destroyed() {
clearInterval(this.timme);
}
}
</script>
<style lang="scss">
.page {
width: 100vw;
height: 100vh;
2024-09-29 10:19:21 +08:00
background-color: #EFEFEF;
box-sizing: border-box;
// padding: 0 20px;
.content{
width: 100%;
height: 90vh;
margin-top: 20rpx;
padding-bottom: 80rpx;
2024-09-29 10:19:21 +08:00
background-color: #EFEFEF;
}
.view-box{
width: 94%;
margin: 20rpx auto;
background-color: #FFF;
border-radius: 10rpx;
padding-top: 20rpx;
.title-view{
font-weight: 600;
color: #757575;
margin-left: 20rpx;
}
}
.view-item{
width: 94%;
margin: 0rpx auto;
padding:20rpx;
display: flex;
align-items: center;
2024-09-29 10:19:21 +08:00
border-bottom: 1rpx solid #EFEFEF;
font-size: 28rpx;
font-weight: bold;
color: #757575;
}
.button-box{
padding: 15rpx 30rpx;
border: 1rpx solid #00337A;
border-radius: 10rpx;
color: #00337A;
margin-left: 20rpx;
}
.img-box{
width: 94%;
height: auto;
margin: 0rpx auto;
padding:20rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
2024-09-29 10:19:21 +08:00
border-bottom: 1rpx solid #EFEFEF;
.img-item {
width: 200upx;
height: 200upx;
border: 1px solid #ddd;
position: relative;
box-sizing: border-box;
background: #eee;
.img {
display: block;
width: 100%;
height: 100%;
}
}
.upload-btn {
display: flex;
justify-content: center;
align-items: center;
.img {
width: 60upx;
height: 60upx;
margin: unset;
}
}
}
}
</style>