password.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="body">
  3. <!-- 公共组件-每个页面必须引入 -->
  4. <public-module></public-module>
  5. <view class="form">
  6. <view class="password dis a-c j-s">
  7. <u-icon name="lock-opened-fill" color="#999" size="28"></u-icon>
  8. <input placeholder="旧密码" v-model="oldPassword" password=true
  9. placeholder-style="color: #C5C5C5;font-size:26upx" />
  10. </view>
  11. <view class="password">
  12. <u-icon name="lock-opened-fill" color="#999" size="28"></u-icon>
  13. <input placeholder="新密码(6-15位数字与字母组合)" v-model="repwd" password=true
  14. placeholder-style="color: #C5C5C5;font-size:26upx" />
  15. </view>
  16. <view class="password">
  17. <u-icon name="lock-opened-fill" color="#999" size="28"></u-icon>
  18. <input placeholder="确认密码" v-model="password" password=true
  19. placeholder-style="color: #C5C5C5;font-size:26upx" />
  20. </view>
  21. <button class="user-set-btn d-flex a-center j-center " :loading="loading" :disabled="disabled"
  22. type="primary" @tap="submit">完成</button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. mapState,
  29. mapMutations
  30. } from "vuex"
  31. export default {
  32. data() {
  33. return {
  34. password: "",
  35. repwd: "",
  36. oldPassword: "",
  37. loading: false,
  38. disabled: true,
  39. }
  40. },
  41. watch: {
  42. password(val) {
  43. this.OnBtnChange();
  44. },
  45. repwd(val) {
  46. this.OnBtnChange();
  47. },
  48. oldPassword(val) {
  49. this.OnBtnChange();
  50. },
  51. },
  52. computed: {
  53. ...mapState(['userInfo'])
  54. },
  55. methods: {
  56. ...mapMutations(['emptyUserInfo']),
  57. // 改变按钮状态
  58. OnBtnChange() {
  59. if (this.password && this.repwd && this.oldPassword) {
  60. this.disabled = false;
  61. return;
  62. }
  63. this.disabled = true;
  64. },
  65. async submit() {
  66. if (!this.$base.passwordRegular.test(this.password)) {
  67. return uni.showToast({
  68. title: '密码须6-15位数字与字母组合',
  69. icon: 'none'
  70. });
  71. }
  72. if (this.password != this.repwd) {
  73. return uni.showToast({
  74. title: '两次密码输入不一致',
  75. icon: "none"
  76. });
  77. }
  78. let res = await this.$http.post('/user/updatePwd?id=' + this.userInfo.sysUser.id + '&password=' + this
  79. .password + '&oldPassword=' + this.oldPassword);
  80. if (res.code == 200) {
  81. this.password = "";
  82. this.repwd = "";
  83. this.oldPassword = "";
  84. uni.showToast({
  85. title: "修改密码成功",
  86. icon: "none"
  87. });
  88. this.emptyUserInfo();
  89. setTimeout(() => {
  90. uni.reLaunch({
  91. url: "/pages/login/login"
  92. })
  93. return true;
  94. }, 500);
  95. } else {
  96. uni.showToast({
  97. title: res.msg,
  98. icon: "none"
  99. });
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style>
  106. .body {
  107. position: absolute;
  108. width: 100%;
  109. height: 100vh;
  110. background-color: #F5F5F5;
  111. }
  112. .form {
  113. width: 100%;
  114. padding: 20upx 5%;
  115. font-size: 30upx;
  116. }
  117. .form .password {
  118. position: relative;
  119. width: 100%;
  120. height: 90upx;
  121. display: flex;
  122. align-items: center;
  123. border-radius: 5upx;
  124. background-color: #FFFFFF;
  125. padding: 0 0 0 20px;
  126. margin: 30rpx 0rpx 50rpx;
  127. }
  128. .form .password input {
  129. width: 100%;
  130. height: 50rpx;
  131. color: rgba($color: #ffffff, $alpha: 0.8);
  132. font-weight: 200;
  133. margin-left: 20px;
  134. }
  135. .icon {
  136. color: #999;
  137. height: 70upx;
  138. font-size: 40upx;
  139. z-index: 10;
  140. position: absolute;
  141. top: 10upx;
  142. left: 10upx;
  143. padding: 0 15upx;
  144. border-right: 2px solid #F5F5F5;
  145. }
  146. </style>