Forget.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="inner_box">
  3. <div class="forget">
  4. <!-- 标题 -->
  5. <div class="title">
  6. 忘记密码
  7. <Back />
  8. </div>
  9. <!-- 手机号 -->
  10. <div class="tel_input_box">
  11. <i class="red">*</i>
  12. <input
  13. class="tel_input"
  14. type="tel"
  15. maxlength="11"
  16. placeholder="请输入手机号"
  17. oninput="value=value.replace(/[^\d]/g,'')"
  18. v-model="phoneNumber"
  19. />
  20. </div>
  21. <!-- 验证码 -->
  22. <div class="captcha_box">
  23. <i class="red">*</i>
  24. <div
  25. class="bind_send"
  26. :class="{ gray: canVerif }"
  27. @click="sendPhoneNumber"
  28. >
  29. {{ verifText }}
  30. </div>
  31. <input
  32. class="captcha_input"
  33. placeholder="请输入验证码"
  34. v-model="captcha"
  35. maxlength="4"
  36. />
  37. </div>
  38. <!-- 密码 -->
  39. <div class="reg_password">
  40. <i class="red">*</i>
  41. <input
  42. class="reg_input_password"
  43. type="password"
  44. placeholder="请输入密码"
  45. password="true"
  46. maxlength="20"
  47. oninput="value=value.replace(/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]|\s+|[^\w\u4e00-\u9fa5\/\-]|[/|]/ig,'');"
  48. v-model="password"
  49. />
  50. </div>
  51. <!-- 确认密码 -->
  52. <div class="reg_password2">
  53. <i class="red">*</i>
  54. <input
  55. class="reg_input_password2"
  56. type="password"
  57. placeholder="请再次输入密码"
  58. password="true"
  59. maxlength="20"
  60. oninput="value=value.replace(/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]|\s+|[^\w\u4e00-\u9fa5\/\-]|[/|]/ig,'');"
  61. v-model="passwordAgin"
  62. />
  63. </div>
  64. <!-- 重置密码 -->
  65. <div v-if="canForget" class="reset_pwd" @click="resetPwd">重置密码</div>
  66. <div v-else class="reset_pwd gray">重置中</div>
  67. <!-- 其他 -->
  68. <div class="other" @click="onLogin">返回登录</div>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import Back from "@/components/Inner/Back"; // 返回
  74. export default {
  75. name: "Forget",
  76. components: {
  77. Back,
  78. },
  79. inject: ["checkCode", "routeLink"],
  80. data() {
  81. return {
  82. phoneNumber: "", // 手机号
  83. captcha: "", // 验证码
  84. password: "", // 密码
  85. passwordAgin: "", // 确认密码
  86. verifText: "获取验证码", // 获取验证码按钮文本
  87. canVerif: false, // 获取验证码按钮是否可以点击
  88. countDownTimer: null, // 验证码倒计时
  89. canSms: true, // 是否可以请求验证码接口
  90. canForget: true, // 是否可以请求忘记密码
  91. };
  92. },
  93. computed: {},
  94. watch: {},
  95. created() {},
  96. mounted() {},
  97. methods: {
  98. // 获取验证码
  99. sendPhoneNumber() {
  100. if (!this.canSms) {
  101. return;
  102. }
  103. const { phoneNumber } = this;
  104. // 1. 验证手机号格式
  105. this.canVerif = this.$utils.checkVerification(phoneNumber);
  106. if (!this.canVerif) {
  107. this.$toast.text("手机号格式不正确");
  108. return;
  109. }
  110. // 3. 请求接口 发送验证码
  111. this.$api
  112. .sendSms({
  113. mobile: phoneNumber,
  114. reason: "forgetPwd",
  115. })
  116. .then((res) => {
  117. this.checkCode(res);
  118. const { code, data } = res.data;
  119. // 错误
  120. if (code) {
  121. this.canVerif = false;
  122. return;
  123. }
  124. // 2. 验证码倒计时
  125. this.countDown();
  126. });
  127. },
  128. // 倒计时
  129. countDown() {
  130. this.canSms = false;
  131. let count = 60;
  132. this.verifText = count + "s";
  133. this.countDownTimer = setInterval(() => {
  134. count--;
  135. this.verifText = count + "s";
  136. // 倒计时结束
  137. if (count === 0) {
  138. this.canVerif = false;
  139. this.verifText = "获取验证码";
  140. this.canSms = true;
  141. clearInterval(this.countDownTimer);
  142. }
  143. }, 1000);
  144. },
  145. // 重置密码
  146. resetPwd() {
  147. const { phoneNumber, captcha, password, passwordAgin } = this;
  148. // 1. 验证手机号格式
  149. const telCheck = this.$utils.checkVerification(phoneNumber);
  150. if (!telCheck) {
  151. this.$toast.text("手机号格式不准确");
  152. return;
  153. }
  154. // 2. 验证验证码是否为空
  155. if (!captcha) {
  156. this.$toast.text("验证码不能为空");
  157. return;
  158. }
  159. // 3. 验证密码
  160. if (!password) {
  161. this.$toast.text("密码不能为空");
  162. return;
  163. }
  164. if (password !== passwordAgin) {
  165. this.$toast.text("两次密码不一致");
  166. return;
  167. }
  168. // 4. 重置密码
  169. if (!this.canForget) {
  170. return;
  171. }
  172. this.canForget = false;
  173. this.$api
  174. .forgetPwd({
  175. mobile: phoneNumber,
  176. smsCode: captcha,
  177. password,
  178. })
  179. .then((res) => {
  180. this.checkCode(res);
  181. this.canForget = true;
  182. const { code } = res.data;
  183. // 错误
  184. if (code) {
  185. return;
  186. }
  187. // 成功
  188. this.onLogin();
  189. this.$toast.text("重置密码成功");
  190. });
  191. },
  192. // 返回登录
  193. onLogin() {
  194. this.routeLink("Login");
  195. },
  196. },
  197. };
  198. </script>
  199. <style lang='less' scoped>
  200. .forget {
  201. width: 700 / @rem;
  202. height: 660 / @rem;
  203. position: absolute;
  204. top: 50%;
  205. left: 50%;
  206. margin-top: -330 / @rem;
  207. margin-left: -350 / @rem;
  208. background-color: #fff;
  209. box-sizing: border-box;
  210. border-radius: 5px;
  211. overflow: hidden;
  212. .red {
  213. line-height: 70 / @rem;
  214. color: #e43633;
  215. float: left;
  216. }
  217. .title {
  218. height: 100 / @rem;
  219. line-height: 100 / @rem;
  220. background-color: #3faeed;
  221. color: #fff;
  222. font-size: 36 / @rem;
  223. }
  224. .tel_input_box,
  225. .captcha_box,
  226. .reg_password,
  227. .reg_password2,
  228. .reset_pwd,
  229. .other {
  230. padding: 0 20 / @rem;
  231. box-sizing: border-box;
  232. }
  233. .tel_input_box,
  234. .captcha_box {
  235. width: 100%;
  236. height: 70 / @rem;
  237. position: relative;
  238. margin-top: 20 / @rem;
  239. }
  240. .tel_input_box {
  241. margin-top: 20 / @rem;
  242. }
  243. .tel_input,
  244. .captcha_input {
  245. width: 94.5%;
  246. height: 75 / @rem;
  247. padding-left: 20 / @rem;
  248. float: right;
  249. font-size: 32 / @rem;
  250. border: 1 / @rem solid #d6d6d6;
  251. box-sizing: border-box;
  252. }
  253. .captcha_input {
  254. width: 60%;
  255. }
  256. .bind_send {
  257. width: 30%;
  258. height: 75 / @rem;
  259. line-height: 70 / @rem;
  260. margin-left: 30 / @rem;
  261. float: right;
  262. color: #ffffff;
  263. font-size: 32 / @rem;
  264. border-radius: 10 / @rem;
  265. background-color: #3faeed;
  266. }
  267. .gray {
  268. background-color: #888;
  269. }
  270. .reg_password,
  271. .reg_password2 {
  272. width: 100%;
  273. height: 70 / @rem;
  274. margin-top: 20 / @rem;
  275. position: relative;
  276. }
  277. .reg_input_password {
  278. width: 94.5%;
  279. height: 70 / @rem;
  280. padding-left: 20 / @rem;
  281. font-size: 32 / @rem;
  282. float: right;
  283. box-sizing: border-box;
  284. border: 1 / @rem solid #d6d6d6;
  285. }
  286. .reg_input_password2 {
  287. width: 94.5%;
  288. height: 70 / @rem;
  289. padding-left: 20 / @rem;
  290. font-size: 32 / @rem;
  291. float: right;
  292. box-sizing: border-box;
  293. border: 1 / @rem solid #d6d6d6;
  294. outline: none;
  295. }
  296. .reset_pwd {
  297. width: 80%;
  298. height: 90 / @rem;
  299. line-height: 90 / @rem;
  300. margin: 20 / @rem auto 0;
  301. border-radius: 15 / @rem;
  302. background-color: #3faeed;
  303. color: #ffffff;
  304. box-sizing: border-box;
  305. font-size: 32 / @rem;
  306. }
  307. .other {
  308. margin-top: 20 / @rem;
  309. float: left;
  310. color: #3faeed;
  311. font-size: 28 / @rem;
  312. }
  313. }
  314. // 横屏
  315. @media screen and (orientation: landscape),
  316. /**竖屏 */ all and (orientation: portrait) and (min-width: 600px) and (min-height: 800px),
  317. /**ipad */ all and (min-device-aspect-ratio: 3/4) and (max-device-aspect-ratio: 4/3),
  318. all and (device-aspect-ratio: 4/3) {
  319. .forget {
  320. width: 350 / @rem;
  321. height: 300 / @rem;
  322. margin-top: -150 / @rem;
  323. margin-left: -175 / @rem;
  324. .title {
  325. height: 40 / @rem;
  326. line-height: 40 / @rem;
  327. font-size: 18 / @rem;
  328. }
  329. .tel_input_box,
  330. .captcha_box,
  331. .reg_password,
  332. .reg_password2,
  333. .reset_pwd,
  334. .other {
  335. padding: 0 10 / @rem;
  336. }
  337. .tel_input_box,
  338. .captcha_box {
  339. height: 40 / @rem;
  340. margin-top: 5 / @rem;
  341. }
  342. .red {
  343. line-height: 40 / @rem;
  344. }
  345. .tel_input_box {
  346. margin-top: 5 / @rem;
  347. }
  348. .tel_input,
  349. .captcha_input {
  350. height: 35 / @rem;
  351. padding-left: 10 / @rem;
  352. font-size: 16 / @rem;
  353. }
  354. .captcha_input {
  355. width: 55.5%;
  356. }
  357. .bind_send {
  358. height: 35 / @rem;
  359. line-height: 35 / @rem;
  360. font-size: 16 / @rem;
  361. border-radius: 5 / @rem;
  362. }
  363. .reg_password,
  364. .reg_password2 {
  365. height: 35 / @rem;
  366. margin-top: 5 / @rem;
  367. }
  368. .reg_input_password {
  369. height: 35 / @rem;
  370. padding-left: 10 / @rem;
  371. font-size: 16 / @rem;
  372. }
  373. .reg_input_password2 {
  374. height: 35 / @rem;
  375. margin-top: 5 / @rem;
  376. padding-left: 10 / @rem;
  377. font-size: 16 / @rem;
  378. }
  379. .reset_pwd {
  380. height: 40 / @rem;
  381. line-height: 40 / @rem;
  382. margin: 15 / @rem auto 0;
  383. border-radius: 7 / @rem;
  384. font-size: 16 / @rem;
  385. }
  386. .other {
  387. margin-top: 8 / @rem;
  388. font-size: 14 / @rem;
  389. }
  390. }
  391. }
  392. </style>