Browse Source

登录页面增加携参判定 支持token跳转及失效后跳转指定登录地址

dedsudiyu 1 month ago
parent
commit
6e0d441819
5 changed files with 37 additions and 9 deletions
  1. 4 0
      api/request/config.js
  2. 4 5
      api/request/request.js
  3. 10 3
      api/request/requestAKY.js
  4. 1 1
      pages/home.vue
  5. 18 0
      pages/login.vue

+ 4 - 0
api/request/config.js

@@ -2,15 +2,19 @@ const config = {
 	//测试
 	// base_url: 'http://192.168.1.55:8080',
 	// aky_url: 'https://sdaqcom.anquanyue.cn',
+	// login_url:'https://sdaqcom.anquanyue.cn/sdaq/login.php',
 	//缙云山
 	// base_url: 'https://sdaqcom.anquanyue.cn/sdaqSale',
 	// aky_url: 'https://sdaqcom.anquanyue.cn', 
+	// login_url:'https://sdaqcom.anquanyue.cn/sdaq/login.php',
 	//萁山
 	// base_url: 'https://qssdaq.anquanyue.cn/qssdaqSale',
 	// aky_url: 'https://qssdaq.anquanyue.cn',
+	// login_url:'https://qssdaq.anquanyue.cn/sdaq/login.php',
 	//方斗山
 	base_url: 'https://fdssdaq.anquanyue.cn/fdssdaqSale',
 	aky_url: 'https://fdssdaq.anquanyue.cn',
+	login_url:'https://fdssdaq.anquanyue.cn/sdaq/login.php',
 	APP_ID: "app_20260603181947",
 	APP_SECRET: "sk_a7f3e9d2c8b5014f6a2e9d7c3b8a5f1e",
 }

+ 4 - 5
api/request/request.js

@@ -98,13 +98,12 @@ export function loginTimeout(params) {
 	uni.removeStorageSync('userId');
 	uni.removeStorageSync('userType');
 	setTimeout(function() {
-		if(uni.getStorageSync('patrolLoginType')){
-			uni.redirectTo({
-				url: '/pages/views/login/patrolLogin',
-			});
+		if(uni.getStorageSync('skipType')){
+			uni.removeStorageSync('skipType');
+			window.location.href = config.login_url;
 		}else{
 			uni.redirectTo({
-				url: '/pages/views/login/login',
+				url: '/pages/login',
 			});
 		}
 	}, 2000);

+ 10 - 3
api/request/requestAKY.js

@@ -77,9 +77,16 @@ export function loginTimeout(params) {
 		duration: 2000
 	});
 	uni.removeStorageSync('token');
+	uni.removeStorageSync('userId');
+	uni.removeStorageSync('userType');
 	setTimeout(function() {
-		uni.redirectTo({
-			url: '/pages/login',
-		});
+		if(uni.getStorageSync('skipType')){
+			uni.removeStorageSync('skipType');
+			window.location.href = config.login_url;
+		}else{
+			uni.redirectTo({
+				url: '/pages/login',
+			});
+		}
 	}, 2000);
 }

+ 1 - 1
pages/home.vue

@@ -46,7 +46,7 @@
 			async getUserInfo() {
 				let obj = {
 					token: uni.getStorageSync('token'),
-				}
+				};
 				const {
 					data
 				} = await getUserInfo(obj)

+ 18 - 0
pages/login.vue

@@ -45,8 +45,26 @@
 		},
 		onShow() {
 			browserDetection();
+			this.getUrlData();
 		},
 		methods: {
+			getUrlData(){
+				const pages = getCurrentPages();
+				const currentPage = pages[pages.length - 1];
+				const fullPath = currentPage.$page ? currentPage.$page.fullPath : currentPage.route;
+				const tokenMatch = fullPath.match(/[?&]token=([^&]+)/);
+				if (tokenMatch && tokenMatch[1]) {
+					const token = tokenMatch[1];
+					uni.setStorageSync('token', token);
+					uni.setStorageSync('skipType', 1);
+					uni.redirectTo({
+						url: '/pages/home',
+					});
+				}else{
+					uni.removeStorageSync('token');
+					uni.removeStorageSync('skipType');
+				}
+			},
 			//登录
 			async login() {
 				let self = this;