password.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="content">
  3. <view class="card">
  4. <u-form :model="form" ref="uForm">
  5. <u-form-item label="手机号" prop="phone" label-width="150">
  6. <u-input v-model="form.phone" placeholder="请输入手机号" maxlength="11" />
  7. </u-form-item>
  8. <u-form-item label="验证码" prop="code" label-width="150">
  9. <u-input v-model="form.code" placeholder="请输入验证码" />
  10. <view slot="right" @click="getCode()">{{codeText}}</view>
  11. </u-form-item>
  12. <u-form-item label="密码" prop="password" label-width="150">
  13. <u-input v-model="form.password" type="password" maxlength="12" placeholder="请输入密码" />
  14. </u-form-item>
  15. <u-form-item label="确认密码" prop="password2" label-width="150">
  16. <u-input v-model="form.password2" type="password" maxlength="12" placeholder="请确认密码" />
  17. </u-form-item>
  18. </u-form>
  19. </view>
  20. <view class="bottom-btn">
  21. <view class="buttom-dom" @click="push">
  22. 确定
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. // 提交信息
  32. form: {
  33. phone: '',
  34. code: '',
  35. password: '',
  36. password2: ''
  37. },
  38. // 验证规则
  39. rules: {
  40. phone: [{
  41. required: true,
  42. message: '请输入手机号',
  43. trigger: ['change', 'blur'],
  44. }],
  45. code: [{
  46. required: true,
  47. message: '请输入验证码',
  48. trigger: ['change', 'blur'],
  49. }],
  50. password: [{
  51. required: true,
  52. message: '请输入密码',
  53. trigger: ['change', 'blur'],
  54. }],
  55. password2: [{
  56. required: true,
  57. message: '请确认密码',
  58. trigger: ['change', 'blur'],
  59. }],
  60. },
  61. // 获取验证码
  62. codeText: '获取验证码'
  63. }
  64. },
  65. onReady() {
  66. this.$refs.uForm.setRules(this.rules);
  67. },
  68. methods: {
  69. // 点击获取验证码
  70. getCode() {
  71. let _this = this;
  72. if (this.form.phone === '') {
  73. this.$u.toast('请先输入手机号')
  74. return false
  75. }
  76. if (this.codeText === '重新获取' || this.codeText === '获取验证码') {
  77. this.request('/sms/send', {
  78. mobile: this.form.phone,
  79. event: 'changepwd'
  80. }, 'GET').then(res => {
  81. _this.codeText = 60;
  82. let time = setInterval(() => {
  83. if (_this.codeText < 1) {
  84. _this.codeText = '重新获取'
  85. clearInterval(time)
  86. } else {
  87. _this.codeText = _this.codeText - 1;
  88. }
  89. }, 1000)
  90. })
  91. }
  92. },
  93. //  提交修改信息
  94. push() {
  95. let _this = this;
  96. this.$refs.uForm.validate(valid => {
  97. if (valid) {
  98. // console.log('验证通过');
  99. if (_this.form.password2.length > 12 || _this.form.password2.length > 6) {
  100. _this.$u.toast('密码长度为6-12位')
  101. return false
  102. }
  103. if (_this.form.password !== _this.form.password2) {
  104. _this.$u.toast('两次输入密码不一致')
  105. return false
  106. }
  107. let data = {
  108. mobile: _this.form.phone,
  109. newpassword: _this.form.password,
  110. captcha: _this.form.code,
  111. user_type: 2
  112. }
  113. _this.request('/user/resetpwd', data, "POST").then(res => {
  114. if (res.code === 1) {
  115. _this.$u.toast('操作成功')
  116. setTimeout(() => {
  117. uni.clearStorage()
  118. getApp().globalData = {
  119. isAdmin: false
  120. }
  121. uni.reLaunch({
  122. url: '/pages/login/login'
  123. })
  124. }, 2000)
  125. }
  126. })
  127. } else {
  128. console.log('验证失败');
  129. }
  130. });
  131. }
  132. }
  133. }
  134. </script>
  135. <style lang="scss">
  136. .content {
  137. padding-top: 40rpx;
  138. }
  139. .card {
  140. width: 93%;
  141. margin: 0 auto;
  142. background-color: #FFFFFF;
  143. padding: 30rpx;
  144. border-radius: 20rpx;
  145. }
  146. .bottom-btn {
  147. width: 100vw;
  148. height: 10vh;
  149. display: flex;
  150. flex-direction: column;
  151. align-items: center;
  152. justify-content: center;
  153. margin-top: 30rpx;
  154. .buttom-dom {
  155. height: 80rpx;
  156. width: 93%;
  157. background-color: #F6B301;
  158. color: #FFFFFF;
  159. text-align: center;
  160. line-height: 80rpx;
  161. color: #FFFFFF;
  162. border-radius: 80rpx;
  163. }
  164. }
  165. </style>