forgetPass.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  6. <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  7. <meta name="format-detection"content="telephone=no">
  8. <title></title>
  9. <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
  10. <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
  11. <link rel="stylesheet" type="text/css" href="../../css/toast.css"/>
  12. <link rel="stylesheet" href="../../css/projeck.css">
  13. <style media="screen">
  14. body,html{
  15. background: #ecf0f1;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div class="api_layout">
  21. <!-- <header class="header-login">
  22. <img class="backBtn" src="../../image/btn_back.png" alt="" onclick="backIndex()">
  23. <p class="api_text">修改密码</p>
  24. </header> -->
  25. <div class="api_forget_phone">
  26. <div class="api_phone">
  27. <input type="number" name="" value="" placeholder="请输入手机号" class="api_phone_bind">
  28. </div>
  29. <div class="api_phone">
  30. <input type="number" name="" value="" placeholder="验证码" class="api_vali">
  31. <button type="button" class="api_btn_vali" id="verify-sms" onclick="changeTitleOnSendSms()">发送验证码</button>
  32. </div>
  33. <div class="api_phone">
  34. <input type="password" placeholder="输入新密码" class="api_new_pass">
  35. </div>
  36. <div class="api_phone">
  37. <input type="password" placeholder="重复新密码" onblur="passVerification()" class="api_new_pass01">
  38. </div>
  39. <div class="api_bnt" onclick="sureForget()">确认修改</div>
  40. </div>
  41. <div class="api_layout">
  42. </body>
  43. </html>
  44. <script type="text/javascript" src="../../script/api.js"></script>
  45. <!-- <script src="../../script/aui-toast.js" charset="utf-8"></script> -->
  46. <!-- <script src="../../script/fastclick.min.js"></script> -->
  47. <script src="../../script/config.js" charset="utf-8"></script>
  48. <script type="text/javascript">
  49. var token,uuid;
  50. var toast = new auiToast();
  51. apiready = function () {
  52. $api.fixStatusBar($api.dom('header'));
  53. var info = $api.getStorage('data');
  54. token = JSON.parse(info).data.access_token;
  55. uuid = JSON.parse(info).data.user.staff_num;
  56. }
  57. function backIndex() {
  58. api.closeWin();
  59. };
  60. var interval;
  61. function changeTitleOnSendSms() {
  62. var phone = $api.dom('.api_phone_bind').value;
  63. var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  64. if (phone == "") {
  65. api.toast({
  66. msg: '电话号码不能为空',
  67. duration: 2000,
  68. location: 'top'
  69. });
  70. return false;
  71. }else if (!reg.test(phone)) {
  72. api.toast({
  73. msg: '电话号码格式不正确',
  74. duration: 2000,
  75. location: 'top'
  76. });
  77. return false;
  78. }else {
  79. phoneFun(token);
  80. interval = setInterval("changeTime()", 1000);
  81. var verify_btn = $api.byId("verify-sms");
  82. verify_btn.style.backgroundColor = "#D9D9D9";
  83. verify_btn.setAttribute('disabled','true');
  84. }
  85. }
  86. //
  87. var remaining_time = 30;
  88. function changeTime() {
  89. var verify_btn = $api.byId("verify-sms");
  90. $api.html(verify_btn, remaining_time + "s后重发");
  91. remaining_time -= 1;
  92. if (remaining_time <= 0) {
  93. window.clearInterval(interval);
  94. remaining_time = 30;
  95. verify_btn.style.backgroundColor = "#009fe8";
  96. verify_btn.removeAttribute('disabled','true');
  97. $api.html(verify_btn, "获取验证码");
  98. // canSms = true;
  99. }
  100. }
  101. function phoneFun(token) {
  102. var phone = $api.dom('.api_phone_bind');
  103. var phoneValue = $api.val(phone);
  104. api.ajax({
  105. url: UrlRouter.vcodeApi,
  106. method: 'post',
  107. headers : {
  108. "Authorization":"Bearer "+ token
  109. },
  110. data: {
  111. values: {
  112. mobile: phoneValue
  113. }
  114. }
  115. },function(ret, err){
  116. if (ret) {
  117. if (ret.code === 3001) {
  118. api.toast({
  119. msg: '电话号码错误',
  120. duration: 2000,
  121. location: 'top'
  122. });
  123. }else if (ret.code === 0) {
  124. api.toast({
  125. msg: '发送成功',
  126. duration: 2000,
  127. location: 'top'
  128. });
  129. }else if (ret.code === 3002) {
  130. api.toast({
  131. msg: '发送失败',
  132. duration: 2000,
  133. location: 'top'
  134. });
  135. }
  136. } else {
  137. api.toast({
  138. msg: '发送失败',
  139. duration: 2000,
  140. location: 'top'
  141. });
  142. }
  143. });
  144. };
  145. // 密码做验证
  146. function passVerification() {
  147. var newPass = $api.dom('.api_new_pass').value,
  148. api_new_pass01 = $api.dom('.api_new_pass01').value;
  149. if (newPass != api_new_pass01) {
  150. api.toast({
  151. msg: '两次密码不一致',
  152. duration: 2000,
  153. location: 'top'
  154. });
  155. return false;
  156. }else {
  157. return true;
  158. }
  159. }
  160. function sureForget() {
  161. var phone = $api.dom('.api_phone_bind').value,
  162. vcode = $api.dom('.api_vali').value,
  163. api_new_pass = $api.dom('.api_new_pass').value;
  164. if (phone != '' && vcode != '' && api_new_pass != '' && passVerification()) {
  165. toast.loading({
  166. title: "加载中",
  167. duration: 2000
  168. });
  169. api.ajax({
  170. url: UrlRouter.repasswordApi,
  171. method: 'post',
  172. headers : {
  173. "Authorization": "Bearer " + token
  174. },
  175. data: {
  176. values: {
  177. mobile:phone,
  178. vcode:vcode,
  179. password:api_new_pass
  180. }
  181. }
  182. },
  183. function(ret, err){
  184. if (ret) {
  185. toast.hide();
  186. if(ret.code === 0){
  187. api.toast({
  188. msg: '修改密码成功',
  189. duration: 2000,
  190. location: 'top'
  191. });
  192. var userInfo = {username:uuid,password:""}
  193. $api.setStorage('userInfo',JSON.stringify(userInfo));
  194. api.openWin({
  195. name: 'login',
  196. reload:true,
  197. slidBackEnabled:false,
  198. url: '../../login.html',
  199. pageParam:{
  200. status:true
  201. }
  202. });
  203. api.closeWin({
  204. name:'index'
  205. });
  206. }else if(ret.code === 4002){
  207. api.toast({
  208. msg: '验证码超时',
  209. duration: 2000,
  210. location: 'top'
  211. });
  212. }
  213. } else {
  214. toast.hide();
  215. api.toast({
  216. msg: '网络错误',
  217. duration: 2000,
  218. location: 'top'
  219. });
  220. }
  221. });
  222. }else {
  223. api.toast({
  224. msg: '手机号,验证码,密码不能为空',
  225. duration: 2000,
  226. location: 'top'
  227. })
  228. }
  229. }
  230. </script>