password.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="container">
  3. <view class="listBox">
  4. <view class="list">
  5. <view class="flex listItem">
  6. <view class="flex titleBox">
  7. <text class="title">手机号</text>
  8. </view>
  9. <view class="right flex">
  10. <input class="input" placeholder="请输入手机号" type="text" v-model="account"
  11. placeholder-class="placeholder" />
  12. </view>
  13. </view>
  14. <view class="flex listItem">
  15. <view class="flex titleBox">
  16. <text class="title">验证码</text>
  17. </view>
  18. <view class="right flex">
  19. <input class="input" v-model="captcha" type="text" placeholder="请填写验证码"
  20. placeholder-class="placeholder" />
  21. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  22. </view>
  23. </view>
  24. <view class="flex listItem">
  25. <view class="flex titleBox">
  26. <text class="title">新密码</text>
  27. </view>
  28. <view class="right flex">
  29. <input class="input" placeholder="请输入新密码" type="text" v-model="password"
  30. placeholder-class="placeholder" />
  31. </view>
  32. </view>
  33. <view class="flex listItem">
  34. <view class="flex titleBox">
  35. <text class="title">确认密码</text>
  36. </view>
  37. <view class="right flex">
  38. <input class="input" placeholder="再次输入密码" type="text" v-model="dbPassword"
  39. placeholder-class="placeholder" />
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- <view class="row b-b">
  45. <text class="tit">手机号</text>
  46. <input class="input" v-model="account" type="text" placeholder="请填写手机号" placeholder-class="placeholder" />
  47. </view>
  48. <view class="row b-b">
  49. <text class="tit">新密码</text>
  50. <input class="input" v-model="password" type="password" placeholder="请填写新密码" placeholder-class="placeholder" />
  51. </view> -->
  52. <view class="base-buttom" :class="{'bg-gray':loding}" @click="loding?'':confirm()">提交</view>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. verify
  58. } from '@/api/login.js';
  59. import {
  60. mapState
  61. } from 'vuex';
  62. import {
  63. registerReset
  64. } from '@/api/set.js';
  65. export default {
  66. data() {
  67. return {
  68. time: '', //保存倒计时对象
  69. countDown: 0, //倒计时
  70. account: '', //原密码
  71. dbPassword: '', //对比密码
  72. password: '', //新密码
  73. loding: false, //是否载入中
  74. };
  75. },
  76. computed: {
  77. ...mapState(['userInfo'])
  78. },
  79. onLoad() {
  80. if (this.userInfo.phone == null) {
  81. this.account = '';
  82. } else {
  83. this.account = this.userInfo.phone;
  84. this.show = false;
  85. }
  86. },
  87. watch: {
  88. // 监听倒计时
  89. countDown(i) {
  90. if (i == 0) {
  91. clearInterval(this.time);
  92. }
  93. }
  94. },
  95. methods: {
  96. //发送验证码
  97. verification() {
  98. let obj = this;
  99. if (this.account == '') {
  100. this.$api.msg('请输入电话号码');
  101. return;
  102. }
  103. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.account)) {
  104. this.$api.msg('请输入正确的手机号');
  105. return;
  106. }
  107. // 判断是否在倒计时
  108. if (obj.countDown > 0) {
  109. return false;
  110. } else {
  111. obj.countDown = 60;
  112. obj.time = setInterval(() => {
  113. obj.countDown--;
  114. }, 1000);
  115. //调用验证码接口
  116. verify({
  117. phone: obj.account,
  118. type: ''
  119. })
  120. .then(({
  121. data
  122. }) => {})
  123. .catch(err => {
  124. console.log(err);
  125. });
  126. }
  127. },
  128. confirm(e) {
  129. this.loding = true;
  130. if (this.dbPassword != this.password) {
  131. this.loding = false;
  132. uni.showModal({
  133. title: '请重新输入',
  134. content: '两次密码输入不一致',
  135. showCancel: false,
  136. });
  137. return
  138. }
  139. registerReset({
  140. account: this.account,
  141. captcha: this.captcha,
  142. password: this.password,
  143. })
  144. .then(({
  145. data
  146. }) => {
  147. this.loding = false;
  148. this.$api.msg('修改成功');
  149. })
  150. .catch(err => {
  151. this.loding = false;
  152. console.log(err);
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss">
  159. page {
  160. background: $page-color-base;
  161. }
  162. .container {
  163. padding-top: 30rpx;
  164. }
  165. .listBox {
  166. margin: $page-row-spacing;
  167. margin-top: 0;
  168. border-radius: 20rpx;
  169. overflow: hidden;
  170. background-color: #FFFFFF;
  171. }
  172. .list {
  173. .input {
  174. text-align: right;
  175. font-size: $font-base;
  176. color: $color-gray;
  177. width: 100%;
  178. }
  179. .listItem {
  180. padding: 35rpx 40rpx;
  181. border-bottom: 1px solid $page-color-light;
  182. .code {
  183. color: #5dbc7c;
  184. font-size: 23rpx;
  185. border-left: 1px solid #eeeeee;
  186. padding-left: 20rpx;
  187. flex-shrink: 0;
  188. text-align: center;
  189. }
  190. }
  191. .listIconImg {
  192. width: 36rpx;
  193. }
  194. .right {
  195. color: $font-color-light;
  196. font-size: $font-base;
  197. flex-grow: 1;
  198. .img {
  199. width: 26rpx;
  200. }
  201. }
  202. .titleBox {
  203. .title {
  204. color: $font-color-base;
  205. font-size: $font-base;
  206. }
  207. }
  208. }
  209. .bg-gray {
  210. background-color: $color-gray;
  211. }
  212. </style>