vue3 antv 静态登录页面

效果图

复制代码
<template>
<!-- 内容区域 -->
  <div class="main">
    <div class="from">
    <!-- 表单 model是antv里边的绑定表单数据 -->
    <a-form :model="formState" ref="formRef">
      <!-- 切换 -->
      <a-tabs :activeKey="data.customActiveKey" @change="handleTabClick">
        <a-tab-pane key="tab1" tab="账号密码登录">
          <a-form-item name="account" :rules="[{required:true,message:'请输入你的用户名'},{validator:handlUsernameOrEmail}]">
              <a-input size="large" type="text" placeholder="账户名邮箱地址" v-model:value="formState.account">
                <!-- prefix:是放在input前边 vue2 写插槽    <template slot="prefix"><user-outlined /></template> -->
                 <template #prefix><user-outlined /></template>
              </a-input>
          </a-form-item>
          <a-form-item  name = "password" :rules="[{required:true,message:'请输入你的密码'},]">
            <a-input size="large" type="password" placeholder="密码" autocomplete="false" v-model:value="formState.password">
               <template #prefix><lock-outlined /></template>
            </a-input>
          </a-form-item>
        </a-tab-pane>
           <a-tab-pane key="tab2" tab="手机号登录">
            <a-form-item>
                <a-input size="large" type="text" placeholder="手机号">
                    <template #prefix><mobile-outlined/></template>
                </a-input>
            </a-form-item>
            <a-row :gutter="16">
              <a-col :span = "16">
                <a-input size="large" type="text" placeholder="验证码">
                  <template #prefix><mail-outlined /></template>
                </a-input>
              </a-col>
              <a-col :span="8">
                <!-- blcok占据一行 -->
                <a-button blcok type="primary">获取验证码</a-button>
              </a-col>
            </a-row>
          </a-tab-pane>
      </a-tabs>

      <a-form-item class="autologin">
        <a-checkbox v-model:checked="formState.rememberMe">自动登录</a-checkbox>
        <router-link to="/user/forget">忘记密码</router-link>
      </a-form-item>

      <a-form-item>
          <a-button size="large" type="primary" htmlType="submit" block @click="submitFn">登录</a-button>
      </a-form-item>

      <div class="user-login-other">
        <span>其他登录方式</span>
        <router-link :to="{ name:'register'}">注册账户</router-link>
      </div>
    </a-form>
    </div>
  </div>
</template>
<script setup>
import { UserOutlined,LockOutlined,MobileOutlined,MailOutlined } from '@ant-design/icons-vue';
import { reactive, ref, onMounted } from "vue";
const formState = reactive({
  account: "",
  password:'',
  rememberMe:true,
});
const data = reactive({
// 绑定tab的key值
  customActiveKey:"tab1",
})
const formRef = ref();
onMounted(()=>{
  console.log('ref',formRef.value);
})
// 登录事件
async function submitFn(){
  if(data.customActiveKey === 'tab1'){//根据tab1来效验不同的内容
    try{
      const values = await formRef.value.validateFields(["account","password",]);//效验账号和密码
      console.log('succes',values);
      // 根据tab切换的情况,执行不同的登录流程
    }catch(error){
      console.log('error',values);
    } 
  }

}
// 效验
function handlUsernameOrEmail(rules,value,){
  const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+){1,2}$/;
  if(regex.test(value)){
    return Promise.resolve('成功');
  }else {
    return Promise.reject('账号是邮箱,请输入正确的邮箱');
  }
}
// 点击事件
function handleTabClick(key){
  data.customActiveKey = key;
}
</script>
<style lang="less" scoped>
.main{
  display: flex;
  justify-content: center;
  align-items: center;
}
.from{
  width: 450px;
  padding: 25px;
  border-radius: 10px;
  background-color:rgba(233,233,233,0.7) ;
}
:deep(.autologin .ant-form-item-control-input-content), .user-login-other{
  display: flex;
  justify-content: space-between;
}
</style>
相关推荐
IT_Octopus24 分钟前
【零基础入门 LLM 开发 · Day 11】:ChatOpenAI vs init_chat_model——一行换供应商
java·前端·javascript
柚yuzumi26 分钟前
React 19 Hooks 入门:函数组件的四大法宝 (useState / useEffect / useRef / useContext)
前端·javascript·架构
deli00730 分钟前
撒下 200 个种子点,平面为什么自己长成蜂窝?Voronoi 图实验室
前端
King禅39 分钟前
JavaScript 调试实战指南:从 console.log 到 DevTools 深度运用
javascript
大文说跨境40 分钟前
多账号环境隔离方案技术选型:指纹浏览器、VPS 与云手机的三种架构对比
java·开发语言·前端
咕白m62542 分钟前
使用 C# 将 TIFF 转换为 PDF
前端·c#
全栈项目管理程序猿44 分钟前
ArcGIS JS 基础教程(28):图层渲染顺序管理
前端·javascript
huakoh1 小时前
MCP 工具报错走哪条通道:三条探针的最小复现检查
前端
用户033307413951 小时前
ParadeDB 的 pg_search 0.26 把十词 BM25 搜索从 129ms 降到 29ms
前端
不爱说话郭德纲1 小时前
从“点点点”到一键出包:我把 uni-app x Android 离线打包做成了脚本
android·前端·uni-app