login.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // index.ts
  2. import { loginType } from "../../utils/loginType"
  3. import { httpUtil } from "../../utils/restful";
  4. Page({
  5. data: {
  6. login_check_tab: 0,
  7. loginType: 0,
  8. showAccPwd: true,
  9. showUpdatePassWordLayout: false,
  10. //短信验证码登录参数
  11. inputPhoneNum: '',
  12. inputVCodeNum: '',
  13. inputPhonePwdLoginNum: '',
  14. inputPwdText: ''
  15. },
  16. onLoad(opention: any) {
  17. console.log("opention.loginType:", opention.loginType)
  18. this.setData({
  19. login_check_tab: 0,
  20. loginType: opention.loginType
  21. })
  22. },
  23. // 点击短信验证码登录
  24. clickPhoneNumLogin: function (event: any) {
  25. console.log("短信验证码登录")
  26. console.log(event)
  27. this.setData({
  28. login_check_tab: 0,
  29. inputPhoneNum: '',
  30. inputPhonePwdLoginNum: ''
  31. })
  32. },
  33. // 点击账号密码登录
  34. clicAccountPasswordLogin: function (event: any) {
  35. console.log("账号密码登录")
  36. console.log(event)
  37. this.setData({
  38. login_check_tab: 1,
  39. inputPhoneNum: '',
  40. inputPhonePwdLoginNum: ''
  41. })
  42. },
  43. // 获取验证码
  44. clickGetVCode: function (event: any) {
  45. console.log("账号密码登录")
  46. },
  47. //账号密码登录——---------------------------
  48. showAccountPwd: function (event: any) {
  49. if (this.data.showAccPwd) {
  50. this.setData({
  51. showAccPwd: false
  52. })
  53. } else {
  54. this.setData({
  55. showAccPwd: true
  56. })
  57. }
  58. },
  59. //显示修改密码的框
  60. showUpdatePwdLayout: function (event: any) {
  61. if (this.data.showUpdatePassWordLayout) {
  62. this.setData({
  63. showUpdatePassWordLayout: false
  64. })
  65. } else {
  66. this.setData({
  67. showUpdatePassWordLayout: true
  68. })
  69. }
  70. },
  71. //跳转注册界面
  72. toRegisterPage: function () {
  73. wx.navigateTo({
  74. url: '../register/register',
  75. })
  76. },
  77. //判断是短信登录还是账号密码登录进行相应登录
  78. toTabIndex: function () {
  79. switch (Number(this.data.login_check_tab)) {
  80. case 0:
  81. //短信验证码登录
  82. this.phoneVCodeLogin();
  83. break;
  84. case 1:
  85. //账号密码登录
  86. this.pwdPhoneLogin();
  87. break;
  88. }
  89. // this.toNextPage();
  90. },
  91. //短信验证码登录
  92. phoneVCodeLogin: function () {
  93. console.log("this.data.inputPhoneNum:" + this.data.inputPhoneNum)
  94. if (!this.data.inputPhoneNum) {
  95. this.showToast('请输入手机号')
  96. return;
  97. }
  98. if (!this.data.inputVCodeNum) {
  99. this.showToast('请输入验证码')
  100. }
  101. let phone = this.data.inputPhoneNum;
  102. let vcode = this.data.inputVCodeNum;
  103. },
  104. //账号密码登录
  105. pwdPhoneLogin: function () {
  106. if (!this.data.inputPhonePwdLoginNum) {
  107. this.showToast('请输入手机号')
  108. return;
  109. }
  110. if (!this.data.inputPwdText) {
  111. this.showToast('请输入密码')
  112. }
  113. let params = {
  114. password: this.data.inputPwdText,
  115. userName: this.data.inputPhonePwdLoginNum
  116. }
  117. httpUtil.wxPost(httpUtil.interfaces.pwdPhoneLogin, params).then((res: any) => {
  118. console.log("res:", res.data)
  119. if (res.data.success) {
  120. console.log("res.data.data:", res.data.data.id)
  121. httpUtil.httpData.userId = res.data.data.id
  122. this.toNextPage()
  123. } else {
  124. this.showToast(res.data.message)
  125. }
  126. }).catch((res) => {
  127. console.log(res)
  128. })
  129. },
  130. bindPhoneInput: function (event: any) {
  131. this.setData({
  132. inputPhoneNum: event.detail.value
  133. })
  134. },
  135. bindPwdLoginPhoneInput: function (event: any) {
  136. this.setData({
  137. inputPhonePwdLoginNum: event.detail.value
  138. })
  139. },
  140. bindVCodeInput: function (event: any) {
  141. this.setData({
  142. inputVCodeNum: event.detail.value
  143. })
  144. },
  145. bindPwdInput: function (event: any) {
  146. this.setData({
  147. inputPwdText: event.detail.value
  148. })
  149. },
  150. //登录成功后跳转界面
  151. toNextPage: function () {
  152. let toUrl = '';
  153. switch (Number(this.data.loginType)) {
  154. case loginType.Teacher:
  155. //教师(去教师的index页面)
  156. toUrl = "../teacher/index/index"
  157. break;
  158. case loginType.Installer:
  159. //安装员(去安装员的index页面)
  160. toUrl = "../installer/index/index"
  161. break;
  162. case loginType.Repairman:
  163. //维修员(去维修员的index页面)
  164. toUrl = "../repairman/index/index"
  165. break;
  166. case loginType.IT:
  167. //IT管理员(去IT管理员的index页面)
  168. toUrl = "../itadministrator/index/index"
  169. break;
  170. }
  171. wx.navigateTo({
  172. url: toUrl,
  173. })
  174. },
  175. showToast: function (message: string) {
  176. wx.showToast({
  177. title: message,
  178. icon: 'none'
  179. })
  180. },
  181. })