parent
52d2592278
commit
dcb121523f
@ -0,0 +1,76 @@
|
|||||||
|
package com.ruoyi.web.controller.test.gl;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.test.domain.Class1;
|
||||||
|
import com.ruoyi.test.domain.DO.StudentClassDO;
|
||||||
|
import com.ruoyi.test.domain.DO.StudentClassList;
|
||||||
|
import com.ruoyi.test.domain.DO.StudentDO;
|
||||||
|
import com.ruoyi.test.seriver.IClass1Service;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Api(tags = "管理端班级管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/gl/classManage")
|
||||||
|
public class ClassManageController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IClass1Service class1Service;
|
||||||
|
|
||||||
|
@ApiOperation("班级查询")
|
||||||
|
@GetMapping("selectClass")
|
||||||
|
public R<List<Class1>> selectClass(String name, String grade)
|
||||||
|
{
|
||||||
|
return R.ok(class1Service.selectClass1(name,grade));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("班级学生查询")
|
||||||
|
@GetMapping("studentListByGradeAndClass1")
|
||||||
|
public R<List<StudentDO>> studentListByGradeAndClass1(String grade, String Class1)
|
||||||
|
{
|
||||||
|
return R.ok(class1Service.studentListByGradeAndClass1(grade,Class1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("新建班级")
|
||||||
|
@PostMapping("addClass1")
|
||||||
|
public R<Integer> addClass1(@RequestBody Class1 class1)
|
||||||
|
{
|
||||||
|
return R.ok(class1Service.addclass1(class1.getName(),class1.getGrade(),class1.getClass1(),class1.getCommand()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("加入班级")
|
||||||
|
@PostMapping("insertClassByStudentList")
|
||||||
|
public R<Integer> insertClassByStudentList(@RequestBody StudentClassList list)
|
||||||
|
{
|
||||||
|
for(StudentClassDO studentClassDO : list.getStudentList()){
|
||||||
|
if(studentClassDO.getGrade()!=null && studentClassDO.getClass1()!=null){
|
||||||
|
class1Service.deleteClass(studentClassDO.getId(),studentClassDO.getGrade(),studentClassDO.getClass1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Long> studentList1 = list.getStudentList().stream()
|
||||||
|
.map(StudentClassDO::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return R.ok(class1Service.insertClassByStudentList(studentList1,list.getGrade(),list.getClass1()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除学生")
|
||||||
|
@DeleteMapping("deleteStudent")
|
||||||
|
public R<Integer> deleteStudent(@RequestParam Long id, @RequestParam String grade, @RequestParam String Class1)
|
||||||
|
{
|
||||||
|
return R.ok(class1Service.deleteClass(id,grade,Class1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("修改班级信息")
|
||||||
|
@PostMapping("updateClass")
|
||||||
|
public R<Integer> updateClass(@RequestBody Class1 class1)
|
||||||
|
{
|
||||||
|
return R.ok(class1Service.updateClass1(class1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.ruoyi.web.controller.test.gl;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
|
import com.ruoyi.system.service.ISysRoleService;
|
||||||
|
import com.ruoyi.test.domain.DO.MessageDO;
|
||||||
|
import com.ruoyi.test.domain.DO.MessageDO1;
|
||||||
|
import com.ruoyi.test.seriver.IMessageService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Api(tags = "管理端消息管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/gl/message")
|
||||||
|
public class MessageController {
|
||||||
|
@Autowired
|
||||||
|
private IMessageService iMessageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysRoleService roleService;
|
||||||
|
|
||||||
|
@ApiOperation("消息列表")
|
||||||
|
@GetMapping("selectMessage")
|
||||||
|
public R<List<MessageDO>> selectMessage(){
|
||||||
|
return R.ok(iMessageService.selectMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除消息")
|
||||||
|
@DeleteMapping("deleteMessage")
|
||||||
|
public R<Integer> deleteMessage(Long id){
|
||||||
|
return R.ok(iMessageService.deleteMessage(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("获取用户")
|
||||||
|
@GetMapping("getUserList")
|
||||||
|
public R<List<SysUser>> getUserList(){
|
||||||
|
List<SysUser> list = roleService.selectUserByRoleKey("student");
|
||||||
|
list.addAll(roleService.selectUserByRoleKey("teacher"));
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("添加消息")
|
||||||
|
@PostMapping("addMessage")
|
||||||
|
public R<Integer> addMessage(@RequestBody MessageDO1 messageDO1){
|
||||||
|
return R.ok(iMessageService.addMessage(messageDO1));
|
||||||
|
}
|
||||||
|
}
|
@ -1,155 +0,0 @@
|
|||||||
package com.ruoyi.web.controller.test.gl;//package com.ruoyi.web.controller.test.gl;
|
|
||||||
//
|
|
||||||
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
//import com.ruoyi.common.core.domain.R;
|
|
||||||
//import com.ruoyi.common.core.domain.entity.SysUser;
|
|
||||||
//import com.ruoyi.common.utils.SecurityUtils;
|
|
||||||
//import io.swagger.annotations.Api;
|
|
||||||
//import io.swagger.annotations.ApiOperation;
|
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
//import org.springframework.web.bind.annotation.*;
|
|
||||||
//
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
//@Api(tags = "管理端用户管理")
|
|
||||||
//@RestController
|
|
||||||
//@RequestMapping("/gl/users")
|
|
||||||
//public class UserController {
|
|
||||||
// @Autowired
|
|
||||||
// private IUserService iUserService;
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// 获取学生列表
|
|
||||||
// */
|
|
||||||
// @ApiOperation("学生列表")
|
|
||||||
// @GetMapping("student")
|
|
||||||
// public R<IPage<User>> selectList(int pagenum){
|
|
||||||
// return R.ok(iUserService.selectStudentList(pagenum));
|
|
||||||
// }
|
|
||||||
// /*获取学生用户名查询查询记录
|
|
||||||
// *@param name 用户名
|
|
||||||
// */
|
|
||||||
// @ApiOperation("学生用户名查询")
|
|
||||||
// @GetMapping("/seleteStudentName")
|
|
||||||
// public R<IPage<User>> selectStudent(int pagenum,String name){
|
|
||||||
// return R.ok(iUserService.selectStudent(pagenum,name));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /*增加学生用户信息
|
|
||||||
// *@param name 用户名
|
|
||||||
// */
|
|
||||||
// @ApiOperation("学生添加用户")
|
|
||||||
// @PostMapping("/insertStudent")
|
|
||||||
// public R<String> inserStudent(@RequestBody UserVo userVo){
|
|
||||||
// User user = new User();
|
|
||||||
// user.setAge(userVo.getAge());
|
|
||||||
// user.setBirthday(userVo.getBirthday());
|
|
||||||
// user.setGrade(userVo.getGrade());
|
|
||||||
// user.setSex(userVo.getSex());
|
|
||||||
// user.setName(userVo.getName());
|
|
||||||
// user.setTname(userVo.getTname());
|
|
||||||
// user.setTelephone(userVo.getTelephone());
|
|
||||||
// user.setRoleKey("2");
|
|
||||||
// user.setState(0L);
|
|
||||||
// SysUser sysUser = SecurityUtils.getLoginUser().getUser();
|
|
||||||
// Long zhid = sysUser.getUserId();
|
|
||||||
// user.setZhId(zhid);
|
|
||||||
// List<User> list = iUserService.selectStudentByZhid(zhid);
|
|
||||||
// if(list.size()==0){
|
|
||||||
// if(iUserService.insertUser(user)!=0){
|
|
||||||
// return R.ok("添加成功!");
|
|
||||||
// }else{
|
|
||||||
// return R.fail("添加失败!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return R.fail("该账号已绑定用户了!");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @ApiOperation("教师列表")
|
|
||||||
// @GetMapping("/teacher")
|
|
||||||
// public R<IPage<User>> selectTeacher(int pagenum){
|
|
||||||
// return R.ok(iUserService.selectTeacherList(pagenum));
|
|
||||||
// }
|
|
||||||
// /*获取教师用户名查询查询记录
|
|
||||||
// *@param name 用户名
|
|
||||||
// */
|
|
||||||
// @ApiOperation("教师用户名查询")
|
|
||||||
// @GetMapping("/seleteTeacherName")
|
|
||||||
// public R<IPage<User>> selectTeacher(int pagenum,String name){
|
|
||||||
// return R.ok(iUserService.selectTeacher(pagenum,name));
|
|
||||||
// }
|
|
||||||
// /*增加教师用户信息
|
|
||||||
// *@param name 用户名
|
|
||||||
// */
|
|
||||||
// @ApiOperation("老师添加用户")
|
|
||||||
// @PostMapping("/insertTeacher")
|
|
||||||
// public R<String> insertTeacher(@RequestBody UserVo userVo){
|
|
||||||
// User user = new User();
|
|
||||||
// user.setAge(userVo.getAge());
|
|
||||||
// user.setBirthday(userVo.getBirthday());
|
|
||||||
// user.setGrade(userVo.getGrade());
|
|
||||||
// user.setSex(userVo.getSex());
|
|
||||||
// user.setName(userVo.getName());
|
|
||||||
// user.setTname(userVo.getTname());
|
|
||||||
// user.setTelephone(userVo.getTelephone());
|
|
||||||
// user.setRoleKey("3");
|
|
||||||
// user.setState(0L);
|
|
||||||
// SysUser sysUser = SecurityUtils.getLoginUser().getUser();
|
|
||||||
// Long zhid = sysUser.getUserId();
|
|
||||||
// user.setZhId(zhid);
|
|
||||||
// List<User> list = iUserService.selectStudentByZhid(zhid);
|
|
||||||
// if(list.size()==0){
|
|
||||||
// if(iUserService.insertUser(user)!=0){
|
|
||||||
// return R.ok("添加成功!");
|
|
||||||
// }else{
|
|
||||||
// return R.fail("添加失败!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return R.fail("该账号已绑定用户了!");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @ApiOperation("管理员列表")
|
|
||||||
// @GetMapping("/Gl")
|
|
||||||
// public R<IPage<User>> selectGl(int pagenum){
|
|
||||||
// return R.ok(iUserService.selectGlList(pagenum));
|
|
||||||
// }
|
|
||||||
// /*获取管理员用户名查询查询记录
|
|
||||||
// *@param name 用户名
|
|
||||||
// */
|
|
||||||
// @ApiOperation("管理员用户名查询")
|
|
||||||
// @GetMapping("/seleteGlName")
|
|
||||||
// public R<IPage<User>> selectGl(int pagenum,String name){
|
|
||||||
// return R.ok(iUserService.selectGl(pagenum,name));
|
|
||||||
// }
|
|
||||||
// /*增加管理员用户信息
|
|
||||||
// *@param name 用户名
|
|
||||||
// */
|
|
||||||
// @ApiOperation("管理员添加用户")
|
|
||||||
// @PostMapping("/insertGl")
|
|
||||||
// public R<String> insertGl(@RequestBody UserVo userVo){
|
|
||||||
// User user = new User();
|
|
||||||
// user.setAge(userVo.getAge());
|
|
||||||
// user.setBirthday(userVo.getBirthday());
|
|
||||||
// user.setGrade(userVo.getGrade());
|
|
||||||
// user.setSex(userVo.getSex());
|
|
||||||
// user.setName(userVo.getName());
|
|
||||||
// user.setTname(userVo.getTname());
|
|
||||||
// user.setTelephone(userVo.getTelephone());
|
|
||||||
// user.setRoleKey("4");
|
|
||||||
// user.setState(0L);
|
|
||||||
// SysUser sysUser = SecurityUtils.getLoginUser().getUser();
|
|
||||||
// Long zhid = sysUser.getUserId();
|
|
||||||
// user.setZhId(zhid);
|
|
||||||
// List<User> list = iUserService.selectStudentByZhid(zhid);
|
|
||||||
// if(list.size()==0){
|
|
||||||
// if(iUserService.insertUser(user)!=0){
|
|
||||||
// return R.ok("添加成功!");
|
|
||||||
// }else{
|
|
||||||
// return R.fail("添加失败!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return R.fail("该账号已绑定用户了!");
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.test.domain.DO;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MessageDO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String teacherName;
|
||||||
|
private String studentName;
|
||||||
|
private String source;
|
||||||
|
private String createtime;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.ruoyi.test.domain.DO;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StudentClassDO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String grade;
|
||||||
|
private String class1;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.ruoyi.test.domain.DO;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StudentClassList {
|
||||||
|
|
||||||
|
private List<StudentClassDO> studentList;
|
||||||
|
private String grade;
|
||||||
|
private String class1;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.ruoyi.test.domain.DO;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StudentDO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public StudentDO(Long id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,231 @@
|
|||||||
|
<template>
|
||||||
|
<el-container style="min-height: 100vh; background-color: #f5f7fa;">
|
||||||
|
<!-- 侧边栏 -->
|
||||||
|
<el-aside :width="sideWidth+'px'" style="background-color: #f1f3f5; box-shadow: 2px 0 6px rgba(0, 21, 41, 0.1); transition: all 0.3s;">
|
||||||
|
<Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow" />
|
||||||
|
</el-aside>
|
||||||
|
|
||||||
|
<el-container>
|
||||||
|
<!-- Header -->
|
||||||
|
<el-header style="border-bottom: 1px solid #e0e0e0; background-color: #fff;">
|
||||||
|
<Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" />
|
||||||
|
</el-header>
|
||||||
|
|
||||||
|
<el-main style="padding: 20px; background-color: #fff; border-radius: 8px;">
|
||||||
|
<!-- 消息管理界面 -->
|
||||||
|
<el-row style="margin-bottom: 20px;">
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-button type="primary" @click="showAddMessageDialog">添加消息</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-table :data="messages" style="width: 100%" :key="messages.id">
|
||||||
|
<el-table-column label="id" prop="id" width="100"></el-table-column>
|
||||||
|
<el-table-column label="发布人" prop="teacherName" width="300"></el-table-column>
|
||||||
|
<el-table-column label="发布对象" prop="studentName" width="300"></el-table-column>
|
||||||
|
<el-table-column label="消息内容" prop="source" width="300"></el-table-column>
|
||||||
|
<el-table-column label="发布时间" prop="createtime" width="180"></el-table-column>
|
||||||
|
<el-table-column label="操作" width="180">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<el-button size="small" @click="deleteMessage(scope.row.id)" type="danger">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<!-- 添加消息对话框 -->
|
||||||
|
<el-dialog :visible.sync="addMessageDialogVisible" title="添加消息" width="500px" :style="{ maxHeight: '80vh' }">
|
||||||
|
<el-form :model="newMessage" label-width="80px" class="form-container">
|
||||||
|
<!-- 消息内容 -->
|
||||||
|
<el-form-item label="消息内容" prop="source" :rules="[{ required: true, message: '消息内容不能为空', trigger: 'blur' }]">
|
||||||
|
<el-input v-model="newMessage.source" type="textarea" placeholder="请输入消息内容" rows="4"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 选择用户下拉框 -->
|
||||||
|
<el-form-item label="选择用户" prop="selectedUsers" :rules="[{ required: true, message: '请选择用户', trigger: 'change' }]">
|
||||||
|
<el-select v-model="newMessage.selectedUsers" multiple placeholder="请选择用户" style="width: 100%">
|
||||||
|
<el-option
|
||||||
|
v-for="user in userList"
|
||||||
|
:key="user.userId"
|
||||||
|
:label="user.userName"
|
||||||
|
:value="user.userId">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button @click="addMessageDialogVisible = false" size="small">取消</el-button>
|
||||||
|
<el-button type="primary" @click="addMessage" size="small">确定</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form>
|
||||||
|
</el-dialog>
|
||||||
|
</el-main>
|
||||||
|
</el-container>
|
||||||
|
</el-container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Header from "@/components/gl/Header.vue";
|
||||||
|
import Aside from "@/components/gl/Aside.vue";
|
||||||
|
import axios from "axios";
|
||||||
|
import source from "echarts/src/data/Source";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "MessageCenter",
|
||||||
|
components: { Aside, Header },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
collapseBtnClass: "el-icon-s-fold",
|
||||||
|
isCollapse: false,
|
||||||
|
sideWidth: 200,
|
||||||
|
logoTextShow: true,
|
||||||
|
messages: [],
|
||||||
|
newMessage: {
|
||||||
|
source: '',
|
||||||
|
selectedUsers: [], // 确保初始化为空数组
|
||||||
|
},
|
||||||
|
userList: [],
|
||||||
|
addMessageDialogVisible: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.userId = this.$route.query.userId; // 从路由获取用户ID
|
||||||
|
this.fetchMessages();
|
||||||
|
this.fetchUserList();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
collapse() {
|
||||||
|
this.isCollapse = !this.isCollapse;
|
||||||
|
if (this.isCollapse) {
|
||||||
|
this.sideWidth = 64;
|
||||||
|
this.collapseBtnClass = "el-icon-s-unfold";
|
||||||
|
this.logoTextShow = false;
|
||||||
|
} else {
|
||||||
|
this.sideWidth = 200;
|
||||||
|
this.collapseBtnClass = "el-icon-s-fold";
|
||||||
|
this.logoTextShow = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async fetchMessages() {
|
||||||
|
try {
|
||||||
|
const token = this.$store.state.tokens[this.userId];
|
||||||
|
if(!token){
|
||||||
|
alert("用户未登录,请重新登录!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const response = await axios.get('http://localhost:8080/gl/message/selectMessage', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if(response.data.code === 200 ) {
|
||||||
|
this.messages = response.data.data;
|
||||||
|
console.log(this.messages);
|
||||||
|
}else{
|
||||||
|
this.$message.error("数据异常");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error("接口异常");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 显示添加消息对话框
|
||||||
|
showAddMessageDialog() {
|
||||||
|
this.newMessage = { source: '', selectedUsers: [] }; // 清空表单
|
||||||
|
this.addMessageDialogVisible = true;
|
||||||
|
},
|
||||||
|
// 添加消息
|
||||||
|
async addMessage() {
|
||||||
|
try {
|
||||||
|
const token = this.$store.state.tokens[this.userId];
|
||||||
|
if (!token) {
|
||||||
|
alert("用户未登录,请重新登录!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const requestData = {
|
||||||
|
id: this.userId,
|
||||||
|
source: this.newMessage.source,
|
||||||
|
list: this.newMessage.selectedUsers, // 发送用户ID数组
|
||||||
|
};
|
||||||
|
console.log(requestData);
|
||||||
|
const response = await axios.post('http://localhost:8080/gl/message/addMessage',
|
||||||
|
requestData,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (response.data.code === 200 && response.data.data > 0) {
|
||||||
|
this.$message.success("添加成功");
|
||||||
|
await this.fetchMessages();
|
||||||
|
this.addMessageDialogVisible = false;
|
||||||
|
} else {
|
||||||
|
this.$message.error("数据异常");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error("接口异常");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 删除消息
|
||||||
|
async deleteMessage(messageId) {
|
||||||
|
try {
|
||||||
|
const token = this.$store.state.tokens[this.userId];
|
||||||
|
if (!token) {
|
||||||
|
alert("用户未登录,请重新登录!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const response = await axios.delete('http://localhost:8080/gl/message/deleteMessage', {
|
||||||
|
params: { id: messageId },
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (response.data.code === 200 && response.data.data > 0){
|
||||||
|
this.$message.success("删除成功");
|
||||||
|
await this.fetchMessages();
|
||||||
|
} else {
|
||||||
|
this.$message.error("数据异常");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error("接口异常");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async fetchUserList() {
|
||||||
|
try {
|
||||||
|
const token = this.$store.state.tokens[this.userId];
|
||||||
|
if (!token) {
|
||||||
|
alert("用户未登录,请重新登录!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const response = await axios.get('http://localhost:8080/gl/message/getUserList', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (response.data.code ===200) {
|
||||||
|
this.userList = response.data.data;
|
||||||
|
}
|
||||||
|
}catch (error){
|
||||||
|
this.$message.error("接口异常");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.form-container {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-form-item {
|
||||||
|
margin-bottom: 20px; /* Adjust spacing between form items */
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in new issue