与牧同行-兽医端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
5.9 KiB

  1. import http from '../../utils/api'
  2. Page({
  3. data: {
  4. // 账号密码
  5. account: '',
  6. password: '',
  7. accountFocus: false,
  8. passwordFocus: false,
  9. passwordVisible: false,
  10. // 协议相关
  11. isAgree: true,
  12. showAgreementModal: false,
  13. modalTitle: '',
  14. modalContent: '',
  15. // 加载状态
  16. isLoading: false,
  17. // 登录状态
  18. canLogin: false
  19. },
  20. onLoad() {
  21. // 检查登录状态
  22. // this.checkLoginStatus()
  23. },
  24. // 检查登录状态
  25. // checkLoginStatus() {
  26. // const token = wx.getStorageSync('token')
  27. // if (token) {
  28. // // 已登录,跳转到首页
  29. // wx.switchTab({
  30. // url: '/pages/home/home'
  31. // })
  32. // }
  33. // },
  34. // 账号输入
  35. onAccountInput(e) {
  36. this.setData({
  37. account: e.detail.value
  38. }, () => {
  39. this.checkCanLogin()
  40. })
  41. },
  42. // 密码输入
  43. onPasswordInput(e) {
  44. this.setData({
  45. password: e.detail.value
  46. }, () => {
  47. this.checkCanLogin()
  48. })
  49. },
  50. // 检查是否可以登录
  51. checkCanLogin() {
  52. const { account, password, isAgree } = this.data
  53. this.setData({
  54. canLogin: account.length >= 4 && password.length >= 6 && isAgree
  55. })
  56. },
  57. // 账号焦点
  58. onAccountFocus() {
  59. this.setData({ accountFocus: true })
  60. },
  61. onAccountBlur() {
  62. this.setData({ accountFocus: false })
  63. },
  64. // 密码焦点
  65. onPasswordFocus() {
  66. this.setData({ passwordFocus: true })
  67. },
  68. onPasswordBlur() {
  69. this.setData({ passwordFocus: false })
  70. },
  71. // 聚焦密码输入框
  72. focusPassword() {
  73. this.setData({ passwordFocus: true })
  74. },
  75. // 切换密码可见性 - 修复版
  76. togglePasswordVisible(e) {
  77. // 阻止事件冒泡
  78. if (e && e.stopPropagation) {
  79. e.stopPropagation()
  80. }
  81. this.setData({
  82. passwordVisible: !this.data.passwordVisible
  83. })
  84. },
  85. // 切换协议同意状态
  86. toggleAgreement() {
  87. this.setData({
  88. isAgree: !this.data.isAgree
  89. }, () => {
  90. this.checkCanLogin()
  91. })
  92. },
  93. // 处理登录
  94. handleLogin() {
  95. const { account, password, isAgree } = this.data
  96. if (!isAgree) {
  97. wx.showToast({
  98. title: '请先同意用户协议',
  99. icon: 'none',
  100. duration: 2000
  101. })
  102. return
  103. }
  104. if (!account || !password) {
  105. wx.showToast({
  106. title: '请输入账号和密码',
  107. icon: 'none',
  108. duration: 2000
  109. })
  110. return
  111. }
  112. if (account.length < 4) {
  113. wx.showToast({
  114. title: '账号长度不能小于4位',
  115. icon: 'none',
  116. duration: 2000
  117. })
  118. return
  119. }
  120. if (password.length < 6) {
  121. wx.showToast({
  122. title: '密码长度不能小于6位',
  123. icon: 'none',
  124. duration: 2000
  125. })
  126. return
  127. }
  128. // 显示加载中
  129. this.setData({ isLoading: true })
  130. // 调用登录接口
  131. http.login({
  132. data: {
  133. phone: account,
  134. password: password,
  135. clientType:'wechat_vet'
  136. },
  137. success: (res) => {
  138. this.setData({ isLoading: false })
  139. if (res.code === 200 && res.token) {
  140. // 保存token
  141. wx.setStorageSync('token', res.token)
  142. wx.showToast({
  143. title: '登录成功',
  144. icon: 'success',
  145. duration: 1500,
  146. success: () => {
  147. setTimeout(() => {
  148. wx.switchTab({
  149. url: '/pages/home/home'
  150. })
  151. }, 1500)
  152. }
  153. })
  154. } else {
  155. wx.showToast({
  156. title: res.msg || '登录失败,请检查账号密码',
  157. icon: 'none',
  158. duration: 2000
  159. })
  160. }
  161. },
  162. fail: (error) => {
  163. this.setData({ isLoading: false })
  164. wx.showToast({
  165. title: '网络错误,请稍后重试',
  166. icon: 'none',
  167. duration: 2000
  168. })
  169. console.error('登录失败:', error)
  170. }
  171. })
  172. },
  173. // 显示用户协议
  174. showAgreement() {
  175. const content = `兽医助手用户协议
  176. 欢迎使用兽医助手
  177. 服务说明
  178. 兽医助手是为兽医专业人士提供的工作辅助平台包括病例管理诊疗记录药品查询等功能
  179. 账号使用
  180. 1. 您需要使用真实信息注册账号
  181. 2. 账号仅限本人使用不得转借他人
  182. 3. 您对账号下的所有行为负责
  183. 信息规范
  184. 1. 请确保录入的诊疗信息真实准确
  185. 2. 尊重动物主人隐私不得泄露客户信息
  186. 3. 遵守医疗行业规范和职业道德
  187. 责任声明
  188. 1. 本平台提供的诊疗建议仅供参考
  189. 2. 最终诊疗方案由执业兽医自行判断
  190. 3. 平台不承担任何医疗责任
  191. 服务变更
  192. 我们保留修改服务条款的权利修改后会通过公告通知
  193. 感谢您使用兽医助手`
  194. this.setData({
  195. showAgreementModal: true,
  196. modalTitle: '用户协议',
  197. modalContent: content
  198. })
  199. },
  200. // 显示隐私政策
  201. showPrivacy() {
  202. const content = `兽医助手隐私政策
  203. 我们重视您的隐私保护
  204. 信息收集
  205. 我们收集以下必要信息
  206. 1. 账号信息手机号姓名执业证书编号
  207. 2. 使用信息登录日志操作记录
  208. 3. 设备信息设备型号系统版本
  209. 信息使用
  210. 1. 用于提供兽医诊疗辅助服务
  211. 2. 优化和改进服务质量
  212. 3. 保障账号安全
  213. 信息保护
  214. 1. 采用加密技术保护数据
  215. 2. 严格控制访问权限
  216. 3. 定期进行安全审计
  217. 信息共享
  218. 1. 未经您同意不向第三方共享信息
  219. 2. 法律要求的情况除外
  220. 3. 可能用于统计分析匿名化处理
  221. 您的权利
  222. 1. 访问更正您的个人信息
  223. 2. 注销账号
  224. 3. 撤回授权
  225. 联系我们
  226. 如有疑问请通过客服渠道联系我们`
  227. this.setData({
  228. showAgreementModal: true,
  229. modalTitle: '隐私政策',
  230. modalContent: content
  231. })
  232. },
  233. // 隐藏弹窗
  234. hideModal() {
  235. this.setData({
  236. showAgreementModal: false
  237. })
  238. }
  239. })