This commit is contained in:
parent
c24113d96f
commit
d13b32ab57
|
|
@ -0,0 +1,184 @@
|
|||
// pages/login/login.js
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isLoading: false,
|
||||
redirectUrl: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
// 获取重定向URL
|
||||
if (options.redirect) {
|
||||
this.setData({
|
||||
redirectUrl: decodeURIComponent(options.redirect)
|
||||
});
|
||||
}
|
||||
|
||||
// 如果已经登录,直接跳转
|
||||
if (app.isLoggedIn()) {
|
||||
this.redirectToTarget();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理登录
|
||||
*/
|
||||
handleLogin() {
|
||||
if (this.data.isLoading) return;
|
||||
|
||||
this.setData({ isLoading: true });
|
||||
|
||||
// 执行登录(必须在点击事件的同步上下文中调用)
|
||||
app.login()
|
||||
.then(result => {
|
||||
console.log('登录成功', result);
|
||||
|
||||
wx.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
});
|
||||
|
||||
// 延迟跳转,让用户看到成功提示
|
||||
setTimeout(() => {
|
||||
// 询问是否开启消息通知
|
||||
this.askForNotification();
|
||||
|
||||
// 跳转到目标页面
|
||||
this.redirectToTarget();
|
||||
}, 1500);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('登录失败', error);
|
||||
|
||||
let errorMsg = '登录失败,请重试';
|
||||
if (error.errMsg) {
|
||||
if (error.errMsg.includes('auth deny') || error.errMsg.includes('deny')) {
|
||||
errorMsg = '您拒绝了授权,无法登录';
|
||||
} else if (error.errMsg.includes('cancel')) {
|
||||
errorMsg = '您取消了授权';
|
||||
}
|
||||
}
|
||||
|
||||
wx.showModal({
|
||||
title: '登录失败',
|
||||
content: errorMsg,
|
||||
showCancel: false
|
||||
});
|
||||
|
||||
this.setData({ isLoading: false });
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 跳过登录
|
||||
*/
|
||||
handleSkipLogin() {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '未登录将无法使用完整功能,确定要跳过吗?',
|
||||
confirmText: '确定跳过',
|
||||
cancelText: '去登录',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
// 执行静默登录
|
||||
this.silentLogin();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 静默登录
|
||||
*/
|
||||
async silentLogin() {
|
||||
try {
|
||||
await app.silentLogin();
|
||||
this.redirectToTarget();
|
||||
} catch (error) {
|
||||
console.error('静默登录失败', error);
|
||||
this.redirectToTarget();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 跳转到目标页面
|
||||
*/
|
||||
redirectToTarget() {
|
||||
const url = this.data.redirectUrl || '/pages/index/index';
|
||||
|
||||
// 判断是否是 TabBar 页面
|
||||
const tabBarPages = [
|
||||
'/pages/index/index',
|
||||
'/pages/device/list/list',
|
||||
'/pages/statistics/index/index',
|
||||
'/pages/warning/list/list',
|
||||
'/pages/profile/index/index'
|
||||
];
|
||||
|
||||
if (tabBarPages.includes(url)) {
|
||||
wx.switchTab({ url });
|
||||
} else {
|
||||
wx.redirectTo({ url });
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 询问是否开启消息通知
|
||||
*/
|
||||
askForNotification() {
|
||||
wx.showModal({
|
||||
title: '开启消息通知',
|
||||
content: '开启后可以及时接收设备检验预警提醒',
|
||||
confirmText: '立即开启',
|
||||
cancelText: '暂不开启',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
this.subscribeMessages();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 订阅消息
|
||||
*/
|
||||
async subscribeMessages() {
|
||||
try {
|
||||
await app.subscribeAllMessages();
|
||||
wx.showToast({
|
||||
title: '订阅成功',
|
||||
icon: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('订阅失败', error);
|
||||
// 订阅失败不影响使用,不显示错误提示
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 显示用户协议
|
||||
*/
|
||||
showAgreement() {
|
||||
wx.showModal({
|
||||
title: '用户协议',
|
||||
content: '这里是用户协议的内容...\n\n1. 用户需遵守相关法律法规\n2. 不得利用本系统从事违法活动\n3. 保护个人信息安全\n4. 合理使用系统资源',
|
||||
showCancel: false,
|
||||
confirmText: '我知道了'
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 显示隐私政策
|
||||
*/
|
||||
showPrivacy() {
|
||||
wx.showModal({
|
||||
title: '隐私政策',
|
||||
content: '这里是隐私政策的内容...\n\n1. 我们会收集您的基本信息\n2. 信息仅用于提供服务\n3. 不会向第三方泄露\n4. 您可以随时删除个人信息',
|
||||
showCancel: false,
|
||||
confirmText: '我知道了'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"navigationBarTitleText": "登录",
|
||||
"navigationStyle": "custom",
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-button": "tdesign-miniprogram/button/button"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<!--pages/login/login.wxml-->
|
||||
<view class="container">
|
||||
<view class="login-header">
|
||||
<view class="logo">
|
||||
<t-icon name="shield" size="120rpx" color="#0052D9" />
|
||||
</view>
|
||||
<view class="app-name">安全工器具预警</view>
|
||||
<view class="app-desc">专业的安全工器具管理系统</view>
|
||||
</view>
|
||||
|
||||
<view class="login-content">
|
||||
<view class="welcome-text">欢迎使用</view>
|
||||
<view class="welcome-desc">请登录以继续使用完整功能</view>
|
||||
|
||||
<view class="features">
|
||||
<view class="feature-item">
|
||||
<t-icon name="check-circle" size="32rpx" color="#0052D9" />
|
||||
<text>设备台账管理</text>
|
||||
</view>
|
||||
<view class="feature-item">
|
||||
<t-icon name="check-circle" size="32rpx" color="#0052D9" />
|
||||
<text>检验预警提醒</text>
|
||||
</view>
|
||||
<view class="feature-item">
|
||||
<t-icon name="check-circle" size="32rpx" color="#0052D9" />
|
||||
<text>统计分析报表</text>
|
||||
</view>
|
||||
<view class="feature-item">
|
||||
<t-icon name="check-circle" size="32rpx" color="#0052D9" />
|
||||
<text>消息实时推送</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="login-actions">
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="large"
|
||||
block
|
||||
bindtap="handleLogin"
|
||||
loading="{{isLoading}}"
|
||||
>
|
||||
<t-icon name="user" size="32rpx" style="margin-right: 16rpx;" />
|
||||
微信快捷登录
|
||||
</t-button>
|
||||
|
||||
<view class="skip-login" bindtap="handleSkipLogin">
|
||||
<text>暂不登录,先看看</text>
|
||||
<t-icon name="chevron-right" size="28rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="login-footer">
|
||||
<view class="agreement">
|
||||
登录即表示同意
|
||||
<text class="link" bindtap="showAgreement">《用户协议》</text>
|
||||
和
|
||||
<text class="link" bindtap="showPrivacy">《隐私政策》</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/* pages/login/login.wxss */
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 80rpx 48rpx 48rpx;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 80rpx;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
background: #fff;
|
||||
border-radius: 50%;
|
||||
margin: 0 auto 32rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.app-name {
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.app-desc {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.login-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.welcome-text {
|
||||
font-size: 40rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.welcome-desc {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.features {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 24rpx;
|
||||
padding: 32rpx;
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #fff;
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.feature-item:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.feature-item text {
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.login-actions {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.skip-login {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.skip-login text {
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
margin-top: 48rpx;
|
||||
}
|
||||
|
||||
.agreement {
|
||||
text-align: center;
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.agreement .link {
|
||||
color: #fff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue