repassword.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="input_box">
  5. <input type="number" v-model="mobile" placeholder="请输入手机号" placeholder-style="color:#999;"/>
  6. </view>
  7. <view class="send_box">
  8. <view class="send_code">
  9. <input type="number" v-model="vcode" placeholder="验证码" placeholder-style="color:#999;"/>
  10. </view>
  11. <view class="send_btn" @click="send_vcode()">
  12. {{send_text}}
  13. </view>
  14. </view>
  15. <view class="input_box">
  16. <input type="password" v-model="password" placeholder="请输入新密码" placeholder-style="color:#999;"/>
  17. </view>
  18. <view class="input_box">
  19. <input type="password" v-model="copypassword" placeholder="请重复新密码" placeholder-style="color:#999;"/>
  20. </view>
  21. <view class="re_btn" @click="repassword()">
  22. 确认修改
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. var testPassword =/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,15}$/
  29. export default {
  30. data() {
  31. return {
  32. mobile:'',
  33. vcode:'',
  34. password:'',
  35. copypassword:'',
  36. send_text:'发送验证码'
  37. };
  38. },
  39. methods:{
  40. send_vcode(){
  41. if(this.mobile.length < 11){
  42. uni.showToast({
  43. icon:'none',
  44. title:'请填写正确的手机号'
  45. })
  46. return
  47. }
  48. if(this.send_text == "发送验证码"){
  49. this.$api.sms_vcode({
  50. mobile:this.mobile
  51. }).then((res)=>{
  52. console.log(res.data)
  53. if(res.data.code == 3001){
  54. uni.showToast({
  55. icon:"none",
  56. title:"电话号码错误"
  57. })
  58. }else if(res.data.code == 3002){
  59. uni.showToast({
  60. icon:"none",
  61. title:"发送失败"
  62. })
  63. }else if(res.data.code == 0){
  64. uni.showToast({
  65. icon:"none",
  66. title:"验证码发送成功"
  67. })
  68. }
  69. })
  70. }
  71. this.send_text = "已发送"
  72. if(this.send_text = "已发送"){
  73. uni.showToast({
  74. icon:"none",
  75. title:"请勿重复发送"
  76. })
  77. }
  78. },
  79. repassword(){
  80. if(this.vcode == ''){
  81. uni.showToast({
  82. icon:'none',
  83. title:'请填写验证码'
  84. })
  85. return
  86. }
  87. if(this.password == '' || this.copypassword == ''){
  88. uni.showToast({
  89. icon:'none',
  90. title:'请填写完整信息'
  91. })
  92. return
  93. }
  94. if(this.password !== this.copypassword){
  95. uni.showToast({
  96. icon:'none',
  97. title:'两次密码输入不一致'
  98. })
  99. return
  100. }
  101. if( !testPassword.test(this.password) ){
  102. uni.showToast({
  103. icon:'none',
  104. title:'密码必须包含大写字母、小写字母、数字和特殊符号且长度在8位至16位之间'
  105. })
  106. return
  107. }
  108. this.$api.user_repassword({
  109. mobile:this.mobile,
  110. vcode:this.vcode,
  111. password:this.password
  112. }).then((res)=>{
  113. console.log(res)
  114. if(res.data.code == 4002){
  115. uni.showToast({
  116. icon:'none',
  117. title:"验证码超时或者错误"
  118. })
  119. return
  120. }else{
  121. uni.setStorageSync('login_password',this.password)
  122. uni.showToast({
  123. icon:'none',
  124. title:'密码修改成功'
  125. })
  126. this.send_text = "发送验证码"
  127. setTimeout(function(){
  128. uni.switchTab({
  129. url:"../../tabbar/my/my"
  130. })
  131. },1000)
  132. }
  133. })
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss">
  139. page{
  140. box-sizing: border-box;
  141. padding: 25rpx;
  142. background-color: #f0f0f0;
  143. }
  144. .content{
  145. width: 700rpx;
  146. .input_box{
  147. margin-bottom: 10px;
  148. padding: 0 25px;
  149. background-color: #fff;
  150. input{
  151. height: 45px;
  152. color: #333;
  153. }
  154. }
  155. .send_box{
  156. display: flex;
  157. justify-content: space-between;
  158. margin-bottom: 10px;
  159. .send_code{
  160. width: 380rpx;
  161. padding: 0 25px;
  162. background-color: #fff;
  163. input{
  164. height: 45px;
  165. color: #333;
  166. }
  167. }
  168. .send_btn{
  169. width: 200rpx;
  170. background-color: #009FE8;
  171. text-align: center;
  172. color: #fff;
  173. line-height: 45px;
  174. }
  175. }
  176. .re_btn{
  177. background-color: #009FE8;
  178. text-align: center;
  179. color: #fff;
  180. line-height: 45px;
  181. }
  182. }
  183. </style>