优化微信网页登录

master
lemon橪 2021-09-10 10:45:37 +08:00
parent 58f33b05dd
commit fe0d888da0
4 changed files with 203 additions and 56 deletions

View File

@ -260,7 +260,7 @@
}, },
fail: (e) => { fail: (e) => {
console.log(e); console.log(this);
this.exception = e; this.exception = e;
uni.showModal({ uni.showModal({
content: "支付失败,如果您已支付,请勿反复支付", content: "支付失败,如果您已支付,请勿反复支付",
@ -298,7 +298,7 @@
WeixinJSBridge.invoke( WeixinJSBridge.invoke(
"getBrandWCPayRequest", "getBrandWCPayRequest",
response.result, response.result,
function(res) { (res) => {
if (res.err_msg == "get_brand_wcpay_request:ok") { if (res.err_msg == "get_brand_wcpay_request:ok") {
// 使, // 使,
//res.err_msgok //res.err_msgok

View File

@ -29,7 +29,6 @@ import storage from "@/utils/storage.js"; //缓存
import { whetherNavigate } from "@/utils/Foundation"; // import { whetherNavigate } from "@/utils/Foundation"; //
import myVerification from "@/components/verification/verification.vue"; // import myVerification from "@/components/verification/verification.vue"; //
import uuid from "@/utils/uuid.modified.js"; // uuid import uuid from "@/utils/uuid.modified.js"; // uuid
import api from "@/config/api.js";
export default { export default {
components: { components: {
myVerification, myVerification,
@ -192,21 +191,8 @@ export default {
}, },
// //
clickLogin() { clickLogin() {
// #ifndef APP-PLUS
//
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
let code = "WECHAT";
let buyer = api.buyer;
window.open(buyer + `/connect/login/web/` + code, "_self");
}
else{
this.$emit("open", "click"); this.$emit("open", "click");
}
// #endif
// #ifdef APP-PLUS
this.$emit("open", "click");
// #endif
}, },
/**点击验证码*/ /**点击验证码*/

View File

@ -1,5 +1,7 @@
<template> <template>
<view v-if="mpWechatLogin"> <view>
<!-- -->
<view v-if="codeLogin">
<!-- 背景 --> <!-- 背景 -->
<view class="login-ball bg-linear-gradient small"></view> <view class="login-ball bg-linear-gradient small"></view>
@ -23,6 +25,10 @@
同意<span @click="handleClick('user')"></span><span @click="handleClick('privacy')"></span> 同意<span @click="handleClick('user')"></span><span @click="handleClick('privacy')"></span>
</div> </div>
</view> </view>
<view v-if="wechatLogin">
<wechatH5Login />
</view>
</view>
</template> </template>
<script> <script>
import codeLogin from "./codeLogin"; import codeLogin from "./codeLogin";
@ -32,25 +38,9 @@ import storage from "@/utils/storage.js";
import { loginCallback } from "@/api/connect.js"; import { loginCallback } from "@/api/connect.js";
import { webConnect } from "@/api/connect.js"; import { webConnect } from "@/api/connect.js";
import config from "@/config/config"; import config from "@/config/config";
import wechatH5Login from "./wechatH5Login.vue";
export default { export default {
onShow() { onShow() {
// #ifdef MP-WEIXIN
this.mpWechatLogin = false;
if (this.$options.filters.isLogin("auth")) {
getCurrentPages().length > 1
? uni.navigateBack({
delta: getCurrentPages().length - 2,
})
: uni.switchTab({
url: "/pages/tabbar/home/index",
});
} else {
uni.navigateTo({
url: "/pages/passport/wechatMPLogin",
});
}
// #endif
//#ifdef H5 //#ifdef H5
let isWXBrowser = /micromessenger/i.test(navigator.userAgent); let isWXBrowser = /micromessenger/i.test(navigator.userAgent);
if (isWXBrowser) { if (isWXBrowser) {
@ -67,7 +57,8 @@ export default {
return { return {
config, config,
lightColor: this.$lightColor, lightColor: this.$lightColor,
mpWechatLogin: true, // wechatLogin: false, //
codeLogin: false, //
value: true, // value: true, //
loginData: { loginData: {
code: true, // code: true, //
@ -80,6 +71,23 @@ export default {
components: { components: {
codeLogin, codeLogin,
onClickLogin, onClickLogin,
wechatH5Login,
},
mounted() {
// #ifndef APP-PLUS
//
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
this.wechatLogin = true;
return;
} else {
this.codeLogin = true;
}
// #endif
// #ifdef APP-PLUS
this.codeLogin = true;
// #endif
}, },
onLoad(options) { onLoad(options) {

View File

@ -0,0 +1,153 @@
<template>
<view class="container">
<u-navbar :custom-back="back" title="公众网页登录"></u-navbar>
<view class="wx-auth-container">
<div class="box">
<view class="logo-info">
<text class="title">欢迎进入{{ projectName }}</text>
</view>
<view class="small-tips">
<view>为您提供优质服务,{{ projectName }}需要获取以下信息</view>
<view>您的公开信息昵称头像</view>
</view>
<view class="btns">
<button @click="getUserProfile()" class="btn-auth">使用微信授权</button>
<div @click="backToHome" class="btn-callback">暂不登录</div>
</view>
</div>
</view>
</view>
</template>
<script>
import { whetherNavigate } from "@/utils/Foundation"; //
import config from "@/config/config";
import api from "@/config/api.js";
export default {
data() {
return {
//
projectName: config.name,
};
},
//codecode
mounted() {
//
uni.showShareMenu({ withShareTicket: true });
},
methods: {
back() {
whetherNavigate();
},
getUserProfile() {
let code = "WECHAT";
let buyer = api.buyer;
window.open(buyer + `/connect/login/web/` + code, "_self");
},
backToHome() {
uni.switchTab({
url: `/pages/tabbar/home/index`,
});
},
},
};
</script>
<style lang="scss" scoped>
.wx-auth-container {
width: 100%;
margin-top: 20%;
}
.logo-info {
display: flex;
flex-wrap: nowrap;
justify-content: flex-start;
flex-direction: row;
align-items: flex-start;
padding: 20rpx;
flex-direction: column;
font-weight: bold;
}
image {
width: 100px;
height: 100px;
text-align: center;
-webkit-transform: scale(2.5);
transform: scale(2.5);
}
text.title,
text.shop {
display: inline-block;
font-size: 60rpx;
color: #333;
}
.box {
margin: 0 32rpx;
}
/* 文字提示*/
.small-tips {
width: 94%;
padding: 20rpx;
font-size: 24rpx;
margin: 0 0 20rpx;
color: #999;
}
.btn-auth {
width: 92%;
background: $light-color;
color: #fff;
margin: 0 auto 40rpx;
border-radius: 100px;
animation: mymove 5s infinite;
-webkit-animation: mymove 5s infinite; /*Safari and Chrome*/
animation-direction: alternate; /*轮流反向播放动画。*/
animation-timing-function: ease-in-out; /*动画的速度曲线*/
/* Safari 和 Chrome */
-webkit-animation: mymove 5s infinite;
-webkit-animation-direction: alternate; /*轮流反向播放动画。*/
-webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
}
.btn-callback {
text-align: center;
font-size: 30rpx;
background: #ededed;
height: 90rpx;
line-height: 90rpx;
border-radius: 100px;
width: 92%;
margin: 0 auto;
}
.btns {
margin-top: 100rpx;
display: flex;
flex-direction: column;
width: 100%;
justify-content: center;
}
@keyframes mymove {
0% {
transform: scale(1); /*开始为原始大小*/
}
25% {
transform: scale(1.1); /*放大1.1倍*/
}
50% {
transform: scale(1);
}
75% {
transform: scale(1.1);
}
}
</style>