changePwd.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="changePwd-container">
  3. <view class="content">
  4. <view class="tishi">请先输入原密码,按步骤操作</view>
  5. <view class="input-group">
  6. <view class="input-row border">
  7. <text class="title">原密码:</text>
  8. <m-input class="m-input" :maxlength="12" type="password" displayable v-model="formCustom.oldPwd" placeholder="请输入原密码"></m-input>
  9. </view>
  10. <view class="input-row">
  11. <text class="title">新密码:</text>
  12. <m-input class="m-input" :maxlength="12" type="password" displayable v-model="formCustom.passwd" placeholder="请输入6-12位新密码"></m-input>
  13. </view>
  14. <view class="input-row">
  15. <text class="title">再次输入:</text>
  16. <m-input class="m-input" :maxlength="12" type="password" displayable v-model="formCustom.passwdCheck" placeholder="请输入6-12位新密码"></m-input>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 按钮 -->
  21. <view class="form-footer-btn">
  22. <u-button size="medium" hover-class="none" shape="circle" @click="handleReset">重置</u-button>
  23. <u-button size="medium" hover-class="none" shape="circle" :loading="loading" :custom-style="customBtnStyle" @click="handleSubmit">保存</u-button>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import mInput from '../../components/m-input.vue'
  29. import { changePwd } from '@/api/user.js'
  30. import { logout } from '@/api/login.js'
  31. export default{
  32. name:'changePwd',
  33. components: {
  34. mInput
  35. },
  36. data(){
  37. return{
  38. formCustom: {
  39. passwd: '',
  40. passwdCheck: '',
  41. oldPwd: ''
  42. },
  43. loading: false,
  44. customBtnStyle: { // 自定义按钮样式
  45. borderColor: '#0DC55F',
  46. backgroundColor: '#0DC55F',
  47. color: '#fff'
  48. },
  49. }
  50. },
  51. methods:{
  52. messageInfo(info){
  53. uni.showToast({
  54. icon:'none',
  55. title: info
  56. })
  57. },
  58. handleSubmit(){
  59. let _this = this
  60. //非空判断密码长度判断
  61. if (this.formCustom.oldPwd === '') {
  62. this.messageInfo("请输入原密码")
  63. return
  64. }
  65. if (this.formCustom.passwd === '') {
  66. this.messageInfo("请输入新密码")
  67. return
  68. }
  69. if (this.formCustom.passwd.length < 6) {
  70. this.messageInfo("新密码最少6位")
  71. return
  72. }
  73. if (this.formCustom.passwdCheck === '') {
  74. this.messageInfo("请再次输入新密码")
  75. return
  76. }
  77. if (this.formCustom.passwdCheck.length < 6) {
  78. this.messageInfo("再次输入新密码最少6位")
  79. return
  80. }
  81. if (this.formCustom.passwdCheck !== this.formCustom.passwd) {
  82. this.messageInfo("再次输入的密码和新密码不一样")
  83. return
  84. }
  85. // 保存
  86. this.loading = true
  87. changePwd({
  88. oldPassword: this.formCustom.oldPwd,
  89. password: this.formCustom.passwd
  90. }).then(res => {
  91. if (res.status == '200') {
  92. this.messageInfo('修改成功, 请重新登录')
  93. setTimeout(function(){
  94. _this.logout()
  95. },800)
  96. } else {
  97. this.messageInfo(res.message)
  98. this.loading = false
  99. }
  100. })
  101. },
  102. logout(){
  103. logout().then(res => {
  104. console.log(res)
  105. this.messageInfo(res.message)
  106. if(res.status == 200){
  107. // this.$store.commit("$closeWebsocket")
  108. this.$store.state.vuex_token = ''
  109. this.$store.state.vuex_userData = ''
  110. uni.setStorageSync('setStatusIndexFunc', 0)
  111. uni.reLaunch({
  112. url: "/pages/login/login"
  113. })
  114. }
  115. this.loading = false
  116. })
  117. },
  118. handleReset (name) {
  119. this.formCustom = {
  120. passwd: '',
  121. passwdCheck: '',
  122. oldPwd: ''
  123. }
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="less">
  129. page{
  130. background: #FFFFFF;
  131. }
  132. .changePwd-container{
  133. width: 100%;
  134. font-size: 28rpx;
  135. padding: 20rpx 40rpx ;
  136. .content{
  137. .tishi{
  138. text-align: center;
  139. line-height: 130rpx;
  140. font-size: 30rpx;
  141. color: #999;
  142. }
  143. .input-group{
  144. margin-top:20rpx;
  145. }
  146. .input-row{
  147. padding: 10rpx 20rpx;
  148. background-color: #F8F8F8;
  149. margin-bottom: 20rpx;
  150. border-radius: 10rpx;
  151. line-height: 32px;
  152. display: flex;
  153. align-items: center;
  154. .title{
  155. width:140rpx;
  156. display: inline-block;
  157. text-align: left;
  158. color:#808080;
  159. }
  160. }
  161. .uni-input-placeholder{
  162. font-size: 26rpx;
  163. color:#989898;
  164. }
  165. }
  166. .u-size-default[data-v-1f520a08]{
  167. height: 92rpx;
  168. }
  169. .m-input-input[data-v-5a85b703]{
  170. position: relative;
  171. bottom: 4rpx;
  172. }
  173. .m-input-icon[data-v-5a85b703]{
  174. position: relative;
  175. bottom: 10rpx;
  176. }
  177. .form-footer-btn{
  178. margin: 140upx 50upx 0;
  179. display: flex;
  180. justify-content: space-between;
  181. }
  182. .form-footer-btn uni-button{
  183. width: 50%;
  184. margin: 0 50upx;
  185. font-size: 30upx;
  186. }
  187. }
  188. </style>