zdppy_api+vue3实现前后端分离的登录功能

实现思路

1、准备zdppy的开发环境
2、使用amauth提供的低代码接口,直接生成login登录接口
3、使用之前开发的登录模板渲染登录界面
4、给登录按钮绑定点击事件
5、给用户名和密码的输入框双向绑定数据
6、使用axios在登录按钮点击的时候,携带用户数据发送POST登录请求
7、处理登录接口的响应

完整代码

后端代码

.env
ZDPPY_MCRUD_HOST=127.0.0.1
ZDPPY_MCRUD_PORT=3306
ZDPPY_MCRUD_USERNAME=root
ZDPPY_MCRUD_PASSWORD=zhangdapeng520
ZDPPY_MCRUD_DATABASE=zdppy_demo

main.py
import contextlib

import api
import mcrud
import amauth
import env

env.load(".env")
db = mcrud.new_env()

amauth.data.init(db, is_init_role=True, is_init_auth=True)


@contextlib.asynccontextmanager
async def lifespan(app):
    yield {"db": db}


app = api.Api(
    routes=[
        api.resp.post("/login", amauth.user.login),
    ],
    middleware=[
        api.middleware.cors(),
    ],
    lifespan=lifespan,
)

if __name__ == '__main__':
    app.run()


前端代码

package.json
{
  "name": "tailwindcss_demo",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@ant-design/icons-vue": "^7.0.1",
    "ant-design-vue": "^4.2.3",
    "axios": "^1.7.2",
    "dayjs": "^1.11.11",
    "vue": "^3.4.29",
    "vue-router": "^4.4.0"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.0.5",
    "autoprefixer": "^10.4.19",
    "postcss": "^8.4.38",
    "tailwindcss": "^3.4.4",
    "vite": "^5.3.1"
  }
}

vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
})

tailwind.config.js
/** @type {import('tailwindcss').Config} */
export default {
    content: ["./src/**/*.{html,js,vue}"],
    theme: {
        extend: {},
    },
    plugins: [],
}
postcss.config.js
export default {
    plugins: {
      tailwindcss: {},
      autoprefixer: {},
    }
  }
index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + Vue</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

src/main.js
import {createApp} from 'vue'
import './style.css'
import 'ant-design-vue/dist/reset.css';

import Antd from 'ant-design-vue';
import App from './App.vue';

const app = createApp(App)
app.use(Antd)
app.mount('#app')

src/style.css
@tailwind base;
@tailwind components;
@tailwind utilities;
src/App.vue
<script setup>
import {message} from "ant-design-vue";
import {ref} from "vue";
import axios from "axios";

const username = ref("")
const password = ref("")

const onLoginButtonClick = () => {
  axios.post('http://127.0.0.1:8888/login', {
    username: username.value,
    password: password.value
  })
      .then(function (response) {
        message.success("login success")
        console.log("response=", response)
        const data = response.data.data
        console.log("data=", data)
        console.log("token=", data.token)
      })
      .catch(function (error) {
        console.log(error);
        message.error(error)
      });
}
</script>
<template>
  <section>
    <span v-for="i in 297" :key="i"></span>
    <div class="signin">
      <div class="content">
        <h2>用户登录</h2>
        <div class="form">
          <div class="inputBox">
            <input type="text" v-model="username"> <i>账号</i>
          </div>
          <div class="inputBox">
            <input type="password" v-model="password"> <i>密码</i>
          </div>
          <div class="links">
            <a href="#">忘记密码</a>
            <a href="#">注册</a>
          </div>
          <div class="inputBox">
            <input type="submit" value="立即登录" @click.prevent="onLoginButtonClick">
          </div>
        </div>
      </div>
    </div>
  </section>
</template>
<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Quicksand', sans-serif;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #000;
}

section {
  position: absolute;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  overflow: hidden;
}

section::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(#000, #0f0, #000);
  animation: animate 5s linear infinite;
}

@keyframes animate {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(100%);
  }
}

section span {
  position: relative;
  display: block;
  width: calc(6.25vw - 2px);
  height: calc(6.25vw - 2px);
  background: #181818;
  z-index: 2;
  transition: 1.5s;
}

section span:hover {
  background: #0f0;
  transition: 0s;
}

section .signin {
  position: absolute;
  width: 400px;
  background: #222;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  border-radius: 4px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 9);
}

section .signin .content {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 40px;
}

section .signin .content h2 {
  font-size: 2em;
  color: #0f0;
  text-transform: uppercase;
}

section .signin .content .form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 25px;
}

section .signin .content .form .inputBox {
  position: relative;
  width: 100%;
}

section .signin .content .form .inputBox input {
  position: relative;
  width: 100%;
  background: #333;
  border: none;
  outline: none;
  padding: 25px 10px 7.5px;
  border-radius: 4px;
  color: #fff;
  font-weight: 500;
  font-size: 1em;
}

section .signin .content .form .inputBox i {
  position: absolute;
  left: 0;
  padding: 15px 10px;
  font-style: normal;
  color: #aaa;
  transition: 0.5s;
  pointer-events: none;
}

.signin .content .form .inputBox input:focus ~ i,
.signin .content .form .inputBox input:valid ~ i {
  transform: translateY(-7.5px);
  font-size: 0.8em;
  color: #fff;
}

.signin .content .form .links {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.signin .content .form .links a {
  color: #fff;
  text-decoration: none;
}

.signin .content .form .links a:nth-child(2) {
  color: #0f0;
  font-weight: 600;
}

.signin .content .form .inputBox input[type="submit"] {
  padding: 10px;
  background: #0f0;
  color: #000;
  font-weight: 600;
  font-size: 1.35em;
  letter-spacing: 0.05em;
  cursor: pointer;
}

input[type="submit"]:active {
  opacity: 0.6;
}

@media (max-width: 900px) {
  section span {
    width: calc(10vw - 2px);
    height: calc(10vw - 2px);
  }
}

@media (max-width: 600px) {
  section span {
    width: calc(20vw - 2px);
    height: calc(20vw - 2px);
  }
}
</style>
<script setup lang="ts">
</script>

效果预览

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/758347.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Linux部署wordpress站点

先安装宝塔面板 yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec 因为wordpress需要php&#xff0c;mysql&#xff0c;apache &#xff0c;httpd环境 参考&#xff1a;Linux 安装宝塔…

【学习】使用PyTorch训练与评估自己的ResNet网络教程

参考&#xff1a;保姆级使用PyTorch训练与评估自己的ResNet网络教程_训练自己的图像分类网络resnet101 pytorch-CSDN博客 项目地址&#xff1a;GitHub - Fafa-DL/Awesome-Backbones: Integrate deep learning models for image classification | Backbone learning/comparison…

HBase Shell命令详解

HBase Shell命令 一、 命名空间 命名空间是 HBase 中用于组织表的一种逻辑容器&#xff0c;类似于文件系统中的文件夹。 Namespace允许用户在 HBase 中更好地管理和组织表&#xff0c;以及提供了隔离和命名约定。 1. 创建命名空间 命令&#xff1a; create_namespace name…

【scrapy】1.scrapy爬虫入门

一、scrapy爬虫框架 Scrapy 框架是一个基于Twisted的一个异步处理爬虫框架&#xff0c;应用范围非常的广泛&#xff0c;常用于数据采集、网络监测&#xff0c;以及自动化测试等。 scrapy框架包括5个主要的组件&#xff1a; Scheduler&#xff1a;事件调度器&#xff0c;它负…

机器学习引领教育革命:智能教育的新时代

&#x1f4dd;个人主页&#x1f339;&#xff1a;Eternity._ &#x1f339;&#x1f339;期待您的关注 &#x1f339;&#x1f339; ❀目录 &#x1f4d2;1. 引言&#x1f4d9;2. 机器学习在教育中的应用&#x1f31e;个性化学习&#x1f319;评估与反馈的智能化⭐教学资源的优…

Lua: 轻量级多用途脚本语言

Lua 是一种高效而轻量级的脚本语言&#xff0c;具备强大的扩展性和灵活性&#xff0c;广泛应用于游戏开发、嵌入式系统、Web 应用等多个领域。本文将深入探讨 Lua 的特性、应用场景以及如何使用 Lua 进行开发。 1. Lua 的起源与发展 Lua 的发展始于上世纪90年代初&#xff0c;…

Java单体架构项目_云霄外卖-特殊点

项目介绍&#xff1a; 定位&#xff1a; 专门为餐饮企业&#xff08;餐厅、饭店&#xff09;定制的一款软件商品 分为&#xff1a; 管理端&#xff1a;外卖商家使用 用户端&#xff08;微信小程序&#xff09;&#xff1a;点餐用户使用。 功能架构&#xff1a; &#xff08…

哎呀呀 又迟到了,还被抓住了,面面相觑 害怕

网络编程 我应该迟点来&#xff0c;唠嗑到35嘿嘿 心疼自己早起呜呜呜&#xff0c;幸运的是35开讲 计算机网络 分4层 应用层&#xff08;Application Layer&#xff09;&#xff1a; 应用层是用户接口和网络应用程序的接口。它允许用户访问网络服务&#xff0c;并支持各种应用程…

Windows系统下文件夹权限详解

文章目录 问题描述文件夹属性 问题描述 今天在Win10系统下&#xff0c;实现文件夹设置权限&#xff0c;具体的方案的涉及到我们公司内部的一款加密软件&#xff0c;不太方便透漏&#xff0c;借此机会&#xff0c;我也重新的回顾下windows系统下的文件夹权限 文件夹属性 打开…

[C++][设计模式][中介者模式]详细讲解

目录 1.动机2.模式定义3.要点总结 1.动机 在软件构建过程中&#xff0c;经常会出现多个对象相互关联的情况&#xff0c;对象之间常常会维持一种复杂的引用关系&#xff0c;如果遇到一些需求的更改&#xff0c;这种直接的引用关系将面临不断的变化在这种情况下&#xff0c;可以…

【小沐学AI】Python实现语音识别(whisper+HuggingFace)

文章目录 1、简介1.1 whisper 2、HuggingFace2.1 安装transformers2.2 Pipeline 简介2.3 Tasks 简介2.3.1 sentiment-analysis2.3.2 zero-shot-classification2.3.3 text-generation2.3.4 fill-mask2.3.5 ner2.3.6 question-answering2.3.7 summarization2.3.8 translation 3、…

PyTorch Tensor进阶操作指南(二):深度学习中的关键技巧

本文主要讲tensor的裁剪、索引、降维和增维 Tensor与numpy互转、Tensor运算等&#xff0c;请看这篇文章 目录 9.1、首先看torch.squeeze()函数&#xff1a; 示例9.1&#xff1a;&#xff08;基本的使用&#xff09; 小技巧1&#xff1a;如何看维数 示例9.2&#xff1a;&a…

ISO15765-2 道路车辆——通过控制器局域网(CAN)进行诊断通信 (翻译版)(万字长文)

ISO15765-2 道路车辆——通过控制器局域网&#xff08;CAN&#xff09;进行诊断通信 (翻译版)(万字长文) 文章目录 ISO15765-2 道路车辆——通过控制器局域网&#xff08;CAN&#xff09;进行诊断通信 (翻译版)(万字长文)第二部分&#xff1a;传输协议和网络层服务前言Foreword…

在navicat对mysql声明无符号字段

1.无符号设置 在 MySQL 中&#xff0c;我们可以使用 UNSIGNED 属性来设置列的无符号属性&#xff0c;这意味着该列只能存储非负整数值。对于一些需要存储正整数的列&#xff0c;比如年龄、数量等&#xff0c;使用 UNSIGNED 属性可以提高数据存储和查询的效率&#xff0c;并且能…

浅谈一下VScode如何配置C环境

1.这几天突然发现在VScode写C程序比在DevC效果更好&#xff0c;因为在VScode中写代码有代码补全功能。所以我突然对在VScode中配置C环境变量产生了兴趣。 2.不过在VScode中配置C环境要是按照官方的来配置有点麻烦。 3.我这里有一个直接配置VScode中C环境变量的应用。 前提是…

原来“山水博客“的分类也是可以拖动排序的

这二天一直用“山水博客”写文章&#xff0c;发现一个问题&#xff0c;好象它的分类不能调整位置&#xff0c;这可是个大bug。首先&#xff0c;界面上没发现拖动相关按钮&#xff1b;如果按住分类拖动&#xff0c;会成这样&#xff1a; 后来仔细看了它的文档&#xff0c;发现它…

智能社区服务小程序的设计

管理员账户功能包括&#xff1a;系统首页&#xff0c;个人中心&#xff0c;用户管理&#xff0c;房屋信息管理&#xff0c;住户信息管理&#xff0c;家政服务管理&#xff0c;家政预约管理&#xff0c;报修信息管理 微信端账号功能包括&#xff1a;系统首页&#xff0c;房屋信…

水果品牌网站开展如何拓宽渠道

对大多数人来说&#xff0c;零售买水果只在乎是买什么水果、哪个产地、价格等因此&#xff0c;对品牌的依赖度相对较低。但对于水果品牌公司来说&#xff0c;货好仅是基本&#xff0c;还需要将品牌发展出去、能获取准属性客户和转化路径。 与零售不同&#xff0c;批发生意或是…

在vs上远程连接Linux写服务器项目并启动后,可以看到服务启动了,但是通过浏览器访问该服务提示找不到页面

应该是被防火墙挡住了&#xff0c;查看这个如何检查linux服务器被防火墙挡住 • Worktile社区 和这个关于Linux下Nginx服务启动&#xff0c;通过浏览器无法访问的问题_linux无法访问nginx-CSDN博客 的提示之后&#xff0c;知道防火墙开了&#xff0c;想着可能是我写的服务器的…

大数据面试题之Spark(1)

目录 Spark的任务执行流程 Spark的运行流程 Spark的作业运行流程是怎么样的? Spark的特点 Spark源码中的任务调度 Spark作业调度 Spark的架构 Spark的使用场景 Spark on standalone模型、YARN架构模型(画架构图) Spark的yarn-cluster涉及的参数有哪些? Spark提交jo…