set-pwd.vue 4.7 KB
Newer Older
C
chenruilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
<!-- 设置密码 -->
<template>
  <view class="uni-content">
    <match-media :min-width="690">
      <view class="login-logo">
        <image :src="logo"></image>
      </view>
      <!-- 顶部文字 -->
      <text class="title title-box ">设置密码</text>
    </match-media>

    <uni-forms class="set-password-form" ref="form" :value="formData" err-show-type="toast">
      <text class="tip">输入密码</text>
      <uni-forms-item name="newPassword">
        <uni-easyinput :focus="focusNewPassword" @blur="focusNewPassword = false" class="input-box"
                       type="password" :inputBorder="false" v-model="formData.newPassword" placeholder="请输入密码">
        </uni-easyinput>
      </uni-forms-item>
      <text class="tip">再次输入密码</text>
      <uni-forms-item name="newPassword2">
        <uni-easyinput :focus="focusNewPassword2" @blur="focusNewPassword2 = false" class="input-box"
                       type="password" :inputBorder="false" v-model="formData.newPassword2" placeholder="请再次输入新密码">
        </uni-easyinput>
      </uni-forms-item>
      <uni-id-pages-sms-form v-model="formData.code" type="set-pwd-by-sms" ref="smsCode" :phone="userInfo.mobile">
      </uni-id-pages-sms-form>
      <view class="link-box">
        <button class="uni-btn send-btn" type="primary" @click="submit">确认</button>
        <button v-if="allowSkip" class="uni-btn send-btn" type="default" @click="skip">跳过</button>
      </view>

    </uni-forms>
    <uni-popup-captcha @confirm="submit" v-model="formData.captcha" scene="set-pwd-by-sms" ref="popup"></uni-popup-captcha>
  </view>
</template>

<script>
import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
import {store, mutations} from '@/uni_modules/uni-id-pages/common/store.js'
import config from '@/uni_modules/uni-id-pages/config.js'

const uniIdCo = uniCloud.importObject("uni-id-co", {
  customUI:true
})
export default {
  name: "set-pwd.vue",
  data () {
    return {
      uniIdRedirectUrl: '',
      loginType: '',
      logo: '/static/logo.png',
      focusNewPassword: false,
      focusNewPassword2: false,
      allowSkip: false,
      formData: {
        code: "",
        captcha: "",
        newPassword: "",
        newPassword2: ""
      },
      rules: passwordMod.getPwdRules('newPassword', 'newPassword2')
    }
  },
  computed: {
    userInfo () {
      return store.userInfo
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  onLoad (e) {
    this.uniIdRedirectUrl = e.uniIdRedirectUrl
    this.loginType = e.loginType

    if (config.setPasswordAfterLogin && config.setPasswordAfterLogin?.allowSkip) {
      this.allowSkip = true
    }
  },
  methods: {
    submit () {
      if(! /^\d{6}$/.test(this.formData.code)){
        this.$refs.smsCode.focusSmsCodeInput = true
        return uni.showToast({
          title: '验证码格式不正确',
          icon: 'none'
        });
      }

      this.$refs.form.validate()
          .then(res => {
            uniIdCo.setPwd({
              password: this.formData.newPassword,
              code: this.formData.code,
              captcha: this.formData.captcha
            }).then(e => {
              uni.showModal({
                content: '密码设置成功',
                showCancel: false,
                success: () => {
                  mutations.loginBack({
                    uniIdRedirectUrl: this.uniIdRedirectUrl,
                    loginType: this.loginType
                  })
                }
              });
            }).catch(e => {
              uni.showModal({
                content: e.message,
                showCancel: false
              });
            })
          }).catch(e => {
            if (e.errCode == 'uni-id-captcha-required') {
              this.$refs.popup.open()
            } else {
              console.log(e.errMsg);
            }
          }).finally(e => {
            this.formData.captcha = ''
          })
    },
    skip () {
124 125 126
      mutations.loginBack({
		uniIdRedirectUrl: this.uniIdRedirectUrl,
	  })
C
chenruilong 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    }
  }
}
</script>

<style scoped lang="scss">
@import "@/uni_modules/uni-id-pages/common/login-page.scss";

.uni-btn[type="default"] {
  color: inherit!important;
}

.uni-content ::v-deep .uni-forms-item {
  margin-bottom: 10px;
}

.popup-captcha {
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  padding: 20rpx;
  background-color: #FFF;
  border-radius: 2px;
  flex-direction: column;
  position: relative;
}

.popup-captcha .title {
  font-weight: normal;
  padding: 0;
  padding-bottom: 15px;
  color: #666;
}

.popup-captcha .close {
  position: absolute;
  bottom: -40px;
  margin-left: -13px;
  left: 50%;
}

.popup-captcha .uni-btn {
  margin: 0;
}
</style>