changePwd.vue 4.6 KB

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