Browse Source

ios登录

zhaoxw 4 years ago
parent
commit
7ca490a261
3 changed files with 108 additions and 10 deletions
  1. 18 0
      App.vue
  2. 6 3
      config/api.js
  3. 84 7
      pages/index/login.vue

+ 18 - 0
App.vue

@@ -1,9 +1,27 @@
 <script>
 	// var VConsole = require("./vconsole.min.js")
+	const NET = require('@/utils/request')
+	const API = require('@/config/api')
 	export default {
 		onLaunch: function() {
 			// var vConsole = new VConsole();
 			console.log('App Launch');
+			// #ifdef APP-PLUS
+			    var version = plus.runtime.versionCode
+				console.log('版本号',version)
+				NET.request(API.getAppVersion, {}, 'GET').then(res => {
+					console.log('获取res')
+					try {
+						console.log('进入try',res)
+						if (version != res.data.version) {
+							console.log('判断版本号')
+							plus.runtime.openURL( res.data.url) 
+						}
+					} catch (e) {
+						console.log('版本号错误', e)
+					}
+				})
+			// #endif
 		},
 		onShow: function() {
 			console.log('App Show');

+ 6 - 3
config/api.js

@@ -6,8 +6,10 @@ const WX_API_BASE = 'https://www.qianjiadi.com/'
 module.exports = {
 	sdkAppID: 1400430241,
 	secretKey: '941e01ca06e94057de3013b235b67a784ea28b45c43decbd518e765f7d5fc140',
-	//  微信登录
+	//  微信+安卓登录
 	WxLogin: WX_API_BASE + 'app/auth/user/wx/login',
+	// ios登录
+	IosLogin: WX_API_BASE + 'app/auth/user/apple/login',
 	//  获取个人信息
 	getMainInfo: WX_API_BASE + 'app/member/selectUserById',
 	//  获取商户信息
@@ -124,8 +126,9 @@ module.exports = {
 	// 获取委托金额
 	getShareTaskPric: WX_API_BASE + 'app/order/user/my/getShareTaskPrice',
 	
-	
-	
 	//  上传文件
 	uploadFile: WX_API_BASE + 'app/uploadManage/upload',
+	
+	// 获取版本号
+	getAppVersion: WX_API_BASE + 'app/auth/getAppLastestVersion/user'
 }

+ 84 - 7
pages/index/login.vue

@@ -20,13 +20,22 @@
 			</button>
 			<!-- #endif -->
 			<!-- #ifdef APP-PLUS -->
-			<button class="authorize-login" @click="getUserinfoApp">
+			<button v-if="!isIos" class="authorize-login" @click="getUserinfoApp">
 				微信一键登录
 			</button>
+			<button v-if="isIos" class="authorize-login-ios" @click="getUserinfoApp">
+				苹果账户登录
+			</button>
+			<button v-if="isIos" class="authorize-login-ios" @click="getUserinfoApp">
+				微信一键登录(苹果)
+			</button>
 			<!-- #endif -->
-			<button class="authorize-login" @click="goIndex">
+			<button v-if="!isIos" class="authorize-login" @click="goIndex">
 				再逛逛
 			</button>
+			<button v-if="isIos" class="authorize-login-ios" @click="goIndex">
+				再逛逛(苹果)
+			</button>
 			<view @click="showAgreement = true" class="agreement">点击登录视为同意<text class="underline">平台服务协议</text></view>
 		</view>
 		{{tipxx}}
@@ -155,9 +164,17 @@
 				showAgreement: false,
 				html: html,
 				windowWidth: 0,
-				windowHeight: 0
+				windowHeight: 0,
+				isIos: false
+				
 			}
 		},
+		onLoad() {
+			// #ifdef APP-PLUS
+			this.isIos = (plus.os.name == "iOS")
+			console.log('isIos:',this.isIos,plus.os.name)
+			// #endif
+		},
 		onReady() {
 			// this.appLoginWx()
 			uni.getSystemInfo({
@@ -237,16 +254,32 @@
 			// 获取app登录权限
 			getUserinfoApp() {
 				let that = this
+				// var isIos = (plus.os.name == "iOS")
+				console.log('isIos:',this.isIos)
 				console.log('app enter')
 				try {
 					uni.login({
-						provider: 'weixin',
+						provider: this.isIos ? 'apple' : 'weixin',
 						success: (res2) => {
 							console.log('res2', res2)
 							uni.getUserInfo({
-								provider: 'weixin',
+								provider: this.isIos ? 'apple' : 'weixin',
 								success: (info) => {
 									console.log('info',info)
+									if (this.isIos) {
+										uni.setStorage({
+											key: 'iosLoginData',
+											data: {
+												email: info.appleInfo.email,
+												fullname: info.appleInfo.fullname,
+												user: info.appleInfo.user
+											}
+										})
+										that.iosLoginData = uni.getStorageSync("iosLoginData")
+										console.log(1111111, that.iosLoginData)
+										that.getUserInfoByIOS()
+										return;
+									}
 									uni.setStorage({
 										key: 'wxLoginData',
 										data: {
@@ -311,7 +344,7 @@
 			},
 			//#endif
 
-			// 发请求获取个人数据 envType:1小程序 0:app
+			// 发请求获取个人数据 envType:1小程序 0:app安卓
 			getUserInfo(envType) {
 				console.log('发请求获取个人数据envType',envType)
 				NET.request(API.WxLogin, {
@@ -345,6 +378,38 @@
 					})
 				})
 			},
+			// ios发请求获取个人数据
+			getUserInfoByIOS() {
+				NET.request(API.IosLogin, {
+					...this.iosLoginData
+				}, 'POST').then(res => {
+					console.log('token',res)
+					uni.setStorage({
+						key: 'token',
+						data: res.data.token
+					})
+					console.log('缓存中iosLoginData',this.iosLoginData)
+					uni.setStorage({
+						key: 'userData',
+						data: {
+							headImage: res.data.avatar,
+							userName: res.data.name,
+							userId: res.data.userId,
+						}
+					})
+					console.log('存个人信息')
+					uni.switchTab({
+						url: '/pages/index/index'
+					})
+					console.log('switchTab')
+				}).catch(error => {
+					console.log(44444, error)
+					this.$refs.uTips.show({
+						title: '微信登录授权失败,请再试试',
+						type: 'warning',
+					})
+				})
+			},
 		},
 	}
 </script>
@@ -443,7 +508,19 @@
 				line-height: 36px;
 				text-align: center;
 			}
-
+            .authorize-login-ios {
+            	width: 210px;
+            	height: 33px;
+            	float: left;
+            	margin: 10px 5px;
+            	background: #FFFFFF;
+            	border-radius: 10px;
+            	font-size: 15px;
+            	font-family: PingFang SC;
+            	// color: #56a83a;
+            	line-height: 33px;
+            	text-align: center;
+            }
 			.authorize-tip {
 				width: 220px;
 				height: 20px;