From d13b32ab579e07a0880aaff2118376860219e348 Mon Sep 17 00:00:00 2001 From: syruan <15555146157@163.com> Date: Mon, 10 Nov 2025 13:43:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login/login.js | 184 +++++++++++++++++++++++++++++++++++++++++ pages/login/login.json | 9 ++ pages/login/login.wxml | 62 ++++++++++++++ pages/login/login.wxss | 114 +++++++++++++++++++++++++ 4 files changed, 369 insertions(+) create mode 100644 pages/login/login.js create mode 100644 pages/login/login.json create mode 100644 pages/login/login.wxml create mode 100644 pages/login/login.wxss diff --git a/pages/login/login.js b/pages/login/login.js new file mode 100644 index 0000000..a5bf49c --- /dev/null +++ b/pages/login/login.js @@ -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: '我知道了' + }); + } +}); + diff --git a/pages/login/login.json b/pages/login/login.json new file mode 100644 index 0000000..dd9dcf5 --- /dev/null +++ b/pages/login/login.json @@ -0,0 +1,9 @@ +{ + "navigationBarTitleText": "登录", + "navigationStyle": "custom", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-button": "tdesign-miniprogram/button/button" + } +} + diff --git a/pages/login/login.wxml b/pages/login/login.wxml new file mode 100644 index 0000000..489dae0 --- /dev/null +++ b/pages/login/login.wxml @@ -0,0 +1,62 @@ + + + + + 安全工器具预警 + 专业的安全工器具管理系统 + + + + 欢迎使用 + 请登录以继续使用完整功能 + + + + + 设备台账管理 + + + + 检验预警提醒 + + + + 统计分析报表 + + + + 消息实时推送 + + + + + + + + + 登录即表示同意 + 《用户协议》 + 和 + 《隐私政策》 + + + + diff --git a/pages/login/login.wxss b/pages/login/login.wxss new file mode 100644 index 0000000..5358494 --- /dev/null +++ b/pages/login/login.wxss @@ -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; +} +