uni-Identify-quality/pages/login/login.vue

148 lines
3.5 KiB
Vue
Raw Normal View History

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" />
2023-09-22 05:13:26 +00:00
<view class="btn">
2024-04-02 06:25:17 +00:00
<u-button v-if="isShow" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" color="transparent"
text="点击登录"></u-button>
2023-09-22 05:13:26 +00:00
</view>
<!-- <view class="btn">
<u-button v-if="isLogoutShow" @click="login" color="transparent">点击登录</u-button>
</view>-->
2023-09-19 03:05:39 +00:00
</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: "",
2023-09-23 06:59:54 +00:00
isShow: false,
isNew: false
2023-09-19 03:05:39 +00:00
};
},
methods: {
async getPhoneNumber(e) {
if (e.detail.errMsg == "getPhoneNumber:ok") {
// 用户允许或去手机号
2023-09-22 05:13:26 +00:00
let res = await this.$api.login.getTel({ code: e.detail.code });
2023-09-19 03:05:39 +00:00
if (res.status == 0) {
2023-09-22 05:13:26 +00:00
uni.setStorageSync("telNum", res.data.telNum);
2023-09-23 06:59:54 +00:00
if (this.isNew) {
uni.reLaunch({
url: "/pages/realName/realName"
});
} else {
uni.reLaunch({
url: "/pages/home/index"
});
}
2023-09-22 05:13:26 +00:00
} else {
this.$common.msgToast(res.msg);
2023-09-19 03:05:39 +00:00
}
} else {
this.$common.msgToast("请不要拒绝哟~重新点击登录");
}
2023-09-23 06:59:54 +00:00
},
//获取openId
async getOpenId() {
uni.login({
provider: "weixin",
success: async res => {
console.log("res.code", res.code);
this.code = res.code;
let res1 = await this.$api.login.login({ code: res.code });
if (res1.status == 0) {
2024-04-02 06:40:22 +00:00
if (res1.data.accountInfo.isNew || !uni.getStorageSync("telNum")) {
this.isShow = true;
this.isNew = res1.data.accountInfo.isNew;
} else {
2023-10-07 02:41:30 +00:00
uni.reLaunch({
url: "/pages/home/index"
});
}
2023-09-22 05:13:26 +00:00
uni.setStorageSync("token", res1.data.token);
2023-09-19 11:18:11 +00:00
} else {
2023-09-23 06:59:54 +00:00
this.$common.msgToast(res1.msg);
2023-09-19 11:18:11 +00:00
}
2023-09-23 06:59:54 +00:00
}
});
},
// info判断用户是401就让他获取openId
2024-04-02 06:40:22 +00:00
// async info() {
// const res = await this.$api.mine.info();
// if (res.status === 0) {
// if (res.data.isNew) {
// //登录未注册
// uni.reLaunch({
// url: "/pages/realName/realName"
// });
// } else {
// //登录已注册
// uni.reLaunch({
// url: "/pages/home/index"
// });
// }
// } else if (res.status === 401) {
// this.getOpenId();
// } else {
// this.$common.msgToast(res.msg);
// }
// }
2023-09-23 06:59:54 +00:00
},
onLoad() {
2024-04-02 06:40:22 +00:00
// if (!uni.getStorageSync("telNum")) {
// this.getOpenId();
// }
// this.info();
this.getOpenId();
2023-09-19 03:05:39 +00:00
}
};
2023-09-19 01:48:45 +00:00
</script>
<style lang="scss" scoped>
2023-09-22 05:13:26 +00:00
/deep/.u-button {
background: red;
}
2024-04-02 06:25:17 +00:00
2023-09-19 03:05:39 +00:00
.main {
2023-09-22 05:13:26 +00:00
background: url("https://cdns.fontree.cn/fonchain-main/prod/image/1381bd18-2f0c-49f1-84f6-d3eceb94f7a7/artwork/6ef00a09-f663-451d-ae0c-0d00cf4068c5.png");
height: 100vh;
2023-09-19 03:05:39 +00:00
display: flex;
align-items: center;
flex-direction: column;
2024-04-02 06:25:17 +00:00
2023-09-19 03:05:39 +00:00
.logo {
2023-11-07 06:35:24 +00:00
margin-top: 250rpx;
width: 398rpx;
height: 744rpx;
2023-09-19 03:05:39 +00:00
}
2024-04-02 06:25:17 +00:00
2023-09-19 11:18:11 +00:00
uni-button:after {
border: 0px;
}
2024-04-02 06:25:17 +00:00
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;
}
2024-04-02 06:25:17 +00:00
2023-09-19 03:05:39 +00:00
@keyframes jump {
from {
bottom: 16%;
}
2024-04-02 06:25:17 +00:00
2023-09-19 03:05:39 +00:00
to {
bottom: 15%;
}
}
}
2023-09-19 01:48:45 +00:00
</style>