login.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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) => {
  118. console.log("res:", res)
  119. }).catch((res) => {
  120. console.log(res)
  121. })
  122. },
  123. bindPhoneInput: function (event: any) {
  124. this.setData({
  125. inputPhoneNum: event.detail.value
  126. })
  127. },
  128. bindPwdLoginPhoneInput: function (event: any) {
  129. this.setData({
  130. inputPhonePwdLoginNum: event.detail.value
  131. })
  132. },
  133. bindVCodeInput: function (event: any) {
  134. this.setData({
  135. inputVCodeNum: event.detail.value
  136. })
  137. },
  138. bindPwdInput: function (event: any) {
  139. this.setData({
  140. inputPwdText: event.detail.value
  141. })
  142. },
  143. //登录成功后跳转界面
  144. toNextPage: function () {
  145. let toUrl = '';
  146. switch (Number(this.data.loginType)) {
  147. case loginType.Teacher:
  148. //教师(去教师的index页面)
  149. toUrl = "../teacher/index/index"
  150. break;
  151. case loginType.Installer:
  152. //安装员(去安装员的index页面)
  153. toUrl = "../installer/index/index"
  154. break;
  155. case loginType.Repairman:
  156. //维修员(去维修员的index页面)
  157. toUrl = "../repairman/index/index"
  158. break;
  159. case loginType.IT:
  160. //IT管理员(去IT管理员的index页面)
  161. toUrl = "../itadministrator/index/index"
  162. break;
  163. }
  164. wx.navigateTo({
  165. url: toUrl,
  166. })
  167. },
  168. showToast: function (message: string) {
  169. wx.showToast({
  170. title: message,
  171. icon: 'none'
  172. })
  173. },
  174. })