|
|
@@ -12,13 +12,13 @@
|
|
|
<text class="ygoa-icon icon-goToWork"></text>
|
|
|
<text class="title">上班</text>
|
|
|
<text class="time">{{ signInTime || '未打卡' }}</text>
|
|
|
- <text class="signStatus" :disabled="isSignInStatusDisabled">({{signInStatusName}})</text>
|
|
|
+ <text class="signStatus" v-if="!isSignInStatusDisabled">({{signInStatusName}})</text>
|
|
|
</view>
|
|
|
<view class="record-item">
|
|
|
<text class="ygoa-icon icon-afterWork"></text>
|
|
|
<text class="title">下班</text>
|
|
|
<text class="time">{{ signOutTime || '未打卡' }}</text>
|
|
|
- <text class="signStatus" :disabled="isSignOutStatusDisabled">({{signOutStatusName}})</text>
|
|
|
+ <text class="signStatus" v-if="!isSignOutStatusDisabled">({{signOutStatusName}})</text>
|
|
|
</view>
|
|
|
<view class="record-item" @click="getAddress">
|
|
|
<text class="ygoa-icon icon-location"></text>
|
|
|
@@ -29,17 +29,12 @@
|
|
|
<!-- 地图 -->
|
|
|
<atl-map :mapKey="config.mapKey" :mapType="mapType" :marker="marker" :polygons="polygons" :isPolygons="true">
|
|
|
<template v-slot:content>
|
|
|
- <view style="position: absolute; bottom: 0; width: 100%; height: 24px; background-color: white">
|
|
|
- <view style="display: flex; align-items: center; justify-content: center">
|
|
|
- </view>
|
|
|
- </view>
|
|
|
</template>
|
|
|
</atl-map>
|
|
|
<!-- 打卡按钮 -->
|
|
|
<view class="footer">
|
|
|
<button type="primary" @click="signInOrOut">{{signName}}</button>
|
|
|
- <!-- <button type="primary" @click="signIn" :disabled="isSignInDisabled">上班签到</button>
|
|
|
- <button type="default" @click="signOut">下班签退</button> -->
|
|
|
+
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
@@ -77,15 +72,28 @@
|
|
|
})
|
|
|
// 组件挂载后初始化当前日期与位置
|
|
|
onMounted(() => {
|
|
|
- showNowTime();
|
|
|
dateInit();
|
|
|
- getlocation();
|
|
|
+ // getlocation();
|
|
|
});
|
|
|
|
|
|
|
|
|
function showNowTime() {
|
|
|
+ // let nowMilliseconds=Date.now();
|
|
|
+ // intervalId.value = setInterval(() => {
|
|
|
+ // nowMilliseconds+=1000;
|
|
|
+ // nowTime.value = new Date(nowMilliseconds).toLocaleString('zh-CN', {
|
|
|
+ // year: 'numeric',
|
|
|
+ // month: '2-digit',
|
|
|
+ // day: '2-digit',
|
|
|
+ // hour: '2-digit',
|
|
|
+ // minute: '2-digit',
|
|
|
+ // second: '2-digit',
|
|
|
+ // hour12: false // 24小时制
|
|
|
+ // });
|
|
|
+ // }, 1000); // 每1秒更新一次
|
|
|
+
|
|
|
intervalId.value = setInterval(() => {
|
|
|
- nowTime.value = getNowTime();
|
|
|
+ nowTime.value = getNowTime()
|
|
|
}, 1000); // 每1秒更新一次
|
|
|
|
|
|
}
|
|
|
@@ -108,6 +116,7 @@
|
|
|
currentDate.value = `${year}-${formattedMonth}-${formattedDay}`; // 设置当前日期
|
|
|
const dayOfWeek = nowDate.getDay(); // 获取当前星期
|
|
|
currentDay.value = weekArr[dayOfWeek]; // 设置当前星期
|
|
|
+ showNowTime();
|
|
|
getTodayAtt();
|
|
|
}
|
|
|
|
|
|
@@ -116,6 +125,13 @@
|
|
|
const signOutTime = ref(''); // 下班签到时间
|
|
|
//打卡按钮文字显示
|
|
|
const signName = ref('上班签到')
|
|
|
+
|
|
|
+ //迟到早退状态,默认隐藏
|
|
|
+ const signInStatusName = ref('迟到')
|
|
|
+ const signOutStatusName = ref('早退')
|
|
|
+ const isSignInStatusDisabled = ref(true)
|
|
|
+ const isSignOutStatusDisabled = ref(true)
|
|
|
+
|
|
|
//获取今天考勤状态
|
|
|
function getTodayAtt() {
|
|
|
const params = {
|
|
|
@@ -123,23 +139,28 @@
|
|
|
rizi: currentDate.value
|
|
|
}
|
|
|
checkAttendance(params).then(res => {
|
|
|
+
|
|
|
if ("success" == res.returnMsg) {
|
|
|
// console.log("kaoqin",res);
|
|
|
const attList = res.returnParams.list;
|
|
|
const time1 = attList.find(item => item.att_type_id === '1');
|
|
|
- const time2 = attList.find(item => item.att_type_id === '2');
|
|
|
+ //拿到所有签退数据后,用pop取最后一个
|
|
|
+ const time2 = attList.filter(item => item.att_type_id === '2').pop();
|
|
|
+ console.log('time2',time2);
|
|
|
if (time1 !== undefined) {
|
|
|
+ // console.log('getTime1',time1);
|
|
|
signInTime.value = time1.att_time.split(' ')[1];
|
|
|
signName.value = '下班签退';
|
|
|
if (isTimeInRange(signInTime.value, ...config.lateTimeRange)) {
|
|
|
- isSignInStatusDisabled.value = true; //迟到
|
|
|
+ isSignInStatusDisabled.value = false; //迟到
|
|
|
}
|
|
|
}
|
|
|
if (time2 !== undefined) {
|
|
|
signOutTime.value = time2.att_time.split(' ')[1];
|
|
|
- if (Array.isArray(config.leaveEarlyTimeRange) && isTimeInRange(signOutTime, "00:00:00", config
|
|
|
- .leaveEarlyTimeRange[0])) {
|
|
|
- isSignOutStatusDisabled.value = true; //早退
|
|
|
+ if (Array.isArray(config.signOutTimeRange) && isTimeInRange(signOutTime.value, "00:00:00",
|
|
|
+ config
|
|
|
+ .signOutTimeRange[0])) {
|
|
|
+ isSignOutStatusDisabled.value = false; //早退
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -157,11 +178,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //迟到早退状态,默认隐藏
|
|
|
- const signInStatusName = ref('迟到')
|
|
|
- const signOutStatusName = ref('早退')
|
|
|
- const isSignInStatusDisabled = ref(false)
|
|
|
- const isSignOutStatusDisabled = ref(false)
|
|
|
+
|
|
|
|
|
|
function signIn() {
|
|
|
const now = getNowTime();
|
|
|
@@ -183,8 +200,8 @@
|
|
|
const now = getNowTime();
|
|
|
const signOut = 2;
|
|
|
//判断打卡时间是否符合
|
|
|
+ console.log('now', now);
|
|
|
if (!isTimeInRange(now, ...config.signOutTimeRange)) {
|
|
|
- // $modal.msg('不在签退时间15:00--20:00内')
|
|
|
$modal.confirm('当前非正常签退时间,是否继续?').then(res => {
|
|
|
if (res) {
|
|
|
getAddress();
|
|
|
@@ -201,21 +218,9 @@
|
|
|
|
|
|
//获取当前时间
|
|
|
function getNowTime() {
|
|
|
- var now = new Date();
|
|
|
- // // 获取小时、分钟和秒
|
|
|
- // var hours = now.getHours(); // 获取小时(0-23)
|
|
|
- // var minutes = now.getMinutes(); // 获取分钟(0-59)
|
|
|
- // var seconds = now.getSeconds(); // 获取秒(0-59)
|
|
|
- // // 将小时、分钟或秒格式化为两位数
|
|
|
- // hours = hours < 10 ? '0' + hours : hours;
|
|
|
- // minutes = minutes < 10 ? '0' + minutes : minutes;
|
|
|
- // seconds = seconds < 10 ? '0' + seconds : seconds;
|
|
|
- // const time1=new Date().toLocaleTimeString('en-US', { hour12: false });
|
|
|
- // console.log('now.toLocaleTimeString(us)',time1);
|
|
|
- // return `${hours}:${minutes}:${seconds}`;
|
|
|
- return now.toLocaleTimeString('en-US', {
|
|
|
+ return new Date().toLocaleTimeString('en-US', {
|
|
|
hour12: false
|
|
|
- })
|
|
|
+ }).substring(0, 8)
|
|
|
}
|
|
|
|
|
|
//判断时间是否在区间内
|
|
|
@@ -250,122 +255,93 @@
|
|
|
|
|
|
// 获取当前定位经纬度
|
|
|
function getlocation() {
|
|
|
- //判断用户是否打开位置权限
|
|
|
- uni.getSetting({
|
|
|
- success(res) {
|
|
|
- // 如果用户未授权
|
|
|
- if (!res.authSetting['scope.userLocation']) {
|
|
|
- $modal.confirm('需要您授权获取地理位置信息').then(res => {
|
|
|
- if (res) {
|
|
|
- // 打开权限设置页面
|
|
|
- uni.openSetting({
|
|
|
- success: (settingData) => {
|
|
|
- if (settingData.authSetting[
|
|
|
- 'scope.userLocation']) {
|
|
|
- // console.log('用户已授权');
|
|
|
- $modal.msg('授权后请重新打开此页面')
|
|
|
- } else {
|
|
|
- // console.log('用户未授权');
|
|
|
- return;
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ //判断用户是否打开位置权限
|
|
|
+ uni.getSetting({
|
|
|
+ success(res) {
|
|
|
+ // 如果用户未授权
|
|
|
+ if (!res.authSetting['scope.userLocation']) {
|
|
|
+ $modal.confirm('需要您授权获取地理位置信息').then(res => {
|
|
|
+ if (res) {
|
|
|
+ // 打开权限设置页面
|
|
|
+ uni.openSetting({
|
|
|
+ success: (settingData) => {
|
|
|
+ if (settingData.authSetting[
|
|
|
+ 'scope.userLocation']) {
|
|
|
+ $modal.msg('授权后请重新打开此页面')
|
|
|
+ reject(new Error("用户未授权"));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: '获取地理位置授权失败',
|
|
|
- icon: 'none',
|
|
|
- success: () => {
|
|
|
- // 返回上一页
|
|
|
- setTimeout(() => {
|
|
|
- $tab.navigateBack()
|
|
|
- }, 1000);
|
|
|
- }
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- })
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: '获取地理位置授权失败',
|
|
|
+ icon: 'none',
|
|
|
+ success: () => {
|
|
|
+ // 返回上一页
|
|
|
+ setTimeout(() => {
|
|
|
+ $tab.navigateBack()
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ reject(new Error("用户未授权"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 已授权,获取位置
|
|
|
+ fetchLocation(resolve, reject);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.error('获取设置失败', err);
|
|
|
+ reject(err); // 拒绝 Promise
|
|
|
}
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- console.error('获取设置失败', err);
|
|
|
- }
|
|
|
+ });
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装获取位置的函数
|
|
|
+ function fetchLocation(resolve, reject) {
|
|
|
wx.getLocation({
|
|
|
- // type: 'gcj02',
|
|
|
success: (res) => {
|
|
|
longitude.value = res.longitude; // 保存经度
|
|
|
latitude.value = res.latitude; // 保存纬度
|
|
|
+ resolve(); // 解析 Promise
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
if (err.errMsg.includes("频繁调用")) {
|
|
|
$modal.msg('请勿频繁调用');
|
|
|
+ reject(new Error("频繁调用错误"));
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- // 获取位置失败时提示用户打开权限
|
|
|
- // uni.showModal({
|
|
|
- // content: '检测到您没打开获取位置功能权限,是否去设置打开?',
|
|
|
- // confirmText: "确认",
|
|
|
- // cancelText: '取消',
|
|
|
- // success: (res) => {
|
|
|
- // console.log('res.confirm', res.confirm);
|
|
|
- // if (res.confirm) {
|
|
|
- // uni.openSetting({
|
|
|
- // success: (res) => {
|
|
|
- // $modal.msg('授权后请重新打开此页面')
|
|
|
- // },
|
|
|
- // fail: (err) => {
|
|
|
- // console.log(err);
|
|
|
- // }
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // uni.showToast({
|
|
|
- // title: '获取地理位置授权失败',
|
|
|
- // icon: 'none',
|
|
|
- // success: () => {
|
|
|
- // // 返回上一页
|
|
|
- // setTimeout(() => {
|
|
|
- // // $modal.msg('返回上一页')
|
|
|
- // $tab.navigateBack()
|
|
|
- // }, 1000);
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
+ console.log('getLocationErr', err);
|
|
|
+ reject(err); // 拒绝 Promise
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 获取当前位置地址
|
|
|
function getAddress() {
|
|
|
- getlocation(); // 获取当前位置
|
|
|
- tranLocationToAddress(); // 执行地址转换
|
|
|
+ getlocation()
|
|
|
+ .then(() => {
|
|
|
+ tranLocationToAddress(); // 执行地址转换
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.error('获取地址失败', err);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// 经纬度转地址
|
|
|
function tranLocationToAddress() {
|
|
|
let locationStr = latitude.value + ',' + longitude.value; // 组合经纬度
|
|
|
tranAddress(locationStr).then(res => {
|
|
|
- console.log('请求成功', res);
|
|
|
+ // console.log('地址转换请求成功', res);
|
|
|
address.value = res.result.address; // 保存地址
|
|
|
})
|
|
|
.catch(err => {
|
|
|
- console.error('请求失败', err); // 请求错误处理
|
|
|
+ console.error('地址转换请求失败', err); // 请求错误处理
|
|
|
})
|
|
|
-
|
|
|
- // uni.request({
|
|
|
- // url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + locationStr + '&key=' + mapKey.value +
|
|
|
- // '&get_poi=1',
|
|
|
- // method: 'GET',
|
|
|
- // success: function(res) {
|
|
|
- // console.log('请求成功', res.data);
|
|
|
- // address.value = res.data.result.address; // 保存地址
|
|
|
- // },
|
|
|
- // fail: function(err) {
|
|
|
- // console.error('请求失败', err); // 请求错误处理
|
|
|
- // }
|
|
|
- // });
|
|
|
}
|
|
|
|
|
|
|