You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.0 KiB
Vue

1 year ago
<template>
1 year ago
<view class="main">
<image src="@/static/image/logo.png" mode="scaleToFill" class="logo" />
<button
class="btn"
v-if="isShow"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
>点击登录</button>
<button class="btn" v-if="isLogoutShow" @click="login"></button>
</view>
1 year ago
</template>
<script>
1 year ago
export default {
data() {
return {
code: "",
openId: "",
isShow: false,
isLogoutShow: false
};
},
methods: {
async getPhoneNumber(e) {
if (e.detail.errMsg == "getPhoneNumber:ok") {
// 用户允许或去手机号
let res = await this.$api.user.loginToken({
wxPhoneCode: e.detail.code,
openid: this.openId
});
if (res.status == 0) {
uni.setStorageSync("token", res.data.token);
1 year ago
uni.redirectTo({
url: "/pages/register/register"
});
1 year ago
}
} else {
this.$common.msgToast("请不要拒绝哟~重新点击登录");
}
1 year ago
},
async login() {
// 获取code
uni.login({
provider: "weixin",
success: async res => {
this.code = res.code;
let res1 = await this.$api.user.loginToken({ wxLoginCode: res.code });
if (res1.status == 0) {
if (res1.data.code == 2) {
this.isShow = true;
this.openId = res1.data.openid;
} else {
uni.setStorageSync("token", res1.data.token);
uni.redirectTo({
url: "/pages/register/register"
});
}
} else {
this.$common.msgToast(res1.msg);
}
}
});
}
},
onLoad() {
this.isLogoutShow = true;
if (!this.isLogoutShow) {
// 获取code
uni.login({
provider: "weixin",
success: async res => {
this.code = res.code;
let res1 = await this.$api.user.loginToken({ wxLoginCode: res.code });
if (res1.status == 0) {
if (res1.data.code == 2) {
this.isShow = true;
this.openId = res1.data.openid;
} else {
uni.setStorageSync("token", res1.data.token);
uni.redirectTo({
url: "/pages/register/register"
});
}
} else {
this.$common.msgToast(res1.msg);
}
}
});
1 year ago
}
}
};
1 year ago
</script>
<style lang="scss" scoped>
1 year ago
.main {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
.logo {
width: 237rpx;
height: 390rpx;
}
1 year ago
uni-button:after {
border: 0px;
}
1 year ago
.btn {
background: transparent;
width: 200rpx;
position: fixed;
bottom: 15%;
1 year ago
color: #fff;
1 year ago
left: 50%;
transform: translateX(-50%);
font-size: 30rpx;
transition: all 1s;
animation: jump 1s ease-in-out infinite alternate;
}
@keyframes jump {
from {
bottom: 16%;
}
to {
bottom: 15%;
}
}
}
1 year ago
</style>