【Vue版本 - 前端实践系列之九】登录注册界面千篇一律?教你做个炫酷的!

简介: 【Vue版本 - 前端实践系列之九】登录注册界面千篇一律?教你做个炫酷的!


html部分
<template>
  <div class="login-wrapper">
    <div :class="['login-container', type == 'login' ? 'active' : '']">
      <div class="switch-wrapper row aCenter jCenter">
        <div class="btn-wrapper row aCenter jCenter">
          <div v-if="type == 'login'" class="txt row aCenter jCenter" @click="type = 'register'">去注册</div>
          <div v-else class="txt row aCenter jCenter" @click="type ='login'">去登录</div>
        </div>
      </div>
      <div :class="['outerBox', type == 'login' ? 'active' : '']">
        <div class="container row aCenter jCenter">
          <div class="login" v-show="type == 'login'">
            <el-form :model="loginUser" status-icon :rules="loginRules" ref="loginForm">
              <img class='ld' src="@/assets/ld.png" />
              <div class="title">登录</div>
              <el-form-item prop="username">
                <el-input type='text' prefix-icon="el-icon-user" placeholder="请输入账号 / 手机号 / 邮箱" v-model="loginUser.username" />
              </el-form-item>
              <el-form-item prop="password">
                <el-input type='password' prefix-icon="el-icon-view" placeholder="请输入密码" v-model="loginUser.password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" class="btn-login" @click="login">登录</el-button>
              </el-form-item>
              <!-- <div class='w100 row aCenter jSb'>
                <el-button type="text" class='forgetPassword' @click="onOpenForgetPassword">忘记密码</el-button>
                <el-button type="text" class='register' @click="onOpenRegister">注册账号</el-button>
              </div> -->
            </el-form>
          </div>
          <div class="register" v-show="type == 'register'">
            <el-form :model="registerUser" status-icon :rules="registerRules" ref="registerForm">
              <img class="ld" src="@/assets/ld.png" />
              <div class="title">注册</div>
              <el-form-item prop="username">
                <el-input type='text' prefix-icon="el-icon-user" placeholder="请输入账号 / 手机号 / 邮箱" v-model="registerUser.username" />
              </el-form-item>
              <el-form-item prop="email">
                <el-input type='text' prefix-icon="el-icon-message" placeholder="请输入邮箱地址" v-model="registerUser.email" />
              </el-form-item>
              <el-form-item prop="mobile">
                <el-input type='number' prefix-icon="el-icon-mobile" placeholder="请输入手机号码" v-model="registerUser.mobile" />
              </el-form-item>
              <el-form-item prop="password">
                <el-input type='password' prefix-icon="el-icon-view" placeholder="请输入密码" v-model="registerUser.password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" class="btn-login" @click="register">确认注册</el-button>
              </el-form-item>
              <!-- <div class='w100 row aCenter jSb'>
                <el-button type="text" class='forgetPassword' @click="onOpenLogin">返回登录</el-button>
              </div> -->
            </el-form>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
复制代码


JS部分
<script>
import xxx from '@/api/xxx'
export default {
  name: 'login',
  data() {
    return {
      type: 'login',    // 类型判断
      loginUser: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      },
      registerUser: {
        username: '',
        password: '',
        email: '',
        mobile: ''
      },
      registerRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入手机号码', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    login() {
          this.$refs.loginForm.validate( async valid => {
              if(valid) {
                    await xxx.login(this.loginUser).then(async r => {
                        console.log('成功了')
                    }).catch(e => {
                        console.log(e)
                        this.Toast(2, '登录失败,请稍后重试')
                        return false
                    })
              } else {
                return false
              }
          })
      },
    register() {
          this.$refs.registerForm.validate(async valid => {
              if(valid) {
                    await xxx.register(this.registerUser).then(r => {
                        console.log('成功了')
                    }).catch(e => {
      console.log(e)
                        return false
                    })
              } else {
                return false
              }
          })
      },
  }
}
</script>
复制代码


css部分
<style scoped>
.login-wrapper{background-color: #ededed;display: flex;width: 100vw;height: 100vh;margin: auto;}
.login-container{background-color: #fff;position: relative;width: 1000px;height: 600px;margin: auto;overflow: hidden;border-radius: 5px;box-shadow: 0 0 10px 5px #ddd;}
.switch-wrapper{position: absolute;z-index: 99;left: 0;overflow: hidden;width: 32%;height: 100%;transition: transform 1s ease-in-out;}
.switch-wrapper::after {content: '';display: block;background-image: url('../../assets/picture.jpg');background-size: 1000px 550px;background-position: top left;width: 100%;height: 100%;overflow: hidden;transition: all 1s ease-in-out;}
.active .switch-wrapper {transform: translateX(calc(1000px - 100%));}
.active .switch-wrapper::after {background-position: top right;}
.txt{width: 100%;height: 100%;transition: all 1s ease-in-out;}
.top-wrapper{position: absolute;width: 260px;height: 168px;top: 50px;background-color: rgba(255, 255, 255,.7);padding: 10px;border-radius: 5px;}
.btn-wrapper{position: absolute;width: 100px;height: 36px;color: #fffffe;background-color: #6689e2;font-size: 15px;border-radius: 30px;cursor: pointer;flex-wrap: wrap;overflow: hidden;}
.outerBox {position: absolute;z-index: 3;left: 32%;overflow: hidden;width: 68%;height: 100%;transition: all 1s ease-in-out;}
.container {width: 100%;height: 100%;background-color: #fffffe;}
.active .outerBox {transform: translateX(calc(-1000px + 100%));}
.ld{width: 200px;height: 40px;position: absolute;right: 16px;top: 16px;}
.title{font-size: 36px;line-height: 1.5;text-align: center;margin-bottom: 30px;color: #666;}
.btn-login{width: 100%;}
.row{display: flex;display: -webkit-flex;flex-direction: row;}
.column{display: flex;display: -webkit-flex;flex-direction: column;}
.aCenter{align-items: center;}
.jCenter{justify-content: center;}
</style>


相关文章
|
7月前
|
JavaScript 前端开发 Java
制造业ERP源码,工厂ERP管理系统,前端框架:Vue,后端框架:SpringBoot
这是一套基于SpringBoot+Vue技术栈开发的ERP企业管理系统,采用Java语言与vscode工具。系统涵盖采购/销售、出入库、生产、品质管理等功能,整合客户与供应商数据,支持在线协同和业务全流程管控。同时提供主数据管理、权限控制、工作流审批、报表自定义及打印、在线报表开发和自定义表单功能,助力企业实现高效自动化管理,并通过UniAPP实现移动端支持,满足多场景应用需求。
725 1
|
3月前
|
存储 前端开发 安全
实现“永久登录”:针对蜻蜓Q系统的用户体验优化方案(前端uni-app+后端Laravel详解)-优雅草卓伊凡
实现“永久登录”:针对蜻蜓Q系统的用户体验优化方案(前端uni-app+后端Laravel详解)-优雅草卓伊凡
223 5
|
8月前
|
移动开发 前端开发 JavaScript
Vue与React两大前端框架的主要差异点
以上就是Vue和React的主要差异点,希望对你有所帮助。在选择使用哪一个框架时,需要根据项目的具体需求和团队的技术栈来决定。
507 83
|
7月前
|
JavaScript 前端开发 编译器
Vue与TypeScript:如何实现更强大的前端开发
Vue.js 以其简洁的语法和灵活的架构在前端开发中广受欢迎,而 TypeScript 作为一种静态类型语言,为 JavaScript 提供了强大的类型系统和编译时检查。将 Vue.js 与 TypeScript 结合使用,不仅可以提升代码的可维护性和可扩展性,还能减少运行时错误,提高开发效率。本文将介绍如何在 Vue.js 项目中使用 TypeScript,并通过一些代码示例展示其强大功能。
345 22
|
9月前
|
人工智能 JavaScript 前端开发
Vue 性能革命:揭秘前端优化的终极技巧;Vue优化技巧,解决Vue项目卡顿问题
Vue在处理少量数据和有限dom的情况下技术已经非常成熟了,但现在随着AI时代的到来,海量数据场景会越来越多,Vue优化技巧也是必备技能。 博客不应该只有代码和解决方案,重点应该在于给出解决方案的同时分享思维模式,只有思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
|
10月前
|
JSON 前端开发 数据可视化
前端开发者狂喜!30K star开源组件库,界面美观度/开发速度双碾压!
嗨,大家好,我是小华同学。Layui 是一款开源前端 UI 组件库,具有极简设计、强大功能和卓越性能,支持布局、表单、表格、弹层等六大模块,组件高度可定制。它无需复杂构建工具,直接面向浏览器开发,极大提升开发效率与界面美观度。适合新手和老手,快来试试吧!
528 0
|
存储 人工智能 前端开发
前端大模型应用笔记(三):Vue3+Antdv+transformers+本地模型实现浏览器端侧增强搜索
本文介绍了一个纯前端实现的增强列表搜索应用,通过使用Transformer模型,实现了更智能的搜索功能,如使用“番茄”可以搜索到“西红柿”。项目基于Vue3和Ant Design Vue,使用了Xenova的bge-base-zh-v1.5模型。文章详细介绍了从环境搭建、数据准备到具体实现的全过程,并展示了实际效果和待改进点。
1110 14
|
JavaScript 前端开发 程序员
前端学习笔记——node.js
前端学习笔记——node.js
379 0
|
SpringCloudAlibaba JavaScript 前端开发
谷粒商城笔记+踩坑(2)——分布式组件、前端基础,nacos+feign+gateway+ES6+vue脚手架
分布式组件、nacos注册配置中心、openfegin远程调用、网关gateway、ES6脚本语言规范、vue、elementUI
谷粒商城笔记+踩坑(2)——分布式组件、前端基础,nacos+feign+gateway+ES6+vue脚手架
|
人工智能 自然语言处理 运维
前端大模型应用笔记(一):两个指令反过来说大模型就理解不了啦?或许该让第三者插足啦 -通过引入中间LLM预处理用户输入以提高多任务处理能力
本文探讨了在多任务处理场景下,自然语言指令解析的困境及解决方案。通过增加一个LLM解析层,将复杂的指令拆解为多个明确的步骤,明确操作类型与对象识别,处理任务依赖关系,并将自然语言转化为具体的工具命令,从而提高指令解析的准确性和执行效率。
521 6