findBackPassword.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view>
  3. <u-navbar title="找回密码" title-color="#101010"></u-navbar>
  4. <view class="main">
  5. <view class="original-password">
  6. <text>手机号码</text><u-input v-model="form.telephone" style="padding: 0 0 0 20px" maxlength="11" type="number" placeholder="请填写手机号" />
  7. </view>
  8. <view class="new-password">
  9. <text>验证码</text><u-input v-model="form.verifyCode" style="padding: 0 0 0 20px" maxlength="6" type="number" placeholder="6位验证码" />
  10. <text class="verification-code" :style="isCodeTipsColor ? 'color: #999999;' : ''" @click="getCode" >{{codeTips}}</text>
  11. </view>
  12. <view class="new-password">
  13. <text>新密码</text><u-input v-model="form.password" style="padding: 0 0 0 20px" class="password-input" type="password" placeholder="创建6-16位组合新密码" :password-icon="true" />
  14. </view>
  15. </view>
  16. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start"
  17. change-text="(Xs)">
  18. </u-verification-code>
  19. <!-- 确认修改 -->
  20. <button class="confirm" @click="retrievePassword" >提交</button>
  21. </view>
  22. </template>
  23. <script>
  24. import * as API from '@/apis/pagejs/user.js'
  25. import {
  26. checkPhone
  27. } from '@/apis/utils'
  28. export default {
  29. data() {
  30. return {
  31. form: {
  32. verifyCode:"",
  33. telephone: '',
  34. password: '',
  35. },
  36. isSendMsgIng: false,
  37. isCodeTipsColor: false,
  38. sendMsgSecond: 60,
  39. codeTips: '',
  40. }
  41. },
  42. onReady() {
  43. var time = this.carhelp.get("getvcodetime");
  44. if (time) {
  45. //this.$refs.uCode.start();
  46. var nowtime = new Date().getTime()
  47. var differ = (nowtime - time) / 1000
  48. if (differ < 2 * 60) {
  49. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  50. this.isSendMsgIng = true;
  51. this.$refs.uCode.start();
  52. this.isCodeTipsColor = true;
  53. }
  54. }
  55. },
  56. methods: {
  57. retrievePassword(){
  58. var checkPhoneResult = checkPhone(this.form.telephone);
  59. if (!this.form.telephone || checkPhoneResult != true) {
  60. uni.showToast({
  61. title: checkPhoneResult,
  62. icon: "none"
  63. })
  64. return;
  65. }
  66. if (!this.form.telephone) {
  67. uni.showToast({
  68. title: "请输入手机号",
  69. icon: "none"
  70. })
  71. return
  72. }
  73. if (!this.form.verifyCode) {
  74. uni.showToast({
  75. title: "请输入验证码",
  76. icon: "none"
  77. })
  78. return
  79. }
  80. if (!this.form.password) {
  81. uni.showToast({
  82. title: "请输入新密码",
  83. icon: "none"
  84. })
  85. return
  86. }
  87. if (this.form.password.length<6||this.form.password.length>16) {
  88. uni.showToast({
  89. title: "请输入6-16位组合新密码",
  90. icon: "none"
  91. })
  92. return
  93. }
  94. uni.showLoading({
  95. title: "加载中",
  96. mask: true,
  97. })
  98. API.retrievePassword(this.form).then((response) => {
  99. uni.hideLoading();
  100. // this.form.password=""
  101. // this.form.oldPassword=""
  102. uni.showModal({
  103. title:"提示",
  104. content:"密码修改成功!",
  105. showCancel:false,
  106. success() {
  107. uni.reLaunch({
  108. url:"/pages/login/login"
  109. })
  110. }
  111. })
  112. }).catch(error => {
  113. uni.showToast({
  114. title: error,
  115. icon: "none"
  116. })
  117. })
  118. },
  119. codeChange(text) {
  120. this.codeTips = text;
  121. },
  122. //倒计时
  123. end() {
  124. this.sendMsgSecond = 60;
  125. this.isSendMsgIng = false;
  126. this.isCodeTipsColor = false;
  127. },
  128. // 获取验证码
  129. getCode() {
  130. if (this.$refs.uCode.canGetCode) {} else {
  131. uni.showToast({
  132. title: '倒计时结束后再发送',
  133. icon: "none"
  134. })
  135. return
  136. }
  137. var checkPhoneResult = checkPhone(this.form.telephone);
  138. if (checkPhoneResult !== true) {
  139. uni.showToast({
  140. icon: "none",
  141. title: checkPhoneResult,
  142. })
  143. return;
  144. }
  145. this.$refs.uCode.start();
  146. this.isCodeTipsColor = true;
  147. },
  148. start() {
  149. if (!this.isSendMsgIng) {
  150. uni.showLoading({
  151. title: "加载中",
  152. mask: true,
  153. })
  154. API.getVerifyCode(this.form).then((response) => {
  155. uni.hideLoading();
  156. this.carhelp.set("getvcodetime", new Date().getTime());
  157. if (!"") {
  158. //倒计时
  159. uni.showToast({
  160. icon: "none",
  161. title: "发送成功"
  162. })
  163. } else {
  164. uni.showToast({
  165. icon: "none",
  166. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  167. })
  168. }
  169. }).catch(error => {
  170. uni.showToast({
  171. title: error,
  172. icon: "none"
  173. })
  174. })
  175. }
  176. },
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .main{
  182. background-color: #fff;
  183. margin-top: 24rpx;
  184. .original-password,.new-password{
  185. line-height: 96rpx;
  186. padding:0 32rpx;
  187. display: flex;
  188. align-items: center;
  189. border-bottom: 1px solid rgba(221,221,221,1);
  190. ::v-deep.u-input__input{
  191. height: 96rpx;
  192. }
  193. }
  194. text{
  195. display: inline-block;
  196. width: 128rpx;
  197. color: rgba(51,51,51,1);
  198. font-size: 32rpx;
  199. }
  200. .verification-code{
  201. width: 160rpx;
  202. color: rgba(22,119,255,1);
  203. font-size: 32rpx;
  204. }
  205. }
  206. // 确认修改
  207. .confirm{
  208. border-radius: 8px;
  209. background-color: rgba(22,119,255,1);
  210. color: rgba(255,255,255,1);
  211. font-size: 32rpx;
  212. line-height: 88rpx;
  213. margin: 24rpx 32rpx;
  214. }
  215. </style>