目录

布局规划前端页面

获取头像+获取Bot列表

对接获取Bot信息+渲染到前端

实现创建一个Bot

前端进行对接插入Bot

实现创建成功关闭和清空

修改时间

实现删除按钮

安装依赖:vue3-ace-editor


布局规划前端页面

使用 bootstrap 的 grids system 进行布局

在 bootstrap 的网址搜索 grids system。

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

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

获取头像+获取Bot列表

对接获取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%">我的Robot</span><button type="button" class="btn btn-warning float-end" style="color:white;" data-bs-toggle="modal" data-bs-target="#add-bot-btn">创建Robot</button><!--    创建robot 模态框 --></div><div class="card-body"><table class="table table-striped table-hover"><thead><tr><th>Robot名称</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-primary" style="color:white; margin-right: 10px;" data-bs-toggle="modal" :data-bs-target="'#update-bot-modal-'+bot.id">修改</button><button type="button" @click="remove_bot(bot)" class="btn btn-danger" style="color:white;">删除</button><!-- 修改bot模态框 --></td></tr></tbody></table></div></div></div></div></div>
</template><script>import $ from 'jquery'
import { ref } from 'vue'
import { useStore } from 'vuex';export default{components:{},setup(){const store = useStore();let bots = ref([]);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();return{bots,}}
}
</script>
<style scoped>
</style>

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

实现创建一个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%">我的Robot</span><button type="button" class="btn btn-warning float-end" style="color:white;" data-bs-toggle="modal" data-bs-target="#add-bot-btn">创建Robot</button><!--    创建robot 模态框 --><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">创建Robot</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="请输入Robot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">Robot简介</label><textarea v-model="botadd.description" class="form-control" id="add-bot-description" rows="3" placeholder="请输入Robot描述"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">Robot代码</label><textarea v-model="botadd.content" class="form-control" id="add-bot-content" rows="3" placeholder="请输入Bot代码"></textarea></div></div></div></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 class="card-body"><table class="table table-striped table-hover "><thead><tr><th>Robot名称</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-primary" style="color:white; margin-right: 10px;" data-bs-toggle="modal" :data-bs-target="'#update-bot-modal-'+bot.id">修改</button><button type="button" @click="remove_bot(bot)" class="btn btn-danger" style="color:white;">删除</button><!-- 修改bot模态框 --></td></tr></tbody></table></div></div></div></div></div>
</template><script>import $ from 'jquery'
import { ref } from 'vue'
import { useStore } from 'vuex';export default{components:{},setup(){const store = useStore();let bots = ref([]);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();return{bots,}}
}
</script>
<style scoped>
</style>

前端进行对接插入Bot

增加一个 add_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%">我的Robot</span><button type="button" class="btn btn-warning float-end" style="color:white;" data-bs-toggle="modal" data-bs-target="#add-bot-btn">创建Robot</button><!--    创建robot 模态框 --><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">创建Robot</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="请输入Robot名称"></div><div class="mb-3"><label for="add-bot-description" class="form-label">Robot简介</label><textarea v-model="botadd.description" class="form-control" id="add-bot-description" rows="3" placeholder="请输入Robot描述"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">Robot代码</label><textarea v-model="botadd.content" class="form-control" id="add-bot-content" rows="3" placeholder="请输入Bot代码"></textarea></div></div></div></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 class="card-body"><table class="table table-striped table-hover "><thead><tr><th>Robot名称</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-primary" style="color:white; margin-right: 10px;" data-bs-toggle="modal" :data-bs-target="'#update-bot-modal-'+bot.id">修改</button><button type="button" @click="remove_bot(bot)" class="btn btn-danger" style="color:white;">删除</button><!-- 修改bot模态框 --></td></tr></tbody></table></div></div></div></div></div>
</template><script>import $ from 'jquery'
import { ref } from 'vue'
import { useStore } from 'vuex';export default{components:{},setup(){const store = useStore();let bots = ref([]);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;}});}const botadd = reactive({title: "",description: "",content: "",error_message: "",});//创建一个 botconst 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;}}})}refresh_bots();return{bots,botadd,add_bot,}}
}
</script>
<style scoped>
</style>

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

修改时间

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

package com.kill9.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
@AllArgsConstructor
public 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;
}

实现创建成功关闭和清空

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;}}

实现删除按钮

删除一个 Bot

增加一个 删除 bot 的函数:

//删除一个 botconst remove_bot = (bot) => {$.ajax({url: "http://127.0.0.1:3000/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();}}})}

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

<button type="button" class="btn btn-danger" @click="remove_bot(bot)">删除</button>

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

修改一个 Bot

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

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;}}})}

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

<!-- 修改bot模态框 --><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">Modify Robot</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">Title</label><input v-model="bot.title" type="text" class="form-control" id="add-bot-title" placeholder="Input Robot Title"></div><div class="mb-3"><label for="add-bot-description" class="form-label">Robot Description</label><textarea v-model="bot.description" class="form-control" id="add-bot-description" rows="3" placeholder="Input Robot Description"></textarea></div><div class="mb-3"><label for="add-bot-code" class="form-label">Robot Code</label><textarea v-model="bot.content" class="form-control" id="add-bot-content" rows="3" placeholder="Input Bot Code"></textarea></div></div><div class="modal-footer"><div class="error-message">{{botadd.error_message}}</div><button type="button" class="btn btn-primary" @click="update_bot(bot)">Save Changes</button><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button></div></div></div></div>

安装依赖:vue3-ace-editor

在 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" />

完成~~

创建个人中心页面(下)相关推荐

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

  2. 黑马头条登录到个人中心页面

    使用vue脚手架创建项目的基本框架,对框架进行修改,将不需要的内容删除. 创建style文件夹,然后在里面创建base.less文件,用于存放全局样式. 创建utils文件夹,用于存放一些项目需要的工 ...

  3. 转:MSDN Visual系列:MOSS企业级搜索之一——在搜索中心里创建自定义搜索页面和标签选项卡...

    MSDN Visual系列:MOSS企业级搜索之一--在搜索中心里创建自定义搜索页面和标签选项卡 原文:http://msdn2.microsoft.com/en-us/library/bb42885 ...

  4. 后台管理系统2——登录、退出、注册功能、个人中心页面

    登录功能的实现 1.登录功能 1.1 页面内容的修改 1.2 路由的实现 1.3 登录页面的设计 1.4 登录逻辑实现 1.5 后台的实现 1.6 登录功能的修改 2 退出系统 3 注册功能 3.1 ...

  5. Vue.js-Day09【项目实战(附带 完整项目源码)-day04:用户个人中心页面、用户登录页面、将项目打包部署到服务器上、项目汇报、实训心得】

    Vue.js实训[基础理论(5天)+项目实战(5天)]博客汇总表[详细笔记] 实战项目源码[链接:https://pan.baidu.com/s/1r0Mje3Xnh8x4F1HyG4aQTA   提 ...

  6. 如何给 SAP Spartacus Storefront 创建新的页面

    page template 不包含 layout 或者 design information. content slot 在页面上的具体位置,以及 layout 和 design 的选择,必须在前端指 ...

  7. 微信小程序怎么新建php文件,微信小程序中创建小程序页面的步骤介绍(图文)...

    本篇文章给大家带来的内容是关于微信小程序之创建小程序页面的步骤介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 创建一个简单的页面,创建小程序页面的具体几个步骤: 1. 在page ...

  8. php登陆页面修改密码的功能,使用bootstrap创建登录注册页面并实现表单验证功能...

    本篇文章给大家介绍一下使用bootstrap创建登录注册页面并实现单验证功能的方法.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助. 用bootstrap做登入注册页面,使用valid ...

  9. 学习ASP.NET Core Razor 编程系列三——创建数据表及创建项目基本页面

    原文:学习ASP.NET Core Razor 编程系列三--创建数据表及创建项目基本页面 学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 ...

最新文章

  1. 193. 一个不错的日历插件
  2. 【PWA学习与实践】(3) 让你的WebApp离线可用
  3. 使用自定义的按钮替换默认的input type='file'
  4. 鸟哥的Linux私房菜(基础篇)-第零章、计算机概论(零.3)
  5. MySQL 常用账户管理及授权操作
  6. flex 平铺布局_flex布局及各种布局的总结
  7. 计算机操作系统原理教程与实训(目录)
  8. 机器学习-吴恩达-笔记-12-推荐系统
  9. 51单片机 外部时钟_基于51单片机的LCD12864显示模拟时钟
  10. 触发器中的 临时表 old 与 new
  11. Windows核心编程_PE文件格式解析
  12. 002 selenium 元素定位
  13. Asp.net MVC 示例项目Suteki.Shop分析之---IOC(控制反转)
  14. 添加控件并处理事件(纯手写)
  15. 解决删除symantec,需要输入密码的问题
  16. hp服务器系统时间一直变慢,怎么解决hp1010 win7打印机打印速度变慢的方法
  17. AIDL 方法参数的in out inout前缀作用
  18. MATLAB积分函数integral()的使用方法
  19. 机器学习笔记~图像的空间分辨率
  20. 深入理解Linux网络技术内幕(十)——帧的接收

热门文章

  1. Windriver 安装和PCIE设备调试遇到的问题记录(持续更新)
  2. iPad + Magic Keyboard蓝牙键盘的快捷键~
  3. 网游双开总显示连接服务器超时,为什么双开网络游戏就会掉线呢?
  4. 某智慧教育公共服务平台视频下载教程
  5. 《文言文复兴系列 3》(江湖一剑客)
  6. 关于个人对GIS市场、GIS应用、GIS行业的一点看法
  7. asp.net客户积分兑换管理系统VS开发sqlserver数据库web结构c#编程计算机网页源码项目
  8. 全球及中国制造执行系统(MES)软件行业未来投资前景预测报告2022-2027年
  9. Java连接MySQL mysql-connector-java-bin.jar驱动包的下载与安装
  10. linux挂载本地iso镜像