ソースを参照

feat(message):新增公告,消息列表数据对接接口
fix(mine/clockIn):修复重复打卡微信返回错误时再次提示授权定位

HMY 1 年間 前
コミット
c49f7b2ae1
3 ファイル変更496 行追加519 行削除
  1. 30 0
      api/message.js
  2. 62 137
      pages/message/index.vue
  3. 404 382
      pages/mine/clockIn/clockIn.vue

+ 30 - 0
api/message.js

@@ -23,4 +23,34 @@ export function GetNoticeList(params) {
 			'params': params
 		}
 	})
+}
+
+//获取公告详情
+export function GetNoticeInfo(params) {
+	return request({
+		url: preUrl,
+		method: 'post',
+		data: {
+			'serviceId': 'eu_notice_2013V0010PHONE002',
+			'params': {
+				'userId': params.userId, //当前用户id
+				'noticeId': params.noticeId
+			}
+		}
+	})
+}
+
+//获取消息详情
+export function GetMessageInfo(params) {
+	return request({
+		url: preUrl,
+		method: 'post',
+		data: {
+			'serviceId': 'oa_2017V002PHONE_messageInfo',
+			'params': {
+				'universalid': params.universalid,
+				'messageId': params.messageId
+			}
+		}
+	})
 }

+ 62 - 137
pages/message/index.vue

@@ -53,8 +53,9 @@
 						styleType="text" activeColor="#409eff"></uni-segmented-control>
 				</view>
 				<view class="content">
-					<view @click="handleToDetail(message)" v-for="(message, index) in notices" :key="index"
-						:class="message.if_read ? ' ' : 'message_container_unread'" class="message_container">
+					<view @click="handleToDetail({ message: message, type: 0 })" v-for="(message, index) in notices"
+						:key="index" :class="message.if_read ? ' ' : 'message_container_unread'"
+						class="message_container">
 						<uni-card :is-full="true">
 							<template v-slot:title>
 								<uni-row>
@@ -68,13 +69,13 @@
 								</uni-row>
 								<uni-row>
 									<view class="message_mid_container">
-										<uni-col :span="16">
+										<uni-col :span="15">
 											<text class="message_title hidden_over">
 												<text :class="message.icon" class="ygoa-icon"></text>
 												<text class="message_title_text">{{ message.title }}</text>
 											</text>
 										</uni-col>
-										<uni-col :span="8">
+										<uni-col :span="9">
 											<text class="message_time">
 												{{ message.sendtime }}
 											</text>
@@ -105,30 +106,31 @@
 						activeColor="#409eff"></uni-segmented-control>
 				</view>
 				<view class="content">
-					<view @click="handleToDetail(message)" v-for="(message, index) in messages" :key="index"
-						:class="message.is_read ? ' ' : 'message_container_unread'" class="message_container">
+					<view @click="handleToDetail({ message: message, type: 1 })" v-for="(message, index) in messages"
+						:key="index" :class="message.isread=='Y' ? ' ' : 'message_container_unread'"
+						class="message_container">
 						<uni-card :is-full="true">
 							<template v-slot:title>
 								<uni-row>
 									<view class="message_top_container">
 										<uni-col :span="24">
 											<text class="message_user">
-												{{ message.user }}
+												{{ message.name }}
 											</text>
 										</uni-col>
 									</view>
 								</uni-row>
 								<uni-row>
 									<view class="message_mid_container">
-										<uni-col :span="19">
+										<uni-col :span="15">
 											<text class="message_title hidden_over">
 												<text :class="message.icon" class="ygoa-icon"></text>
 												<text class="message_title_text">{{ message.title }}</text>
 											</text>
 										</uni-col>
-										<uni-col :span="4">
+										<uni-col :span="9">
 											<text class="message_time">
-												{{ message.time }}
+												{{ message.sendtime }}
 											</text>
 										</uni-col>
 									</view>
@@ -148,9 +150,7 @@
 			<uni-fab :pattern="{icon:'headphones'}" :popMenu="false" horizontal="right"
 				@fabClick="clickFabButton"></uni-fab>
 		</view>
-		<view class="checkIn_button">
-			<uni-fab :pattern="{icon:'calendar'}" :popMenu="false" horizontal="left" @fabClick="clickCheckIn"></uni-fab>
-		</view>
+
 	</view>
 </template>
 
@@ -160,22 +160,19 @@
 	import $tab from '@/plugins/tab.js';
 	import processList from '@/components/ygoa/processList.vue'
 	import { useUserStore } from '@/store/user.js'
+	import { GetMessageList, GetNoticeList } from '@/api/message.js';
 	onLoad((options) => {
 		if (options.to == 'clockIn') {
 			$tab.navigateTo('/pages/mine/clockIn/clockIn')
 		}
 	})
-	import { GetMessageList, GetNoticeList } from '@/api/message.js';
+
 	onMounted(() => {
 		onClickItem({ currentIndex: 0 })
 		onClickItem2({ currentIndex: 0 })
 	})
 	const userStore = useUserStore()
-	function clickCheckIn() {
-		console.log('clickCheckIn', userStore.user);
-		// console.log('getUserInfo', getUserInfo());
-		// $tab.navigateTo('/pages/mine/clockIn/clockIn')
-	}
+
 	// 分段器选项列表
 	const items = reactive(['全部', '已读', '未读'])
 	// 分段器选项
@@ -224,89 +221,49 @@
 			step: 0
 		},
 	])
-	// const msg = reactive({
-	// 	msgId: '1',
-	// 	title: '账户2 的加班申请',
-	// 	userName: '账户2',
-	// 	createTime: '2024/10/10',
-	// 	icon: 'icon-announce',
-	// 	is_read: '1',
-	// 	msgType: '0',//0消息或1公告
-	// })
+
 
 	// 点击消息分段器
 	function onClickItem({ currentIndex }) {
 		current.value = currentIndex
-		console.log("onClickItem", currentIndex);
+		let params = {};
 		switch (currentIndex) {
 			case 0:
-				messages.value = [
-					{
-						id: 3,
-						user: "账户3",
-						title: "未读公告3未读公告3未读公告3未读公告3未读公告3未读公告3",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-announce',
-						is_read: 0
-					},
-					{
-						id: 4,
-						user: "账户4",
-						title: "未读通知4",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-notify',
-						is_read: 0
-					}
-				]
+				params = {
+					"currentUser": userStore.user.useId,
+					"isRead": "",
+					"pSize": "5",
+					"type": "",
+					"p": "1",
+				}
+				GetMessageList(params).then(res => {
+					messages.value = res.returnParams.list;
+				})
+
 				break;
 			case 1:
-				console.log("case1")
-				messages.value = [
-					{
-						id: 1,
-						user: "账户1",
-						title: "已读公告1",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-announce',
-						is_read: 1
-					},
-					// {
-					// 	id: 2,
-					// 	user: "账户2",
-					// 	title: "已读通知2",
-					// 	content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-					// 	time: "2024/10/10",
-					// 	icon: 'icon-notify',
-					// 	is_read: 1
-					// }
-				];
-				console.log(messages.value);
-
+				params = {
+					"currentUser": userStore.user.useId,
+					"isRead": "1",
+					"pSize": "5",
+					"type": "",
+					"p": "1",
+				}
+				GetMessageList(params).then(res => {
+					messages.value = res.returnParams.list;
+				})
 				break;
 			case 2:
-				messages.value = [
-					{
-						id: 3,
-						user: "账户3",
-						title: "未读公告3未读公告3未读公告3未读公告3未读公告3未读公告3",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-announce',
-						is_read: 0
-					},
-					{
-						id: 4,
-						user: "账户4",
-						title: "未读通知4",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-notify',
-						is_read: 0
-					}
-				]
+				params = {
+					"currentUser": userStore.user.useId,
+					"isRead": "0",
+					"pSize": "5",
+					"type": "",
+					"p": "1",
+				}
+				GetMessageList(params).then(res => {
+					messages.value = res.returnParams.list;
+				})
 				break;
 		}
 	}
@@ -317,7 +274,6 @@
 		console.log(currentIndex);
 		switch (currentIndex) {
 			case 0:
-				// console.log('userStore', JSON.parse(JSON.stringify(userStore.user)))
 				const params1 = {
 					"notice_title": "",
 					"p": "1",
@@ -327,59 +283,28 @@
 				}
 				GetNoticeList(params1).then(res => {
 					// console.log(res);
-					notices.value=res.returnParams.noticelist.list;
+					notices.value = res.returnParams.noticelist.list;
 				})
 				break;
 			case 1:
-				notices.value = [
-					{
-						id: 1,
-						user: "账户1",
-						title: "已读公告1",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-announce',
-						is_read: 1
-					},
-					{
-						id: 2,
-						user: "账户2",
-						title: "已读通知2",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-notify',
-						is_read: 1
-					}
-				]
+				notices.value = [];
 				break;
 			case 2:
-				notices.value = [
-					{
-						id: 3,
-						user: "账户3",
-						title: "未读公告3未读公告3未读公告3未读公告3未读公告3未读公告3",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-announce',
-						is_read: 0
-					},
-					{
-						id: 4,
-						user: "账户4",
-						title: "未读通知4",
-						content: "消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容消息内容",
-						time: "2024/10/10",
-						icon: 'icon-notify',
-						is_read: 0
-					}
-				]
+				notices.value = [];
 				break;
 		}
 	}
 	// 点击消息
-	function handleToDetail({ id }) {
-		$tab.navigateTo('/pages/message/detail/index?id=' + id)
-		console.log('handleToDetail', id);
+	function handleToDetail({ message, type }) {
+		switch (type) {
+			case 0:
+				$tab.navigateTo('/pages/message/detail/index?type=' + type + '&noticeId=' + message.id)
+				break
+			case 1:
+				$tab.navigateTo('/pages/message/detail/index?type=' + type + '&messageId=' + message.messageid+ '&universalId=' + message.universalid)
+				break
+		}
+		console.log('handleToDetail', type);
 	}
 	function clickFabButton() {
 		console.log('clickFabButton');

+ 404 - 382
pages/mine/clockIn/clockIn.vue

@@ -36,7 +36,7 @@
 		</atl-map>
 		<!-- 打卡按钮 -->
 		<view class="footer">
-			<button type="primary" @click="signIn">上班签到</button>
+			<button type="primary" @click="signIn" :disabled="isSignInDisabled">上班签到</button>
 			<button type="default" @click="signOut">下班签退</button>
 		</view>
 	</view>
@@ -44,403 +44,425 @@
 
 
 <script setup>
-import { onMounted,reactive,ref} from 'vue';
-// 导入地理位置相关函数
-import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
-import {point,polygon} from "@turf/helpers";
-import {useUserStore} from '@/store/user';
-import $modal from '@/plugins/modal.js'
-import $tab from '@/plugins/tab.js';
-import config from '@/config.js';
-import {createAttendance,TranAddress,CheckAttendance} from '@/api/mine.js'
-const userStore = useUserStore();
-const thisUser = userStore.user;
-
-// 组件挂载后初始化当前日期与位置
-onMounted(() => {
-	dateInit();
-	getlocation();
-});
-
-
-// 当前日期和时间相关信息
-const currentDate = ref('2023-04-01');
-const currentDay = ref('星期三');
-const clockInStatus = ref(''); // 打卡状态
-const weekArr = reactive(['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']); // 星期数组
-const signInTime = ref(''); // 上班签到时间
-const signOutTime = ref(''); // 下班签到时间
-
-// 初始化日期
-function dateInit() {
-	const nowDate = new Date();
-	const year = nowDate.getFullYear(); // 获取年份
-	const month = nowDate.getMonth() + 1; // 获取月份
-	const day = nowDate.getDate(); // 获取日期
-	// 格式化月份和日期为两位数
-	const formattedMonth = month < 10 ? '0' + month : month;
-	const formattedDay = day < 10 ? '0' + day : day;
-	currentDate.value = `${year}-${formattedMonth}-${formattedDay}`; // 设置当前日期
-	const dayOfWeek = nowDate.getDay(); // 获取当前星期
-	currentDay.value = weekArr[dayOfWeek]; // 设置当前星期
-	getTodayAtt();
-}
-
-//获取今天考勤状态
-function getTodayAtt() {
-
-	const params = {
-		universalid: thisUser.useId,
-		rizi: currentDate.value
+	import {
+		onMounted,
+		reactive,
+		ref
+	} from 'vue';
+	// 导入地理位置相关函数
+	import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
+	import {
+		point,
+		polygon
+	} from "@turf/helpers";
+	import {
+		useUserStore
+	} from '@/store/user';
+	import $modal from '@/plugins/modal.js'
+	import $tab from '@/plugins/tab.js';
+	import config from '@/config.js';
+	import {
+		createAttendance,
+		TranAddress,
+		CheckAttendance
+	} from '@/api/mine.js'
+	const userStore = useUserStore();
+	const thisUser = userStore.user;
+
+	// 组件挂载后初始化当前日期与位置
+	onMounted(() => {
+		dateInit();
+		getlocation();
+	});
+
+
+	// 当前日期和时间相关信息
+	const currentDate = ref('2023-04-01');
+	const currentDay = ref('星期三');
+	const clockInStatus = ref(''); // 打卡状态
+	const weekArr = reactive(['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']); // 星期数组
+	const signInTime = ref(''); // 上班签到时间
+	const signOutTime = ref(''); // 下班签到时间
+
+	// 初始化日期
+	function dateInit() {
+		const nowDate = new Date();
+		const year = nowDate.getFullYear(); // 获取年份
+		const month = nowDate.getMonth() + 1; // 获取月份
+		const day = nowDate.getDate(); // 获取日期
+		// 格式化月份和日期为两位数
+		const formattedMonth = month < 10 ? '0' + month : month;
+		const formattedDay = day < 10 ? '0' + day : day;
+		currentDate.value = `${year}-${formattedMonth}-${formattedDay}`; // 设置当前日期
+		const dayOfWeek = nowDate.getDay(); // 获取当前星期
+		currentDay.value = weekArr[dayOfWeek]; // 设置当前星期
+		getTodayAtt();
 	}
-	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');
-			if (time1 !== undefined) {
-				signInTime.value = time1.att_time.split(' ')[1];
-			}
-			if (time2 !== undefined) {
-				signOutTime.value = time2.att_time.split(' ')[1];
+
+	//获取今天考勤状态
+	function getTodayAtt() {
+
+		const params = {
+			universalid: thisUser.useId,
+			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');
+				if (time1 !== undefined) {
+					signInTime.value = time1.att_time.split(' ')[1];
+				}
+				if (time2 !== undefined) {
+					signOutTime.value = time2.att_time.split(' ')[1];
+				}
 			}
+		})
+	}
+
+	// const attType = ref(0)
+	// 上班签到
+	const isSignInDisabled=ref(false)
+	function signIn() {
+		const now = getNowTime();
+		//判断打卡时间是否符合
+		if (!isTimeInRange(now, '08:30:00', '10:00:00')) {
+			$modal.msg('不在签到时间8:30--10:00内')
+			return;
+		}
+		// attType.value=1;
+		var attType = 1;
+		getAddress();
+		if(clockIn(attType)){
+			isSignInDisabled.value=true
 		}
-	})
-}
-
-// const attType = ref(0)
-// 上班签到
-function signIn() {
-	const now = getNowTime();
-	//判断打卡时间是否符合
-	if (!isTimeInRange(now, '08:30:00', '10:00:00')) {
-		$modal.msg('不在签到时间8:30--10:00内')
-		return;
+	};
+
+	// 下班签退
+	function signOut() {
+		const now = getNowTime();
+		//判断打卡时间是否符合
+		if (!isTimeInRange(now, '15:00:00', '20:00:00')) {
+			$modal.msg('不在签退时间15:00--20:00内')
+			return;
+		}
+
+		var attType = 2;
+		getAddress();
+		clockIn(attType); // 执行打卡并获取结果
+	};
+
+	//获取当前时间
+	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;
+		return `${hours}:${minutes}:${seconds}`;
 	}
-	// attType.value=1;
-	var attType = 1;
-	getAddress();
-	clockIn(attType); // 执行打卡
-};
-
-// 下班签退
-function signOut() {
-	const now = getNowTime();
-	//判断打卡时间是否符合
-	if (!isTimeInRange(now, '15:00:00', '20:00:00')) {
-		$modal.msg('不在签退时间15:00--20:00内')
-		return;
+
+	//判断时间是否在区间内
+	function isTimeInRange(time, startTime, endTime) {
+		// 将时间字符串转换为Date对象
+		var timeObj = new Date('1970-01-01T' + time + 'Z');
+		var startObj = new Date('1970-01-01T' + startTime + 'Z');
+		var endObj = new Date('1970-01-01T' + endTime + 'Z');
+		// 比较时间
+		return timeObj >= startObj && timeObj <= endObj;
 	}
 
-	var attType = 2;
-	getAddress();
-	clockIn(attType); // 执行打卡并获取结果
-};
-
-//获取当前时间
-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;
-	return `${hours}:${minutes}:${seconds}`;
-}
-
-//判断时间是否在区间内
-function isTimeInRange(time, startTime, endTime) {
-	// 将时间字符串转换为Date对象
-	var timeObj = new Date('1970-01-01T' + time + 'Z');
-	var startObj = new Date('1970-01-01T' + startTime + 'Z');
-	var endObj = new Date('1970-01-01T' + endTime + 'Z');
-	// 比较时间
-	return timeObj >= startObj && timeObj <= endObj;
-}
-
-
-// 地图配置信息
-// const mapKey = config.mapKey; // 地图API密钥
-const mapType = ref('tmap'); // 地图类型
-const address = ref(''); // 初始化地址
-
-// 打卡定位信息
-const longitude = ref(0); // 经度
-const latitude = ref(0); // 纬度
-
-// 标记信息
-const marker = reactive({
-	id: 1,
-	latitude: 25.958812,
-	longitude: 119.213036,
-	width: 50, // 标记宽度
-	height: 50, // 标记高度
-	title: '宇光同行' // 标记标题
-});
-
-// 获取当前定位经纬度
-function getlocation() {
-	wx.getLocation({
-		// type: 'gcj02',
-		success: (res) => {
-			longitude.value = res.longitude; // 保存经度
-			latitude.value = res.latitude; // 保存纬度
-		},
-		fail: (err) => {
-			// 获取位置失败时提示用户打开权限
-			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);
-							}
-						});
-					}
-				}
-			});
-		},
+
+	// 地图配置信息
+	// const mapKey = config.mapKey; // 地图API密钥
+	const mapType = ref('tmap'); // 地图类型
+	const address = ref(''); // 初始化地址
+
+	// 打卡定位信息
+	const longitude = ref(0); // 经度
+	const latitude = ref(0); // 纬度
+
+	// 标记信息
+	const marker = reactive({
+		id: 1,
+		latitude: 25.958812,
+		longitude: 119.213036,
+		width: 50, // 标记宽度
+		height: 50, // 标记高度
+		title: '宇光同行' // 标记标题
 	});
-}
-
-// 获取当前位置地址
-async function getAddress() {
-	getlocation(); // 获取当前位置
-	tranAddress(); // 执行地址转换
-}
-
-// 经纬度转地址
-function tranAddress() {
-	let locationStr = latitude.value + ',' + longitude.value; // 组合经纬度
-	TranAddress(locationStr).then(res => {
-		console.log('请求成功', res);
-		address.value = res.result.address; // 保存地址
-	})
-		.catch(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); // 请求错误处理
-	// 	}
-	// });
-}
-
-
-// 多边形区域设置
-const polygons = reactive([{
-	points: [{
-		latitude: 25.9591401,
-		longitude: 119.21292356
-	},
-	{
-		latitude: 25.95828592,
-		longitude: 119.21261955
-	},
-	{
-		latitude: 25.9576709,
-		longitude: 119.21458294
-	},
-	{
-		latitude: 25.95845106,
-		longitude: 119.21486162
-	},
-	{
-		latitude: 25.9591401,
-		longitude: 119.21292356
+	// 获取当前定位经纬度
+	function getlocation() {
+		wx.getLocation({
+			// type: 'gcj02',
+			success: (res) => {
+				longitude.value = res.longitude; // 保存经度
+				latitude.value = res.latitude; // 保存纬度
+			},
+			fail: (err) => {
+				if (err.errMsg.includes("频繁调用")) {
+					$modal.msg('请勿频繁调用');
+					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);
+								}
+							});
+						}
+					}
+				});
+			},
+		});
 	}
-	],
-	strokeWidth: 1, // 边框宽度
-	strokeColor: "#ff000066", // 边框颜色
-	fillColor: "#ff000016", // 填充颜色
-}]);
-
-// 打卡
-function clockIn(attType) {
-	// 发起打卡请求相关业务逻辑
-	//判断是否已经打过卡
-	if (isClockIn(attType)) {
-		return;
+
+	// 获取当前位置地址
+	function getAddress() {
+		getlocation(); // 获取当前位置
+		tranAddress(); // 执行地址转换
 	}
-	var now = new Date();
-	// 使用toISOString()获取一个ISO格式的字符串,然后替换T为空格,并去除最后的Z(表示UTC时间)
-	var formatted = now.toISOString().replace('T', ' ').replace('Z', '');
-	var localString = new Date(formatted + '-08:00').toISOString().replace('T', ' ').replace('Z', '');
-	// console.log('nowtime',formatted,localString);
-	const params = {
-		user_name: thisUser.userName,
-		user_id: thisUser.useId,
-		kaoqin_type: attType,
-		now_date: localString,
-		longitude: longitude.value,
-		latitude: latitude.value,
-		address: address.value,
-		unitId: thisUser.unitId
-	};
-	createAttendance(params).then(res => {
-		// console.log('createAttendance',res);
-		if ("success" == res.returnMsg) {
-			uni.showToast({
-				title: "打卡成功",
-				icon: 'none'
-			});
-			getTodayAtt(); //更新今日考勤数据
-		} else {
+
+	// 经纬度转地址
+	function tranAddress() {
+		let locationStr = latitude.value + ',' + longitude.value; // 组合经纬度
+		TranAddress(locationStr).then(res => {
+				console.log('请求成功', res);
+				address.value = res.result.address; // 保存地址
+			})
+			.catch(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); // 请求错误处理
+		// 	}
+		// });
+	}
+
+
+	// 多边形区域设置
+	const polygons = reactive([{
+		points: [{
+				latitude: 25.9591401,
+				longitude: 119.21292356
+			},
+			{
+				latitude: 25.95828592,
+				longitude: 119.21261955
+			},
+			{
+				latitude: 25.9576709,
+				longitude: 119.21458294
+			},
+			{
+				latitude: 25.95845106,
+				longitude: 119.21486162
+			},
+			{
+				latitude: 25.9591401,
+				longitude: 119.21292356
+			}
+		],
+		strokeWidth: 1, // 边框宽度
+		strokeColor: "#ff000066", // 边框颜色
+		fillColor: "#ff000016", // 填充颜色
+	}]);
+
+	// 打卡
+	function clockIn(attType) {
+		// 发起打卡请求相关业务逻辑
+		//判断是否已经打过卡
+		if (isClockIn(attType)) {
+			return;
+		}
+		var now = new Date();
+		// 使用toISOString()获取一个ISO格式的字符串,然后替换T为空格,并去除最后的Z(表示UTC时间)
+		var formatted = now.toISOString().replace('T', ' ').replace('Z', '');
+		var localString = new Date(formatted + '-08:00').toISOString().replace('T', ' ').replace('Z', '');
+		// console.log('nowtime',formatted,localString);
+		const params = {
+			user_name: thisUser.userName,
+			user_id: thisUser.useId,
+			kaoqin_type: attType,
+			now_date: localString,
+			longitude: longitude.value,
+			latitude: latitude.value,
+			address: address.value,
+			unitId: thisUser.unitId
+		};
+		createAttendance(params).then(res => {
+			// console.log('createAttendance',res);
+			if ("success" == res.returnMsg) {
+				uni.showToast({
+					title: "打卡成功",
+					icon: 'none'
+				});
+				getTodayAtt(); //更新今日考勤数据
+				return true;
+			} else {
+				uni.showToast({
+					title: "未在指定范围,打卡失败",
+					icon: 'none'
+				});
+				return false;
+			}
+		})
+		// const _polygons = polygons.map((polygon) => {
+		// 	return polygon.points.map((i) => [
+		// 		Number(i.longitude),
+		// 		Number(i.latitude),
+		// 	]);
+		// });
+		// const _point = point([longitude.value, latitude.value]); // 用当前坐标创建点
+		// const _polygon = polygon(_polygons); // 创建多边形
+		// const f = booleanPointInPolygon(_point, _polygon); // 判断点是否在多边形内	
+	}
+
+	//判断是否已经打卡
+	function isClockIn(attType) {
+		var attTypeData = '';
+		switch (attType) {
+			case 1:
+				attTypeData = signInTime.value;
+				break;
+			case 2:
+				break;
+		}
+		console.log('attTypeData', attTypeData);
+		if ('' !== attTypeData) {
 			uni.showToast({
-				title: "未在指定范围,打卡失败",
+				title: "请勿重复打卡",
 				icon: 'none'
 			});
+			return true;
 		}
-	})
-	// const _polygons = polygons.map((polygon) => {
-	// 	return polygon.points.map((i) => [
-	// 		Number(i.longitude),
-	// 		Number(i.latitude),
-	// 	]);
-	// });
-	// const _point = point([longitude.value, latitude.value]); // 用当前坐标创建点
-	// const _polygon = polygon(_polygons); // 创建多边形
-	// const f = booleanPointInPolygon(_point, _polygon); // 判断点是否在多边形内	
-}
-
-//判断是否已经打卡
-function isClockIn(attType) {
-	var attTypeData = '';
-	switch (attType) {
-		case 1:
-			attTypeData = signInTime.value;
-			break;
-		case 2:
-			break;
-	}
-	console.log('attTypeData', attTypeData);
-	if ('' !== attTypeData) {
-		uni.showToast({
-			title: "请勿重复打卡",
-			icon: 'none'
-		});
-		return true;
+		return false;
 	}
-	return false;
-}
 </script>
 
 <style>
-@import "@/static/font/ygoa/iconfont.css";
-
-.ygoa-icon {
-	margin-right: 20rpx;
-	font-size: 50rpx;
-}
-
-.container {
-	display: flex;
-	flex-direction: column;
-	align-items: center;
-	padding: 20rpx;
-}
-
-.header {
-	width: 100%;
-	height: 200rpx;
-	background-color: #f8f8f8;
-	display: flex;
-	flex-direction: column;
-	align-items: center;
-	justify-content: center;
-}
-
-.day {
-	font-size: 55rpx;
-	font-weight: bold;
-}
-
-.date {
-	font-size: 30rpx;
-	color: #666;
-}
-
-.status {
-	font-size: 24rpx;
-	color: black;
-}
-
-.record {
-	width: 100%;
-	margin-top: 20rpx;
-	border-top: 1px solid #ddd;
-	border-bottom: 1px solid #ddd;
-	padding: 0 15rpx;
-}
-
-.record-item {
-	display: flex;
-	align-items: center;
-	height: 100rpx;
-	border-bottom: 1px solid #eee;
-}
-
-.icon {
-	width: 50rpx;
-	height: 50rpx;
-	margin-right: 10rpx;
-}
-
-.title {
-	font-size: 28rpx;
-}
-
-.time {
-	font-size: 24rpx;
-	color: #999;
-	margin-left: auto;
-}
-
-.map {
-	width: 100%;
-	height: 500rpx;
-	margin-top: 20rpx;
-}
-
-.footer {
-	width: 100%;
-	margin-top: 20rpx;
-	display: flex;
-	justify-content: space-around;
-}
-
-button {
-	width: 45%;
-}
+	@import "@/static/font/ygoa/iconfont.css";
+
+	.ygoa-icon {
+		margin-right: 20rpx;
+		font-size: 50rpx;
+	}
+
+	.container {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		padding: 20rpx;
+	}
+
+	.header {
+		width: 100%;
+		height: 200rpx;
+		background-color: #f8f8f8;
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		justify-content: center;
+	}
+
+	.day {
+		font-size: 55rpx;
+		font-weight: bold;
+	}
+
+	.date {
+		font-size: 30rpx;
+		color: #666;
+	}
+
+	.status {
+		font-size: 24rpx;
+		color: black;
+	}
+
+	.record {
+		width: 100%;
+		margin-top: 20rpx;
+		border-top: 1px solid #ddd;
+		border-bottom: 1px solid #ddd;
+		padding: 0 15rpx;
+	}
+
+	.record-item {
+		display: flex;
+		align-items: center;
+		height: 100rpx;
+		border-bottom: 1px solid #eee;
+	}
+
+	.icon {
+		width: 50rpx;
+		height: 50rpx;
+		margin-right: 10rpx;
+	}
+
+	.title {
+		font-size: 28rpx;
+	}
+
+	.time {
+		font-size: 24rpx;
+		color: #999;
+		margin-left: auto;
+	}
+
+	.map {
+		width: 100%;
+		height: 500rpx;
+		margin-top: 20rpx;
+	}
+
+	.footer {
+		width: 100%;
+		margin-top: 20rpx;
+		display: flex;
+		justify-content: space-around;
+	}
+
+	button {
+		width: 45%;
+	}
 </style>