Bladeren bron

Signed-off-by: 1004749546@qq.com <1004749546@qq.com>
提交

1004749546@qq.com 4 jaren geleden
bovenliggende
commit
e10d004cac
4 gewijzigde bestanden met toevoegingen van 35 en 36 verwijderingen
  1. 4 4
      api/login.js
  2. 0 1
      libs/axios.js
  3. 1 1
      pages/index/index.vue
  4. 30 30
      pages/login/login.vue

+ 4 - 4
api/login.js

@@ -5,15 +5,15 @@ export const login = params => {
     url: `login`,
     method: 'post',
 	header: { 'Content-Type': 'application/x-www-form-urlencoded' },
-	data:`code=${params.code}&encryptedData=${params.encryptedData}&iv=${params.iv}`
-  }).then(res => res.data);
+	data: params
+  })
 };
 export const logout = params => {
   return axios.request({
     url: `logout`,
     data: params,
     method: 'get'
-  }).then(res => res.data);
+  })
 };
 
 // 验证是否登录过
@@ -23,7 +23,7 @@ export const checkLogin = () => {
     return axios.request({
       url: `checkToken`,
       method: 'get'
-    }).then(res => res.data);
+    })
   } else {
     return new Promise(resolve => {
       resolve({

+ 0 - 1
libs/axios.js

@@ -9,7 +9,6 @@ const request = (opts, hasToken) => {
 		}
 	if(!hasToken){
 		header['X-AUTH-TOKEN'] = authorization
-		header['X-HEADER-APPID'] = 'vb/TIFOLtHqF5qWlwFKVie3SAD9Ef1ec8ERVkvn5brk='
 	}	
 	//此token是登录成功后后台返回保存在storage中的
 	let DefaultOpts = {

+ 1 - 1
pages/index/index.vue

@@ -108,9 +108,9 @@
 			this.mapCtx = uni.createMapContext('map')
 		},
 		onShow() {
-			this.checkLogin()
 		},
 		onLoad() {
+			this.checkLogin()
 			this.getUserLocation()
 		},
 		methods: {

+ 30 - 30
pages/login/login.vue

@@ -16,7 +16,9 @@
 				lanuch: true
 			}
 		},
-		onShow() {},
+		onShow() {
+			
+		},
 		mounted() {},
 		onLoad(option) {
 			console.log(option)
@@ -31,46 +33,44 @@
 		},
 		methods: {
 			getPhoneNumber(e) {
+				let _this = this
 				uni.showLoading({
 					mask: true,
 					title: '加载中'
 				});
+				console.log(e.target.encryptedData,'eeeeeee')
 				if (e.target.errMsg === 'getPhoneNumber:ok') {
 					uni.login({
-						success(result) {
-							if (result.code) {
-								login({
-									code: result.code,
-									encryptedData: e.target.encryptedData,
-									iv: e.target.iv
-								}).then(res => {
-									uni.hideLoading();
-									if (res.status === '200') {
-										console.log(res.data, 'login data')
-										uni.setStorageSync('token', res.data.token);
-										uni.setStorageSync('phone', res.data.phone);
-										uni.setStorageSync('userId', res.data.userId);
-										if (this.path === '/pages/index/main' || this.lanuch) {
-											uni.reLaunch({
-												url: this.path
-											});
-										} else {
-											uni.redirectTo({
-												url: this.path
-											});
-										}
+						success(res) {
+							login({
+								code: res.code,
+								encryptedData: e.target.encryptedData,
+								iv: e.target.iv
+							}).then(res => {
+								uni.hideLoading();
+								console.log(res, 'login data')
+								if (res.status == '200') {
+									console.log(res.data, 'login data')
+									uni.setStorageSync('token', res.data);
+									if (_this.path === '/pages/index/main' || _this.lanuch) {
+										uni.reLaunch({
+											url: _this.path
+										});
 									} else {
-										uni.showToast({
-											title: res.message,
-											icon: 'none',
-											duration: 2500
+										uni.redirectTo({
+											url: _this.path
 										});
 									}
-								});
-							}
+								} else {
+									uni.showToast({
+										title: res.message,
+										icon: 'none',
+										duration: 2500
+									});
+								}
+							});
 						}
 					})
-
 				} else {
 					uni.showToast({
 						title: '授权失败',