Browse Source

perf: 优化登录

lizhaocai 3 months ago
parent
commit
8fd161aac5

+ 6 - 3
pages/discovery/discovery.vue

@@ -24,7 +24,7 @@
 		
 		<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" >
 			<swiper-item v-for="item of companyList" :key="item.id" style="position:relative">
-				<view style="position: absolute;bottom: 28px;right: 16px;color: #ffffff75;" class="swiper-item uni-bg-red">{{item.company}}</view>
+				<!-- <view style="position: absolute;bottom: 28px;right: 16px;color: #ffffff75;" class="swiper-item uni-bg-red">{{item.company}}</view> -->
 				<image :src="item.picUrl?item.picUrl:'../../static/bg.png'" style="width: 100%;height: 100%;"></image>
 			</swiper-item>
 		</swiper>
@@ -33,7 +33,7 @@
 		</view>
 		<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" >
 			<swiper-item v-for="item of prodList" :key="item.id">
-				<view style="position: absolute;bottom: 28px;right: 16px;color: #ffffff75;" class="swiper-item uni-bg-red">{{item.company}}</view>
+				<!-- <view style="position: absolute;bottom: 28px;right: 16px;color: #ffffff75;" class="swiper-item uni-bg-red">{{item.company}}</view> -->
 				<image :src="item.picUrl?item.picUrl:'../../static/bg.png'" style="width: 100%;height: 100%;"></image>
 			</swiper-item>
 			 
@@ -84,7 +84,10 @@
 			})
 		},
 		methods: {
-			
+			fetchData(){
+				this.loadData()
+				this.loadData2()
+			},
 			loadData() {
 				let that = this;
 				request.post('/slbTopad/premiumCompanies', {

+ 20 - 16
pages/index/auth.vue

@@ -1,7 +1,7 @@
 <template>
 	<view style="display: flex;align-items: center;justify-content: center;height: 100vh;">
 		<!-- <image src="../../static/logo.png" style="width: 90px;height:80px"></image> -->
-		 <tn-loading mode="circle" size="60"></tn-loading>
+		 <!-- <tn-loading mode="circle" size="60"></tn-loading> -->
 
 	</view>
 	
@@ -11,26 +11,30 @@
 	import request from '../../utils/request'
 	
 	export default {
+		name: 'Auth',
 		data() {
 			return {
 				
 			}
 		},
-		onLoad(options) {			 
-			let that = this;
-			uni.login({
-				success(res) {
-					 console.error(res);
-					 that.loginByCode(res.code);
-				},
-				fail(res) {
-					//登录失效,
-					// uni.hideLoading();
-					uni.redirectTo({
-						url:'/pages/index/index'
-					})
-				}
-			});
+		created() {		
+			uni.redirectTo({
+				url:'/pages/index/index'
+			})
+			// let that = this;
+			// uni.login({
+			// 	success(res) {
+			// 		 console.error(res);
+			// 		 that.loginByCode(res.code);
+			// 	},
+			// 	fail(res) {
+			// 		//登录失效,
+			// 		uni.hideLoading();
+			// 		uni.redirectTo({
+			// 			url:'/pages/index/index'
+			// 		})
+			// 	}
+			// });
 		
 		},
 		methods: {

+ 123 - 0
pages/index/autoLogin.vue

@@ -0,0 +1,123 @@
+<template>
+	<view style="display: flex;align-items: center;justify-content: center;height: 100vh;">
+		<!-- <image src="../../static/logo.png" style="width: 90px;height:80px"></image> -->
+		 <tn-loading mode="circle" size="60"></tn-loading>
+
+	</view>
+	
+</template>
+
+<script>
+	import request from '../../utils/request'
+	
+	export default {
+		name: 'Auth',
+		data() {
+			return {
+				
+			}
+		},
+		created() {			 
+			let that = this;
+			uni.login({
+				success(res) {
+					 console.error(res);
+					 that.loginByCode(res.code);
+				},
+				fail(res) {
+					//登录失效,
+					// uni.hideLoading();
+					// uni.redirectTo({
+					// 	url:'/pages/index/index'
+					// })
+				}
+			});
+		
+		},
+		methods: {
+			loginByCode(frontId) {
+				const that = this;
+				uni.setStorageSync('loginStatus', 'false');
+				wx.getUserInfo({
+				  success: function(res) {
+					console.error(res);
+					request.post("/slbMpAutoLogin", {
+					 		code:frontId, 
+					 	    appType:'ma',
+							encryptedData:res.encryptedData,
+							iv: res.iv
+					 	}, {
+						login: false,
+						warn:false,
+						loading:false
+					}).then(res2=>{
+						console.error(res2);
+						if(res2.success){
+							//登录成功
+							uni.setStorageSync('loginStatus', 'true');
+							uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
+							uni.setStorageSync('userNo', res2.resultMap.accountName);
+							that.getUserInfo();
+						}else{
+							console.error(12345);
+							uni.setStorageSync('loginStatus', 'false');
+							uni.removeStorageSync('userMap');
+							uni.removeStorageSync('userNo');
+							uni.removeStorageSync('userInfo');
+							// uni.redirectTo({
+							// 	url:'/pages/index/index'
+							// })
+							//登录失败,
+							// uni.login({
+							// 	success(res) {
+							// 		 console.error(res);
+							// 		 that.getOpenId(res.code);
+							// 	},
+							// 	fail(res) {
+							// 		 console.error(res);
+							// 		uni.hideLoading();
+							// 	}
+							// });
+							 
+						}
+						console.error(res2);
+					});
+					 
+					 
+				  }
+				})
+				 
+				
+			},
+			getUserInfo() {
+					  let that = this;
+					  request.post('/slbWxma/getPersonlInfo', {
+					  	 
+					  }).then(res => {
+							  console.warn(res);
+							  if(res&&res.success){
+								  that.personInfo = res.resultMap.userInfo||{};
+								  uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
+								  // uni.redirectTo({
+								  // 	url:'/pages/index/index'
+								  // })
+							  }else{
+								  uni.setStorageSync('loginStatus', 'false');
+								  uni.removeStorageSync('userMap');
+								  uni.removeStorageSync('userNo');
+								  uni.removeStorageSync('userInfo');
+								  // uni.redirectTo({
+								  // 	url:'/pages/index/index'
+								  // })
+							  }
+					  	console.warn(res);
+					  })
+			   
+			},
+		}
+	}
+</script>
+
+<style>
+
+</style>

+ 7 - 1
pages/index/index.vue

@@ -58,14 +58,16 @@
 				<Mine ref="mine"></Mine>
 			</scroll-view>
 		</view>
-
+		<Auth></Auth>
 		<tn-tabbar v-model="currentIndex" :list="tabbarList" activeColor="#1d60b1" inactiveColor="#AAAAAA"
 			activeIconColor="#1d60b1" :animation="true" :safeAreaInsetBottom="true" @change="switchTabbar"></tn-tabbar>
 			<canvas type="2d" id="myCanvas" style="width: 450px; height: 450px;left:9000px;position:fixed;"></canvas>
+		
 	</view>
 </template>
 
 <script>
+	import Auth from '../index/autoLogin.vue'
 	import Home from '../home/home.vue'
 	import Comm from '../comm/comm.vue'
 	import Discovery from '../discovery/discovery.vue'
@@ -73,6 +75,7 @@
     import request from '../../utils/request'
 	export default {
 		components: {
+			Auth,
 			Home,
 			Comm,
 			Discovery,
@@ -151,6 +154,9 @@
 			if (this.currentIndex === 1&&this.$refs.comm) {
 				this.$refs.comm.fetchData();
 			}
+			if (this.currentIndex === 2&&this.$refs.discovery) {
+				this.$refs.discovery.fetchData();
+			}
 		},
 		methods: {
 			// 切换导航

+ 2 - 2
pages/mine/mine.vue

@@ -358,8 +358,8 @@
 		  		 	title: '注销成功',
 		  		 	icon: 'none'
 		  		 })
-				 uni.navigateTo({
-				   url: '/pages/index/auth'
+				 uni.reLaunch({
+				   url: '/pages/index/index'
 				 })
 		  	}else{
 				uni.showToast({

File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/.sourcemap/mp-weixin/common/runtime.js.map


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/.sourcemap/mp-weixin/pages/discovery/discovery.js.map


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/.sourcemap/mp-weixin/pages/index/auth.js.map


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/.sourcemap/mp-weixin/pages/index/index.js.map


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/.sourcemap/mp-weixin/pages/mine/mine.js.map


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/common/runtime.js


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/common/vendor.js


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/pages/discovery/discovery.js


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/pages/discovery/discovery.wxml


File diff suppressed because it is too large
+ 11 - 2
unpackage/dist/dev/mp-weixin/pages/index/auth.js


+ 1 - 3
unpackage/dist/dev/mp-weixin/pages/index/auth.json

@@ -1,6 +1,4 @@
 {
   "navigationBarTitleText": "",
-  "usingComponents": {
-    "tn-loading": "/tuniao-ui/components/tn-loading/tn-loading"
-  }
+  "usingComponents": {}
 }

+ 1 - 1
unpackage/dist/dev/mp-weixin/pages/index/auth.wxml

@@ -1 +1 @@
-<view style="display:flex;align-items:center;justify-content:center;height:100vh;"><tn-loading vue-id="59016948-1" mode="circle" size="60" bind:__l="__l"></tn-loading></view>
+<view style="display:flex;align-items:center;justify-content:center;height:100vh;"></view>

File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/pages/index/index.js


+ 1 - 0
unpackage/dist/dev/mp-weixin/pages/index/index.json

@@ -4,6 +4,7 @@
     "tn-nav-bar": "/tuniao-ui/components/tn-nav-bar/tn-nav-bar",
     "tn-loading": "/tuniao-ui/components/tn-loading/tn-loading",
     "tn-tabbar": "/tuniao-ui/components/tn-tabbar/tn-tabbar",
+    "auth": "/pages/index/autoLogin",
     "home": "/pages/home/home",
     "comm": "/pages/comm/comm",
     "discovery": "/pages/discovery/discovery",

File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/pages/index/index.wxml


File diff suppressed because it is too large
+ 1 - 1
unpackage/dist/dev/mp-weixin/pages/mine/mine.js


+ 1 - 0
utils/request.js

@@ -127,6 +127,7 @@ function baseRequest(config, options) {
 					return;
 				}
 				else if(data._redirect||data.msg=='未登录'){
+					uni.removeStorageSync('userNo');
 					// if(uni.getStorageSync('userNo')){
 					// 	uniShowModal('', '账号过期,重新登录?', {
 					// 		showCancel: true,