import http from '../../utils/api' Page({ data: { // 账号密码 account: '', password: '', accountFocus: false, passwordFocus: false, passwordVisible: false, // 协议相关 isAgree: true, showAgreementModal: false, modalTitle: '', modalContent: '', // 加载状态 isLoading: false, // 登录状态 canLogin: false }, onLoad() { // 检查登录状态 // this.checkLoginStatus() }, // 检查登录状态 // checkLoginStatus() { // const token = wx.getStorageSync('token') // if (token) { // // 已登录,跳转到首页 // wx.switchTab({ // url: '/pages/home/home' // }) // } // }, // 账号输入 onAccountInput(e) { this.setData({ account: e.detail.value }, () => { this.checkCanLogin() }) }, // 密码输入 onPasswordInput(e) { this.setData({ password: e.detail.value }, () => { this.checkCanLogin() }) }, // 检查是否可以登录 checkCanLogin() { const { account, password, isAgree } = this.data this.setData({ canLogin: account.length >= 4 && password.length >= 6 && isAgree }) }, // 账号焦点 onAccountFocus() { this.setData({ accountFocus: true }) }, onAccountBlur() { this.setData({ accountFocus: false }) }, // 密码焦点 onPasswordFocus() { this.setData({ passwordFocus: true }) }, onPasswordBlur() { this.setData({ passwordFocus: false }) }, // 聚焦密码输入框 focusPassword() { this.setData({ passwordFocus: true }) }, // 切换密码可见性 - 修复版 togglePasswordVisible(e) { // 阻止事件冒泡 if (e && e.stopPropagation) { e.stopPropagation() } this.setData({ passwordVisible: !this.data.passwordVisible }) }, // 切换协议同意状态 toggleAgreement() { this.setData({ isAgree: !this.data.isAgree }, () => { this.checkCanLogin() }) }, // 处理登录 handleLogin() { const { account, password, isAgree } = this.data if (!isAgree) { wx.showToast({ title: '请先同意用户协议', icon: 'none', duration: 2000 }) return } if (!account || !password) { wx.showToast({ title: '请输入账号和密码', icon: 'none', duration: 2000 }) return } if (account.length < 4) { wx.showToast({ title: '账号长度不能小于4位', icon: 'none', duration: 2000 }) return } if (password.length < 6) { wx.showToast({ title: '密码长度不能小于6位', icon: 'none', duration: 2000 }) return } // 显示加载中 this.setData({ isLoading: true }) // 调用登录接口 http.login({ data: { phone: account, password: password, clientType:'wechat_vet' }, success: (res) => { this.setData({ isLoading: false }) if (res.code === 200 && res.token) { // 保存token wx.setStorageSync('token', res.token) wx.showToast({ title: '登录成功', icon: 'success', duration: 1500, success: () => { setTimeout(() => { wx.switchTab({ url: '/pages/home/home' }) }, 1500) } }) } else { wx.showToast({ title: res.msg || '登录失败,请检查账号密码', icon: 'none', duration: 2000 }) } }, fail: (error) => { this.setData({ isLoading: false }) wx.showToast({ title: '网络错误,请稍后重试', icon: 'none', duration: 2000 }) console.error('登录失败:', error) } }) }, // 显示用户协议 showAgreement() { const content = `兽医助手用户协议 欢迎使用兽医助手! 一、服务说明 兽医助手是为兽医专业人士提供的工作辅助平台,包括病例管理、诊疗记录、药品查询等功能。 二、账号使用 1. 您需要使用真实信息注册账号 2. 账号仅限本人使用,不得转借他人 3. 您对账号下的所有行为负责 三、信息规范 1. 请确保录入的诊疗信息真实准确 2. 尊重动物主人隐私,不得泄露客户信息 3. 遵守医疗行业规范和职业道德 四、责任声明 1. 本平台提供的诊疗建议仅供参考 2. 最终诊疗方案由执业兽医自行判断 3. 平台不承担任何医疗责任 五、服务变更 我们保留修改服务条款的权利,修改后会通过公告通知。 感谢您使用兽医助手!` this.setData({ showAgreementModal: true, modalTitle: '用户协议', modalContent: content }) }, // 显示隐私政策 showPrivacy() { const content = `兽医助手隐私政策 我们重视您的隐私保护 一、信息收集 我们收集以下必要信息: 1. 账号信息:手机号、姓名、执业证书编号 2. 使用信息:登录日志、操作记录 3. 设备信息:设备型号、系统版本 二、信息使用 1. 用于提供兽医诊疗辅助服务 2. 优化和改进服务质量 3. 保障账号安全 三、信息保护 1. 采用加密技术保护数据 2. 严格控制访问权限 3. 定期进行安全审计 四、信息共享 1. 未经您同意,不向第三方共享信息 2. 法律要求的情况除外 3. 可能用于统计分析(匿名化处理) 五、您的权利 1. 访问、更正您的个人信息 2. 注销账号 3. 撤回授权 六、联系我们 如有疑问,请通过客服渠道联系我们` this.setData({ showAgreementModal: true, modalTitle: '隐私政策', modalContent: content }) }, // 隐藏弹窗 hideModal() { this.setData({ showAgreementModal: false }) } })