5.2 创建个人中心页面-前端部分

news/2024/5/5 20:25:59/文章来源:https://blog.csdn.net/qq_41046821/article/details/126699953

😊如果写的可以帮到你,可以点个赞吗,你的支持就是我写下去的动力。😊

本文阅读大概 10 分钟, 自己写加思考大概 1 ~ 2 小时。建议:代码可以手抄, 但不要复制。


1. 整体框架

在这里插入图片描述


2. 前端页面布局

使用 bootstrap 的 grids system 进行布局。页面规划如下:


在这里插入图片描述


bootstrap 的网址搜索 grids system

一行分为12份,左边3份,为头像;右边9份,白色区域 cards,加上按钮创建 bot,获取 Bot 列表

views.user.bot.UserBotIndexView.vue 下修改,实现基本的个人 bot 信息展示。

<template><div class="container"><div class="row"><div class="col-3"><div class="card" style="margin-top: 20px;"><div class="card-body"><img :src="$store.state.user.photo" alt="" style="width: 100%;"></div></div></div><div class="col-9"><div class="card" style="margin-top: 20px;"><div class="card-header"><span style="font-size: 130%;">我的Bot</span><button type="button" class="btn btn-primary float-end">创建Bot</button></div><div class="card-body"><thead><tr><th>名称</th><th>创建时间</th><th>操作</th></tr><tbody><tr><td>{{ bot.title }}</td><td>{{ bot.createtime }}</td><td><button type="button" class="btn btn-secondary" style="margin-right: 10px;">修改</button><button type="button" class="btn btn-danger">删除</button></td></tr></tbody></thead></div></div></div></div></div></template>

实现 refresh_bot,获取上节课的 API: /user/bot/getlist/ 查询 bot 列表,通过获取后端信息把数据展示在前端上。

<script>
import { ref, reactive } from 'vue'
import $ from 'jquery'
import { useStore } from 'vuex'export default {const store = useStore();const refresh_bots = () => {$.ajax({url: "http://127.0.0.1:8080/user/bot/getlist/",type: "get",headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {bots.value = resp;}})}refresh_bots();}
}
</script>

获取用户信息成功:


在这里插入图片描述

3. 前端页面创建、修改、删除 Bot

3.1 创建一个 Bot

在点击 创建Bot 按钮的时候需要一个弹窗。在 bootstrap 中寻找一个 modals

views.user.bot.UserBotIndexView.vue 下修改,增加一个模态框,然后丰富模态框的内容。

<template><div class="container"><div class="row"><div class="col-3"><div class="card" style="margin-top: 20px;"><div class="card-body"><img :src="$store.state.user.photo" alt="" style="width: 100%;"></div></div></div><div class="col-9"><div class="card" style="margin-top: 20px;"><div class="card-header"><span style="font-size: 130%;">我的Bot</span><button type="button" class="btn btn-primary float-end">创建Bot</button>//增加一个模态框<div class="modal fade" id="add-bot-btn" tabindex="-1"><div class="modal-dialog modal-xl"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">创建Bot</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><div class="mb-3"><label for="add-bot-title" class="form-label">名称</label><input v-model="botadd.title" type="text" class="form-control" id="add-bot-title" placeholder="请输入Bot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">简介</label><textarea v-model="botadd.sescription" class="form-control" id="add-bot-description" rows="3" placeholder="请输入Bot简介"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">代码</label><textarea v-model="botadd.content" class="form-control" id="add-bot-content" rows="3" placeholder="请输入Bot代码"></textarea></div></div><div class="modal-footer">//增加报错信息<div class="error-message">{{ botadd.error_message }}</div><button type="button" class="btn btn-primary" @click="add_bot">创建</button><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button></div></div></div></div></div><div class="card-body"><thead><tr><th>名称</th><th>创建时间</th><th>操作</th></tr><tbody><tr><td>{{ bot.title }}</td><td>{{ bot.createtime }}</td><td><button type="button" class="btn btn-secondary" style="margin-right: 10px;">修改</button><button type="button" class="btn btn-danger">删除</button></td></tr></tbody></thead></div></div></div></div></div></template>

增加一个 add_bot 函数:

<script>
import { ref, reactive } from 'vue'
import $ from 'jquery'
import { useStore } from 'vuex'export default {const store = useStore();const botadd = reactive({title: "",description: "",content: "",error_message: "",});const refresh_bots = () => {$.ajax({url: "http://127.0.0.1:8080/user/bot/getlist/",type: "get",headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {bots.value = resp;}})}refresh_bots();//创建一个 botconst add_bot = () => {botadd.error_message = "";$.ajax({url: "http://127.0.0.1:8080/user/bot/add/",type: "post",data: {title: botadd.title,description: botadd.description,content: botadd.content,},headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {if (resp.error_message === "success") {botadd.title = "";botadd.description = "";botadd.content = "";Modal.getInstance("#add-bot-btn").hide();refresh_bots();} else {botadd.error_message = resp.error_message;}}})}return {bots,botadd,add_bot,}}
}
</script>

创建完成后需要绑定前端的信息。在前面的地方加上 v-model,同时增加一个 触发事件。

<div class="modal-body"><div class="mb-3"><label for="add-bot-title" class="form-label">名称</label><input v-model="botadd.title" type="text" class="form-control" id="add-bot-title" placeholder="请输入Bot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">简介</label><textarea v-model="botadd.sescription" class="form-control" id="add-bot-description" rows="3" placeholder="请输入Bot简介"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">代码</label><textarea v-model="botadd.content" class="form-control" id="add-bot-content" rows="3" placeholder="请输入Bot代码"></textarea></div></div><div class="modal-footer">//增加报错信息<div class="error-message">{{ botadd.error_message }}</div><button type="button" class="btn btn-primary" @click="add_bot">创建</button><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button></div>

在这里插入图片描述


如果创建 Bot 的时候时间出现问题:在后端的 pojo 里修改,加上时区:

package com.kob.backend.pojo;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.util.Date;@Data
@NoArgsConstructor
@AllArgsConstructorpublic class Bot {@TableId(type = IdType.AUTO)private Integer id; //在pojo里最好用Integer,否则会报警告private Integer userId; //pojo里要用驼峰命名法和数据库的下划线对应private String title;private String description;private String Content;private Integer rating;@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")private Date createtime;@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")private Date modifytime;
}

成功效果如下:


在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


3.2 删除一个 Bot

增加一个 删除 bot 的函数:

<script>
import { ref, reactive } from 'vue'
import $ from 'jquery'
import { useStore } from 'vuex'export default {const store = useStore();const botadd = reactive({title: "",description: "",content: "",error_message: "",});const refresh_bots = () => {$.ajax({url: "http://127.0.0.1:8080/user/bot/getlist/",type: "get",headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {bots.value = resp;}})}refresh_bots();//创建一个 botconst add_bot = () => {botadd.error_message = "";$.ajax({url: "http://127.0.0.1:8080/user/bot/add/",type: "post",data: {title: botadd.title,description: botadd.description,content: botadd.content,},headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {if (resp.error_message === "success") {botadd.title = "";botadd.description = "";botadd.content = "";Modal.getInstance("#add-bot-btn").hide();refresh_bots();} else {botadd.error_message = resp.error_message;}}})}//删除一个 botconst remove_bot = (bot) => {$.ajax({url: "http://127.0.0.1:8080/user/bot/remove/",type: "post",data: {bot_id: bot.id,},headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {console.log(resp);if (resp.error_message === "success") {refresh_bots();}}})}return {bots,botadd,add_bot,remove_bot,}}
}
</script>

同时需要在上文绑定 删除 按钮。

<div class="card-body"><thead><tr><th>名称</th><th>创建时间</th><th>操作</th></tr><tbody><tr><td>{{ bot.title }}</td><td>{{ bot.createtime }}</td><td><button type="button" class="btn btn-secondary" style="margin-right: 10px;">修改</button><button type="button" class="btn btn-danger" @click="remove_bot(bot)">删除</button></td></tr></tbody></thead></div>

如果删除的时候提示没有权限,可能是因为后端的 RemoveServiceImpl.java 文件出错,在里面修改即可。

成功效果:


在这里插入图片描述


在这里插入图片描述


3.3 修改一个 Bot

views.user.bot.UserBotIndexView.vue 下修改。

<script>
import { ref, reactive } from 'vue'
import $ from 'jquery'
import { useStore } from 'vuex'export default {const store = useStore();const botadd = reactive({title: "",description: "",content: "",error_message: "",});const refresh_bots = () => {$.ajax({url: "http://127.0.0.1:8080/user/bot/getlist/",type: "get",headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {bots.value = resp;}})}refresh_bots();//创建一个 botconst add_bot = () => {botadd.error_message = "";$.ajax({url: "http://127.0.0.1:8080/user/bot/add/",type: "post",data: {title: botadd.title,description: botadd.description,content: botadd.content,},headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {if (resp.error_message === "success") {botadd.title = "";botadd.description = "";botadd.content = "";Modal.getInstance("#add-bot-btn").hide();refresh_bots();} else {botadd.error_message = resp.error_message;}}})}//删除一个 botconst remove_bot = (bot) => {$.ajax({url: "http://127.0.0.1:8080/user/bot/remove/",type: "post",data: {bot_id: bot.id,},headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {console.log(resp);if (resp.error_message === "success") {refresh_bots();}}})}const update_bot = (bot) => {botadd.error_message = "";$.ajax({url: "http://127.0.0.1:8080/user/bot/update/",type: "post",data: {bot_id: bot.id,title: bot.title,description: bot.description,content: bot.content,},headers: {Authorization: "Bearer " + store.state.user.token,},success(resp) {if (resp.error_message === "success") {Modal.getInstance('#update-bot-modal-' + bot.id).hide();refresh_bots();} else {botadd.error_message = resp.error_message;}}})}return {bots,botadd,add_bot,remove_bot,update_bot,}}
}
</script>

修改每一个 bot 的时候需要有对应单独的一个模态框。

<template><div class="container"><div class="row"><div class="col-3"><div class="card" style="margin-top: 20px;"><div class="card-body"><img :src="$store.state.user.photo" alt="" style="width: 100%;"></div></div></div><div class="col-9"><div class="card" style="margin-top: 20px;"><div class="card-header"><span style="font-size: 130%;">我的Bot</span><button type="button" class="btn btn-primary float-end" data-bs-toggle="modal" data-bs-target="#add-bot-btn">创建Bot</button><div class="modal fade" id="add-bot-btn" tabindex="-1"><div class="modal-dialog modal-xl"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">创建Bot</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><div class="mb-3"><label for="add-bot-title" class="form-label">名称</label><input v-model="botadd.title" type="text" class="form-control" id="add-bot-title" placeholder="请输入Bot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">简介</label><textarea v-model="botadd.sescription" class="form-control" id="add-bot-description" rows="3" placeholder="请输入Bot简介"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">代码</label><VAceEditor</div></div><div class="modal-footer"><div class="error-message">{{ botadd.error_message }}</div><button type="button" class="btn btn-primary" @click="add_bot">创建</button><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button></div></div></div></div></div><div class="card-body"><table class="table table-hover"><thead><tr><th>名称</th><th>创建时间</th><th>操作</th></tr></thead><tbody><tr v-for="bot in bots" :key="bot.id"><td>{{ bot.title }}</td><td>{{ bot.createtime }}</td><td><button type="button" class="btn btn-secondary" style="margin-right: 10px;" data-bs-toggle="modal" :data-bs-target="'#update-bot-modal-' + bot.id">修改</button><button type="button" class="btn btn-danger" @click="remove_bot(bot)">删除</button><div class="modal fade" :id="'update-bot-modal-' + bot.id" tabindex="-1"><div class="modal-dialog modal-xl"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">修改Bot</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><div class="mb-3"><label for="add-bot-title" class="form-label">名称</label><input v-model="bot.title" type="text" class="form-control" id="add-bot-title" placeholder="请输入Bot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">简介</label><textarea v-model="bot.sescription" class="form-control" id="add-bot-description" rows="3" placeholder="请输入Bot简介"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">代码</label></div></div><div class="modal-footer"><div class="error-message">{{ bot.error_message }}</div><button type="button" class="btn btn-primary" @click="update_bot(bot)">保存修改</button><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button></div></div></div></div></td></tr></tbody></table></div></div></div></div></div></template>

成功效果如下:


在这里插入图片描述


3.4 实现代码框

  • 在 vue 界面添加依赖 vue3-ace-editor
  • 添加组件
import { VAceEditor } from 'vue3-ace-editor';
import ace from 'ace-builds';
ace.config.set("basePath", "https://cdn.jsdelivr.net/npm/ace-builds@" + require('ace-builds').version + "/src-noconflict/")
<VAceEditorv-model:value="botadd.content"@init="editorInit"lang="c_cpp"theme="textmate"style="height: 300px" />

在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


代码地址

King of Bots

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

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

相关文章

达梦数据库图形化工具

图形化工具列表 (1)DM数据库配置助手 (2)DM服务查看器 (3)DM管理工具 (4)DM控制台工具 (5)DM数据库迁移工具 (6)DM性能监测工具图形化工具详解 界面展示DM数据库配置助手[dmdba@localhost tool]$ ./dbca.sh DM服务查看器DM管理工具DM控制台工具DM数据库迁移工具DM性能监测工具功…

马拉车算法

这篇博客写的非常清晰 https://zhuanlan.zhihu.com/p/549242325 给定一个字符串,问有多少个以 k,f,c 结尾的回文子串。#include<bits/stdc++.h> using namespace std; #define lowbit(x) x&(-x) #define ll long long const int maxn=1e6+5; int n,sum; ll len[maxn…

22-09-04 西安 谷粒商城(01)MySQL主从复制、MyCat读写分离、MyCat分库分表

人人尽说江南好&#xff0c;游人只合江南老。 春水碧于天&#xff0c;画船听雨眠。 MySQL主从复制 mysql主从复制&#xff1a;分摊读写压力&#xff08;cpu计算压力&#xff09; 写交给主库&#xff0c;读有主从分摊处理&#xff08;原因是写操作较少&#xff0c;读操作较多&…

面试官:单核 CPU 支持 Java 多线程吗?为什么?被问懵了!

由于现在大多计算机都是多核CPU,多线程往往会比单线程更快,更能够提高并发,但提高并发并不意味着启动更多的线程来执行。更多的线程意味着线程创建销毁开销加大、上下文非常频繁,你的程序反而不能支持更高的TPS。 时间片 多任务系统往往需要同时执行多道作业。作业数往往大…

ABAP-LP01和PDF打印机配置

事务代码SPAD1.LP01配置2.PDF配置

Netty+WebSocket整合STOMP协议

1.STOMP协议简介 常用的WebSocket协议定义了两种传输信息类型:文本信息和二进制信息。类型虽然被确定,但是他们的传输体是没有规定的,也就是说传输体可以自定义成什么样的数据格式都行,只要客户端和服务端约定好,得到数据后能够按照约定的语义解析数据就好。相较于Http协议…

猿创征文|我的后端成长之路(985科班两年,我发现了大学正确打开方式)

零.前言 当看到官方的这个活动的时候&#xff0c;我突然感到手指充满了力量&#xff0c;好像是我的键盘要向我尖端放电&#xff0c;谁还不是怀着满腔的热忱来写这篇文章帮助未来的学弟学妹们避坑呢&#xff1f;(其实是为了活动的奖励&#x1f917;)。不过不要在意这些细节&…

本地连接是干什么的?

当您创建家庭或小型办公网络时&#xff0c;运行 windows XP Professional 或 windows XP home edition 的计算机将连接到局域网 (Lan)。 安装 windows XP 时&#xff0c;将检测您的网络适配器&#xff0c;而且将创建本地连接。 像所有其他连接类型一样&#xff0c;它将出现在…

【深蓝学院】- Multiplane Images and Neural Rendering

01 view Synthesis problem Definition 02 View synthesis with multiplane Image(MPI) MPI的缺陷&#xff1a; 不是真正的三维表达不同视角观测的RGB是不变的 与MPI不一样的地方&#xff1a;不是手工设计的&#xff0c;而是整体输入 不同视角的RGB是不一样的 缺陷&#xff1…

Pytorch优化器全总结(一)SGD、ASGD、Rprop、Adagrad

目录 写在前面 一、 torch.optim.SGD 随机梯度下降 SGD代码 SGD算法解析 1.MBGD&#xff08;Mini-batch Gradient Descent&#xff09;小批量梯度下降法 2.Momentum动量 3.NAG(Nesterov accelerated gradient) SGD总结 二、torch.optim.ASGD随机平均梯度下降 三、torc…

【手把手】ios苹果打包——遇见项目实战|超详细的教程分享

六年代码两茫茫&#xff0c;不思量&#xff0c;自难忘 6年资深前端主管一枚&#xff0c;只分享技术干货&#xff0c;项目实战经验 关注博主不迷路~ 文章目录前言weex介绍eeui介绍一、安装CocoaPods1.CocoaPods介绍2.CocoaPods的安装二、登录开发者中心四、添加测试手机设备五、…

2022最新iOS证书(.p12)、描述文件(.mobileprovision)申请和HBuider打包及注意注意事项

制作p12证书1、在钥匙串界面中,选中安装好的开发者证书,【右键】选择导出在弹出的界面中3、在接下来的弹窗中填写p12文件的安装密码(后面他人安装该p12文件时需要输入这个密码,重要)4、继续上面的步骤,这里需要输入电脑的开机密码,p12开发者证书到这里即制作完成。以上就…

【芯片前端】根据数据有效选择输出的握手型FIFO结构探究

前言 之前要做一个一读多写的fifo&#xff0c;也就是master写入数据到fifo中&#xff0c;多个slave读取数据&#xff0c;结构如下图所示&#xff1a; 由于slave需要的数据一致&#xff0c;fifo内只需要例化一个ram以节约空间。这个fifo的具体结构下次博客中再来讨论。在这个fi…

Git 之 revert

转自: Git 之 revertrevert 可以撤销指定的提交内容,撤销后会生成一个新的commit。 1、两种commit: 当讨论 revert 时,需要分两种情况,因为 commit 分为两种:一种是常规的 commit,也就是使用 git commit 提交的 commit; 另一种是 merge commit,在使用 git merge 合并两…

mysql 主从备份原理

mysql 主从备份原理 1.1 用途及条件 mysql主从复制用途实时灾备,用于故障切换 读写分离,提供查询服务 备份,避免影响业务主从部署必要条件:主库开启binlog日志(设置log-bin参数) 主从server-id不同 从库服务器能连通主库2.1 主从原理在备库 B 上通过 change master 命令,…

服务端挂了,客户端的 TCP 连接还在吗?

作者:小林coding 计算机八股文网站:https://xiaolincoding.com大家好,我是小林。 如果「服务端挂掉」指的是「服务端进程崩溃」,服务端的进程在发生崩溃的时候,内核会发送 FIN 报文,与客户端进行四次挥手。 但是,如果「服务端挂掉」指的是「服务端主机宕机」,那么是不会…

[第二章 web进阶]XSS闯关-1

定义:跨站脚本(Cross_Site Scripting,简称为XSS或跨站脚本或跨站脚本攻击)是一种针对网站应用程序的安全漏洞攻击技术,是代码注入的一种。它允许恶意用户将代码注入网页,其他用户浏览网页时就会受到影响。恶意用户利用XSS代码攻击成功后,可能得到包括但不限于更高的权限、会…

K8s简介之什么是K8s

1.概述 欢迎来到K8s入门课程。Kubernetes,也被称为K8s或Kube,是谷歌推出的业界最受欢迎的容器编排器。本K8s教程由一系列关于K8s的文章组成。在第一部分,我们将讨论什么是K8s和K8s的基本概念。 本课程是专为初学者开设的,你可以零基础学习这项技术。我们将带你了解全部K8s的…

第2章 第一个Spring Boot项目

开发工具选择 工欲善其事必先利其器&#xff0c;我们进行Java项目开发&#xff0c;选择一个好的集成开发工具&#xff08;IDE&#xff09;对提高我们的开发调试效率有非常大的帮助。这里我们选择大名鼎鼎的IDEA &#xff0c;它全称 IntelliJ IDEA。 ​IntelliJ IDEA公认最好的J…

【云原生 | Kubernetes 系列】K8s 实战 如何给应用注入数据 II 将pod数据传递给容器

将pod数据传递给容器前言一、通过环境变量将 Pod 信息传递给容器1.1、用 Container 字段作为环境变量的值二、通过文件将 Pod 信息呈现给容器2.1、存储容器字段总结前言 在上一篇文章中&#xff0c;我们学习了针对容器设置启动时要执行的命令和参数、定义相互依赖的环境变量、为…