Selaa lähdekoodia

修改启动app登录拦截

qukaidi 4 vuotta sitten
vanhempi
commit
23e741b4f2
4 muutettua tiedostoa jossa 23 lisäystä ja 21 poistoa
  1. 8 15
      App.vue
  2. 12 3
      pages/home/index.vue
  3. 2 2
      pages/login/index.vue
  4. 1 1
      pages/login/register_3.vue

+ 8 - 15
App.vue

@@ -1,27 +1,14 @@
 <script>
-	import {mapState,mapMutations} from 'vuex'
+	import {mapMutations} from 'vuex'
 	export default {
 		// 此处globalData为了演示其作用,不是uView框架的一部分
 		globalData: {
 			username: '白居易'
 		},
-		computed: {
-			...mapState(['hasLogin'])
-		},
 		methods:{
 			...mapMutations(['login'])
 		},
-		onLaunch() {
-			// 1.1.0版本之前关于http拦截器代码,已平滑移动到/common/http.interceptor.js中
-			// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明):
-			// import httpInterceptor from '@/common/http.interceptor.js'
-			// Vue.use(httpInterceptor, app)
-			if (!this.hasLogin) {
-				this.$u.route({
-					url: "pages/login/index",
-					type: "redirect"
-				})
-			}
+		created() {
 			let storeInfo=uni.getStorageSync("storeInfo")||"";
 			if(storeInfo.storeId){
 				uni.getStorage({
@@ -32,6 +19,12 @@
 				})
 			}
 		},
+		onLaunch() {
+			// 1.1.0版本之前关于http拦截器代码,已平滑移动到/common/http.interceptor.js中
+			// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明):
+			// import httpInterceptor from '@/common/http.interceptor.js'
+			// Vue.use(httpInterceptor, app)
+		},
 	}
 </script>
 

+ 12 - 3
pages/home/index.vue

@@ -47,7 +47,10 @@
 </template>
 
 <script>
-	import {mapState} from 'vuex'
+	import {
+		mapState,
+		mapMutations
+	} from 'vuex'
 	import {
 		request
 	} from '../../common/request/request'
@@ -77,7 +80,12 @@
 			}
 		},
 		created() {
-			if (this.hasLogin) {
+			if (!this.hasLogin) {
+				this.$u.route({
+					url: "pages/login/index",
+					type: "redirect"
+				})
+			} else {
 				uni.showLoading({
 					title: '加载中...'
 				});
@@ -93,8 +101,9 @@
 					.finally(() => {
 						this.loading = false;
 						uni.hideLoading();
-				})
+					})
 			}
+
 		},
 		computed: {
 			...mapState(['hasLogin'])

+ 2 - 2
pages/login/index.vue

@@ -78,6 +78,8 @@
 			        this.networkType=res.networkType
 			    }
 			});
+		},
+		created() {
 			if(this.hasLogin){
 				this.$u.route({
 					url: 'pages/home/index',
@@ -85,8 +87,6 @@
 				})
 			}
 		},
-		created() {
-		},
 		methods: {
 			...mapMutations(['login']),
 			toUser(provider){

+ 1 - 1
pages/login/register_3.vue

@@ -262,7 +262,7 @@
 					console.log(res)
 					if (res.data.code == 0) {
 						this.loading = true
-						this.$u.toast("注册成功");
+						this.$u.toast(res.data.msg);
 						setTimeout(() => {
 							this.$u.route({
 								url: 'pages/login/index',