change_pwd.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!-- 修改密码 -->
  2. <template>
  3. <view class="uni-content">
  4. <match-media :min-width="690">
  5. <view class="login-logo">
  6. <image :src="logo"></image>
  7. </view>
  8. <!-- 顶部文字 -->
  9. <text class="title title-box">修改密码</text>
  10. </match-media>
  11. <uni-forms ref="form" :value="formData" err-show-type="toast">
  12. <uni-forms-item name="oldPassword">
  13. <uni-easyinput :focus="focusOldPassword" @blur="focusOldPassword = false" class="input-box"
  14. type="password" :inputBorder="false" v-model="formData.oldPassword" placeholder="请输入旧密码">
  15. </uni-easyinput>
  16. </uni-forms-item>
  17. <uni-forms-item name="newPassword">
  18. <uni-easyinput :focus="focusNewPassword" @blur="focusNewPassword = false" class="input-box"
  19. type="password" :inputBorder="false" v-model="formData.newPassword" placeholder="请输入新密码">
  20. </uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item name="newPassword2">
  23. <uni-easyinput :focus="focusNewPassword2" @blur="focusNewPassword2 = false" class="input-box"
  24. type="password" :inputBorder="false" v-model="formData.newPassword2" placeholder="请再次输入新密码">
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. <button class="uni-btn send-btn-box" type="primary" @click="submit">提交</button>
  28. </uni-forms>
  29. </view>
  30. </template>
  31. <script>
  32. import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
  33. import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
  34. const uniIdCo = uniCloud.importObject("uni-id-co", {
  35. customUI:true
  36. })
  37. export default {
  38. mixins: [mixin],
  39. data() {
  40. return {
  41. focusOldPassword: false,
  42. focusNewPassword: false,
  43. focusNewPassword2: false,
  44. formData: {
  45. 'oldPassword': '',
  46. 'newPassword': '',
  47. 'newPassword2': '',
  48. },
  49. rules: {
  50. oldPassword: {
  51. rules: [{
  52. required: true,
  53. errorMessage: '请输入新密码',
  54. },
  55. {
  56. pattern: /^.{6,20}$/,
  57. errorMessage: '密码为6 - 20位',
  58. }
  59. ]
  60. },
  61. ...passwordMod.getPwdRules('newPassword', 'newPassword2')
  62. },
  63. logo: "/static/logo.png"
  64. }
  65. },
  66. onReady() {
  67. this.$refs.form.setRules(this.rules)
  68. },
  69. onShow() {
  70. // #ifdef H5
  71. document.onkeydown = event => {
  72. var e = event || window.event;
  73. if (e && e.keyCode == 13) { //回车键的键值为13
  74. this.submit()
  75. }
  76. };
  77. // #endif
  78. },
  79. methods: {
  80. /**
  81. * 完成并提交
  82. */
  83. submit() {
  84. console.log("formData", this.formData);
  85. console.log('rules', this.rules);
  86. this.$refs.form.validate()
  87. .then(res => {
  88. let {
  89. oldPassword,
  90. newPassword
  91. } = this.formData
  92. uniIdCo.updatePwd({
  93. oldPassword,
  94. newPassword
  95. }).then(e => {
  96. console.log(e);
  97. uni.removeStorageSync('uni_id_token');
  98. uni.setStorageSync('uni_id_token_expired', 0)
  99. uni.redirectTo({
  100. url:'/uni_modules/uni-id-pages/pages/login/login-withpwd'
  101. })
  102. }).catch(e => {
  103. uni.showModal({
  104. content: e.message,
  105. showCancel: false
  106. });
  107. })
  108. }).catch(errors => {
  109. let key = errors[0].key
  110. key = key.replace(key[0], key[0].toUpperCase())
  111. console.log(key, 'focus' + key);
  112. this['focus' + key] = true
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  120. @media screen and (max-width: 690px) {
  121. .uni-content{
  122. margin-top: 15px;
  123. }
  124. }
  125. @media screen and (min-width: 690px) {
  126. .uni-content{
  127. padding: 30px 40px 40px;
  128. }
  129. }
  130. </style>