2023-09-19 01:48:45 +00:00
|
|
|
<template>
|
2023-09-19 03:05:39 +00:00
|
|
|
<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>
|
2023-09-19 01:48:45 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-09-19 03:05:39 +00:00
|
|
|
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);
|
2023-09-19 11:18:11 +00:00
|
|
|
uni.redirectTo({
|
|
|
|
url: "/pages/register/register"
|
|
|
|
});
|
2023-09-19 03:05:39 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.$common.msgToast("请不要拒绝哟~重新点击登录");
|
|
|
|
}
|
2023-09-19 11:18:11 +00:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-09-19 03:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-09-19 01:48:45 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-09-19 03:05:39 +00:00
|
|
|
.main {
|
2023-09-20 11:59:14 +00:00
|
|
|
background: url("@/static/image/login-bg.png") no-repeat;
|
2023-09-19 03:05:39 +00:00
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
flex-direction: column;
|
|
|
|
.logo {
|
|
|
|
width: 237rpx;
|
|
|
|
height: 390rpx;
|
|
|
|
}
|
2023-09-19 11:18:11 +00:00
|
|
|
uni-button:after {
|
|
|
|
border: 0px;
|
|
|
|
}
|
2023-09-19 03:05:39 +00:00
|
|
|
.btn {
|
|
|
|
background: transparent;
|
|
|
|
width: 200rpx;
|
|
|
|
position: fixed;
|
|
|
|
bottom: 15%;
|
2023-09-19 11:18:11 +00:00
|
|
|
color: #fff;
|
2023-09-19 03:05:39 +00:00
|
|
|
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%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-19 01:48:45 +00:00
|
|
|
</style>
|