123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <template>
- <div class="page">
- <div class="page-content">
- <el-form :model="formData" :rules="rules" label-position="top" ref="form">
- <el-form-item label="手机号" prop="mobile">
- <el-input
- placeholder="请输入手机号"
- maxlength="11"
- v-model="formData.mobile"
- ></el-input>
- </el-form-item>
- <el-form-item label="验证码" prop="verifyCode">
- <div class="verify-code">
- <el-input
- placeholder="请输入验证码"
- maxlength="6"
- v-model="formData.verifyCode"
- ></el-input>
- <div class="send" @click="onSend">{{ sendCodeBtnText }}</div>
- </div>
- </el-form-item>
- <el-form-item label="新密码" prop="password">
- <el-input
- type="password"
- placeholder="请输入新密码"
- v-model="formData.password"
- ></el-input>
- </el-form-item>
- <el-form-item label="确认密码" prop="confirmPwd">
- <el-input
- type="password"
- placeholder="请输入确认密码"
- v-model="formData.confirmPwd"
- ></el-input>
- </el-form-item>
- </el-form>
- <div class="submit-button">
- <div class="back btn" @click="onBack">返回</div>
- <div class="submit btn" @click="onSubmit">提交</div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { isMobile, validPassword } from '~/utils/validator'
- import { mapGetters } from 'vuex'
- export default {
- layout: 'app-hyt',
- data() {
- const passwordValidate = (rule, value, callback) => {
- console.log(value)
- if (validPassword(value)) {
- callback()
- } else {
- callback(new Error('密码只能包含英文大小写和数字'))
- }
- }
- const confirmPwdValide = (rule, value, callback) => {
- if (this.formData.password !== value) {
- callback(new Error('两次输入的密码不一致'))
- } else {
- callback()
- }
- }
- return {
- sendStatus: 0,
- timer: null,
- formData: {
- mobile: '',
- verifyCode: '',
- password: '',
- confirmPwd: '',
- },
- rules: {
- mobile: [
- { required: true, message: '请输入手机号', trigger: ['blur'] },
- ],
- verifyCode: [
- { required: true, message: '请输入验证码', trigger: ['blur'] },
- ],
- password: [
- { required: true, message: '请输入新密码', trigger: ['blur'] },
- { min: 6, message: '密码长度不能小于6位', trigger: ['blur'] },
- { validator: passwordValidate, trigger: ['blur'] },
- ],
- confirmPwd: [
- { required: true, message: '请输入确认密码', trigger: ['blur'] },
- { validator: confirmPwdValide, trigger: ['blur'] },
- ],
- },
- }
- },
- computed: {
- ...mapGetters(['authUserId', 'routePrefix']),
- sendCodeBtnText() {
- return this.sendStatus === 0
- ? '发送验证码'
- : `再次发送${this.sendStatus}s`
- },
- },
- methods: {
- // 返回
- onBack() {
- this.$router.back()
- },
- // 提交
- async onSubmit() {
- try {
- await this.$refs.form.validate()
- this.onResetPassword()
- } catch (error) {
- console.log(error)
- }
- },
- // 忘记密码
- async onResetPassword() {
- try {
- await this.$http.api.clubUserReset({
- mobile: this.formData.mobile,
- verifyCode: this.formData.verifyCode,
- password: this.formData.password,
- authUserId: this.authUserId,
- })
- this.$toast('密码修改成功,请重新登录')
- setTimeout(() => {
- this.logout()
- }, 2000)
- } catch (error) {
- console.log(error)
- }
- },
- // 退出登录
- logout() {
- this.$store.dispatch('user/logout')
- this.$removeStorage(this.routePrefix, 'userInfo')
- this.backHome()
- },
- // 回到首页
- backHome() {
- window.location.href = window.location.origin + this.routePrefix
- },
- // 发送短信验证码
- async onSend() {
- if (this.sendStatus > 0) return
- // 验证手机号是否合法
- if (!isMobile(this.formData.mobile)) {
- this.$toast('请输入正确的手机号')
- return
- }
- try {
- // 发送验证码
- await this.$http.api.clubUserCodeSend({
- mobile: this.formData.mobile,
- authUserId: this.authUserId,
- type: this.formType === 'register' ? 1 : 2,
- })
- this.$toast('验证码已发送')
- // 开启倒计时
- this.countdown()
- } catch (error) {
- console.log(error)
- }
- },
- countdown() {
- this.sendStatus = 30
- this.timer = setInterval(() => {
- if (this.sendStatus === 0) {
- clearInterval(this.timer)
- return
- }
- this.sendStatus--
- }, 1000)
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- @media screen and (min-width: 768px) {
- .page {
- position: relative;
- min-height: calc(100vh - 80px - 80px);
- background-color: #fff;
- overflow: hidden;
- }
- .page-content {
- width: 518px;
- margin: 0 auto;
- margin-top: 100px;
- .verify-code {
- width: 100%;
- display: flex;
- align-items: center;
- .send {
- flex-shrink: 0;
- margin-left: 16px;
- height: 40px;
- text-align: center;
- line-height: 40px;
- width: 118px;
- background: #4093B5;
- border-radius: 4px;
- font-size: 16px;
- color: #fff;
- cursor: pointer;
- }
- }
- .submit-button {
- display: flex;
- align-items: center;
- justify-content: center;
- margin-top: 32px;
- .btn {
- text-align: center;
- width: 118px;
- height: 40px;
- border-radius: 4px;
- font-size: 16px;
- cursor: pointer;
- box-sizing: border-box;
- margin: 0 16px;
- &.back {
- border: 1px solid #4093B5;
- color: #4093B5;
- line-height: 38px;
- }
- &.submit {
- background: #4093B5;
- color: #fff;
- line-height: 40px;
- }
- }
- }
- }
- }
- @media screen and (max-width: 768px) {
- .page-content {
- padding: 10vw 4vw 0;
- .verify-code {
- width: 100%;
- display: flex;
- align-items: center;
- .send {
- flex-shrink: 0;
- margin-left: 2.4vw;
- height: 40px;
- text-align: center;
- line-height: 40px;
- width: 24.2vw;
- background: #4093B5;
- border-radius: 0.4vw;
- font-size: 3.4vw;
- color: #fff;
- cursor: pointer;
- }
- }
- .submit-button {
- margin-top: 20vw;
- .btn {
- text-align: center;
- height: 40px;
- border-radius: 0.4vw;
- font-size: 3.4vw;
- cursor: pointer;
- box-sizing: border-box;
- margin-bottom: 3.2vw;
- &.back {
- border: 1px solid #4093B5;
- color: #4093B5;
- line-height: 38px;
- }
- &.submit {
- background: #4093B5;
- color: #fff;
- line-height: 40px;
- }
- }
- }
- }
- }
- </style>
|