changePassword.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="pages">
  3. <uni-forms class="form" :value="dataObj" ref="formData" :rules="rules" :border="true"
  4. label-width="100">
  5. <uni-forms-item label="原密码" name="password" :required="true" label-width="100">
  6. <input :value="dataObj.password" type="password" @input="binddata('password',$event.detail.value)"
  7. class="uni-input" placeholder="请输入原密码" />
  8. </uni-forms-item>
  9. <uni-forms-item label="新密码" name="oldPassword" :required="true" label-width="100">
  10. <input :value="dataObj.oldPassword" type="password" @input="binddata('oldPassword',$event.detail.value)"
  11. class="uni-input" placeholder="请输入新密码" />
  12. </uni-forms-item>
  13. <uni-forms-item label="确认密码" name="newPassword" :required="true" label-width="100">
  14. <input :value="dataObj.newPassword" type="password" @input="binddata('newPassword',$event.detail.value)"
  15. class="uni-input" placeholder="请再输一次新密码" />
  16. </uni-forms-item>
  17. </uni-forms>
  18. <button class="but" type="default" :loading="loading" :disabled="loading" @tap="changePass">确认</button>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. updatePassword,
  24. exit
  25. } from '@/common/api.js'
  26. export default {
  27. data() {
  28. return {
  29. dataObj: {
  30. password: "",
  31. oldPassword: "",
  32. newPassword: ""
  33. },
  34. loading: false,
  35. rules: {
  36. password: {
  37. rules: [{
  38. required: true,
  39. errorMessage: '请输入原密码',
  40. }, ]
  41. },
  42. oldPassword: {
  43. rules: [{
  44. required: true,
  45. errorMessage: '请输入新密码',
  46. },
  47. {
  48. validateFunction: function(rule, value, data, callback) {
  49. // let reg = /(?=.*([a-zA-Z].*))(?=.*[0-9].*)[a-zA-Z0-9-*/+.~!@#$%^&*()]{6,20}$/;
  50. // console.log(value)
  51. if (value.length>20||value.length<6) {
  52. // if (!reg.test(value)) {
  53. callback('密码长度6-20位')
  54. }
  55. return true
  56. }
  57. }
  58. ]
  59. },
  60. newPassword: {
  61. rules: [{
  62. required: true,
  63. errorMessage: '请再输一次新密码',
  64. },
  65. {
  66. validateFunction: function(rule, value, data, callback) {
  67. if (data.newPassword != data.oldPassword) {
  68. callback('两次密码输入不一致')
  69. }
  70. return true
  71. }
  72. }
  73. ]
  74. },
  75. }
  76. }
  77. },
  78. onReady() {
  79. this.$refs.formData.setRules(this.rules)
  80. },
  81. methods: {
  82. binddata(v, e) {
  83. this.dataObj[v] = e
  84. },
  85. changePass() {
  86. this.$refs.formData.submit().then(res => {
  87. this.loading = true
  88. console.log(this.dataObj)
  89. console.log(this.$store.state.Token)
  90. updatePassword({
  91. ...this.dataObj,
  92. userId:this.$store.state.Token
  93. }).then(res =>{
  94. console.log(res)
  95. this.loading = false
  96. plus.nativeUI.toast('密码修改成功,请重新登录')
  97. setTimeout(() =>{
  98. exit().then(res => {
  99. this.$store.dispatch('setToken', "")
  100. this.$store.dispatch('setUsers', "{}")
  101. uni.reLaunch({
  102. url: '/pages/native/login'
  103. });
  104. }).catch(e => {
  105. plus.nativeUI.toast('服务退出登录失败,正强制退出...')
  106. setTimeout(() =>{
  107. this.$store.dispatch('setToken', "")
  108. this.$store.dispatch('setUsers', "{}")
  109. uni.reLaunch({
  110. url: '/pages/native/login'
  111. });
  112. },1000)
  113. })
  114. },2000)
  115. }).catch(e =>{
  116. console.log(e)
  117. plus.nativeUI.toast(e.data.msg)
  118. this.loading = false
  119. })
  120. }).catch(err => {
  121. console.log('表单错误信息:', err);
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. .form {
  129. border-bottom: 1px solid #EEEEEE;
  130. }
  131. .uni-input{
  132. padding: 0 15rpx;
  133. }
  134. .but {
  135. width: 600rpx;
  136. margin-top: 420rpx;
  137. background-color: #0099FF;
  138. color: #fff;
  139. }
  140. </style>