839877316@qq.com 5 달 전
부모
커밋
fd0f1eb288
4개의 변경된 파일358개의 추가작업 그리고 167개의 파일을 삭제
  1. 96 69
      pages/index/index.vue
  2. 27 9
      pages/tabbar/visitor.vue
  3. 80 18
      pagesA/public/phone-login.vue
  4. 155 71
      pagesA/task/detail.vue

+ 96 - 69
pages/index/index.vue

@@ -520,77 +520,98 @@
 				return true;
 			},
 
-			// 提交表单
-			async submitForm() {
-				if (!this.validateForm()) {
-					return;
-				}
-
-				// 过滤空的随行人员
-				const validAccompanyPersons = this.formData.accompanyPersons.filter(person =>
-					person.name && person.phone
-				);
-
-				// 构建提交数据
-				const submitData = {
-					visitDate: this.formData.visitTime, // 访问时间
-					userId: this.formData.employeeId, // 员工id(从选择的员工中获取user_id)
-					empName: this.formData.employeeName, // 访问部门人(员工姓名)
-					visDept: this.formData.visitorCompany, // 访客单位
-					visitPerson: this.formData.visitorName, // 访客姓名
-					visitorTel: this.formData.visitorPhone, // 访客手机
-					visitorNum: (validAccompanyPersons.length + 1).toString(), // 访问人数(访客+随行人员)
-					visitReson: this.formData.visitReason, // 访问事由
-					accPerson: JSON.stringify(validAccompanyPersons) // 随行人员转为JSON字符串
-				};
-
-				console.log('提交数据:', submitData);
+		// 提交表单
+		async submitForm() {
+			if (!this.validateForm()) {
+				return;
+			}
 
-				try {
-					// 调用后端接口提交数据
-					const response = await addVisit(submitData);
-					console.log('提交响应:', response);
+			// 检查是否已登录(通过 openid 缓存判断)
+			const openid = uni.getStorageSync('openid');
+			console.log('当前 openid:', openid);
+			
+			if (!openid) {
+				// 未登录,弹出授权登录组件
+				console.log('未登录,弹出授权登录组件');
+				uni.showToast({
+					title: '请先登录',
+					icon: 'none',
+					duration: 1500
+				});
+				// 延迟弹出登录框,确保提示显示
+				setTimeout(() => {
+					this.$refs.authLoginPopup.open();
+				}, 500);
+				return;
+			}
 
-					// 检查返回结果(支持 code === 200 或 code === "200")
-					if (response && (response.code === 200 || response.code === "200")) {
-						this.$refs.authLoginPopup.open()
-						uni.showToast({
-							title: response.msg || '操作成功',
-							icon: 'success',
-							duration: 2000
-						});
-						this.$refs.successPopup.open();
-						// 延迟返回上一页
-						// setTimeout(() => {
-						// 	uni.navigateBack({
-						// 		fail: () => {
-						// 			// 如果返回失败,跳转到访客页面
-						// 			uni.switchTab({
-						// 				url: '/pages/tabbar/visitor'
-						// 			});
-						// 		}
-						// 	});
-						// }, 2000);
-					} else {
-						// 提交失败
-						uni.showToast({
-							title: response.msg || response.message || '提交失败,请重试',
-							icon: 'none',
-							duration: 2000
-						});
-					}
-				} catch (error) {
-					console.error('提交异常:', error);
-					// 优先使用后端返回的错误信息
-					const errorMsg = error.data?.msg || error.msg || error.message || '提交失败,请重试';
+			// 已登录,继续提交表单
+			console.log('已登录,继续提交表单');
+
+			// 过滤空的随行人员
+			const validAccompanyPersons = this.formData.accompanyPersons.filter(person =>
+				person.name && person.phone
+			);
+
+			// 构建提交数据
+			const submitData = {
+				visitDate: this.formData.visitTime, // 访问时间
+				userId: this.formData.employeeId, // 员工id(从选择的员工中获取user_id)
+				empName: this.formData.employeeName, // 访问部门人(员工姓名)
+				visDept: this.formData.visitorCompany, // 访客单位
+				visitPerson: this.formData.visitorName, // 访客姓名
+				visitorTel: this.formData.visitorPhone, // 访客手机
+				visitorNum: (validAccompanyPersons.length + 1).toString(), // 访问人数(访客+随行人员)
+				visitReson: this.formData.visitReason, // 访问事由
+				accPerson: JSON.stringify(validAccompanyPersons) // 随行人员转为JSON字符串
+			};
+
+			console.log('提交数据:', submitData);
+
+			try {
+				// 调用后端接口提交数据
+				const response = await addVisit(submitData);
+				console.log('提交响应:', response);
+
+				// 检查返回结果(支持 code === 200 或 code === "200")
+				if (response && (response.code === 200 || response.code === "200")) {
+					uni.showToast({
+						title: response.msg || '操作成功',
+						icon: 'success',
+						duration: 2000
+					});
+					this.$refs.successPopup.open();
+					// 延迟返回上一页
+					// setTimeout(() => {
+					// 	uni.navigateBack({
+					// 		fail: () => {
+					// 			// 如果返回失败,跳转到访客页面
+					// 			uni.switchTab({
+					// 				url: '/pages/tabbar/visitor'
+					// 			});
+					// 		}
+					// 	});
+					// }, 2000);
+				} else {
+					// 提交失败
 					uni.showToast({
-						title: errorMsg,
+						title: response.msg || response.message || '提交失败,请重试',
 						icon: 'none',
 						duration: 2000
 					});
 				}
+			} catch (error) {
+				console.error('提交异常:', error);
+				// 优先使用后端返回的错误信息
+				const errorMsg = error.data?.msg || error.msg || error.message || '提交失败,请重试';
+				uni.showToast({
+					title: errorMsg,
+					icon: 'none',
+					duration: 2000
+				});
+			}
 
-			},
+		},
 
 			// 关闭成功弹框
 			closeSuccessPopup() {
@@ -633,12 +654,18 @@
 				});
 			},
 
-			// 登录成功回调
-			onLoginSuccess(userInfo) {
-				console.log('登录成功,用户信息:', userInfo);
-				// 更新当前页面的用户信息
-				this.user = userInfo;
-			},
+		// 登录成功回调
+		onLoginSuccess(userInfo) {
+			console.log('登录成功,用户信息:', userInfo);
+			// 更新当前页面的用户信息
+			this.user = userInfo;
+			// 登录成功后提示用户可以继续提交
+			uni.showToast({
+				title: '登录成功,请继续提交',
+				icon: 'success',
+				duration: 1500
+			});
+		},
 
 			// 登录弹窗关闭回调
 			onLoginClose() {

+ 27 - 9
pages/tabbar/visitor.vue

@@ -1,11 +1,11 @@
 <template>
 	<!-- 访客记录 -->
 	<view class="container">
-		<template v-if="!isLogin">
+		<template v-if="!isEmployeeLogin">
 			<!-- 未登录状态 -->
 			<view class="no-login">
 				<image src="/static/images/no-login.png" mode="aspectFit" class="no-login-image"></image>
-				<text class="no-login-text">登录后查看更多内容</text>
+				<text class="no-login-text">请使用员工账号登录</text>
 				<button class="login-btn" @click="goToLogin">去登录</button>
 			</view>
 		</template>
@@ -69,21 +69,23 @@
 					current: 1,
 					size: 10,
 				},
-				hasMore: true
+				hasMore: true,
+				isEmployeeLogin: false // 是否是员工登录
 			};
 		},
 		computed: {
 			...mapGetters(['isLogin'])
 		},
 		onLoad() {
-			this.user = uni.getStorageSync("user")
-			console.log(uni.getStorageSync("user"), "usususuus")
-			this.getList();
-
+			this.checkEmployeeLogin();
 		},
 
 		onShow() {
-
+			// 每次显示页面时检查登录状态
+			this.checkEmployeeLogin();
+			if (this.isEmployeeLogin) {
+				this.getList();
+			}
 			// 监听刷新列表事件
 			uni.$on('refreshVisitList', () => {
 				this.refresh();
@@ -99,6 +101,22 @@
 			uni.stopPullDownRefresh();
 		},
 		methods: {
+			// 检查员工登录状态
+			checkEmployeeLogin() {
+				const user = uni.getStorageSync('user');
+				console.log('检查员工登录状态,user:', user);
+				
+				if (user && Object.keys(user).length > 0) {
+					// user 缓存有值,已登录
+					this.isEmployeeLogin = true;
+					this.user = user;
+				} else {
+					// user 缓存没有值,未登录
+					this.isEmployeeLogin = false;
+					this.user = {};
+				}
+			},
+
 			// Refresh list
 			refresh() {
 				this.visitList = []
@@ -222,7 +240,7 @@
 			// 跳转到登录页面
 			goToLogin() {
 				uni.navigateTo({
-					url: '/pagesA/public/login'
+					url: '/pagesA/public/phone-login'
 				});
 			},
 		}

+ 80 - 18
pagesA/public/phone-login.vue

@@ -29,8 +29,8 @@
 
 <script>
 	import {
-
-		phoneLogin
+		phoneLogin,
+		wxLogin
 	} from '@/config/api.js';
 	export default {
 		data() {
@@ -41,7 +41,7 @@
 		},
 		methods: {
 			// 处理登录
-			handleLogin() {
+			async handleLogin() {
 				if (!this.account) {
 					uni.showToast({
 						title: '请输入账号',
@@ -56,26 +56,71 @@
 					});
 					return;
 				}
-				console.log('登录信息:', {
-					account: this.account,
-					password: this.password
+				
+				uni.showLoading({
+					title: '登录中...',
+					mask: true
 				});
-				let params = {
-					"username": this.account,
-					"password": this.password,
-					"wxid": "3"
-				}
-				phoneLogin(params).then((res) => {
-					console.log(res, "登陆成功")
+				
+				try {
+					console.log('登录信息:', {
+						account: this.account,
+						password: this.password
+					});
+					
+					// 第一步:手机号登录 (system/info/login)
+					let params = {
+						"username": this.account,
+						"password": this.password,
+						"wxid": "3"
+					}
+					const phoneRes = await phoneLogin(params);
+					console.log(phoneRes, "手机号登录成功")
 
-					uni.setStorageSync('access_token', res.token);
+					// 保存手机号登录返回的token
+					uni.setStorageSync('access_token', phoneRes.token);
+					
 					// 保存用户信息到缓存
-					if (res.user) {
-						uni.setStorageSync('user', res.user);
+					if (phoneRes.user) {
+						uni.setStorageSync('user', phoneRes.user);
+					}
+
+					// 第二步:微信登录 (system/link/login)
+					const loginRes = await this.wxLoginPromise();
+					console.log('微信登录凭证code:', loginRes.code);
+
+					const wxRes = await wxLogin({
+						code: loginRes.code
+					});
+					console.log('微信登录响应:', wxRes);
+
+					// 保存微信登录返回的openid
+					if (wxRes.openid) {
+						uni.setStorageSync('openid', wxRes.openid);
+					}
+
+					// 如果微信登录返回了新的token,也保存
+					const wxToken = wxRes.token || wxRes.access_token;
+					if (wxToken) {
+						uni.setStorageSync('access_token', wxToken);
+						uni.setStorageSync('token', wxToken);
+					}
+
+					// 如果微信登录返回了用户信息,也保存
+					if (wxRes.user) {
+						uni.setStorageSync('user', wxRes.user);
+					}
+
+					// 保存完整的微信登录数据
+					if (wxRes) {
+						uni.setStorageSync('loginData', wxRes);
 					}
 
+					// 更新store状态
 					this.$store.commit('isLogin', true);
 
+					uni.hideLoading();
+
 					uni.showToast({
 						title: '登录成功',
 						icon: 'success',
@@ -88,9 +133,26 @@
 							url: '/pages/index/index'
 						});
 					}, 1000);
+					
+				} catch (error) {
+					console.error('登录错误:', error);
 					uni.hideLoading();
-				})
-
+					uni.showToast({
+						title: error.message || '登录失败,请重试',
+						icon: 'none'
+					});
+				}
+			},
+			
+			// 微信登录 Promise 封装
+			wxLoginPromise() {
+				return new Promise((resolve, reject) => {
+					uni.login({
+						provider: 'weixin',
+						success: (res) => resolve(res),
+						fail: (err) => reject(new Error('获取登录凭证失败'))
+					});
+				});
 			}
 		},
 

+ 155 - 71
pagesA/task/detail.vue

@@ -2,6 +2,10 @@
 	
 	<!-- 任务详情 -->
 	<view class="container">
+		<!-- 状态标签 -->
+		<view class="status-bar" :class="getStatusBarClass(visitDetail.status)">
+			<text class="status-text">{{ visitDetail.status }}</text>
+		</view>
 
 		<!-- 详情内容 -->
 		<view class="detail-container">
@@ -174,6 +178,17 @@
 			}
 		},
 		methods: {
+			// 获取状态栏样式类
+			getStatusBarClass(status) {
+				const statusClassMap = {
+					'待访问': 'status-bar-pending-visit',
+					'已访问': 'status-bar-visited',
+					'待审核': 'status-bar-pending-review',
+					'已拒绝': 'status-bar-rejected'
+				};
+				return statusClassMap[status] || 'status-bar-default';
+			},
+
 			// 获取访问详情
 			getVisitDetail() {
 				// 从缓存中获取数据
@@ -239,96 +254,107 @@
 				this.confirmAction = '';
 			},
 
-			// 确认通过
-			async approveVisit() {
-				this.$refs.confirmPopup.close();
+		// 确认通过
+		async approveVisit() {
+			this.$refs.confirmPopup.close();
+
+			uni.showLoading({
+				title: '处理中...'
+			});
 
-				uni.showLoading({
-					title: '处理中...'
+			try {
+				// 调用接口,状态改为 0=待访问(通过)
+				const response = await updateVisitInfo({
+					id: this.visitDetail.id,
+					visitStatus: '0'
 				});
 
-				try {
-					// 调用接口,状态改为 1=已访问(通过)
-					const response = await updateVisitInfo({
-						id: this.visitDetail.id,
-						visitStatus: '0'
-					});
+				uni.hideLoading();
 
-					uni.hideLoading();
-
-					if (response && response.code === 200) {
-						// 更新本地状态
-						this.visitDetail.status = '已访问';
-
-						// 显示成功提示
-						this.resultType = 'success';
-						this.resultTitle = '审核通过';
-						this.resultMessage = '访问申请已通过,访客将收到通知';
-						this.$refs.resultPopup.open();
-
-						// 通知 visitor.vue 刷新列表
-						uni.$emit('refreshVisitList');
-					} else {
-						uni.showToast({
-							title: response.msg || '操作失败',
-							icon: 'none'
-						});
-					}
-				} catch (error) {
-					uni.hideLoading();
-					console.error('审核通过失败:', error);
+				if (response && response.code === 200) {
+					// 实时更新本地状态
+					this.visitDetail.status = '待访问';
+					
+					// 强制页面刷新
+					this.$forceUpdate();
+
+					// 显示成功提示
+					this.resultType = 'success';
+					this.resultTitle = '审核通过';
+					this.resultMessage = '访问申请已通过,访客将收到通知';
+					this.$refs.resultPopup.open();
+
+					// 通知 visitor.vue 刷新列表
+					uni.$emit('refreshVisitList');
+					
+					console.log('审核通过,状态已更新为:', this.visitDetail.status);
+				} else {
 					uni.showToast({
-						title: '操作失败,请重试',
+						title: response.msg || '操作失败',
 						icon: 'none'
 					});
 				}
+			} catch (error) {
+				uni.hideLoading();
+				console.error('审核通过失败:', error);
+				uni.showToast({
+					title: '操作失败,请重试',
+					icon: 'none'
+				});
+			}
 
-			},
+		},
 
-			// 确认拒绝
-			async rejectVisit() {
-				this.$refs.confirmPopup.close();
+		// 确认拒绝
+		async rejectVisit() {
+			this.$refs.confirmPopup.close();
+
+			uni.showLoading({
+				title: '处理中...'
+			});
 
-				uni.showLoading({
-					title: '处理中...'
+			try {
+				// 调用接口,状态改为 3=已拒绝
+				const response = await updateVisitInfo({
+					id: this.visitDetail.id,
+					visitStatus: '3'
 				});
 
-				try {
-					// 调用接口,状态改为 3=已拒绝
-					const response = await updateVisitInfo({
-						id: this.visitDetail.id,
-						visitStatus: '3'
-					});
+				uni.hideLoading();
 
-					uni.hideLoading();
-
-					if (response && response.code === 200) {
-						// 更新本地状态
-						this.visitDetail.status = '已拒绝';
-
-						// 显示成功提示
-						this.resultType = 'success';
-						this.resultTitle = '审核完成';
-						this.resultMessage = '访问申请已拒绝,访客将收到通知';
-						this.$refs.resultPopup.open();
-// 通知 visitor.vue 刷新列表
-						uni.$emit('refreshVisitList');
-					} else {
-						uni.showToast({
-							title: response.msg || '操作失败',
-							icon: 'none'
-						});
-					}
-				} catch (error) {
-					uni.hideLoading();
-					console.error('拒绝访问失败:', error);
+				if (response && response.code === 200) {
+					// 实时更新本地状态
+					this.visitDetail.status = '已拒绝';
+					
+					// 强制页面刷新
+					this.$forceUpdate();
+
+					// 显示成功提示
+					this.resultType = 'success';
+					this.resultTitle = '审核完成';
+					this.resultMessage = '访问申请已拒绝,访客将收到通知';
+					this.$refs.resultPopup.open();
+
+					// 通知 visitor.vue 刷新列表
+					uni.$emit('refreshVisitList');
+					
+					console.log('审核拒绝,状态已更新为:', this.visitDetail.status);
+				} else {
 					uni.showToast({
-						title: '操作失败,请重试',
+						title: response.msg || '操作失败',
 						icon: 'none'
 					});
 				}
+			} catch (error) {
+				uni.hideLoading();
+				console.error('拒绝访问失败:', error);
+				uni.showToast({
+					title: '操作失败,请重试',
+					icon: 'none'
+				});
+			}
 
-			},
+		},
 
 			// 关闭结果弹框
 			closeResultPopup() {
@@ -347,6 +373,64 @@
 		padding-bottom: 140rpx;
 	}
 
+	// 状态栏样式
+	.status-bar {
+		margin: 20rpx;
+		padding: 20rpx 30rpx;
+		border-radius: 12rpx;
+		text-align: center;
+		
+		.status-text {
+			font-size: 32rpx;
+			font-weight: 600;
+		}
+
+		&.status-bar-pending-visit {
+			background: linear-gradient(135deg, rgba(76, 175, 80, 0.1) 0%, rgba(76, 175, 80, 0.2) 100%);
+			border: 2rpx solid rgba(76, 175, 80, 0.3);
+			
+			.status-text {
+				color: #4CAF50;
+			}
+		}
+
+		&.status-bar-visited {
+			background: linear-gradient(135deg, rgba(33, 150, 243, 0.1) 0%, rgba(33, 150, 243, 0.2) 100%);
+			border: 2rpx solid rgba(33, 150, 243, 0.3);
+			
+			.status-text {
+				color: #2196F3;
+			}
+		}
+
+		&.status-bar-pending-review {
+			background: linear-gradient(135deg, rgba(255, 152, 0, 0.1) 0%, rgba(255, 152, 0, 0.2) 100%);
+			border: 2rpx solid rgba(255, 152, 0, 0.3);
+			
+			.status-text {
+				color: #FF9800;
+			}
+		}
+
+		&.status-bar-rejected {
+			background: linear-gradient(135deg, rgba(244, 67, 54, 0.1) 0%, rgba(244, 67, 54, 0.2) 100%);
+			border: 2rpx solid rgba(244, 67, 54, 0.3);
+			
+			.status-text {
+				color: #F44336;
+			}
+		}
+
+		&.status-bar-default {
+			background: linear-gradient(135deg, rgba(158, 158, 158, 0.1) 0%, rgba(158, 158, 158, 0.2) 100%);
+			border: 2rpx solid rgba(158, 158, 158, 0.3);
+			
+			.status-text {
+				color: #999;
+			}
+		}
+	}
+
 	.detail-container {
 		padding: 20rpx;
 	}