password.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view>
  3. <u-navbar title="修改密码" autoBack placeholder></u-navbar>
  4. <view class="card_password">
  5. <view class="item_pass">
  6. <view class="pass_title">旧密码<span style="color: red;">*</span></view>
  7. <u-input v-show="isText1 === true" placeholder="请填写密码" border="surround" v-model="userInfo.oldCode"
  8. class="input_class_pwd" :password="true">
  9. <template slot="suffix" v-if="userInfo.oldCode">
  10. <u-icon name="eye-off" @click="isText1 = false" size="20"></u-icon>
  11. </template>
  12. </u-input>
  13. <u-input v-show="isText1 === false" placeholder="请填写密码" border="surround" v-model="userInfo.oldCode"
  14. class="input_class_pwd" :password="false">
  15. <template slot="suffix" v-if="userInfo.oldCode">
  16. <u-icon name="eye-fill" @click="isText1 = true" size="20"></u-icon>
  17. </template>
  18. </u-input>
  19. </view>
  20. <view class="item_pass">
  21. <view class="pass_title">新密码<span style="color: red;">*</span></view>
  22. <u-input v-show="isText2 === true" placeholder="请填写新密码" border="surround" v-model="userInfo.sedNewCode"
  23. class="input_class_pwd" :password="true">
  24. <template slot="suffix" v-if="userInfo.sedNewCode">
  25. <u-icon name="eye-off" @click="isText2 = false" size="20"></u-icon>
  26. </template>
  27. </u-input>
  28. <u-input v-show="isText2 === false" placeholder="请填写新密码" border="surround" v-model="userInfo.sedNewCode"
  29. class="input_class_pwd" :password="false">
  30. <template slot="suffix" v-if="userInfo.sedNewCode">
  31. <u-icon name="eye-fill" @click="isText2 = true" size="20"></u-icon>
  32. </template>
  33. </u-input>
  34. </view>
  35. <view class="item_pass">
  36. <view class="pass_title">再次输入新密码<span style="color: red;">*</span></view>
  37. <u-input v-show="isText3 === true" placeholder="请再次填写新密码" border="surround" v-model="userInfo.newCode"
  38. class="input_class_pwd" :password="true">
  39. <template slot="suffix" v-if="userInfo.newCode">
  40. <u-icon name="eye-off" @click="isText3 = false" size="20"></u-icon>
  41. </template>
  42. </u-input>
  43. <u-input v-show="isText3 === false" placeholder="请再次填写新密码" border="surround" v-model="userInfo.newCode"
  44. class="input_class_pwd" :password="false">
  45. <template slot="suffix" v-if="userInfo.newCode">
  46. <u-icon name="eye-fill" @click="isText3 = true" size="20"></u-icon>
  47. </template>
  48. </u-input>
  49. </view>
  50. </view>
  51. <view class="card_btn">
  52. <u-button type="primary" :disabled="disabled" text="提交" @click="amend"></u-button>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. userInfo: {
  61. oldCode: '',
  62. sedNewCode: '',
  63. newCode: ''
  64. },
  65. isText1: true,
  66. isText2: true,
  67. isText3: true,
  68. }
  69. },
  70. computed: {
  71. disabled() {
  72. if (this.userInfo.oldCode == '' || this.userInfo.sedNewCode == '' || this.userInfo.newCode == '') {
  73. return true;
  74. } else {
  75. return false;
  76. }
  77. },
  78. },
  79. methods: {
  80. amend() {
  81. if (this.userInfo.sedNewCode === this.userInfo.newCode) {
  82. this.$api.put('/api/user/pwd/set', {
  83. oldPassword: this.userInfo.oldCode,
  84. newPassword: this.userInfo.newCode,
  85. }).then(res => {
  86. if (res.code == 200) {
  87. this.$cache.removeToken()
  88. this.$cache.removeCache('userInfo')
  89. uni.redirectTo({
  90. url: '/pages/login'
  91. })
  92. } else {
  93. uni.showToast({
  94. title: res.data.msg,
  95. icon: 'none'
  96. });
  97. }
  98. })
  99. } else {
  100. uni.showToast({
  101. title: '输入两次密码不一样',
  102. icon: 'none'
  103. });
  104. }
  105. },
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. page {
  111. background-color: #fff !important;
  112. }
  113. .card_password {
  114. padding: 20rpx 40rpx 40rpx 40rpx;
  115. }
  116. .item_pass {
  117. margin-top: 30rpx;
  118. }
  119. .pass_title {
  120. margin-bottom: 20rpx;
  121. }
  122. .card_btn {
  123. margin: 40rpx;
  124. }
  125. </style>