change.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="change-layout">
  3. <div class="change-con">
  4. <div class="input">
  5. {{info.userName}}
  6. </div>
  7. <div class="input yanzhengma">
  8. <input autocomplete="off" v-model="code" type="text" placeholder="验证码">
  9. <div v-if="!jishi" @click="getAuthCode" class="code btn parmary">获取验证码</div>
  10. <div v-else class="code btn parmary">{{interTime}}s后重新发送</div>
  11. </div>
  12. <div class="input">
  13. <input autocomplete="off" maxlength="12" v-model="password" type="password" placeholder="新密码">
  14. </div>
  15. <div @click="submit" class="btn parmary">
  16. 提交
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import {mapState} from 'vuex'
  23. export default {
  24. computed: {
  25. ...mapState({
  26. token: state => state.user.token,
  27. info: state => state.user.info
  28. })
  29. },
  30. data () {
  31. return {
  32. password: '',
  33. phone: '',
  34. interTime: 60,
  35. jishi: false,
  36. code: ''
  37. }
  38. },
  39. methods: {
  40. async getAuthCode () {
  41. let {userName, country} = this.info
  42. let res = await this.$store.dispatch('getAuthCode', {
  43. phone: userName,
  44. code: country === '中国' ? 86 : country
  45. })
  46. if (res) {
  47. this.interl && clearInterval(this.interl)
  48. this.interl = null
  49. this.jishi = true
  50. this.interl = setInterval(() => {
  51. this.interTime--
  52. if (this.interTime <= 0) {
  53. this.jishi = false
  54. this.interTime = 60
  55. clearInterval(this.interl)
  56. this.interl = null
  57. }
  58. }, 1000)
  59. }
  60. },
  61. async submit () {
  62. let check = value => {
  63. for (let i = 0, len = value.length; i < len; i++) {
  64. if (!value[i].val) {
  65. return this.$toast.show('warn', value[i].name + '不能为空')
  66. }
  67. }
  68. return true
  69. }
  70. let checkStr = [
  71. {
  72. name: '验证码',
  73. val: this.code
  74. },
  75. {
  76. name: '密码',
  77. val: this.password
  78. }
  79. ]
  80. if (!check(checkStr)) {
  81. return
  82. }
  83. let params = {
  84. password: this.password,
  85. phoneNum: this.info.userName,
  86. msgAuthCode: this.code
  87. }
  88. let res = await this.$http({
  89. method: 'post',
  90. headers: {
  91. token: this.token
  92. },
  93. data: params,
  94. url: 'user/changePassword'
  95. })
  96. let data = res.data
  97. if (data.code === 0) {
  98. this.$toast.show('success', '密码修改成功,请重新登录')
  99. this.$store.commit('logout')
  100. this.$router.push({name: 'home'})
  101. } else {
  102. this.$toast.show('warn', `修改失败,${data.msg}`)
  103. }
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .change-layout{
  110. $theme-color: #1fe4dc;
  111. $border-color: #e7e7e7;
  112. margin-bottom: 300px;
  113. .input{
  114. width: 300px;
  115. margin-bottom: 20px;
  116. }
  117. input {
  118. appearance: none;
  119. line-height: 36px;
  120. height: 36px;
  121. width: 100%;
  122. border: solid 1px $border-color;
  123. padding-left: 10px;
  124. &:focus {
  125. border: solid 1px $theme-color;
  126. }
  127. }
  128. .btn {
  129. text-align: center;
  130. cursor: pointer;
  131. }
  132. .parmary {
  133. background-color: $theme-color;
  134. height: 36px;
  135. width: 120px;
  136. line-height: 36px;
  137. }
  138. .change-con{
  139. padding: 30px 0 30px 40px;
  140. width: 850px;
  141. .yanzhengma{
  142. display: flex;
  143. align-items: center;
  144. input{
  145. width: 180px;
  146. }
  147. }
  148. }
  149. }
  150. </style>