2024-03-13 10:54:22 +08:00
|
|
|
<template>
|
|
|
|
|
<view class="page">
|
2025-07-30 09:20:18 +08:00
|
|
|
<u-navbar :is-back="false" :title="titleTxt" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='36' >
|
2024-03-13 10:54:22 +08:00
|
|
|
|
|
|
|
|
</u-navbar>
|
|
|
|
|
<view class="imgbox">
|
2025-07-28 10:53:56 +08:00
|
|
|
<image src="https://api.ccttiot.com/smartmeter/img/static/uGPwljIaEppyKAT1iQaW" mode=""></image>
|
2024-03-13 10:54:22 +08:00
|
|
|
</view>
|
2025-07-30 09:20:18 +08:00
|
|
|
<button class="button" @click="getPhoneNumber" >
|
2025-07-28 10:53:56 +08:00
|
|
|
授权登录
|
|
|
|
|
</button>
|
2024-03-13 10:54:22 +08:00
|
|
|
<view class="tip">
|
2025-07-28 10:53:56 +08:00
|
|
|
<image src="https://api.ccttiot.com/smartmeter/img/static/u4LEl3cUFgF9uN30ESnF" mode=""></image>
|
|
|
|
|
我已同意并阅读《服务条款》《法律条款及隐私政策》
|
2024-03-13 10:54:22 +08:00
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-07-30 10:10:31 +08:00
|
|
|
import { navigateToPage } from "../../utils/router.js";
|
2025-08-02 10:35:11 +08:00
|
|
|
import { wxLogin } from "../../api/auth/auth.js";
|
2025-08-02 14:46:43 +08:00
|
|
|
import { forceHideLoading, AutoLoadingManager } from "../../utils/loading-manager.js";
|
2025-07-30 10:10:31 +08:00
|
|
|
|
2024-03-13 10:54:22 +08:00
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
bgc: {
|
2025-07-28 10:53:56 +08:00
|
|
|
backgroundColor: "#fff",
|
2024-03-13 10:54:22 +08:00
|
|
|
},
|
2025-07-30 09:20:18 +08:00
|
|
|
titleTxt:"登录",
|
2024-03-13 10:54:22 +08:00
|
|
|
chooseType:true,
|
|
|
|
|
usertype:'',
|
|
|
|
|
login:false
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-08-02 10:35:11 +08:00
|
|
|
onLoad() {
|
|
|
|
|
// 初始化页面loading管理器
|
2025-08-02 14:46:43 +08:00
|
|
|
this.pageLoading = new AutoLoadingManager()
|
2025-08-02 10:35:11 +08:00
|
|
|
},
|
|
|
|
|
onUnload() {
|
|
|
|
|
// 页面卸载时清除loading
|
|
|
|
|
forceHideLoading();
|
|
|
|
|
if (this.pageLoading) {
|
|
|
|
|
this.pageLoading.destroy()
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-03-13 10:54:22 +08:00
|
|
|
methods: {
|
|
|
|
|
userType(num){
|
|
|
|
|
this.chooseType=false
|
|
|
|
|
this.login=true
|
2025-07-30 09:20:18 +08:00
|
|
|
if(num===1){
|
2024-03-13 10:54:22 +08:00
|
|
|
this.usertype='01'
|
2024-03-25 19:46:07 +08:00
|
|
|
}else{
|
|
|
|
|
this.usertype='00'
|
2024-03-13 10:54:22 +08:00
|
|
|
}
|
|
|
|
|
},
|
2025-07-30 09:20:18 +08:00
|
|
|
getPhoneNumber() {
|
2024-03-13 10:54:22 +08:00
|
|
|
let that = this;
|
2025-08-02 10:35:11 +08:00
|
|
|
uni.login({
|
2025-07-30 09:20:18 +08:00
|
|
|
success(res) {
|
|
|
|
|
if (res.code) {
|
|
|
|
|
console.log('登录!', res);
|
|
|
|
|
let data = {
|
|
|
|
|
loginCode: res.code,
|
|
|
|
|
appId:1,
|
|
|
|
|
};
|
2025-08-02 10:35:11 +08:00
|
|
|
|
|
|
|
|
// 显示页面loading
|
|
|
|
|
if (that.pageLoading) {
|
|
|
|
|
that.pageLoading.show('登录中...')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxLogin(data).then((res) => {
|
|
|
|
|
// 确保清除loading
|
|
|
|
|
if (that.pageLoading) {
|
|
|
|
|
that.pageLoading.hide()
|
|
|
|
|
}
|
|
|
|
|
forceHideLoading();
|
|
|
|
|
|
2025-07-30 09:20:18 +08:00
|
|
|
if (res.code == 200) {
|
|
|
|
|
console.log(res,'resres');
|
2025-08-02 10:35:11 +08:00
|
|
|
uni.setStorageSync('token', res.token);
|
|
|
|
|
// 显示成功提示
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '登录成功',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
duration: 1500
|
|
|
|
|
});
|
|
|
|
|
// 延迟跳转,让用户看到成功提示
|
|
|
|
|
setTimeout(() => {
|
2025-08-02 14:03:12 +08:00
|
|
|
that.ceshi()
|
2025-08-02 10:35:11 +08:00
|
|
|
}, 1500);
|
|
|
|
|
} else {
|
|
|
|
|
// 处理业务逻辑错误
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: res.msg || '登录失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
// 确保清除loading
|
|
|
|
|
if (that.pageLoading) {
|
|
|
|
|
that.pageLoading.hide()
|
2025-07-30 09:20:18 +08:00
|
|
|
}
|
2025-08-02 10:35:11 +08:00
|
|
|
forceHideLoading();
|
|
|
|
|
|
|
|
|
|
console.error('登录失败:', error);
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '登录失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
});
|
2025-07-30 09:20:18 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fail(err) {
|
2025-08-02 10:35:11 +08:00
|
|
|
console.error('微信登录失败:', err);
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '微信登录失败',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
});
|
2025-07-30 09:20:18 +08:00
|
|
|
}
|
|
|
|
|
});
|
2024-03-13 10:54:22 +08:00
|
|
|
},
|
2025-07-30 09:31:34 +08:00
|
|
|
async ceshi() {
|
2025-08-02 10:35:11 +08:00
|
|
|
// 确保清除loading状态
|
|
|
|
|
if (this.pageLoading) {
|
|
|
|
|
this.pageLoading.hide()
|
|
|
|
|
}
|
|
|
|
|
forceHideLoading();
|
|
|
|
|
|
2025-07-30 10:10:31 +08:00
|
|
|
// 使用路由仓库跳转到首页
|
|
|
|
|
navigateToPage('index');
|
2025-07-30 09:31:34 +08:00
|
|
|
},
|
2024-03-13 10:54:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" >
|
|
|
|
|
page{
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
}
|
|
|
|
|
.page {
|
|
|
|
|
position: relative; /* 添加相对定位 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.imgbox {
|
2025-07-28 10:53:56 +08:00
|
|
|
margin:102rpx auto ;
|
|
|
|
|
width: 730rpx;
|
|
|
|
|
height: 422rpx;
|
2024-03-13 10:54:22 +08:00
|
|
|
z-index: 0;
|
|
|
|
|
|
|
|
|
|
image {
|
2025-07-28 10:53:56 +08:00
|
|
|
width: 730rpx;
|
|
|
|
|
height: 422rpx;
|
2024-03-13 10:54:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-28 10:53:56 +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-07-28 10:53:56 +08:00
|
|
|
font-size: 40rpx;
|
2024-03-13 10:54:22 +08:00
|
|
|
color: #FFFFFF;
|
|
|
|
|
}
|
2025-07-28 10:53:56 +08:00
|
|
|
.tip{
|
|
|
|
|
margin-top:128rpx ;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
font-size: 20rpx;
|
|
|
|
|
color: #979797;
|
|
|
|
|
image{
|
|
|
|
|
width: 26rpx;
|
|
|
|
|
height: 26rpx;
|
2024-03-13 10:54:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-28 10:53:56 +08:00
|
|
|
|
|
|
|
|
|
2024-03-13 10:54:22 +08:00
|
|
|
</style>
|