password.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="bd-password">
  3. <template v-if="isPhone">
  4. <view class="bd-item dir-left-nowrap cross-center">
  5. <image src="./image/phone.png" class="bd-label box-grow-0"></image>
  6. <input class="bd-input box-grow-1" v-model="mobile" placeholder="请输入手机号" type="text">
  7. </view>
  8. <view class="bd-item dir-left-nowrap cross-center">
  9. <image src="./image/image.png" class="bd-label box-grow-0"></image>
  10. <input class="bd-input box-grow-1" v-model="pic_captcha" placeholder="请输入图形验证码" type="text">
  11. <image :src="imageUrl" @click="getImageUrl" class="bd-image box-grow-0"></image>
  12. </view>
  13. <view class="bd-item dir-left-nowrap cross-center">
  14. <image src="./image/message.png" class="bd-label box-grow-0"></image>
  15. <input class="bd-input box-grow-1" v-model="sms_captcha" placeholder="请输入短消息验证码" type="text">
  16. <view v-if="!isSend" class="bd-btn box-grow-0" @click="getVerCode">获取验证码</view>
  17. <view v-else class="bd-btn box-grow-0 bd-send" >重新发送{{ timeNum }}S</view>
  18. </view>
  19. </template>
  20. <view class="bd-item dir-left-nowrap cross-center" v-else>
  21. <image src="./image/password.png" class="bd-label box-grow-0"></image>
  22. <input class="bd-input box-grow-1" v-model="old_password" placeholder="请输入旧密码" type="password">
  23. </view>
  24. <view class="bd-item dir-left-nowrap cross-center">
  25. <image src="./image/password.png" class="bd-label box-grow-0"></image>
  26. <input class="bd-input box-grow-1" v-model="new_password" placeholder="请输入新密码" type="password">
  27. </view>
  28. <view class="bd-item dir-left-nowrap cross-center">
  29. <image src="./image/password.png" class="bd-label box-grow-0"></image>
  30. <input class="bd-input box-grow-1" v-model="again_password" placeholder="请确认新密码" type="password">
  31. </view>
  32. <view
  33. class="bd-bottom"
  34. :class="1 ? 'bd-yes-agree' : 'bd-no-agree'" @click="modify">
  35. 确认
  36. </view>
  37. <view class="bd-agree-group dir-right-nowrap cross-center" v-if="!isPhone">
  38. <text class="bd-color" @click="isPhone = true">使用绑定手机验证修改密码</text>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { mapState } from 'vuex';
  44. export default {
  45. name: "password",
  46. data() {
  47. return {
  48. old_password: '',
  49. new_password: '',
  50. again_password: '',
  51. imageUrl: '',
  52. isPhone: false,
  53. sms_captcha: '',
  54. timeNum: 60,
  55. timeIng: 0,
  56. pic_captcha:'',
  57. validate_code_id: '',
  58. isSend: false,
  59. mobile: ''
  60. }
  61. },
  62. computed: {
  63. ...mapState({
  64. userInfo: state => state.user.info
  65. })
  66. },
  67. methods: {
  68. modify: function() {
  69. this.again_password = this.again_password.trim();
  70. this.new_password = this.new_password.trim();
  71. if (this.new_password === this.again_password) {
  72. let data = {
  73. old_password: this.old_password,
  74. new_password: this.new_password,
  75. again_password: this.again_password,
  76. validate_code_id: this.validate_code_id,
  77. sms_captcha: this.sms_captcha,
  78. mobile: this.mobile,
  79. type: ''
  80. }
  81. if (this.isPhone) {
  82. delete data.old_password;
  83. data.type = 'u_mobile_password';
  84. } else {
  85. delete data.sms_captcha;
  86. delete data.mobile;
  87. delete data.validate_code_id;
  88. data.type = 'u_password';
  89. }
  90. this.$request({
  91. url: this.$api.registered.password,
  92. method: "post",
  93. data: data
  94. }).then(response => {
  95. if (response.code === 0) {
  96. this.$store.dispatch('user/refreshInfo');
  97. this.$storage.removeStorageSync('_USER_ACCESS_TOKEN');
  98. uni.navigateTo({
  99. url: '/pages/registered/sign'
  100. });
  101. } else {
  102. uni.showToast({
  103. icon: 'none',
  104. title: response.msg
  105. });
  106. }
  107. });
  108. } else {
  109. uni.showToast({
  110. icon: 'none',
  111. title: '两次密码不统一'
  112. })
  113. }
  114. },
  115. getVerCode() {
  116. this.timeNum = 60;
  117. this.$request({
  118. url: this.$api.registered.sms,
  119. method: "post",
  120. data: {
  121. mobile: this.mobile,
  122. pic_captcha: this.pic_captcha
  123. }
  124. }).then(response => {
  125. if (response.code === 0) {
  126. this.isSend = true;
  127. this.validate_code_id = response.data.validate_code_id;
  128. this.change();
  129. } else {
  130. this.getImageUrl();
  131. uni.showToast({
  132. icon: 'none',
  133. title: response.msg
  134. });
  135. }
  136. });
  137. },
  138. change: function () {
  139. clearInterval(this.timeIng);
  140. this.timeIng = setInterval(() => {
  141. this.timeNum--;
  142. if (this.timeNum === 0) {
  143. clearInterval(this.timeIng);
  144. this.isSend = false;
  145. }
  146. }, 1000);
  147. },
  148. getImageUrl: function() {
  149. this.$request({
  150. url: this.$api.registered.captcha,
  151. data: {
  152. refresh: true
  153. }
  154. }).then(response => {
  155. this.imageUrl = response.url;
  156. });
  157. }
  158. },
  159. mounted() {
  160. this.getImageUrl();
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. .bd-password {
  166. min-height: 100vh;
  167. background-color: #ffffff;
  168. padding: 46upx 42upx;
  169. }
  170. .bd-item {
  171. height: 100upx;
  172. border-bottom: 2upx solid #f4f4f4;
  173. }
  174. .bd-label {
  175. width: 36upx;
  176. height: 36upx;
  177. margin: 0 25upx 0 2upx;
  178. }
  179. .bd-input {
  180. height: 36upx;
  181. }
  182. .bd-image {
  183. width: 160upx;
  184. height: 67upx;
  185. }
  186. .bd-bottom {
  187. height: 88upx;
  188. line-height: 88upx;
  189. color: #ffffff;
  190. font-size: 36upx;
  191. border-radius: 44upx;
  192. margin-top: 68upx;
  193. text-align: center;
  194. }
  195. .bd-yes-agree {
  196. background: rgba(255, 69, 68, 1);
  197. }
  198. .bd-no-agree {
  199. background: rgba(255, 69, 68, 0.5);
  200. }
  201. .bd-agree-group {
  202. margin-top: 42upx;
  203. }
  204. .bd-color {
  205. font-size: 28upx;
  206. color: #ff4544;
  207. }
  208. .bd-btn {
  209. border-left: 1upx solid #f4f4f4;
  210. width: 226upx;
  211. height: 53upx;
  212. line-height: 53upx;
  213. font-size: 32upx;
  214. color: #ff4544;
  215. text-align: center;
  216. }
  217. </style>