添加账号密码登录页面的跳转逻辑,优化登录方式选择;更新项目配置以支持不同登录方式,提升用户体验。
| | |
| | | "pages/feedback/feedback", |
| | | "pages/wxlogin/wxlogin", |
| | | "pages/login/login", |
| | | "pages/accountLogin/accountLogin", |
| | | "pages/wxbind/wxbind", |
| | | "pages/rechargeList/rechargeList", |
| | | "pages/wallet/wallet", |
New file |
| | |
| | | const app = getApp(); |
| | | const storage = require('../../utils/storage.js'); |
| | | const { |
| | | post |
| | | } = require('../../api/request.js'); |
| | | const { PROJECT_CONFIG } = require('../../utils/projectConfig.js'); |
| | | const { setBaseUrl } = require('../../api/config.js'); |
| | | |
| | | Page({ |
| | | |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | username: '', |
| | | password: '', |
| | | passwordVisible: false, |
| | | projectName: '嘉峪关项目', // 默认项目名称 |
| | | selectedProject: 'JYG', // 默认项目代码 |
| | | showErrorDialog: false, |
| | | fromBack: false, // 标记是否是从返回按钮返回的 |
| | | manualNavigate: false // 标记是否是通过编程方式导航的 |
| | | }, |
| | | |
| | | /** |
| | | * 绑定用户名输入 |
| | | */ |
| | | bindUsernameInput: function (e) { |
| | | this.setData({ |
| | | username: e.detail.value |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 绑定密码输入 |
| | | */ |
| | | bindPasswordInput: function (e) { |
| | | this.setData({ |
| | | password: e.detail.value |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 切换密码显示状态 |
| | | */ |
| | | togglePasswordVisibility: function () { |
| | | this.setData({ |
| | | passwordVisible: !this.data.passwordVisible |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 登录 |
| | | */ |
| | | login: function () { |
| | | const { |
| | | username, |
| | | password |
| | | } = this.data; |
| | | |
| | | // 验证用户名和密码 |
| | | if (!username.trim()) { |
| | | wx.showToast({ |
| | | title: '请输入用户名', |
| | | icon: 'none' |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | if (!password.trim()) { |
| | | wx.showToast({ |
| | | title: '请输入密码', |
| | | icon: 'none' |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 显示加载中 |
| | | wx.showLoading({ |
| | | title: '登录中...', |
| | | mask: true |
| | | }); |
| | | |
| | | // 标记为手动导航,确保不会触发返回逻辑 |
| | | console.log('登录按钮点击,设置manualNavigate=true'); |
| | | this.setData({ |
| | | manualNavigate: true |
| | | }); |
| | | |
| | | this.accountLogin(); |
| | | }, |
| | | |
| | | /** |
| | | * 跳转到注册页面 |
| | | */ |
| | | goToRegister: function () { |
| | | wx.showToast({ |
| | | title: '注册功能暂未开放', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 跳转到忘记密码页面 |
| | | */ |
| | | goToForgetPassword: function () { |
| | | wx.showToast({ |
| | | title: '找回密码功能暂未开放', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }); |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad: function (options) { |
| | | console.log('accountLogin页面加载,options:', options); |
| | | |
| | | // 设置页面数据 |
| | | this.setData({ |
| | | fromBack: false, // 标记是否是从返回按钮返回的 |
| | | manualNavigate: false // 标记是否是通过编程方式导航的 |
| | | }); |
| | | |
| | | // 从URL参数获取项目信息 |
| | | if (options && options.project) { |
| | | const project = options.project; |
| | | // 直接使用传入的项目名称,不再手动转换 |
| | | const projectName = options.projectName || '默认项目'; |
| | | |
| | | console.log(`从URL参数获取项目信息: ${project} (${projectName})`); |
| | | |
| | | this.setData({ |
| | | selectedProject: project, |
| | | projectName: projectName |
| | | }); |
| | | |
| | | // 同步更新全局项目设置 |
| | | if (getApp().globalData) { |
| | | getApp().globalData.selectedProject = project; |
| | | |
| | | // 设置对应的tag |
| | | if (project === 'JYG') { |
| | | getApp().globalData.tag = 'ym'; |
| | | } else if (project === 'MQ') { |
| | | getApp().globalData.tag = 'mq'; |
| | | } |
| | | |
| | | // 更新 BASEURL |
| | | try { |
| | | // 使用导入的setBaseUrl函数设置baseUrl |
| | | setBaseUrl(project); |
| | | |
| | | // 从PROJECT_CONFIG中获取serverUrl |
| | | const serverUrl = PROJECT_CONFIG[project]?.serverUrl; |
| | | if (serverUrl) { |
| | | getApp().globalData.baseUrl = serverUrl; |
| | | console.log('设置baseUrl成功:', serverUrl); |
| | | } |
| | | } catch (e) { |
| | | console.error('设置baseUrl失败:', e); |
| | | } |
| | | } |
| | | |
| | | // 检查项目配置的登录方式是否与当前页面匹配 |
| | | const projectConfig = PROJECT_CONFIG[project]; |
| | | if (projectConfig && projectConfig.loginType !== 'account') { |
| | | console.log(`当前项目配置的登录方式为${projectConfig.loginType},自动跳转到验证码登录页面`); |
| | | |
| | | // 设置手动导航标记,避免触发返回逻辑 |
| | | this.setData({ manualNavigate: true }); |
| | | |
| | | // 延迟执行跳转,确保页面完全加载 |
| | | setTimeout(() => { |
| | | wx.redirectTo({ |
| | | url: `/pages/login/login?project=${project}&projectName=${projectName}` |
| | | }); |
| | | }, 100); |
| | | } |
| | | } else { |
| | | console.log('未从URL获取到项目信息,使用默认值'); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面初次渲染完成 |
| | | */ |
| | | onReady() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | onShow() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面隐藏 |
| | | */ |
| | | onHide() { |
| | | // 如果不是通过编程方式导航,则可能是点击了返回按钮 |
| | | // 注意:在某些情况下,微信可能会直接调用onUnload而跳过onHide |
| | | if (!this.data.manualNavigate) { |
| | | console.log('页面隐藏,可能是点击了返回按钮'); |
| | | this.setData({ |
| | | fromBack: true |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | | */ |
| | | onUnload() { |
| | | console.log('页面卸载,fromBack=', this.data.fromBack); |
| | | console.log('页面卸载,manualNavigate=', this.data.manualNavigate); |
| | | |
| | | // 如果是从返回按钮返回的,且不是通过编程方式导航 |
| | | if (this.data.fromBack && !this.data.manualNavigate) { |
| | | console.log('检测到从返回按钮返回,跳转到首页'); |
| | | wx.reLaunch({ |
| | | url: '/pages/index/index' |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |
| | | onPullDownRefresh() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 页面上拉触底事件的处理函数 |
| | | */ |
| | | onReachBottom() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |
| | | onShareAppMessage() { |
| | | return { |
| | | title: '大禹节水灌溉系统', |
| | | path: '/pages/index/index', |
| | | imageUrl: '/images/share-img.jpg' // 自定义分享图片 |
| | | }; |
| | | }, |
| | | |
| | | /** |
| | | * 账号密码登录 |
| | | */ |
| | | accountLogin() { |
| | | const { username, password, selectedProject } = this.data; |
| | | |
| | | // 构建请求参数 |
| | | const data = { |
| | | username: username, |
| | | password: password |
| | | }; |
| | | |
| | | // 发送登录请求 |
| | | post({ |
| | | url: '/wx/user/passwordLogin', |
| | | data: data, |
| | | isShowLoding: true |
| | | }).then(res => { |
| | | // 隐藏加载提示 |
| | | wx.hideLoading(); |
| | | |
| | | if (res && res.success) { |
| | | // 登录成功,保存token等信息 |
| | | storage.set('token', res.content.token); |
| | | storage.set('userInfo', res.content); |
| | | |
| | | // 更新全局数据 |
| | | if (app.globalData) { |
| | | app.globalData.token = res.content.token; |
| | | app.globalData.userInfo = res.content; |
| | | } |
| | | |
| | | // 跳转到首页 |
| | | wx.switchTab({ |
| | | url: '/pages/home/home' |
| | | }); |
| | | } else { |
| | | // 登录失败 |
| | | wx.showToast({ |
| | | title: res.msg || '登录失败,请检查账号密码', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | }).catch(err => { |
| | | // 隐藏加载提示 |
| | | wx.hideLoading(); |
| | | |
| | | // 显示错误信息 |
| | | wx.showToast({ |
| | | title: '网络错误,请稍后重试', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }); |
| | | |
| | | console.error('登录失败:', err); |
| | | }); |
| | | } |
| | | }); |
New file |
| | |
| | | { |
| | | "navigationBarTitleText": "账号密码登录", |
| | | "navigationBarTextStyle": "white" |
| | | } |
New file |
| | |
| | | <!--pages/accountLogin/accountLogin.wxml--> |
| | | <view class="login-container"> |
| | | <view class="logo-container"> |
| | | |
| | | </view> |
| | | |
| | | <view class="form-container"> |
| | | <view class="title">账号密码登录</view> |
| | | |
| | | <view class="input-wrapper"> |
| | | <view class="input-icon user-icon"></view> |
| | | <input class="input" type="text" placeholder="请输入用户名" bindinput="bindUsernameInput" /> |
| | | </view> |
| | | |
| | | <view class="input-wrapper"> |
| | | <view class="input-icon lock-icon"></view> |
| | | <input class="input" password="{{!passwordVisible}}" placeholder="请输入密码" bindinput="bindPasswordInput" /> |
| | | <view class="eye-button" bindtap="togglePasswordVisibility"> |
| | | <view class="{{passwordVisible ? 'eye-open-icon' : 'eye-close-icon'}}"></view> |
| | | </view> |
| | | </view> |
| | | |
| | | <view class="login-btn-container"> |
| | | <button class="login-button" bindtap="login">登录</button> |
| | | </view> |
| | | |
| | | <view class="footer-links"> |
| | | <view class="link" bindtap="goToForgetPassword">忘记密码</view> |
| | | </view> |
| | | </view> |
| | | |
| | | <view class="project-info"> |
| | | <text>当前项目: {{projectName}}</text> |
| | | </view> |
| | | |
| | | </view> |
New file |
| | |
| | | /* pages/accountLogin/accountLogin.wxss */ |
| | | |
| | | .login-container { |
| | | display: flex; |
| | | flex-direction: column; |
| | | height: 100vh; |
| | | width: 100%; |
| | | background-color: #f5f5f5; |
| | | } |
| | | |
| | | .logo-container { |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | padding: 60rpx 0; |
| | | } |
| | | |
| | | .logo-circle { |
| | | width: 200rpx; |
| | | height: 200rpx; |
| | | border-radius: 50%; |
| | | background: #1890FF; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | color: white; |
| | | font-size: 80rpx; |
| | | font-weight: bold; |
| | | } |
| | | |
| | | .form-container { |
| | | background-color: #fff; |
| | | border-radius: 20rpx; |
| | | margin: 0 40rpx; |
| | | padding: 40rpx; |
| | | box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); |
| | | } |
| | | |
| | | .title { |
| | | font-size: 40rpx; |
| | | font-weight: bold; |
| | | color: #333; |
| | | margin-bottom: 40rpx; |
| | | text-align: center; |
| | | } |
| | | |
| | | .input-wrapper { |
| | | display: flex; |
| | | align-items: center; |
| | | border-bottom: 1rpx solid #e0e0e0; |
| | | margin-bottom: 40rpx; |
| | | padding-bottom: 20rpx; |
| | | } |
| | | |
| | | .input-icon { |
| | | width: 40rpx; |
| | | height: 40rpx; |
| | | margin-right: 20rpx; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | color: #1890FF; |
| | | font-weight: bold; |
| | | font-size: 32rpx; |
| | | } |
| | | |
| | | .user-icon::before { |
| | | content: "👤"; |
| | | } |
| | | |
| | | .lock-icon::before { |
| | | content: "🔒"; |
| | | } |
| | | |
| | | .eye-open-icon::before { |
| | | content: "👁️"; |
| | | } |
| | | |
| | | .eye-close-icon::before { |
| | | content: "👁️🗨️"; |
| | | } |
| | | |
| | | .input { |
| | | flex: 1; |
| | | height: 60rpx; |
| | | font-size: 32rpx; |
| | | color: #333; |
| | | } |
| | | |
| | | .eye-button { |
| | | padding: 10rpx; |
| | | font-size: 32rpx; |
| | | width: 60rpx; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | } |
| | | |
| | | .login-btn-container { |
| | | margin-top: 60rpx; |
| | | } |
| | | |
| | | .login-button { |
| | | height: 90rpx; |
| | | background-color: #1890FF; |
| | | color: #fff; |
| | | font-size: 34rpx; |
| | | border-radius: 45rpx; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | } |
| | | |
| | | .footer-links { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | margin-top: 40rpx; |
| | | font-size: 28rpx; |
| | | } |
| | | |
| | | .link { |
| | | color: #1890FF; |
| | | } |
| | | |
| | | .project-info { |
| | | position: fixed; |
| | | bottom: 40rpx; |
| | | width: 100%; |
| | | text-align: center; |
| | | font-size: 32rpx; |
| | | padding: 16rpx 0; |
| | | background-color: rgba(255, 255, 255, 0.8); |
| | | backdrop-filter: blur(5px); |
| | | box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1); |
| | | } |
| | | |
| | | .project-info text { |
| | | display: inline-block; |
| | | padding: 8rpx 24rpx; |
| | | color: #fff; |
| | | border-radius: 30rpx; |
| | | font-weight: 500; |
| | | box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.2); |
| | | background: linear-gradient(45deg, #1890FF, #36a9fc); |
| | | } |
| | | |
| | | .project-info.mq text { |
| | | background: linear-gradient(45deg, #18c063, #36d486); |
| | | } |
| | | |
| | | image { |
| | | position: fixed; |
| | | left: 0; |
| | | bottom: 0; |
| | | display: block; |
| | | width: 100%; |
| | | height: 100%; |
| | | z-index: -999; |
| | | } |
| | |
| | | |
| | | openValve: function (e) { |
| | | const app = getApp(); |
| | | if (app.globalData.isLoggedIn) { |
| | | wx.navigateTo({ |
| | | url: '/pages/waterIntake/waterIntake', |
| | | }) |
| | | } else { |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error' |
| | | }) |
| | | // 检查当前项目是否需要登录 |
| | | const currentProject = app.globalData.selectedProject; |
| | | if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) { |
| | | // 需要登录的项目,检查是否已登录 |
| | | if (!app.globalData.isLoggedIn) { |
| | | // 未登录,显示提示并阻止操作 |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | |
| | | // 获取项目配置 |
| | | const projectConfig = PROJECT_CONFIG[currentProject]; |
| | | if (projectConfig) { |
| | | // 询问用户是否前往登录 |
| | | wx.showModal({ |
| | | title: '提示', |
| | | content: '您需要登录后才能使用开阀功能,是否立即登录?', |
| | | confirmText: '前往登录', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | // 用户点击确认,直接调用wxLogin方法 |
| | | this.wxLogin(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 已登录或不需要登录的项目,执行开阀操作 |
| | | wx.navigateTo({ |
| | | url: '/pages/waterIntake/waterIntake', |
| | | }) |
| | | }, |
| | | |
| | | // calculateScrollViewHeight: function () { |
| | | // wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => { |
| | | // let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0); |
| | |
| | | }, |
| | | openValveList() { |
| | | const app = getApp(); |
| | | if (app.globalData.isLoggedIn) { |
| | | wx.navigateTo({ |
| | | url: '/pages/valveList/valveList', |
| | | }) |
| | | } else { |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error' |
| | | }) |
| | | // 检查当前项目是否需要登录 |
| | | const currentProject = app.globalData.selectedProject; |
| | | if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) { |
| | | // 需要登录的项目,检查是否已登录 |
| | | if (!app.globalData.isLoggedIn) { |
| | | // 未登录,显示提示并阻止操作 |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | |
| | | // 获取项目配置 |
| | | const projectConfig = PROJECT_CONFIG[currentProject]; |
| | | if (projectConfig) { |
| | | // 询问用户是否前往登录 |
| | | wx.showModal({ |
| | | title: '提示', |
| | | content: '您需要登录后才能查看开关阀记录,是否立即登录?', |
| | | confirmText: '前往登录', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | // 用户点击确认,直接调用wxLogin方法 |
| | | this.wxLogin(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 已登录或不需要登录的项目,执行查看记录操作 |
| | | wx.navigateTo({ |
| | | url: '/pages/valveList/valveList', |
| | | }) |
| | | }, |
| | | feedBack() { |
| | | wx.showToast({ |
| | |
| | | }); |
| | | } |
| | | }, |
| | | //轮灌 |
| | | irrigation() { |
| | | if (getApp().globalData.isLoggedIn) { |
| | | wx.navigateTo({ |
| | | url: '/pages/irrigation/irrigation', |
| | | }) |
| | | } else { |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error' |
| | | }) |
| | | const app = getApp(); |
| | | // 检查当前项目是否需要登录 |
| | | const currentProject = app.globalData.selectedProject; |
| | | if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) { |
| | | // 需要登录的项目,检查是否已登录 |
| | | if (!app.globalData.isLoggedIn) { |
| | | // 未登录,显示提示并阻止操作 |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | |
| | | // 获取项目配置 |
| | | const projectConfig = PROJECT_CONFIG[currentProject]; |
| | | if (projectConfig) { |
| | | // 询问用户是否前往登录 |
| | | wx.showModal({ |
| | | title: '提示', |
| | | content: '您需要登录后才能使用轮灌功能,是否立即登录?', |
| | | confirmText: '前往登录', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | // 用户点击确认,直接调用wxLogin方法 |
| | | this.wxLogin(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 已登录或不需要登录的项目,执行轮灌操作 |
| | | wx.navigateTo({ |
| | | url: '/pages/irrigation/irrigation', |
| | | }) |
| | | }, |
| | | handleChange(e) { |
| | | const item = e.currentTarget.dataset.item; |
| | |
| | | * 扫码开阀 |
| | | */ |
| | | scenCode() { |
| | | const app = getApp(); |
| | | // 检查当前项目是否需要登录 |
| | | const currentProject = app.globalData.selectedProject; |
| | | if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) { |
| | | // 需要登录的项目,检查是否已登录 |
| | | if (!app.globalData.isLoggedIn) { |
| | | // 未登录,显示提示并阻止扫码 |
| | | wx.showToast({ |
| | | title: '请先登录', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | |
| | | // 获取项目配置 |
| | | const projectConfig = PROJECT_CONFIG[currentProject]; |
| | | if (projectConfig) { |
| | | // 询问用户是否前往登录 |
| | | wx.showModal({ |
| | | title: '提示', |
| | | content: '您需要登录后才能使用扫码开阀功能,是否立即登录?', |
| | | confirmText: '前往登录', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | // 用户点击确认,直接调用wxLogin方法 |
| | | this.wxLogin(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 已登录或不需要登录的项目,执行扫码操作 |
| | | const that = this; |
| | | wx.scanCode({ |
| | | success(res) { |
| | |
| | | } |
| | | |
| | | // 如果当前已在登录页,不再跳转 |
| | | if (currentRoute === 'pages/login/login') { |
| | | if (currentRoute === 'pages/login/login' || currentRoute === 'pages/accountLogin/accountLogin') { |
| | | console.log('当前已在登录页,不再跳转'); |
| | | return; |
| | | } |
| | |
| | | wx.setStorageSync('_attempted_login_redirect', 'true'); |
| | | } catch (e) {} |
| | | |
| | | // wx.navigateTo({ |
| | | // url: `/pages/login/login?project=${this.data.selectedProject}`, |
| | | // success: () => console.log('成功跳转到登录页'), |
| | | // fail: (err) => console.error('跳转到登录页失败:', err) |
| | | // }); |
| | | // 根据项目配置的loginType决定跳转到哪个登录页面 |
| | | // 此处不做跳转,注释掉原有代码 |
| | | // const projectInfo = PROJECT_CONFIG[currentProject]; |
| | | // const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录 |
| | | |
| | | // if (loginType === 'account') { |
| | | // // 账号密码登录 |
| | | // wx.navigateTo({ |
| | | // url: `/pages/accountLogin/accountLogin?project=${currentProject}`, |
| | | // success: () => console.log('成功跳转到账号密码登录页'), |
| | | // fail: (err) => console.error('跳转到账号密码登录页失败:', err) |
| | | // }); |
| | | // } else { |
| | | // // 验证码登录 |
| | | // wx.navigateTo({ |
| | | // url: `/pages/login/login?project=${currentProject}`, |
| | | // success: () => console.log('成功跳转到验证码登录页'), |
| | | // fail: (err) => console.error('跳转到验证码登录页失败:', err) |
| | | // }); |
| | | // } |
| | | } |
| | | }) |
| | | .catch(err => { |
| | |
| | | return; |
| | | } |
| | | |
| | | // 出错时也跳转到登录页 |
| | | // wx.navigateTo({ |
| | | // url: `/pages/login/login?project=${this.data.selectedProject}`, |
| | | // success: () => console.log('错误后成功跳转到登录页'), |
| | | // fail: (err) => console.error('错误后跳转到登录页失败:', err) |
| | | // }); |
| | | // 出错时也跳转到登录页,根据loginType决定跳转目标 |
| | | // 此处不做跳转,注释掉原有代码 |
| | | // const projectInfo = PROJECT_CONFIG[currentProject]; |
| | | // const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录 |
| | | |
| | | // if (loginType === 'account') { |
| | | // // 账号密码登录 |
| | | // wx.navigateTo({ |
| | | // url: `/pages/accountLogin/accountLogin?project=${currentProject}`, |
| | | // success: () => console.log('错误后成功跳转到账号密码登录页'), |
| | | // fail: (err) => console.error('错误后跳转到账号密码登录页失败:', err) |
| | | // }); |
| | | // } else { |
| | | // // 验证码登录 |
| | | // wx.navigateTo({ |
| | | // url: `/pages/login/login?project=${currentProject}`, |
| | | // success: () => console.log('错误后成功跳转到验证码登录页'), |
| | | // fail: (err) => console.error('错误后跳转到验证码登录页失败:', err) |
| | | // }); |
| | | // } |
| | | }); |
| | | }, |
| | | |
| | |
| | | wx.hideLoading(); |
| | | if (response.code === "0001") { |
| | | if (response.content.client.clientId === "") { |
| | | // 未绑定账号,跳转到登录页面并传递当前项目信息 |
| | | // 未绑定账号,根据项目配置的loginType跳转到相应的登录页面 |
| | | const projectInfo = PROJECT_CONFIG[this.data.selectedProject]; |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录 |
| | | |
| | | if (loginType === 'account') { |
| | | // 账号密码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/accountLogin/accountLogin?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | } else { |
| | | // 验证码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | } |
| | | } else { |
| | | this.setData({ |
| | | userName: response.content.client.clientName, |
| | |
| | | |
| | | } |
| | | } else if (response.code === "1003") { |
| | | // 未绑定账号,跳转到登录页面并传递当前项目信息 |
| | | // 未绑定账号,根据项目配置的loginType跳转到相应的登录页面 |
| | | const projectInfo = PROJECT_CONFIG[this.data.selectedProject]; |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录 |
| | | |
| | | if (loginType === 'account') { |
| | | // 账号密码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/accountLogin/accountLogin?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | } else { |
| | | // 验证码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | } |
| | | } else { |
| | | wx.showToast({ |
| | | title: '登录失败', |
| | |
| | | wx.hideLoading(); |
| | | console.error('登录请求失败:', error); |
| | | if(error.code==="1003"){ |
| | | // 未绑定账号,跳转到登录页面并传递当前项目信息 |
| | | // 未绑定账号,根据项目配置的loginType跳转到相应的登录页面 |
| | | const projectInfo = PROJECT_CONFIG[this.data.selectedProject]; |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录 |
| | | |
| | | if (loginType === 'account') { |
| | | // 账号密码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/accountLogin/accountLogin?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | } else { |
| | | // 验证码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` |
| | | }); |
| | | } |
| | | }else{ |
| | | wx.showToast({ |
| | | title: '登录失败,请重试', |
| | |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | // 添加用户点击头像或用户名登录的处理逻辑 |
| | | handleUserTap() { |
| | | const app = getApp(); |
| | | // 如果已登录,不需要跳转到登录页面 |
| | | if (app.globalData.isLoggedIn) { |
| | | return; |
| | | } |
| | | |
| | | // 检查当前项目是否需要登录 |
| | | const currentProject = app.globalData.selectedProject; |
| | | if (currentProject && PROJECT_CONFIG[currentProject]) { |
| | | const projectConfig = PROJECT_CONFIG[currentProject]; |
| | | |
| | | if (!projectConfig.needLogin) { |
| | | console.log('handleUserTap: 当前项目不需要登录:', currentProject); |
| | | // 不需要登录的项目,显示项目名称 |
| | | this.setData({ |
| | | userName: projectConfig.displayName |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 根据项目配置的loginType决定跳转到哪个登录页面 |
| | | const loginType = projectConfig.loginType || 'code'; // 默认使用验证码登录 |
| | | |
| | | if (loginType === 'account') { |
| | | // 账号密码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/accountLogin/accountLogin?project=${currentProject}&projectName=${projectConfig.displayName}` |
| | | }); |
| | | } else { |
| | | // 验证码登录 |
| | | wx.navigateTo({ |
| | | url: `/pages/login/login?project=${currentProject}&projectName=${projectConfig.displayName}` |
| | | }); |
| | | } |
| | | } else { |
| | | // 如果没有当前项目配置,默认跳转到验证码登录 |
| | | wx.navigateTo({ |
| | | url: '/pages/login/login' |
| | | }); |
| | | } |
| | | }, |
| | | }) |
| | |
| | | const { |
| | | post |
| | | } = require('../../api/request.js'); |
| | | const { PROJECT_CONFIG } = require('../../utils/projectConfig.js'); |
| | | const { setBaseUrl } = require('../../api/config.js'); |
| | | |
| | | Page({ |
| | | |
| | |
| | | }, |
| | | |
| | | /** |
| | | * 跳转到账号密码登录页面 |
| | | */ |
| | | goToAccountLogin: function() { |
| | | // 获取当前项目信息,传递给accountLogin页面 |
| | | const { selectedProject, projectName } = this.data; |
| | | |
| | | // 跳转到账号密码登录页面 |
| | | wx.navigateTo({ |
| | | url: `/pages/accountLogin/accountLogin?project=${selectedProject}&projectName=${projectName}` |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad: function (options) { |
| | |
| | | |
| | | // 更新 BASEURL |
| | | try { |
| | | const { PROJECT_URLS } = require('../../api/config.js'); |
| | | getApp().globalData.baseUrl = PROJECT_URLS[project]; |
| | | // 使用导入的setBaseUrl函数设置baseUrl |
| | | setBaseUrl(project); |
| | | |
| | | // 从PROJECT_CONFIG中获取serverUrl |
| | | const serverUrl = PROJECT_CONFIG[project]?.serverUrl; |
| | | if (serverUrl) { |
| | | getApp().globalData.baseUrl = serverUrl; |
| | | console.log('设置baseUrl成功:', serverUrl); |
| | | } |
| | | } catch (e) { |
| | | console.error('设置baseUrl失败:', e); |
| | | } |
| | | } |
| | | |
| | | // 检查项目配置的登录方式是否与当前页面匹配 |
| | | const projectConfig = PROJECT_CONFIG[project]; |
| | | if (projectConfig && projectConfig.loginType === 'account') { |
| | | console.log(`当前项目配置的登录方式为account,自动跳转到账号密码登录页面`); |
| | | |
| | | // 设置手动导航标记,避免触发返回逻辑 |
| | | this.setData({ manualNavigate: true }); |
| | | |
| | | // 延迟执行跳转,确保页面完全加载 |
| | | setTimeout(() => { |
| | | wx.redirectTo({ |
| | | url: `/pages/accountLogin/accountLogin?project=${project}&projectName=${projectName}` |
| | | }); |
| | | }, 100); |
| | | } |
| | | } else { |
| | | console.log('未从URL获取到项目信息,使用默认值'); |
| | | } |
| | |
| | | <view class="login-btn-container"> |
| | | <button class="login-button" bindtap="login">登录</button> |
| | | </view> |
| | | |
| | | <view class="footer-links"> |
| | | <view class="link" bindtap="goToForgetPassword">忘记密码</view> |
| | | <view class="link" bindtap="goToAccountLogin">账号密码登录</view> |
| | | </view> |
| | | </view> |
| | | |
| | | <view class="project-info"> |
| | |
| | | } |
| | | |
| | | .link { |
| | | color: #1aad19; |
| | | color: #1890FF; |
| | | } |
| | | |
| | | .project-info { |
| | |
| | | URL_233: 'https://sp.dayuyanjiuyuan.top/', |
| | | URL_55: 'https://irrigate.dayuyanjiuyuan.top/', |
| | | URL_166: 'https://no253541tf71.vicp.fun/', |
| | | URL_121: 'https://shifanqu1.dayuyanjiuyuan.top/' |
| | | URL_121: 'https://shifanqu1.dayuyanjiuyuan.top/', |
| | | URL_87:'http://192.168.10.87:54321/' |
| | | }; |
| | | |
| | | const PROJECT_CONFIG = { |
| | |
| | | displayName: '嘉峪关项目', |
| | | operatorId: '2025040415305200007', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | loginType: 'code', // 验证码登录 |
| | | serverId: '55', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_55; |
| | |
| | | displayName: '民勤项目', |
| | | operatorId: '2025033115305200006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | loginType: 'code', // 验证码登录 |
| | | serverId: '121', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_121; |
| | |
| | | displayName: '测试项目', |
| | | operatorId: '', // 统一ID用于operator和clientId |
| | | needLogin: true, // 需要登录 |
| | | loginType: 'account', // 账号密码登录 |
| | | serverId: '166', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_166; |
| | |
| | | displayName: '金昌项目', |
| | | operatorId: '', // 统一ID用于operator和clientId 2025041710412400006 |
| | | needLogin: true, // 需要登录 |
| | | loginType: 'code', // 账号密码登录 |
| | | serverId: '121', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_121; |
| | | } |
| | | }, |
| | | LZXM: { |
| | | tag: 'lz', |
| | | displayName: '凉州项目', |
| | | operatorId: '', // 统一ID用于operator和clientId |
| | | needLogin: true, // 不需要登录 |
| | | loginType: 'code', // 验证码登录 |
| | | serverId: '121', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_121; |
| | |
| | | displayName: '甘肃农科院', |
| | | operatorId: '', // 统一ID用于operator和clientId |
| | | needLogin: true, // 不需要登录 |
| | | loginType: 'code', // 账号密码登录 |
| | | serverId: '233', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_233; |
| | | } |
| | | } |
| | | // , |
| | | // LOCTEST:{ |
| | | // tag: 'ym', |
| | | // displayName: '本机测试项目', |
| | | // operatorId: '', // 统一ID用于operator和clientId |
| | | // needLogin: true, // 需要登录 |
| | | // serverId: '87', |
| | | // get serverUrl() { |
| | | // return SERVER_INFO.URL_87; |
| | | // } |
| | | // } |
| | | }; |
| | | |
| | | module.exports = { |