Forráskód Böngészése

refactor:微信登录

zhanghui 2 éve
szülő
commit
b2a3ad62ec
8 módosított fájl, 168 hozzáadás és 12 törlés
  1. 25 2
      App.vue
  2. 12 0
      common/js/api.js
  3. 1 1
      common/js/env.js
  4. 0 6
      common/js/request.js
  5. 2 0
      main.js
  6. 3 0
      pages/index/index.vue
  7. 64 0
      pages/login/index.rpx.css
  8. 61 3
      pages/login/login.vue

+ 25 - 2
App.vue

@@ -5,9 +5,32 @@
 <script>
 	export default {
 		onLaunch: function() {
-		    uni.hideTabBar({
-                animation:false
+            let that = this;
+            wx.login({
+                success(re) {
+                    that.$api.wxAuthLogin({code:re.code}).then(res=>{
+                        uni.setStorageSync('userInfo',res.data.data.userInfo)
+                        uni.setStorageSync('accessToken',res.data.data.access_token)
+                        uni.setStorageSync('phoneIsBind',res.data.data.phoneIsBind)
+
+                        if (res.data.data.phoneIsBind){
+                            uni.switchTab({
+                                url: '/pages/index/index',
+                            })
+                        }
+
+
+
+                    })
+
+                },
             })
+
+
+
+
+
+
 			console.log('App Launch')
 		},
 		onShow: function() {

+ 12 - 0
common/js/api.js

@@ -5,6 +5,18 @@ import request from '../js/request.js';
 
 
 export default {
+
+    /**
+     * 微信静默登录
+     */
+    wxAuthLogin(data){
+        return request({
+            url: '/auth/xcxLogin',
+            method: 'POST',
+            data: data
+        })
+    },
+
      payTheBill(data) {
         return request({
             url: '/recruit/recruitmsg/payTheBill',

+ 1 - 1
common/js/env.js

@@ -5,7 +5,7 @@ export default { //存放变量的容器
 	appid: '__UNI__1EEA945',
 	// baseUrl: 'https://recruit.gzzzyd.com/api'
 	// baseUrl: 'http://127.0.0.1:8888',
-	baseUrl: 'http://192.168.0.108:8888',
+	baseUrl: 'https://jje.admin.xinyuekj.com.cn',
 
 	uploadUrl: '/v1/file/put-file'
 

+ 0 - 6
common/js/request.js

@@ -27,12 +27,6 @@ function service(options = {}) {
 				// 这里可以做一些状态码判断以及操作
 				// 返回错误信息
 				rejected(res)
-
-				if (res.data.code === 401){
-					uni.navigateTo({
-						url: '/pages/welcome/index'
-					})
-				}
 			} else {
 				// 请求回来的状态码为200则返回内容
 				resolved(res)

+ 2 - 0
main.js

@@ -4,8 +4,10 @@ import Vue from 'vue'
 import './uni.promisify.adaptor'
 import api from './common/js/api'
 import uView from "uview-ui";
+const baseUrl = 'https://jje.admin.xinyuekj.com.cn/';
 Vue.use(uView);
 Vue.config.productionTip = false
+Vue.prototype.$baseUrl = baseUrl;
 Vue.prototype.$api = api;
 App.mpType = 'app'
 const app = new Vue({

+ 3 - 0
pages/index/index.vue

@@ -22,6 +22,9 @@
 			}
 		},
 		onLoad() {
+			uni.hideTabBar({
+				animation:false
+			})
 
 		},
 		methods: {

+ 64 - 0
pages/login/index.rpx.css

@@ -0,0 +1,64 @@
+.page{
+    padding: 0 60rpx;
+}
+.title{
+    height: 152rpx;
+    font-size: 48rpx;
+    font-family: PingFangSC-Semibold, PingFang SC;
+    font-weight: 600;
+    color: #333333;
+    line-height: 76rpx;
+}
+.h-logo{
+    margin-top: 40rpx;
+}
+.logo-img{
+    width: 320rpx;
+    height: 244rpx;
+}
+.login-btn{
+    width: 638rpx;
+    height: 84rpx;
+    background: #FFE05C;
+    border-radius: 42rpx;
+    margin-top: 160rpx;
+}
+.weixinLogin{
+    font-size: 28rpx;
+    font-family: PingFangSC-Regular, PingFang SC;
+    font-weight: 400;
+    color: #333333;
+    line-height: 84rpx;
+    margin-left: 16rpx;
+}
+.login-form{
+    margin-top: 40rpx;
+    font-size: 28rpx;
+    font-family: PingFangSC-Regular, PingFang SC;
+    font-weight: 400;
+    color: #999999;
+    line-height: 44rpx;
+}
+.o{
+    width: 24rpx;
+    height: 24rpx;
+    border: 1px solid #999999;
+    border-radius: 20rpx;
+    margin-top: 8rpx;
+}
+.text1{
+    margin-left: 10rpx;
+}
+
+.login-form1{
+    width: 595rpx;
+    font-size: 28rpx;
+    font-family: PingFangSC-Regular, PingFang SC;
+    font-weight: 400;
+    color: #999999;
+    line-height: 35rpx;
+}
+.bottom{
+    margin-top: 120rpx;
+
+}

+ 61 - 3
pages/login/login.vue

@@ -1,6 +1,43 @@
 <template>
-	<view class="content">
-		登录
+	<view class="page">
+		<view class="content">
+			<view class="title flex-col justify-center">
+				<text>HI,您好!</text>
+				<text>欢迎登录</text>
+			</view>
+			<view class="h-logo  flex-row justify-center">
+				<image class="logo-img" src="../../static/logo.png"></image>
+			</view>
+
+			<button class="login-btn flex-row justify-center" @click="wechatCodeLogin">
+				<u-icon name="weixin-fill" color="green" size="26"></u-icon>
+				<text class="weixinLogin">授权微信登录</text>
+			</button>
+
+
+<!--			<view class="login-form flex-row justify-between">-->
+<!--				<view class="flex-row">-->
+<!--					<view  class="o"></view>-->
+<!--					<view  class="v"></view>-->
+<!--					<text class="text1">自动登录</text>-->
+<!--				</view>-->
+
+<!--				<view @click="gotoRetieveAccount()" class="forget-acconut-password">-->
+<!--					<text>找回账号</text>-->
+<!--				</view>-->
+<!--			</view>-->
+
+			<view class="bottom flex-row justify-between">
+					<view  class="o"></view>
+					<view  class="v"></view>
+					<view class="login-form1 ">
+						<text class="text2">允许我们在必要的场景下合理使用你的相关信息,且阅读并同意</text>
+						<text class="text3">《会员协议》、《服务对象协《隐私协议》</text>
+						<text class="text2">等内容</text>
+					</view>
+			</view>
+
+		</view>
 	</view>
 </template>
 
@@ -15,7 +52,28 @@
 
 		},
 		methods: {
+			wechatCodeLogin(){
+				let that = this;
+				wx.login({
+					success(re) {
+						that.$api.wxAuthLogin({code:re.code}).then(res=>{
+							uni.setStorageSync('userInfo',res.data.data.userInfo)
+							uni.setStorageSync('accessToken',res.data.data.access_token)
+							uni.setStorageSync('phoneIsBind',res.data.data.phoneIsBind)
+
+							if (res.data.data.phoneIsBind){
+								uni.switchTab({
+									url: '/pages/index/index',
+								})
+							}else {
+
+							}
+
+						})
 
+					},
+				});
+			},
 		}
 	}
 </script>
@@ -23,4 +81,4 @@
 <style>
 	@import '/common/css/common.css';
 	@import './index.rpx.css';
-</style>
+</style>