2023.6.21

1. 添加文件上传下载
2. 添加AOP记录运行耗时
This commit is contained in:
KaiyuanOSG 2023-06-21 10:00:29 +08:00
parent c6c30a9934
commit 0e7178143c
31 changed files with 1068 additions and 104 deletions

14
pom.xml
View File

@ -87,6 +87,20 @@
<artifactId>fastjson</artifactId>
<version>1.2.31_noneautotype</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.19</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/aspectj/aspectjrt -->
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.4</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,57 @@
package com.sdut.labex.KJPA;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
* File: KJPA
* Created: 2023/6/19
* Author: springforest
* Description:
*/
public class KJPA {
public static void save(Object obj) throws Exception {
StringBuffer sql = new StringBuffer("insert into");
StringBuffer fields = new StringBuffer("(");
StringBuffer filedValues = new StringBuffer("values(");
Class c = obj.getClass();
String className = c.getSimpleName().toLowerCase();
sql.append(" " + className + " ");
Field[] fs = c.getDeclaredFields();
for (Field f : fs) {
String fieldName = f.getName();
fields.append(fieldName + ",");
f.setAccessible(true);
Object fieldValue = f.get(obj);
filedValues.append("'").append(fieldValue).append("',");
}
fields.delete(fields.length() - 1, fields.length());
fields.append(")");
filedValues.delete(filedValues.length() - 1, filedValues.length());
filedValues.append(")");
sql.append(fields).append(filedValues);
System.out.println(sql);
//这行会触发Driver.class中静态初始化块的执行
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://106.15.196.199:3306/DCMS?allowMultiQueries=true&useUnicode=true&characterEncoding=utf8";
String username = "root";
String password = "Udkklzxc123.";
try (Connection cnn = DriverManager.getConnection(url, username, password);
Statement stmt = cnn.createStatement()) {//Try-with-resource
int count = stmt.executeUpdate(sql.toString());
System.out.println(count != 0 ? "成功" : "失败");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,42 @@
package com.sdut.labex.common;
import com.sdut.labex.entity.LogEntity;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.concurrent.Callable;
/**
* File: LogThread
* Created: 2023/6/21
* Author: springforest
* Description:
*/
public class LogThread implements Callable<String> {
private LogEntity log;
private DataSource dataSource;
public LogThread(LogEntity log, DataSource dataSource) {
this.log = log;
this.dataSource = dataSource;
}
@Override
public String call() throws Exception {
String sql = "insert into log(content,date,cost) values(?,?,?)";
try (Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, log.getContent());
ps.setString(2, log.getDate());
ps.setLong(3, log.getCost());
int count = ps.executeUpdate();
return count > 0 ? "success" : "fail";
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,69 @@
package com.sdut.labex.config;
import com.sdut.labex.common.LogThread;
import com.sdut.labex.entity.LogEntity;
import com.sdut.labex.service.LogService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.text.SimpleDateFormat;
import java.util.concurrent.ExecutorService;
import static java.lang.System.currentTimeMillis;
/**
* File: AppConfig
* Created: 2023/6/21
* Author: springforest
* Description:
*/
@Configuration
@Aspect
@EnableAspectJAutoProxy
public class AppConfig {
@Resource
private LogService logService;
@Resource
private DataSource dataSource;
@Resource
private ExecutorService es;
public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Pointcut("execution(* com.sdut.labex.controller.*.*(..))")
public void syslog() {
}
@Around("syslog()")
public Object first(ProceedingJoinPoint joinPoint) throws Throwable {
String name = joinPoint.getSignature().getName();
long statTime = currentTimeMillis();
Object proceed = joinPoint.proceed(joinPoint.getArgs());
long endTime = currentTimeMillis();
String date = sdf.format(statTime);
long cost = endTime - statTime;
System.out.println("方法" + name + "执行时间为" + cost + "毫秒");
LogEntity log = new LogEntity();
log.setContent(name);
log.setDate(date);
log.setCost(cost);
//另开一个线程运行日志入库的操作因为该操作耗时较长
LogThread logThread = new LogThread(log, dataSource);
es.submit(logThread);
//
return proceed;
}
}

View File

@ -20,8 +20,8 @@ public class MVBConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(tokenInterceptor)
.excludePathPatterns("/login/**")
.excludePathPatterns("/register/**");
//registry.addInterceptor(tokenInterceptor)
// .excludePathPatterns("/login/**")
// .excludePathPatterns("/register/**");
}
}

View File

@ -0,0 +1,21 @@
package com.sdut.labex.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* File: ThreadPoolConfig
* Created: 2023/6/21
* Author: springforest
* Description:
*/
@Configuration
public class ThreadPoolConfig {
@Bean
public ExecutorService getPool() {
return Executors.newFixedThreadPool(5);
}
}

View File

@ -78,6 +78,7 @@ public class ExperimentsController {
//获取实验列表
@PostMapping("/experiments/{pageNum}/{pageSize}")
public ResVo getExperiments(@RequestBody JSONObject jsonObject, @PathVariable int pageNum, @PathVariable int pageSize) {
//todo: 如果用户为老师则只能看到自己的实验
Experiment experiment = ExperimentFactory.createExperiment(jsonObject);
return experimentsService.getExperiments(experiment, pageNum, pageSize);
}

View File

@ -0,0 +1,70 @@
package com.sdut.labex.controller;
import cn.hutool.core.io.resource.InputStreamResource;
import com.sdut.labex.service.FileService;
import com.sdut.labex.utils.ResVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
/**
* File: UploadController
* Created: 2023/6/20
* Author: springforest
* Description:
*/
@RestController
@CrossOrigin
@Slf4j
public class FileController {
@Resource
private FileService fileService;
@PostMapping("/upload")
public ResVo uploadFile(MultipartFile file) {
log.info(file.getOriginalFilename());
return fileService.uploadFile(file);
}
@PostMapping("/download")
public ResponseEntity<InputStreamResource> downloadFile(@RequestParam("path") String path) {
// 拼接文件路径
File file = new File(path);
// 检查文件是否存在
if (!file.exists()) {
log.error("文件不存在:" + path);
return ResponseEntity.notFound().build();
}
try {
// 创建文件输入流
InputStream inputStream = Files.newInputStream(file.toPath());
// 创建输入流资源
InputStreamResource resource = new InputStreamResource(inputStream);
// 设置响应头
HttpHeaders headers = new HttpHeaders();
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.badRequest().build();
}
}
}

View File

@ -5,6 +5,7 @@ import com.sdut.labex.Factory.UserFactory;
import com.sdut.labex.entity.User;
import com.sdut.labex.service.UserService;
import com.sdut.labex.utils.ResVo;
import com.sdut.labex.utils.UserHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -29,7 +30,7 @@ public class UserController {
@PutMapping("/changePassword")
public ResVo changePassword(@RequestBody JSONObject jsonObject) {
String id = jsonObject.getString("id");
String id = UserHolder.getUser().getId();
String oldPassword = jsonObject.getString("oldPassword");
String newPassword = jsonObject.getString("newPassword");
return userService.changePassword(id, oldPassword, newPassword);

View File

@ -0,0 +1,37 @@
package com.sdut.labex.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 文件
*
* @TableName file
*/
@TableName(value = "file")
@Data
public class FileEntity implements Serializable {
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 文件名
*/
private String name;
/**
* 文件路径
*/
private String path;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,42 @@
package com.sdut.labex.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 日志
*
* @TableName log
*/
@TableName(value = "log")
@Data
public class LogEntity implements Serializable {
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
*
*/
private String content;
/**
*
*/
private String date;
/**
*
*/
private Long cost;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,42 @@
package com.sdut.labex.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 实验提交记录
*
* @TableName submit_records
*/
@TableName(value = "submit_records")
@Data
public class SubmitRecords implements Serializable {
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 实验ID
*/
private Integer experimentId;
/**
* 学生ID
*/
private Integer studentId;
/**
* 文件路径
*/
private String filePath;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -49,7 +49,7 @@ public class TokenInterceptor implements HandlerInterceptor {
if (token != null && !JWTUtil.isExpired(token)) {
User user = usersMapper.selectById(JWTUtil.decode(token).getClaim("id").asString());
if (user == null) {
return false;
return true;
}
//保存到本线程
UserHolder.saveUser(user);
@ -58,7 +58,7 @@ public class TokenInterceptor implements HandlerInterceptor {
}
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return false;
return true;
}
@Override

View File

@ -0,0 +1,20 @@
package com.sdut.labex.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdut.labex.entity.LogEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @author springforest
* @description 针对表log(日志)的数据库操作Mapper
* @createDate 2023-06-21 08:49:57
* @Entity com.sdut.labex.entity.Log
*/
@Mapper
public interface LogMapper extends BaseMapper<LogEntity> {
}

View File

@ -0,0 +1,20 @@
package com.sdut.labex.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdut.labex.entity.SubmitRecords;
import org.apache.ibatis.annotations.Mapper;
/**
* @author springforest
* @description 针对表submit_records(实验提交记录)的数据库操作Mapper
* @createDate 2023-06-20 14:41:09
* @Entity com.sdut.labex.entity.SubmitRecords
*/
@Mapper
public interface SubmitRecordsMapper extends BaseMapper<SubmitRecords> {
}

View File

@ -0,0 +1,13 @@
package com.sdut.labex.service;
import com.sdut.labex.utils.ResVo;
import org.springframework.web.multipart.MultipartFile;
/**
* @author springforest
* @description 针对表file(文件)的数据库操作Service
* @createDate 2023-06-20 13:09:53
*/
public interface FileService {
public ResVo uploadFile(MultipartFile file);
}

View File

@ -0,0 +1,15 @@
package com.sdut.labex.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sdut.labex.entity.LogEntity;
/**
* @author springforest
* @description 针对表log(日志)的数据库操作Service
* @createDate 2023-06-21 08:49:57
*/
public interface LogService extends IService<LogEntity> {
public void insertLog(LogEntity log);
}

View File

@ -0,0 +1,13 @@
package com.sdut.labex.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sdut.labex.entity.SubmitRecords;
/**
* @author springforest
* @description 针对表submit_records(实验提交记录)的数据库操作Service
* @createDate 2023-06-20 14:41:09
*/
public interface SubmitRecordsService extends IService<SubmitRecords> {
}

View File

@ -0,0 +1,59 @@
package com.sdut.labex.service.impl;
import com.sdut.labex.service.FileService;
import com.sdut.labex.utils.ResVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* @author springforest
* @description 针对表file(文件)的数据库操作Service实现
* @createDate 2023-06-20 13:09:53
*/
@Service
@Slf4j
public class FileServiceImpl implements FileService {
@Override
public ResVo uploadFile(MultipartFile file) {
String fileName = file.getOriginalFilename();
File directory = new File("files");
if (!directory.exists()) {
directory.mkdir(); // 如果目录不存在创建目录
}
File savedFile = null;
if (fileName != null) {
savedFile = new File(directory, fileName);
} else {
return ResVo.error("文件名为空");
}
try {
// 保存文件内容
byte[] fileContent = file.getBytes();
try (FileOutputStream fos = new FileOutputStream(savedFile)) {
fos.write(fileContent);
}
log.info("文件保存成功:" + savedFile.getAbsolutePath());
Map<String, Object> map = new HashMap<>();
map.put("path", savedFile.getAbsolutePath());
return ResVo.ok(map);
} catch (IOException e) {
e.printStackTrace();
return ResVo.error("文件保存失败:" + e.getMessage());
}
}
}

View File

@ -0,0 +1,35 @@
package com.sdut.labex.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.entity.LogEntity;
import com.sdut.labex.mapper.LogMapper;
import com.sdut.labex.service.LogService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author springforest
* @description 针对表log(日志)的数据库操作Service实现
* @createDate 2023-06-21 08:49:57
*/
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, LogEntity>
implements LogService {
@Resource
private LogMapper logMapper;
@Override
public void insertLog(LogEntity log) {
try {
logMapper.insert(log);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,22 @@
package com.sdut.labex.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.entity.SubmitRecords;
import com.sdut.labex.mapper.SubmitRecordsMapper;
import com.sdut.labex.service.SubmitRecordsService;
import org.springframework.stereotype.Service;
/**
* @author springforest
* @description 针对表submit_records(实验提交记录)的数据库操作Service实现
* @createDate 2023-06-20 14:41:09
*/
@Service
public class SubmitRecordsServiceImpl extends ServiceImpl<SubmitRecordsMapper, SubmitRecords>
implements SubmitRecordsService {
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sdut.labex.mapper.FileMapper">
<resultMap id="BaseResultMap" type="com.sdut.labex.entity.FileEntity">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="path" column="path" jdbcType="VARCHAR"/>
<result property="experimentId" column="experiment_id" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id,name,path,
experiment_id
</sql>
</mapper>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sdut.labex.mapper.LogMapper">
<resultMap id="BaseResultMap" type="com.sdut.labex.entity.LogEntity">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="date" column="date" jdbcType="VARCHAR"/>
<result property="cost" column="cost" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,content,date,
cost
</sql>
</mapper>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sdut.labex.mapper.SubmitRecordsMapper">
<resultMap id="BaseResultMap" type="com.sdut.labex.entity.SubmitRecords">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="experimentId" column="experiment_id" jdbcType="INTEGER"/>
<result property="studentId" column="student_id" jdbcType="INTEGER"/>
<result property="filePath" column="file_path" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,experiment_id,student_id,
file_path
</sql>
</mapper>

View File

@ -48,6 +48,13 @@ const routes = [
path: '/ApplyExperiment',
name: 'ApplyExperiment',
component: () => import('../views/ApplyExperiment/ApplyExperiment.vue')
},
{
path: '/Upload',
name: 'Upload',
component: () => import('../views/Admin/Upload.vue')
}
]
},

View File

@ -0,0 +1,73 @@
<template>
<el-space>
<el-upload :on-change="fileChange" :show-file-list="false" :auto-upload="false">
<el-button type="warning">上传</el-button>
</el-upload>
<el-button type="warning" @click="download()">下载</el-button>
</el-space>
</template>
<script>
let formData = new FormData;
export default {
name: 'Upload',
methods: {
fileChange(files, fileList) {
formData.append('file', files.raw)
files = null;
this.loading = true;
this.$http({
method: 'post',
url: '/upload',
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(res => {
if (res.data.code === 200) {
this.$notify({
title: '上传成功',
message: res.data.msg,
type: 'success'
});
} else {
this.$notify({
title: '文件解析失败',
message: res.data.msg,
type: 'error'
});
}
formData = null;
formData = new FormData();
this.loading = false;
})
},
download() {
const fileName = "example.txt"; //
this.$http({
url: "/download",
method: "POST",
params: {
path: "/Users/springforest/IdeaProjects/LabEx-Server/files/22级新生信息.xlsx"
},
responseType: "blob" // blob
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = url;
link.download = fileName;
link.click();
window.URL.revokeObjectURL(url);
}).catch((error) => {
console.error("下载文件失败:", error);
});
}
},
};
</script>
<style scoped>
</style>

View File

@ -1,56 +1,49 @@
<template>
<el-page-header content="实验项目申请" style="margin-bottom: 30px" @back="this.$router.push('/Home')"/>
<el-card>
<div>
<form @submit.prevent="onSubmit">
<form @submit.prevent="submit">
<el-form-item label="项目名称">
<el-input v-model="form.name" type="text" id="name" required/>
</el-form-item>
<el-form-item label="项目类型">
<el-checkbox-group v-model="form.type">
<el-checkbox label="类型一" name="type" />
<el-checkbox label="类型二" name="type" />
<el-checkbox label="类型三" name="type" />
<el-checkbox label="类型四" name="type" />
</el-checkbox-group>
</el-form-item>
<el-form-item label="备注">
<el-input v-model="form.desc" type="textarea" style="margin-left: 30px"/>
<el-form-item label="上课班级">
<el-input v-model="form.className" type="text" id="name" required/>
</el-form-item>
<el-form-item class="btn-Ex">
<el-button type="primary" @click="onSubmit">确认</el-button>
<el-button @click="cancelApply">取消</el-button>
<el-button type="primary" @click="submit">确认</el-button>
</el-form-item>
</form>
</div>
</el-card>
<el-card style="margin-top: 10px">
<span style="width: 100%">待规划项目</span>
<el-radio-group v-model="size">
<el-radio label="large">Large</el-radio>
<el-radio>Default</el-radio>
<el-radio label="small">Small</el-radio>
</el-radio-group>
<el-table :data="itemList" style="width: 100%">
<el-table-column fixed prop="name" label="项目名称" width="150" />
<el-table-column prop="type" label="项目种类" width="120" />
<el-table-column prop="state" label="审批状态" width="120" />
<el-table-column prop="address" label="项目描述" width="600" />
<el-table-column fixed="right" label="操作" width="120">
<el-table-column fixed prop="name" label="项目名称"/>
<el-table-column prop="className" label="上课班级"/>
<el-table-column prop="status" label="审批状态">
<template #default="scope">
<el-tag v-show="scope.row.status === 0" type="warning">待审核</el-tag>
<el-tag v-show="scope.row.status === 2" type="danger">拒绝</el-tag>
<el-tag v-show="scope.row.status === 1" type="success">通过</el-tag>
</template>
</el-table-column>
<el-table-column fixed="right" label="操作">
<template #default>
<el-button link type="primary" size="small" @click="setting"
>Detail</el-button
>
<el-button link type="primary" size="small">设置</el-button>
<el-button link type="primary" size="small">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="getList"
@current-change="getList"
v-model:current-page="form.pageNum"
v-model:page-size="form.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="form.total"/>
</el-card>
</template>
<script>
import axios from 'axios';
import {computed, ref} from 'vue'
import {ElMessage} from "element-plus";
const size = ref('')
computed(() => {
@ -70,36 +63,54 @@ export default {
itemList: [],
form: {
name: '',
type: [],
desc: '',
className: '',
pageNum: 1,
pageSize: 10,
total: 0
},
size: '',
}
},
mounted() {
//
axios.get('http://localhost:8080/room').then(response => {
this.itemList = response.data;
});
this.getList()
},
methods: {
onSubmit() {
axios.post('http://localhost:8080/room', this.form)
.then(response => {
console.log(response.data);
//
submit() {
this.$http({
url: "/experiment",
method: "post",
data: this.form
}).then(({data}) => {
if (data.code !== 200) {
ElMessage({
message: '信息获取失败',
type: 'error',
})
.catch(error => {
console.error(error);
//
});
},
cancelApply(){
this.$router.push('/Home');
},
setting(){
this.$router.push('/BorrowRoom')
} else {
ElMessage({
message: data.msg,
type: 'success',
})
this.getList()
}
})
},
getList() {
this.$http({
url: "/experiments/" + this.form.pageNum + "/" + this.form.pageSize,
method: 'post',
data: {}
}).then(({data}) => {
if (data.code !== 200) {
ElMessage({
message: '信息获取失败',
type: 'error',
})
} else {
this.itemList = data.list;
}
})
},
}
}
</script>

View File

@ -0,0 +1,224 @@
<template>
<el-page-header content="实验批阅" style="margin-bottom: 30px" @back="this.$router.push('/Login')"/>
<el-card style="max-width: 1200px;margin:0 auto;background-color: #f9fafb">
<div style="display: flex;justify-content: space-between;align-items: center">
<el-space>
<el-button type="primary" style="margin-right: 10px;" @click="dialogVisibleForAdd = true">添加成员</el-button>
<el-upload :on-change="fileChange" :show-file-list="false" :auto-upload="false">
<el-button type="warning" :loading="loading">上传</el-button>
</el-upload>
</el-space>
>
</div>
<!--表格展示-->
<div style="margin-top: 20px">
<el-table :data="userList" border stripe v-loading="loading">
<el-table-column align="center" prop="id" label="ID"/>
<el-table-column align="center" prop="username" label="姓名"/>
<el-table-column align="center" prop="className" label="班级"/>
<el-table-column align="center" prop="department" label="学院"/>
<el-table-column align="center" prop="role" label="身份"/>
<el-table-column align="center" label="操作">
<template #default="scope">
<el-button type="primary" @click="update(scope.row)">
<span style="margin-left: 3px">更新</span>
</el-button>
<el-button type="danger" @click="remove(scope.row.id)">
<span style="margin-left: 3px">删除</span>
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<el-pagination
@size-change="getUser"
@current-change="getUser"
v-model:current-page="pageNum"
v-model:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
<!--添加用户的对话框-->
<el-dialog title="添加用户" v-model="dialogVisibleForAdd" width="30%" style="padding-top: 30px">
<el-form ref="addForm" :model="addForm" label-width="100px">
<el-form-item label="工号">
<el-input :disabled="isEdit" v-model="addForm.id" placeholder="请输入工号..."></el-input>
</el-form-item>
<el-form-item label="姓名">
<el-input v-model="addForm.username" placeholder="请输入姓名..."></el-input>
</el-form-item>
<el-form-item label="班级">
<el-input v-model="addForm.className" placeholder="请输入班级..."></el-input>
</el-form-item>
<el-form-item label="学院">
<el-input v-model="addForm.department" placeholder="请输入班级..."></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input v-model="addForm.password" placeholder="请输入密码..."></el-input>
</el-form-item>
<el-form-item label="身份">
<el-input v-model="addForm.role" placeholder="请输入密码..."></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="addUser"> </el-button>
<el-button @click="dialogVisibleForAdd = false"> </el-button>
</span>
</el-dialog>
</el-card>
</template>
<script>
import {ElMessage, ElMessageBox} from "element-plus";
let formData = new FormData;
export default {
name: "UserManage",
data() {
return {
loading: true,
isEdit: false,
pageSize: 30,
pageNum: 1,
total: 0,
addForm: {
id: '',
username: '',
role: 'teacher',
password: '123456',
className: '',
department: ''
},
userList: [],
dialogVisibleForAdd: false,
}
},
mounted() {
this.getUser();
},
methods: {
getUser() {
this.loading = true;
this.userList = [];
this.$http({
method: 'post',
url: '/user/' + this.pageNum + '/' + this.pageSize,
data: {
id: '',
username: ''
}
}).then(({data}) => {
this.userList = data.list;
this.total = data.total;
this.loading = false;
})
},
addUser() {
let method = '';
if (this.isEdit) {
method = 'put';
} else {
method = 'post';
}
this.$http({
method: method,
url: '/user',
data: this.addForm
}).then(({data}) => {
if (data.code === 200) {
ElMessage({
message: '操作成功',
type: 'success'
})
this.isEdit = false;
this.dialogVisibleForAdd = false;
this.addForm.username = '';
this.addForm.id = '';
this.addForm.password = '123456';
this.getUser();
} else {
ElMessage({
message: data.msg,
type: 'error'
})
}
})
},
update(row) {
this.addForm = JSON.parse(JSON.stringify(row));
this.isEdit = true;
this.dialogVisibleForAdd = true;
},
remove(id) {
ElMessageBox.confirm(
'该操作不可撤销',
'警告',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
this.$http({
method: 'delete',
url: '/user/' + id,
}).then(res => {
this.getUser();
ElMessage({
type: 'success',
message: '删除成功',
})
})
})
.catch(() => {
ElMessage({
type: 'info',
message: '删除已取消',
})
})
},
fileChange(files, fileList) {
formData.append('file', files.raw)
files = null;
this.loading = true;
this.$http({
method: 'post',
url: '/addUserBatch',
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(res => {
if (res.data.code === 200) {
this.$notify({
title: '上传成功',
message: res.data.msg,
type: 'success'
});
} else {
this.$notify({
title: '文件解析失败',
message: res.data.msg,
type: 'error'
});
}
formData = null;
formData = new FormData();
this.loading = false;
})
},
}
}
</script>
<style scoped>
</style>

View File

@ -1,5 +1,5 @@
<template>
<el-page-header content="借用登记" style="margin-bottom: 30px" @back="this.$router.push('/Login')"/>
<el-page-header content="教室申请" style="margin-bottom: 30px" @back="this.$router.push('/Login')"/>
<el-card>
<Table :msg="borrowForm"/>
<el-divider/>

View File

@ -11,15 +11,18 @@
text-color="#fff"
:router="true">
<div style="height: 70px;width: 100%;padding-top: 20px">
<img src="../assets/img/logoW.png" style="height: 60%;width: 80%; margin-left: 20px;margin-top: 5px" alt="">
<img src="../assets/img/logoW.png" style="height: 60%;width: 80%; margin-left: 20px;margin-top: 5px"
alt="">
</div>
<el-menu-item index="/ApplyExperiment">实验项目申请</el-menu-item>
<el-menu-item index="/BorrowRoom">教室借用</el-menu-item>
<el-menu-item index="/ExperimentCheck">实验项目批阅</el-menu-item>
<el-menu-item index="/BorrowRoom">教室申请</el-menu-item>
<el-menu-item index="/RecordList">记录查询</el-menu-item>
<el-menu-item index="/Admit">项目审核</el-menu-item>
<el-menu-item index="/UserManage">用户管理</el-menu-item>
<el-menu-item index="/RoomTimeAndReasonManage">系统管理</el-menu-item>
<el-menu-item index="/Personal">个人信息</el-menu-item>
<el-menu-item index="/Upload">上传</el-menu-item>
</el-menu>
</div>
</el-aside>

View File

@ -19,10 +19,10 @@
>
<el-form label-width="120px">
<el-form-item label="旧密码">
<el-input v-model="userInfo.oldPwd"/>
<el-input v-model="userInfo.oldPassword"/>
</el-form-item>
<el-form-item label="新密码">
<el-input v-model="userInfo.newPwd"/>
<el-input v-model="userInfo.newPassword"/>
</el-form-item>
</el-form>
<template #footer>
@ -45,9 +45,8 @@ export default {
userId: '',
role: '',
username: '',
userDepart:'',
newPwd:'',
oldPwd:''
newPassword: '',
oldPassword: ''
},
pwdVisable: false
}
@ -61,7 +60,7 @@ export default {
methods: {
changePwd() {
this.$http({
url:'/changePwd',
url: '/changePassword',
method: 'put',
data: this.userInfo
}).then(({data}) => {