第五章---创建个人中心页面(下)

news/2024/5/10 1:24:47/文章来源:https://blog.csdn.net/m0_51366201/article/details/134911647

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" data-bs-toggle="modal" data-bs-target="#add-bot-btn">创建Bot</button><!-- Modal --><div class="modal fade" id="add-bot-btn" tabindex="-1"><div class="modal-dialog modal-xl"><div class="modal-content"><div class="modal-header"><h1 class="modal-title fs-5" id="exampleModalLabel">创建Bot</h1><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><form><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" aria-describedby="emailHelp" placeholder="请输入Bot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">简介</label><textarea v-model="botadd.description"  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-code" rows="7" placeholder="请编写Bot代码"></textarea></div></form></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-striped 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;">修改</button><button type="button" class="btn btn-danger">删除</button></td></tr></tbody></table></div></div></div></div></div>
</template>

增加一个 add_bot 函数:

<script>import { ref,reactive } from 'vue'import $ from 'jquery'import { useStore } from 'vuex';import { Modal } from 'bootstrap/dist/js/bootstrap';export default {setup() {const store = useStore();let bots = ref([]);const botadd = reactive({title: "",description: "",content: "",error_message: "",});const refresh_bots = () => {$.ajax({url: "http://127.0.0.1:3000/user/bot/getlist/",type: "get",headers: {Authorization:"Bearer " + store.state.user.token,},success(resp) {bots.value = resp;}})}refresh_bots();const add_bot = () => {botadd.error_message = "",$.ajax({url: "http://127.0.0.1:3000/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-editorace-builds
  • 添加组件
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" />

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

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

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

相关文章

【链表Linked List】力扣-117 填充每个节点的下一个右侧节点指针II

目录 问题描述 解题过程 官方题解 问题描述 给定一个二叉树&#xff1a; struct Node {int val;Node *left;Node *right;Node *next; } 填充它的每个 next 指针&#xff0c;让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点&#xff0c;则将 next 指针设置为 N…

【Matlab算法】多维函数求解的基本概念

多维函数求解的基本概念 多维函数最优化问题最优化算法最优化问题的类型最优化算法的分类常用的多维函数求解方法结语 多维函数 多维函数是指定义在 R n \mathbb{R}^n Rn 上的函数&#xff0c;其中 n n n 是函数的维数。例如&#xff0c; f ( x , y ) x 2 y 2 f(x, y) x^…

令牌桶算法理解学习(限流算法)

令牌桶算法是网络流量整形&#xff08;Traffic Shaping&#xff09;和速率限制&#xff08;Rate Limiting&#xff09;中最常使用的一种算法。典型情况下&#xff0c;令牌桶算法用来控制发送到网络上的数据的数目&#xff0c;并允许突发数据的发送。 用简单的话语来说就是限制…

react.js源码二

三、调度Scheduler scheduling(调度)是fiber reconciliation的一个过程&#xff0c;主要决定应该在何时做什么?在stack reconciler中&#xff0c;reconciliation是“一气呵成”&#xff0c;对于函数来说&#xff0c;这没什么问题&#xff0c;因为我们只想要函数的运行结果&…

读书笔记-《数据结构与算法》-摘要4[插入排序]

插入排序 核心&#xff1a;通过构建有序序列&#xff0c;对于未排序序列&#xff0c;在已排序序列中从后向前扫描(对于单向链表则只能从前往后遍历)&#xff0c;找到相应位置并插入。实现上通常使用in-place排序(需用到O(1)的额外空间) 从第一个元素开始&#xff0c;该元素可…

Http请求(bug)——路径变量传参遇到特殊符号的问题 URL中的#,?,符号作用

前言 本篇博客分析路径变量传参遇到特殊符号的问题&#xff0c;阐述了URL中的#&#xff0c;&#xff1f;&#xff0c;&符号作用。 目录 前言引出路径变量传参遇到特殊符号的问题问题描述问题分析 URL中的 #&#xff0c;&#xff1f;&#xff0c;&符号的作用URL中# 的作…

sqlite3.44.2的编译

文章目录 sqlite3.44.2的编译概述笔记解决shell.c编译报错的方法整理 - 正常可用的编译脚本过程剩下的事情验证编译出的输出是否可以给工程正常使用?END sqlite3.44.2的编译 概述 想从源码编译一份Sqlite3.44.2出来. 编译sqlite3.44.2前置需要的TCL环境已经编译出来到了, 做…

前端入门:HTML初级指南,网页的简单实现!

代码部分&#xff1a; <!DOCTYPE html> <!-- 上方为DOCTYPE声明&#xff0c;指定文档类型为HTML --> <html lang"en"> <!-- html标签为整个页面的根元素 --> <head> <!-- title标签用于定义文档标题 --> <title>初始HT…

Google Bard vs. ChatGPT 4.0:文献检索、文献推荐功能对比

在这篇博客中&#xff0c;我们将探讨和比较四个不同的人工智能模型——ChatGPT 3.5、ChatGPT 4.0、ChatGPT 4.0插件和Google Bard。我们将通过三个问题的测试结果来评估它们在处理特定任务时的效能和响应速度。 导航 问题 1: 统计自Vehicle Routing Problem (VRP)第一篇文章发…

PHP对接企业微信

前言 最近在做项目中&#xff0c;要求在后台管理中有企业微信管理的相关功能。相关准备工作&#xff0c;需要准备好企业微信账号&#xff0c;添加自建应用&#xff0c;获得相应功能的权限&#xff0c;以及agentid、secre等。 参考文档&#xff1a; 企业微信开发文档 功能实现 因…

ChatGPT学习笔记

1 ChatGPT架构图 &#xff08;ChatGPT_Diagram.svg来自于【OpenA | Introducing ChatGPT】&#xff09; 2 模型训练 ChatGPT在训练时使用了PPO方法&#xff1b;

RabbitMq整合Springboot超全实战案例+图文演示+源码自取

目录 介绍 简单整合 简单模式 定义 代码示例 work模式 定义 代码示例 pubsub模式 定义 代码示例 routing模式 定义 代码示例 top模式 定义 代码 下单付款加积分示例 介绍 代码 可靠性投递示例 介绍 代码 交换机投递确认回调 队列投递确认回调 ​延迟消…

LLM之Agent(五)| AgentTuning:清华大学与智谱AI提出AgentTuning提高大语言模型Agent能力

​论文地址&#xff1a;https://arxiv.org/pdf/2310.12823.pdf Github地址&#xff1a;https://github.com/THUDM/AgentTuning 在ChatGPT带来了大模型的蓬勃发展&#xff0c;开源LLM层出不穷&#xff0c;虽然这些开源的LLM在各自任务中表现出色&#xff0c;但是在真实环境下作…

线性回归实战

3.1 使用正规方程进行求解 3.1.1 简单线性回归 公式 &#xff1a; y w x b y wx b ywxb 一元一次方程&#xff0c;在机器学习中一元表示一个特征&#xff0c;b表示截距&#xff0c;y表示目标值。 使用代码进行实现&#xff1a; 导入包 import numpy as np import matp…

单点登录方案调研与实现

作用 在一个系统登录后&#xff0c;其他系统也能共享该登录状态&#xff0c;无需重新登录。 演进 cookie → session → token →单点登录 Cookie 可以实现浏览器和服务器状态的记录&#xff0c;但Cookie会出现存储体积过大和可以在前后端修改的问题 Session 为了解决Co…

day70

今日回顾 session 中间件 auth session Cookie虽然在一定程度上解决了“保持状态”的需求&#xff0c;但是由于Cookie本身最大支持4096字节&#xff0c;以及Cookie本身保存在客户端&#xff0c;可能被拦截或窃取&#xff0c;因此就需要有一种新的东西&#xff0c;它能支持更…

西南科技大学C++程序设计实验七(继承与派生二)

一、实验目的 1. 掌握多继承程序设计 2. 掌握虚基类编程 3. 拓展学习可视化程序设计中的继承与派生应用 二、实验任务 重点:掌握虚基类的定义与实现,拓展其功能。 阅读分析、完善程序。下面程序(1)与程序(2)分别是没有使用虚基类和使用虚基类的代码,其中A是最上层基…

【海思SS528 | VO】MPP媒体处理软件V5.0 | VO模块编程总结

&#x1f601;博客主页&#x1f601;&#xff1a;&#x1f680;https://blog.csdn.net/wkd_007&#x1f680; &#x1f911;博客内容&#x1f911;&#xff1a;&#x1f36d;嵌入式开发、Linux、C语言、C、数据结构、音视频&#x1f36d; &#x1f923;本文内容&#x1f923;&a…

在Spring Cloud中使用组件Ribbon和Feign,并分别创建子模块注册到Eureka中去

ok&#xff0c;在上篇文章中我们讲了在Spring cloud中使用Zuul网关&#xff0c;这篇文章我们将Spring Cloud的五大核心组件的Ribbon和Feign分别创建一个微服务模块。 题外话&#xff0c;本篇博客就是配置子模块&#xff0c;或者说是微服务&#xff0c;然后将微服务正式启动之前…

【Python】 生成二维码

创建了一个使用 python 创建二维码的程序。 下面是生成的程序的图像。 功能描述 输入网址&#xff08;URL&#xff09;。 输入二维码的名称。 当单击 QR 码生成按钮时&#xff0c;将使用 QRname 中输入的字符将 QR 码生成为图像。 程序代码 import qrcode import tkinterd…