baodeng_xcx/pages/login/login.vue

215 lines
4.8 KiB
Vue
Raw Normal View History

2024-03-13 10:54:22 +08:00
<template>
<view class="page">
<u-navbar :is-back="false" :title="tittxt" :border-bottom="false" :background="bgc" title-color='#fff' title-size='36' height='36' >
</u-navbar>
<view class="imgbox">
2025-05-14 15:14:12 +08:00
<image src="https://api.ccttiot.com/smartmeter/img/static/uGfU2kTWiHxXEWrNAOuA" mode=""></image>
2024-03-13 10:54:22 +08:00
</view>
2025-05-14 15:14:12 +08:00
<button class="ceshi" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" >
授权登录
</button>
<!-- <button class="ceshi" @click="btndl">测试登录</button> -->
<button class="zanbu" @click="btnzanbu">暂不登录</button>
2024-03-13 10:54:22 +08:00
<view class="tip">
2025-05-14 15:14:12 +08:00
<u-checkbox-group>
<u-checkbox v-model="checked" shape="circle" active-color="#FF8998" size="26"></u-checkbox>
</u-checkbox-group> <text style="color: #FF8998;"></text>
2024-03-13 10:54:22 +08:00
</view>
</view>
</template>
<script>
export default {
data() {
return {
bgc: {
2025-05-14 15:14:12 +08:00
backgroundColor: "#010000",
2024-03-13 10:54:22 +08:00
},
2025-05-14 15:14:12 +08:00
tittxt:"登录",
2024-03-13 10:54:22 +08:00
chooseType:true,
usertype:'',
2025-05-14 15:14:12 +08:00
login:false,
checked:false,
2024-03-13 10:54:22 +08:00
}
},
methods: {
2025-05-14 15:14:12 +08:00
// 测试登录
btndl(){
if(this.checked == false){
uni.showToast({
title: '请勾选服务协议,法律条款以及隐私政策',
icon: 'none',
duration:2000
})
2024-03-25 19:46:07 +08:00
}else{
2025-05-14 15:14:12 +08:00
this.$u.post(`/loginById?userId=1`).then((res) => {
if(res.code == 200){
wx.setStorageSync('token', res.token);
uni.switchTab({
url: '/pages/index/index'
})
}else if(res.msg == null){
uni.showToast({
title: '未知错误',
icon: 'none',
duration:2000
})
}else{
uni.showToast({
title: res.msg,
icon: 'none',
duration:2000
})
}
})
2024-03-13 10:54:22 +08:00
}
},
2025-05-14 15:14:12 +08:00
// 暂不登录
btnzanbu(){
uni.switchTab({
url:'/pages/index/index'
})
},
2024-03-13 10:54:22 +08:00
getPhoneNumber(e) {
2025-05-14 15:14:12 +08:00
if(this.checked == false){
uni.showToast({
title: '请勾选服务协议,法律条款以及隐私政策',
icon: 'none',
duration:2000
})
return
}
2024-03-13 10:54:22 +08:00
let that = this;
console.log("eeeeeeee", e);
const wxLoginAsync = () => {
return new Promise((resolve, reject) => {
wx.login({
success(res) {
if (res.code) {
console.log('登录!', res);
let data = {
2025-05-14 15:14:12 +08:00
loginCode: res.code,
2024-03-13 10:54:22 +08:00
mobileCode: e.detail.code,
2025-05-14 15:14:12 +08:00
appId:that.$store.state.appid
2024-03-13 10:54:22 +08:00
};
resolve(data);
} else {
reject(res.errMsg);
}
},
fail(err) {
reject(err);
}
});
});
};
wxLoginAsync()
.then(async (data) => {
2025-05-14 15:14:12 +08:00
this.$u.post("/wxLogin",data).then((res) => {
2024-03-13 10:54:22 +08:00
if (res.code == 200) {
console.log(res,'resres');
wx.setStorageSync('token', res.token);
that.ceshi()
}
});
})
.catch((err) => {
console.error(err);
});
},
async ceshi() {
2025-05-14 15:14:12 +08:00
this.$u.get("/getInfo").then((res) => {
2024-03-13 10:54:22 +08:00
console.log('进入跳转');
2024-03-25 19:46:07 +08:00
uni.switchTab({
url: '/pages/index/index'
})
2024-03-13 10:54:22 +08:00
});
},
}
}
</script>
<style lang="scss" >
page{
2025-05-14 15:14:12 +08:00
// background: #010000;
2024-03-13 10:54:22 +08:00
}
.page {
position: relative; /* 添加相对定位 */
}
2025-05-14 15:14:12 +08:00
.zanbu{
font-weight: 600;
font-size: 36rpx;
color: #808080;
position: fixed;
bottom: 292rpx;
left: 50%;
transform: translateX(-50%);
background-color: transparent;
}
.ceshi{
width: 614rpx;
height: 108rpx;
border-radius: 54rpx 54rpx 54rpx 54rpx;
border: 2rpx solid #FF8998;
background-color: transparent;
font-weight: 600;
font-size: 36rpx;
color: #FF8998;
display: flex;
align-items: center;
justify-content: center;
position: fixed;
bottom: 398rpx;
left: 50%;
transform: translateX(-50%);
}
2024-03-13 10:54:22 +08:00
.imgbox {
2025-05-14 15:14:12 +08:00
width: 100%;
height: 100vh;
2024-03-13 10:54:22 +08:00
z-index: 0;
2025-05-14 15:14:12 +08:00
position: fixed;
top: 0;
left: 0;
2024-03-13 10:54:22 +08:00
image {
2025-05-14 15:14:12 +08:00
width: 100%;
height: 100%;
2024-03-13 10:54:22 +08:00
}
}
2025-05-14 15:14:12 +08:00
.button{
margin-top: 200rpx;
width: 586rpx;
height: 90rpx;
background: #4C97E7;
border-radius: 54rpx 54rpx 54rpx 54rpx;
2024-03-13 10:54:22 +08:00
font-weight: 500;
2025-05-14 15:14:12 +08:00
font-size: 40rpx;
2024-03-13 10:54:22 +08:00
color: #FFFFFF;
}
2025-05-14 15:14:12 +08:00
/deep/ .u-checkbox{
width: 40rpx !important;
}
.tip{
display: flex;
flex-wrap: nowrap;
align-items: center;
justify-content: center;
font-size: 24rpx;
color: #FFFFFF;
position: fixed;
left: 50%;
transform: translateX(-50%);
bottom: 204rpx;
z-index: 1;
width: 100%;
image{
width: 26rpx;
height: 26rpx;
2024-03-13 10:54:22 +08:00
}
}
2025-05-14 15:14:12 +08:00
2024-03-13 10:54:22 +08:00
</style>