change.vue 4.0 KB

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