Browse Source

商户端ios登录

zhaoxw 4 years ago
parent
commit
912fadb5bd
3 changed files with 111 additions and 18 deletions
  1. 18 0
      App.vue
  2. 4 1
      config/api.js
  3. 89 17
      pages/index/index.vue

+ 18 - 0
App.vue

@@ -1,7 +1,25 @@
 <script>
+	const NET = require('@/utils/request')
+	const API = require('@/config/api')
 	export default {
 		onLaunch: function() {
 			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');

+ 4 - 1
config/api.js

@@ -11,6 +11,8 @@ module.exports = {
 	WxLogin: WX_API_BASE + 'app/auth/merchant/wx/login',
 	//  微信登录
 	getWxUserPhone: WX_API_BASE + 'app/auth/wx/getWxUserPhone',
+	// ios登录
+	IosLogin: WX_API_BASE + 'app/auth/merchant/apple/login',
 	//  授权码登录
 	authorizeSignIn: WX_API_BASE + 'app/auth/merchant/authCodeRegister',
 	//  注册商铺数据
@@ -117,7 +119,8 @@ module.exports = {
 	//  删除授权用户
 	deleteAuthorizeUser: WX_API_BASE + 'app/auth/merchant/my/delAuthUser/',
 
-
 	//  上传文件
 	uploadFile: WX_API_BASE + 'app/uploadManage/upload',
+	// 获取版本号
+	getAppVersion: WX_API_BASE + 'app/auth/getAppLastestVersion/merchant'
 }

+ 89 - 17
pages/index/index.vue

@@ -247,12 +247,14 @@
 			return {
 				wxLoginData: null,
 				wxPhoneData: null,
+				iosLoginData: nul,
 				userNmae: '',
 				tipxx: '',
 				showAgreement: false,
 				html: html,
 				windowWidth: 0,
-				windowHeight: 0
+				windowHeight: 0,
+				isIos: false
 			}
 		},
 		onLoad() {
@@ -265,6 +267,13 @@
 			uni.removeStorage({
 				key: 'wxLoginData'
 			})
+			uni.removeStorage({
+				key: 'iosLoginData'
+			})
+			// #ifdef APP-PLUS
+			this.isIos = (plus.os.name == "iOS")
+			console.log('isIos:',this.isIos,plus.os.name)
+			// #endif
 		},
 		onReady() {
 			// this.appLoginWx()
@@ -341,29 +350,44 @@
 			//  获取app登录权限
 			getUserinfoApp() {
 				let that = this
+				console.log('isIos:',this.isIos)
 				console.log('app enter')
 				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)
-								uni.setStorage({
-									key: 'wxLoginData',
-									data: {
-										nickName: info.userInfo.nickName,
-										gender: info.userInfo.gender,
-										avatarUrl: info.userInfo.avatarUrl,
-										unionId: info.userInfo.unionId,
-										openId:info.userInfo.openId
-									}
-								})
-								that.wxLoginData = uni.getStorageSync("wxLoginData")
-								console.log(1111111, that.wxLoginData)
-								// that.userNmae = JSON.parse(that.wxLoginData.rawData).nickName
-								that.getUserInfo()
+								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()
+								} else {
+									uni.setStorage({
+										key: 'wxLoginData',
+										data: {
+											nickName: info.userInfo.nickName,
+											gender: info.userInfo.gender,
+											avatarUrl: info.userInfo.avatarUrl,
+											unionId: info.userInfo.unionId,
+											openId:info.userInfo.openId
+										}
+									})
+									that.wxLoginData = uni.getStorageSync("wxLoginData")
+									console.log(1111111, that.wxLoginData)
+									// that.userNmae = JSON.parse(that.wxLoginData.rawData).nickName
+									that.getUserInfo()
+								}
 								this.$refs.uTips.show({
 									title: '获取角色信息成功',
 									type: 'success',
@@ -434,6 +458,54 @@
 					})
 				})
 			},
+			// #ifdef APP-PLUS
+			// 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,
+							tenantName: res.data.tenantName,
+							isMaster: res.extra.auth.isMaster,
+							registerFlag: res.extra.auth.registerFlag,
+							auditState: res.extra.auth.auditState,
+							roleInfos: res.extra.auth2.roleInfos
+						}
+					})
+					console.log('存个人信息')
+					if (res.extra.auth.registerFlag == 1 && res.extra.auth.auditState == 2) {
+						uni.switchTab({
+							url: '/pages/index/home'
+						})
+					} else if (res.extra.auth.registerFlag == 1 && res.extra.auth.auditState != 2) {
+						uni.navigateTo({
+							url: '/pages/index/registerState'
+						})
+					} else {
+						uni.navigateTo({
+							url: '/pages/index/authorize'
+						})
+					}
+				}).catch(error => {
+					console.log(error)
+					this.$refs.uTips.show({
+						title: '微信登录授权失败,请再试试',
+						type: 'warning',
+					})
+				})
+			}
+			//#endif
 		},
 	}
 </script>