فهرست منبع

修改启动页跳转登录页面的问题,添加token

qukaidi 4 سال پیش
والد
کامیت
13daae78cb
10فایلهای تغییر یافته به همراه77 افزوده شده و 35 حذف شده
  1. 31 10
      App.vue
  2. 1 0
      common/request/request.js
  3. 1 1
      manifest.json
  4. 11 1
      pages.json
  5. 2 9
      pages/home/index.vue
  6. 19 0
      pages/index.vue
  7. 1 10
      pages/login/index.vue
  8. 2 2
      pages/login/register.vue
  9. 1 0
      pages/login/register_3.vue
  10. 8 2
      store/index.js

+ 31 - 10
App.vue

@@ -1,21 +1,36 @@
 <script>
-	import {mapMutations} from 'vuex'
+	import {
+		mapState,
+		mapMutations
+	} from 'vuex'
 	export default {
 		// 此处globalData为了演示其作用,不是uView框架的一部分
+		computed: {
+			...mapState(['hasLogin'])
+		},
 		globalData: {
 			username: '白居易'
 		},
-		methods:{
+		methods: {
 			...mapMutations(['login'])
 		},
 		created() {
-			let storeInfo=uni.getStorageSync("storeInfo")||"";
-			if(storeInfo.storeId){
+			const storeInfo = uni.getStorageSync("storeInfo") || "";
+			if (storeInfo) {
 				uni.getStorage({
-					key:"storeInfo",
-					success:(res)=>{
+					key: "storeInfo",
+					success: (res) => {
 						this.login(res.data)
-					}
+						this.$u.route({
+							url: 'pages/home/index',
+							type: 'switchTab',
+						})
+					},
+				})
+			} else {
+				this.$u.route({
+					url: "pages/login/index",
+					type:"redirect"
 				})
 			}
 		},
@@ -25,12 +40,15 @@
 			// import httpInterceptor from '@/common/http.interceptor.js'
 			// Vue.use(httpInterceptor, app)
 		},
+		onShow() {
+		}
 	}
 </script>
 
 <style lang="scss">
 	@import "uview-ui/index.scss";
 	@import "common/demo.scss";
+
 	/*每个页面公共css */
 	// uni-page-head
 	//     {
@@ -39,15 +57,18 @@
 	.u-checkbox__label[data-v-54acf820] {
 		color: #B2B2B2 !important;
 	}
+
 	.uni-input-placeholder {
 		color: #B2B2B2 !important;
 	}
-	page{
+
+	page {
 		height: 100%;
 		background-color: #F4F4F4;
 		font-weight: 500;
 	}
-	.u-skeleton{
+
+	.u-skeleton {
 		height: 100%;
 	}
-</style>
+</style>

+ 1 - 0
common/request/request.js

@@ -36,6 +36,7 @@ export function request(config) {
 
 //在uni-app中使用对app有效果,h5不需要
 axios.defaults.adapter = function (config) {
+	config.headers.Authorization = uni.getStorageSync('token');
     return new Promise((resolve, reject) => {
         var settle = require('axios/lib/core/settle');
         var buildURL = require('axios/lib/helpers/buildURL');

+ 1 - 1
manifest.json

@@ -16,7 +16,7 @@
             }
         },
         "splashscreen" : {
-            "alwaysShowBeforeRender" : true,
+            "alwaysShowBeforeRender" : false,
             "waiting" : true,
             "autoclose" : true,
             "delay" : 0

+ 11 - 1
pages.json

@@ -11,6 +11,16 @@
 	// 	}]
 	// },
 	"pages": [
+		{
+		    "path" : "pages/index",
+		    "style" :                                                                                    
+		    {
+		       "app-plus": {
+		       	"titleNView": false
+		       }
+		    }
+		    
+		},
 		// 首页
 		{
 			"path": "pages/home/index",
@@ -50,7 +60,7 @@
 				}
 			}
 		}
-	],
+    ],
 	"subPackages": [{
 		"root": "pages/home",
 		"pages": [{

+ 2 - 9
pages/home/index.vue

@@ -80,19 +80,13 @@
 			}
 		},
 		created() {
-			if (!this.hasLogin) {
-				this.$u.route({
-					url: "pages/login/index",
-					type: "redirect"
-				})
-			} else {
+			if (this.hasLogin) {
 				uni.showLoading({
 					title: '加载中...'
 				});
 				axios.all([this.getBanners(), this.getTiceList()])
 					.then(axios.spread((one, two) => {
 						this.bannersList = one.data.data.map(t => t.imgPath)
-						console.log(this.bannersList)
 						this.noticebarList = two.data.data.map(t => t.msgContent)
 					}))
 					.catch(err => {
@@ -101,9 +95,8 @@
 					.finally(() => {
 						this.loading = false;
 						uni.hideLoading();
-					})
+				})
 			}
-
 		},
 		computed: {
 			...mapState(['hasLogin'])

+ 19 - 0
pages/index.vue

@@ -0,0 +1,19 @@
+<template>
+	<view>
+		
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				
+			};
+		}
+	}
+</script>
+
+<style lang="scss">
+
+</style>

+ 1 - 10
pages/login/index.vue

@@ -67,7 +67,7 @@
 		computed: {
 			...mapState(['hasLogin'])
 		},
-		onLoad() {
+		created() {
 			uni.getSystemInfo({
 			    success:(res)=>{
 					this.SystemInfo=res
@@ -79,14 +79,6 @@
 			    }
 			});
 		},
-		created() {
-			if(this.hasLogin){
-				this.$u.route({
-					url: 'pages/home/index',
-					type: 'switchTab',
-				})
-			}
-		},
 		methods: {
 			...mapMutations(['login']),
 			toUser(provider){
@@ -121,7 +113,6 @@
 						}
 					}).then(res => {
 						if (res.data.code == 0) {
-							console.log(res.data.data)
 							this.toUser(res.data.data)
 							uni.$emit('login', {
 								msg: '登录成功'

+ 2 - 2
pages/login/register.vue

@@ -32,8 +32,8 @@
 			注:上传完营业执照请确认和营业执照一致。
 		</view>
 		<view style="margin: 30rpx;">
-			<!-- <u-button type="primary" @click="nextStep" v-if="showLicense&&showStore">下一步</u-button> -->
-						<u-button type="primary" @click="nextStep">下一步</u-button>
+			<u-button type="primary" @click="nextStep" v-if="showLicense&&showStore">下一步</u-button>
+						<!-- <u-button type="primary" @click="nextStep">下一步</u-button> -->
 		</view>
 	</view>
 </template>

+ 1 - 0
pages/login/register_3.vue

@@ -227,6 +227,7 @@
 				this.brandAgentLvQueryList = this.checkedAgentlist.reduce((res, item) => {
 					res.push({
 						agent_id: item.agent_id,
+						agent_name:item.name,
 						brand: item.brand,
 						brandCode: item.brandCode,
 						kunnr: item.kunnr,

+ 8 - 2
store/index.js

@@ -65,7 +65,7 @@ const store = new Vuex.Store({
 		//显示提示消息相关配置
 		showToastDuration : 4000,
 		showServerErrorMsg: '连接服务器异常!',
-		hasLogin:false ,//用户是否登录
+		hasLogin:false,//用户是否登录
 		storeInfo:{}//存放用户账号数据
 		
 	},
@@ -97,7 +97,10 @@ const store = new Vuex.Store({
 				key:"storeInfo",
 				data:provider
 			})
-			console.log(state.storeInfo)
+			uni.setStorage({
+			    key: 'token',
+			    data: provider.token,
+			});
 		},
 		logout(state){
 			state.hasLogin=false;
@@ -105,6 +108,9 @@ const store = new Vuex.Store({
 			uni.removeStorage({
 				key:"storeInfo"
 			})
+			uni.removeStorage({
+				key:"token"
+			})
 		}
 	}
 })