set-pwd.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 class="set-password-form" ref="form" :value="formData" err-show-type="toast">
  12. <text class="tip">输入密码</text>
  13. <uni-forms-item name="newPassword">
  14. <uni-easyinput :focus="focusNewPassword" @blur="focusNewPassword = false" class="input-box"
  15. type="password" :inputBorder="false" v-model="formData.newPassword" placeholder="请输入密码">
  16. </uni-easyinput>
  17. </uni-forms-item>
  18. <text class="tip">再次输入密码</text>
  19. <uni-forms-item name="newPassword2">
  20. <uni-easyinput :focus="focusNewPassword2" @blur="focusNewPassword2 = false" class="input-box"
  21. type="password" :inputBorder="false" v-model="formData.newPassword2" placeholder="请再次输入新密码">
  22. </uni-easyinput>
  23. </uni-forms-item>
  24. <uni-id-pages-sms-form v-model="formData.code" type="set-pwd-by-sms" ref="smsCode" :phone="userInfo.mobile">
  25. </uni-id-pages-sms-form>
  26. <view class="link-box">
  27. <button class="uni-btn send-btn" type="primary" @click="submit">确认</button>
  28. <button v-if="allowSkip" class="uni-btn send-btn" type="default" @click="skip">跳过</button>
  29. </view>
  30. </uni-forms>
  31. <uni-popup-captcha @confirm="submit" v-model="formData.captcha" scene="set-pwd-by-sms" ref="popup"></uni-popup-captcha>
  32. </view>
  33. </template>
  34. <script>
  35. import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
  36. import {store, mutations} from '@/uni_modules/uni-id-pages/common/store.js'
  37. import config from '@/uni_modules/uni-id-pages/config.js'
  38. const uniIdCo = uniCloud.importObject("uni-id-co", {
  39. customUI:true
  40. })
  41. export default {
  42. name: "set-pwd.vue",
  43. data () {
  44. return {
  45. uniIdRedirectUrl: '',
  46. loginType: '',
  47. logo: '/static/logo.png',
  48. focusNewPassword: false,
  49. focusNewPassword2: false,
  50. allowSkip: false,
  51. formData: {
  52. code: "",
  53. captcha: "",
  54. newPassword: "",
  55. newPassword2: ""
  56. },
  57. rules: passwordMod.getPwdRules('newPassword', 'newPassword2')
  58. }
  59. },
  60. computed: {
  61. userInfo () {
  62. return store.userInfo
  63. }
  64. },
  65. onReady() {
  66. this.$refs.form.setRules(this.rules)
  67. },
  68. onLoad (e) {
  69. this.uniIdRedirectUrl = e.uniIdRedirectUrl
  70. this.loginType = e.loginType
  71. if (config.setPasswordAfterLogin && config.setPasswordAfterLogin?.allowSkip) {
  72. this.allowSkip = true
  73. }
  74. },
  75. methods: {
  76. submit () {
  77. if(! /^\d{6}$/.test(this.formData.code)){
  78. this.$refs.smsCode.focusSmsCodeInput = true
  79. return uni.showToast({
  80. title: '验证码格式不正确',
  81. icon: 'none'
  82. });
  83. }
  84. this.$refs.form.validate()
  85. .then(res => {
  86. uniIdCo.setPwd({
  87. password: this.formData.newPassword,
  88. code: this.formData.code,
  89. captcha: this.formData.captcha
  90. }).then(e => {
  91. uni.showModal({
  92. content: '密码设置成功',
  93. showCancel: false,
  94. success: () => {
  95. mutations.loginBack({
  96. uniIdRedirectUrl: this.uniIdRedirectUrl,
  97. loginType: this.loginType
  98. })
  99. }
  100. });
  101. }).catch(e => {
  102. uni.showModal({
  103. content: e.message,
  104. showCancel: false
  105. });
  106. })
  107. }).catch(e => {
  108. if (e.errCode == 'uni-id-captcha-required') {
  109. this.$refs.popup.open()
  110. } else {
  111. console.log(e.errMsg);
  112. }
  113. }).finally(e => {
  114. this.formData.captcha = ''
  115. })
  116. },
  117. skip () {
  118. mutations.loginBack({
  119. uniIdRedirectUrl: this.uniIdRedirectUrl,
  120. })
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  127. .uni-btn[type="default"] {
  128. color: inherit!important;
  129. }
  130. .uni-content ::v-deep .uni-forms-item {
  131. margin-bottom: 10px;
  132. }
  133. .popup-captcha {
  134. /* #ifndef APP-NVUE */
  135. display: flex;
  136. /* #endif */
  137. padding: 20rpx;
  138. background-color: #FFF;
  139. border-radius: 2px;
  140. flex-direction: column;
  141. position: relative;
  142. }
  143. .popup-captcha .title {
  144. font-weight: normal;
  145. padding: 0;
  146. padding-bottom: 15px;
  147. color: #666;
  148. }
  149. .popup-captcha .close {
  150. position: absolute;
  151. bottom: -40px;
  152. margin-left: -13px;
  153. left: 50%;
  154. }
  155. .popup-captcha .uni-btn {
  156. margin: 0;
  157. }
  158. </style>