login.vue 10.8 KB
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 124 125 126 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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
<template>
  <el-dialog close-icon="CircleClose" center
    v-model="show" class="pcloginpop" width="450px" :append-to-body="true" :title="title"
    destroy-on-close :show-close="showClose" :close-on-click-modal="false" @close="close"
  >

    <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form" v-if="loginStatus==0">
      <el-form-item prop="username">

        <el-input
          v-model.trim="loginForm.username"
          size="large"
          auto-complete="off"
          placeholder="账号(注册时使用的邮箱/手机号码)"
        >

        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model.trim="loginForm.password"
          type="password"
          size="large" show-password
          auto-complete="off"
          placeholder="密码"
          @keyup.enter="handleLogin"
        >
        </el-input>
      </el-form-item>
      <el-form-item v-if="captchaEnabled" prop="code">
        <el-input
          v-model.trim="loginForm.code"
          size="large"
          auto-complete="off"
          placeholder="验证码"
          @keyup.enter="handleLogin"
        >
          <template #append>
            <div class="login-code">
              <img :src="codeUrl" class="login-code-img" @click="getCode">
            </div>
          </template>
        </el-input>

      </el-form-item>

      <el-form-item style="width:100%;">
        <el-button
          class="loginBtn"
          :loading="loading"
          size="large"
          type="primary"
          style="width:100%;"
          @click.prevent="handleLogin"
        >
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
      </el-form-item>
      <el-form-item>
<!--        <span style="color: #999;font-size: 12px;">*默认密码是会员号+证件号后四位+)*%</span>-->
        <div style="display: flex;justify-content: space-between;width: 100%;">
          <a class="text-primary" @click="showChangePassword">忘记密码?</a>
          <a @click="showRegister" class="text-primary">账号注册></a>
        </div>
      </el-form-item>
      <el-form-item>
        <div class="agreeLine">
          登录或注册即代表同意
          <a>《用户协议》</a>
          <a>《隐私政策》</a>
        </div>
      </el-form-item>
    </el-form>

    <div v-if="loginStatus==1">
      <div class="rItem r1" @click="goRegister(1)">
        <h3>机构用户</h3>
      </div>
      <div class="rItem r2" @click="goRegister(0)">
        <h3>个人用户</h3>
      </div>
    </div>
    <div v-if="loginStatus==2">
      <el-form ref="changePasswordRef" :model="changePasswordForm" :rules="changePasswordRules" class="login-form">
        <el-form-item prop="username">

          <el-input
              v-model.trim="changePasswordForm.username"
              size="large"
              auto-complete="off"
              placeholder="注册时使用的邮箱/手机号码"
          >

          </el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-input
              v-model.trim="changePasswordForm.code"
              size="large"
              auto-complete="off"
              placeholder="邮箱/手机验证码"
              @keyup.enter="handleLogin"
          >
            <template #append>
              <span class="text-primary" @click="sendsmsMsg">
                发送验证码
              </span>
            </template>
          </el-input>
          <div class="vcodeBox" :style="isShow?'height:240px':'height:0'">
            <Vcode :show="isShow" type="inside" @success="codeSuccess" @close="codeClose" @fail='codeFail'></Vcode>
          </div>
        </el-form-item>

        <el-form-item prop="password">
          <el-input
              v-model.trim="changePasswordForm.password"
              type="password"
              size="large" show-password
              auto-complete="off"
              placeholder="新密码"
              @keyup.enter="handleLogin"
          >
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
              v-model.trim="changePasswordForm.confirmPassword"
              type="password"
              size="large" show-password
              auto-complete="off"
              placeholder="确认密码"
          >
          </el-input>
        </el-form-item>
        <el-form-item style="width:100%;">
          <el-button
              class="loginBtn"
              :loading="loading"
              size="large"
              type="primary"
              style="width:100%;"
              @click.prevent="handleLogin"
          >
            <span>确定</span>
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<script setup>
import { getCodeImg } from '@/api/login'
import * as match from '@/apiPc/match'
import Cookies from 'js-cookie'
import useUserStore from '@/store/modules/user'
import { useRouter } from 'vue-router'
import { getCurrentInstance, ref, watch } from 'vue'
import { ElMessage,ElMessageBox} from 'element-plus'
const emit = defineEmits(['submitForm'])
const userStore = useUserStore()
const router = useRouter()
const { proxy } = getCurrentInstance()
const loginForm = ref({
  username: '',
  password: '',
  rememberMe: false,
  code: '',
  uuid: ''
})
const countDown = ref(null)
const loginRules = {
  username: [{ required: true, trigger: 'change', message: '请输入您的会员号' }],
  password: [{ required: true, trigger: 'change', message: '请输入您账号密码' }],
  code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
}

const show = ref(false)
const loginStatus = ref(0)
const title = ref('用户登录')
const showClose = ref(true)
const codeUrl = ref('')
const loading = ref(false)

// 验证码开关
const captchaEnabled = ref(true)
//忘记密码
const isShow = ref(false)
const isCodeTrue = ref(false)
const counting = ref(false)
const changePasswordForm = ref({
  username:'',
  password:'',
  confirmPassword:''
})

const open = (params) => {
  show.value = true
  showClose.value = !(params?.notShowClose || false)
  getCode()
  getCookie()
}
defineExpose({
  open
})
function handleLogin() {
  proxy.$refs.loginRef.validate(valid => {
    if (valid) {
      loading.value = true
      // 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
      if (loginForm.value.rememberMe) {
        Cookies.set('telno', loginForm.value.telno, { expires: 30 })
        Cookies.set('rememberMe', loginForm.value.rememberMe, { expires: 30 })
      } else {
        // 否则移除
        Cookies.remove('telno')
        Cookies.remove('rememberMe')
      }
      // 调用action的登录方法
      userStore.loginPc(loginForm.value).then(() => {
        // router.push({ path: redirect.value || '/index' })
        show.value = false
        emit('submitForm')
      }).catch(() => {
        loading.value = false
        // 重新获取验证码
        if (captchaEnabled.value) {
          getCode()
        }
      })
    }
  })
}
function close() {
  loginStatus.value=0
  title.value = '用户登录'
}
function showChangePassword() {
  loginStatus.value=2
  title.value = '忘记密码/密码重置'
}
function showRegister() {
  loginStatus.value=1
  title.value = '账号注册'
}
function goRegister(n) {
  if(n==0){
    show.value = false
    router.push({
      path: `/register/0`
    })
  } else {
    show.value = false
    router.push({
      path: `/register/1`
    })
  }
}
function getCode() {
  getCodeImg().then(res => {
    captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
    if (captchaEnabled.value) {
      codeUrl.value = 'data:image/gif;base64,' + res.data.img
      loginForm.value.uuid = res.data.uuid
    }
  })
}

function getCookie() {
  const telno = Cookies.get('telno')
  const rememberMe = Cookies.get('rememberMe')
  loginForm.value = {
    telno: telno === undefined ? loginForm.value.telno : telno,
    rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  }
}
function sendsmsMsg() {
  if(!changePasswordForm.value.account){
    ElMessage.error('请填写手机/邮箱')
    return
  }
  if(counting.value){
    return
  } else {
    isShow.value = true
  }
}
</script>

<style lang="scss" scoped>
.ltitle {
  border-bottom: 1px solid #e1e1e1;
  color: #1EC886;
  position: relative;
}

.ltitle::after {
  content: '';
  position: absolute;
  width: 4em;
  height: 2px;
  background: #1EC886;
  left: 0;
  bottom: -1px;
}

.loginLogo {
  display: block;
  margin: auto;
  position: absolute;
  top: -80px;
  left: 0;
  right: 0;
}

.loginBtn {height: 40px;
  background: linear-gradient(-90deg, #8623FC, #453DEA);
  border-radius: 20px;
  font-size: 18px;
  &:hover{
    //background: linear-gradient(90deg, #8623FC, #453DEA);
    box-shadow: 0 0 10px #453DEA;
  }
}


.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.login-form {
  border-radius: 6px;
  position: relative;
  background: #ffffff;
  padding: 0 25px 5px;

  .el-input {
    height: 40px;
    :deep(.el-input__wrapper){box-shadow: none;border-bottom:1px solid #E5E5E5; }
    input {
      height: 40px;
    }
  }

  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 0px;
  }
}

.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}

.login-code {
  height: 40px;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}

.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}

.login-code-img {
  height: 40px;float: right;
}

:deep(.el-input-group__append) {
  background: #fff;padding: 0;
  color: #fff;box-shadow: none;
  div{color: #fff;}
}
.agreeLine{
  a{font-weight: 600;color: #000;
    &:hover{text-decoration: underline;}
  }
}
.rItem{height: 130px;cursor: pointer;width: 350px;padding: 1px;margin:20px auto;
  h3{font-size: 30px;margin: 50px;}
  &.r1{background: url("@/assets/dance/r1b.png") no-repeat left;
    &:hover{background: url("@/assets/dance/r1.png") no-repeat left;}
  }
  &.r2{background: url("@/assets/dance/r2b.png") no-repeat left;
    &:hover{background: url("@/assets/dance/r2.png") no-repeat left;}
  }
  &:hover{color: #fff;}
}
</style>