增加用户管理和登录
This commit is contained in:
parent
558f1f4699
commit
e1d5e2850b
@ -40,9 +40,14 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
|
@ -13,7 +13,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {"cn.com.tenlion"})
|
||||
@MapperScan("cn.com.tenlion.mapper")
|
||||
@MapperScan("cn.com.tenlion.**.mapper")
|
||||
public class AimzProjectApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -0,0 +1,68 @@
|
||||
package cn.com.tenlion.auth.controller;
|
||||
|
||||
import cn.com.tenlion.auth.entity.LoginUser;
|
||||
import cn.com.tenlion.auth.entity.User;
|
||||
import cn.com.tenlion.auth.filter.SystemFilter;
|
||||
import cn.com.tenlion.auth.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sign")
|
||||
public class SignController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private HttpServletRequest httpServletRequest;
|
||||
@Autowired
|
||||
private HttpServletResponse httpServletResponse;
|
||||
|
||||
@PostMapping("/signin")
|
||||
public Map<String, Object> signin(@RequestBody LoginUser body) {
|
||||
if (!StringUtils.hasText(body.getUsername())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "用户名不能为空");
|
||||
}};
|
||||
}
|
||||
if (!StringUtils.hasText(body.getPassword())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "密码不能为空");
|
||||
}};
|
||||
}
|
||||
User user = userService.getByUsername(body.getUsername());
|
||||
if (user == null) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "用户不存在");
|
||||
}};
|
||||
}
|
||||
if (!StringUtils.pathEquals(user.getPassword(), body.getPassword())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "密码错误");
|
||||
}};
|
||||
}
|
||||
httpServletRequest.getSession().setAttribute(SystemFilter.SESSION_USER, user);
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 0);
|
||||
put("msg", "success");
|
||||
}};
|
||||
}
|
||||
|
||||
@GetMapping("signout")
|
||||
public void signout() throws IOException {
|
||||
httpServletRequest.getSession().removeAttribute(SystemFilter.SESSION_USER);
|
||||
httpServletResponse.sendRedirect("/route/login.html");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package cn.com.tenlion.auth.controller;
|
||||
|
||||
import cn.com.tenlion.auth.entity.User;
|
||||
import cn.com.tenlion.auth.service.UserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("save")
|
||||
public Map<String, Object> save(@RequestBody User user) {
|
||||
if (!StringUtils.hasText(user.getUsername())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "用户名不能为空");
|
||||
}};
|
||||
}
|
||||
if (!StringUtils.hasText(user.getPassword())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "密码不能为空");
|
||||
}};
|
||||
}
|
||||
User byUsername = userService.getByUsername(user.getUsername());
|
||||
if (byUsername != null) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "用户已存在");
|
||||
}};
|
||||
}
|
||||
userService.save(user);
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 0);
|
||||
put("msg", "success");
|
||||
}};
|
||||
}
|
||||
|
||||
@PutMapping("update/{userId}")
|
||||
public Map<String, Object> update(@PathVariable("userId") Long userId, @RequestBody User user) {
|
||||
if (!StringUtils.hasText(user.getUsername())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "用户名不能为空");
|
||||
}};
|
||||
}
|
||||
if (!StringUtils.hasText(user.getPassword())) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "密码不能为空");
|
||||
}};
|
||||
}
|
||||
User byUsername = userService.getByUsername(user.getUsername());
|
||||
if (byUsername != null && userId == byUsername.getId()) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 400);
|
||||
put("msg", "用户已存在");
|
||||
}};
|
||||
}
|
||||
user.setId(userId);
|
||||
userService.updateById(user);
|
||||
return new HashMap<String, Object>() {{
|
||||
put("code", 0);
|
||||
put("msg", "success");
|
||||
}};
|
||||
}
|
||||
|
||||
@GetMapping("get/{userId}")
|
||||
public User get(@PathVariable("userId") Long userId) {
|
||||
return userService.getById(userId);
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public List<User> list() {
|
||||
return userService.list(new QueryWrapper<>()).stream().peek(user -> user.setPassword(null)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cn.com.tenlion.auth.entity;
|
||||
|
||||
public class LoginUser {
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
return username == null ? "" : username.trim();
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password == null ? "" : password.trim();
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cn.com.tenlion.auth.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;
|
||||
|
||||
@TableName("SYS_USER")
|
||||
public class User {
|
||||
|
||||
@TableId(value = "ID", type = IdType.AUTO)
|
||||
private Long id;
|
||||
@TableField(value = "USERNAME")
|
||||
private String username;
|
||||
@TableField(value = "PASSWORD")
|
||||
private String password;
|
||||
@TableField(value = "NICKNAME")
|
||||
private String nickname;
|
||||
@TableField(value = "EMAIL")
|
||||
private String email;
|
||||
@TableField(value = "PHONE")
|
||||
private String phone;
|
||||
@TableField(value = "GMT_CREATE")
|
||||
private String gmtCreate;
|
||||
|
||||
public Long getId() {
|
||||
return id == null ? 0 : id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username == null ? "" : username.trim();
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password == null ? "" : password.trim();
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname == null ? "" : nickname.trim();
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email == null ? "" : email.trim();
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone == null ? "" : phone.trim();
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getGmtCreate() {
|
||||
return gmtCreate == null ? "" : gmtCreate.trim();
|
||||
}
|
||||
|
||||
public void setGmtCreate(String gmtCreate) {
|
||||
this.gmtCreate = gmtCreate;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.com.tenlion.auth.filter;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SystemFilter implements Filter {
|
||||
|
||||
public static final String SESSION_USER = "SESSION_USER";
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
|
||||
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
Object sessionUser = session.getAttribute(SESSION_USER);
|
||||
if (sessionUser == null) {
|
||||
httpServletResponse.sendRedirect("/route/login.html");
|
||||
return;
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package cn.com.tenlion.auth.init;
|
||||
|
||||
import cn.com.tenlion.auth.entity.User;
|
||||
import cn.com.tenlion.auth.mapper.IUserMapper;
|
||||
import cn.com.tenlion.auth.service.UserService;
|
||||
import cn.com.tenlion.mapper.IAppMapper;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Component
|
||||
public class AppAuthStart implements ApplicationRunner {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppAuthStart.class);
|
||||
|
||||
@Autowired
|
||||
private IAppMapper appMapper;
|
||||
@Autowired
|
||||
private IUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
String checkTableName = appMapper.checkTableExists("SYS_USER");
|
||||
if (!StringUtils.hasText(checkTableName)) {
|
||||
LOG.debug("用户表不存在");
|
||||
appMapper.updateSql("CREATE TABLE `SYS_USER` (\n" +
|
||||
"`ID` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n" +
|
||||
"`USERNAME` varchar(255) DEFAULT NULL COMMENT '用户名',\n" +
|
||||
"`PASSWORD` varchar(255) DEFAULT NULL COMMENT '密码',\n" +
|
||||
"`NICKNAME` varchar(255) DEFAULT NULL COMMENT '昵称',\n" +
|
||||
"`EMAIL` varchar(255) DEFAULT NULL COMMENT '邮箱',\n" +
|
||||
"`PHONE` varchar(255) DEFAULT NULL COMMENT '手机号',\n" +
|
||||
"`GMT_CREATE` varchar(255) DEFAULT NULL COMMENT '创建时间'\n" +
|
||||
");");
|
||||
}
|
||||
Long userCount = userMapper.selectCount(new QueryWrapper<>());
|
||||
if (userCount == 0) {
|
||||
LOG.debug("用户表为空");
|
||||
User user = new User();
|
||||
user.setUsername("admin");
|
||||
user.setPassword("123456");
|
||||
user.setNickname("管理员");
|
||||
user.setPhone("12345678910");
|
||||
user.setEmail("admin@tenlion.cn");
|
||||
user.setGmtCreate(DateUtil.now());
|
||||
userMapper.insert(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package cn.com.tenlion.auth.mapper;
|
||||
|
||||
import cn.com.tenlion.auth.entity.User;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface IUserMapper extends BaseMapper<User> {
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package cn.com.tenlion.auth.service;
|
||||
|
||||
import cn.com.tenlion.auth.entity.User;
|
||||
import cn.com.tenlion.auth.mapper.IUserMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserService extends ServiceImpl<IUserMapper, User> {
|
||||
|
||||
public User getByUsername(String username) {
|
||||
return getOne(new QueryWrapper<User>().eq("USERNAME", username));
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package cn.com.tenlion.config;
|
||||
|
||||
import cn.com.tenlion.auth.filter.SystemFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@ -19,4 +22,14 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addViewController("/").setViewName("forward:/route/login.html");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<SystemFilter> systemFilter() {
|
||||
FilterRegistrationBean<SystemFilter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(new SystemFilter());
|
||||
registration.addUrlPatterns("/route/pages/*","/api/*");
|
||||
registration.setName("systemFilter");
|
||||
registration.setOrder(1);
|
||||
return registration;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
</li>
|
||||
<li>
|
||||
<div class="form-item-block">
|
||||
<button type="button" class="submit" id="submit" onclick="onSubmit()">登录</button>
|
||||
<button type="button" class="submit" id="submit">登录</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@ -62,14 +62,55 @@
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="assets/crpm/js/swiper/swiper-bundle.min.js"></script>
|
||||
<script src="assets/crpm/js/swiper/swiper-bundle.min.js"></script>、
|
||||
<script src="assets/crpm/js/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['element', 'layer', 'util'], function () {
|
||||
var element = layui.element;
|
||||
var layer = layui.layer;
|
||||
var util = layui.util;
|
||||
var $ = layui.$;
|
||||
|
||||
new Swiper('.bg-container', {
|
||||
autoplay: true,
|
||||
})
|
||||
var onSubmit = function () {
|
||||
$('#submit').click(function () {
|
||||
var loadingIndex;
|
||||
$.ajax({
|
||||
url: 'sign/signin',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify({
|
||||
username: $('#username').val(),
|
||||
password: $('#password').val()
|
||||
}),
|
||||
success: function(resp) {
|
||||
console.log(resp)
|
||||
if(resp.code === 0) {
|
||||
window.open('route/pages/index.html', '_self')
|
||||
} else {
|
||||
layer.msg(resp.msg);
|
||||
}
|
||||
},
|
||||
error: function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
layer.msg(data.msg);
|
||||
},
|
||||
beforeSend: function() {
|
||||
loadingIndex = layer.msg('正在登录...', {
|
||||
icon: 16,
|
||||
shade: 0.01
|
||||
});;
|
||||
},
|
||||
complete: function() {
|
||||
layer.close(loadingIndex);
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
@ -416,7 +416,7 @@
|
||||
<li class="layui-nav-item layui-hide layui-show-sm-inline-block">
|
||||
<a href="javascript:void(0);" class="quiteColor">管理员</a>
|
||||
<dl class="layui-nav-child">
|
||||
<dd><a href="javascript:void(0);" class="quiteColor2">退出</a></dd>
|
||||
<dd><a href="javascript:void(0);" class="quiteColor2" id="signoutBtn">退出</a></dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
@ -808,6 +808,10 @@
|
||||
homepage.style.display = 'none';
|
||||
});
|
||||
|
||||
$('#signoutBtn').click(function() {
|
||||
window.open('sign/signout', '_self')
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
221
cjscdsjkbpt/src/main/resources/static/route/pages/user/list.html
Normal file
221
cjscdsjkbpt/src/main/resources/static/route/pages/user/list.html
Normal file
@ -0,0 +1,221 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="/"/>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>车间生产大数据看板平台</title>
|
||||
<link rel="stylesheet" href="assets/crpm/js/layui/css/layui.css" />
|
||||
<link rel="stylesheet" href="assets/crpm/index/index13/index13.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="list-page-container">
|
||||
<div class="search-form-container">
|
||||
<form class="layui-form" lay-filter="searchForm">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-xs2">
|
||||
<div class="layui-form-item searchBox">
|
||||
<div class="layui-input-block inputBox">
|
||||
<input type="text" class="layui-input" id="keywords" name="keywords" placeholder="请输入关键字">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-col-xs2">
|
||||
<button type="button" class="layui-btn" lay-submit lay-filter="searchFilter">搜索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="datatable-container">
|
||||
<table class="layui-hide" id="datatable" lay-filter="datatable"></table>
|
||||
<!-- 表头按钮组 -->
|
||||
<script type="text/html" id="headerToolBar">
|
||||
<div class="layui-btn-group">
|
||||
<button type="button" class="layui-btn layui-btn-sm" id="saveBtn" lay-event="saveEvent"><i class="layui-icon layui-icon-add-circle"></i>新增</button>
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="updateBtn" lay-event="updateEvent"> <i class="layui-icon layui-icon-edit"></i>编辑</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" id="removeBtn" lay-event="removeEvent"><i class="layui-icon layui-icon-delete"></i>删除</button>
|
||||
</div>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/crpm/js/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.use(["form", "table"], function () {
|
||||
var form = layui.form;
|
||||
var table = layui.table;
|
||||
var layer = layui.layer;
|
||||
var util = layui.util;
|
||||
var $ = layui.$;
|
||||
var $win = $(window);
|
||||
|
||||
var initTableData = function(keywords) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'api/data/list/49a150/0b46f6',
|
||||
data: 'keywords=' + (keywords ? encodeURI(keywords) : ''),
|
||||
contentType: "application/json;charset=utf-8",
|
||||
success: function(resp) {
|
||||
var datas = resp;
|
||||
table.render({
|
||||
elem: "#datatable",
|
||||
id: 'datatable',
|
||||
height: $win.height() - 83,
|
||||
toolbar: '#headerToolBar',
|
||||
cols: [
|
||||
[
|
||||
{ type: "checkbox", fixed: "left" },
|
||||
{
|
||||
field: "rowNum",
|
||||
width: 80,
|
||||
title: "序号",
|
||||
fixed: "left",
|
||||
align: "center",
|
||||
templet: "<span>{{d.LAY_NUM}}</span>",
|
||||
},
|
||||
{
|
||||
field: 'wd',
|
||||
title: '温度',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'sd',
|
||||
title: '湿度',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'PM25',
|
||||
title: 'PM25',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'PM10',
|
||||
title: 'PM10',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'CO2',
|
||||
title: 'CO2',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'zs',
|
||||
title: '噪声',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'gzqd',
|
||||
title: '光照强度',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'qy',
|
||||
title: '气压',
|
||||
minWidth: 80,
|
||||
},
|
||||
]
|
||||
],
|
||||
data: datas,
|
||||
page: true,
|
||||
limits: [20, 50, 100, 200],
|
||||
limit: 20,
|
||||
});
|
||||
},
|
||||
error: function(resp) {
|
||||
console.error(resp);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var addEvent = function() {
|
||||
// 事件 - 增删改
|
||||
table.on('toolbar(datatable)', function(obj) {
|
||||
var layEvent = obj.event;
|
||||
var checkStatus = table.checkStatus('datatable');
|
||||
var checkDatas = checkStatus.data;
|
||||
if(layEvent === 'saveEvent') {
|
||||
top.layer.open({
|
||||
type: 2,
|
||||
title: false,
|
||||
closeBtn: false,
|
||||
shadeClose: true,
|
||||
content: 'route/pages/0b46f6/save.html',
|
||||
area: ['400px', '100%'],
|
||||
offset: 'r',
|
||||
anim: 'slideLeft',
|
||||
end: function() {
|
||||
initTableData();
|
||||
}
|
||||
});
|
||||
} else if(layEvent === 'updateEvent') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.layer.msg('请勾选要编辑的数据');
|
||||
} else if(checkDatas.length > 1) {
|
||||
top.layer.msg('不能编辑多条数据');
|
||||
} else {
|
||||
top.layer.open({
|
||||
type: 2,
|
||||
title: false,
|
||||
closeBtn: false,
|
||||
shadeClose: true,
|
||||
content: 'route/pages/0b46f6/update.html?id='+ checkDatas[0].id,
|
||||
area: ['400px', '100%'],
|
||||
offset: 'r',
|
||||
anim: 'slideLeft',
|
||||
end: function() {
|
||||
initTableData();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if(layEvent === 'removeEvent') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.layer.msg('请勾选要删除的数据');
|
||||
} else {
|
||||
var ids = '';
|
||||
for(var i = 0, item; item = checkDatas[i++];) {
|
||||
if(i > 1) {
|
||||
ids += ',';
|
||||
}
|
||||
ids += item.id;
|
||||
}
|
||||
top.layer.confirm('确定删除吗?', {title: false}, function(index) {
|
||||
top.layer.close(index);
|
||||
var loadingIndex;
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: 'api/data/delete/49a150/0b46f6?ids=' + ids,
|
||||
contentType: "application/json;charset=utf-8",
|
||||
success: function(resp) {
|
||||
top.layer.msg('删除成功');
|
||||
initTableData();
|
||||
},
|
||||
error: function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
top.layer.msg(data.msg);
|
||||
},
|
||||
beforeSend: function() {
|
||||
loadingIndex = top.layer.msg('正在删除...', {
|
||||
icon: 16,
|
||||
shade: 0.01
|
||||
});;
|
||||
},
|
||||
complete: function() {
|
||||
top.layer.close(loadingIndex);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
form.on('submit(searchFilter)', function(formData) {
|
||||
initTableData(formData.field.keywords);
|
||||
});
|
||||
}
|
||||
|
||||
initTableData();
|
||||
addEvent();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
137
cjscdsjkbpt/src/main/resources/static/route/pages/user/save.html
Normal file
137
cjscdsjkbpt/src/main/resources/static/route/pages/user/save.html
Normal file
@ -0,0 +1,137 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="/"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>车间生产大数据看板平台</title>
|
||||
<link rel="stylesheet" href="assets/crpm/js/layui/css/layui.css" />
|
||||
<link rel="stylesheet" href="assets/crpm/index/index13/index13.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="form-container">
|
||||
<form class="layui-form" lay-filter="dataForm">
|
||||
<div class="form-header">环境监测新增数据</div>
|
||||
<div class="form-body">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">温度</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="wd" placeholder="请输入温度">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">湿度</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="sd" placeholder="请输入湿度">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">PM25</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="PM25" placeholder="请输入PM25">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">PM10</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="PM10" placeholder="请输入PM10">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">CO2</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="CO2" placeholder="请输入CO2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">噪声</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="zs" placeholder="请输入噪声">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">光照强度</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="gzqd" placeholder="请输入光照强度">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">气压</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="qy" placeholder="请输入气压">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-footer">
|
||||
<div class="layui-btn-group">
|
||||
<button type="button" class="layui-btn layui-btn-sm" id="submitBtn" lay-submit lay-filter="confirmFilter">提交</button>
|
||||
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" id="closeBtn" lay-submit lay-filter="closeFilter">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/crpm/js/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['form'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var util = layui.util;
|
||||
var $ = layui.$;
|
||||
var $win = $(window);
|
||||
|
||||
var close = function() {
|
||||
top.layer.close(top.layer.getFrameIndex(window.name))
|
||||
}
|
||||
|
||||
var init = function() {}
|
||||
|
||||
var addEvent = function() {
|
||||
// 提交表单
|
||||
form.on('submit(confirmFilter)', function(formData) {
|
||||
top.layer.confirm('确定提交吗?', {title: false}, function(index) {
|
||||
top.layer.close(index);
|
||||
var loadingIndex;
|
||||
$.ajax({
|
||||
url: 'api/data/save/49a150/0b46f6',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(formData.field),
|
||||
success: function(resp) {
|
||||
var loadLayerIndex;
|
||||
var layerIndex = top.layer.confirm('保存成功,继续添加?', {title: false}, function(index) {
|
||||
top.layer.close(index);
|
||||
window.location.reload();
|
||||
}, function() {
|
||||
close();
|
||||
});
|
||||
},
|
||||
error: function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
top.layer.msg(data.msg);
|
||||
},
|
||||
beforeSend: function() {
|
||||
loadingIndex = top.layer.msg('正在提交...', {
|
||||
icon: 16,
|
||||
shade: 0.01
|
||||
});;
|
||||
},
|
||||
complete: function() {
|
||||
top.layer.close(loadingIndex);
|
||||
}
|
||||
})
|
||||
});
|
||||
return false;
|
||||
});
|
||||
form.on('submit(closeFilter)', function(formData) {
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
addEvent();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,161 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="/"/>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>车间生产大数据看板平台</title>
|
||||
<link rel="stylesheet" href="assets/crpm/js/layui/css/layui.css" />
|
||||
<link rel="stylesheet" href="assets/crpm/index/index13/index13.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="form-container">
|
||||
<form class="layui-form" lay-filter="dataForm">
|
||||
<div class="form-header">环境监测编辑数据</div>
|
||||
<div class="form-body">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">温度</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="wd" placeholder="请输入温度">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">湿度</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="sd" placeholder="请输入湿度">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">PM25</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="PM25" placeholder="请输入PM25">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">PM10</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="PM10" placeholder="请输入PM10">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">CO2</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="CO2" placeholder="请输入CO2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">噪声</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="zs" placeholder="请输入噪声">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">光照强度</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="gzqd" placeholder="请输入光照强度">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label13">气压</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" class="layui-input" name="qy" placeholder="请输入气压">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-footer">
|
||||
<div class="layui-btn-group">
|
||||
<button type="button" class="layui-btn layui-btn-sm" id="submitBtn" lay-submit lay-filter="confirmFilter">提交</button>
|
||||
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" id="closeBtn" lay-submit lay-filter="closeFilter">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/crpm/js/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['form'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var util = layui.util;
|
||||
var $ = layui.$;
|
||||
var $win = $(window);
|
||||
var id = layui.url().search.id;
|
||||
|
||||
var close = function() {
|
||||
top.layer.close(top.layer.getFrameIndex(window.name))
|
||||
}
|
||||
|
||||
var init = function() {
|
||||
var loadingIndex;
|
||||
$.ajax({
|
||||
url: 'api/data/get/49a150/0b46f6/id/'+ id,
|
||||
success: function(resp) {
|
||||
form.val('dataForm', resp);
|
||||
form.render(null, 'dataForm');
|
||||
},
|
||||
error: function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
top.layer.msg(data.msg);
|
||||
},
|
||||
beforeSend: function() {
|
||||
loadingIndex = top.layer.msg('正在加载...', {
|
||||
icon: 16,
|
||||
shade: 0.01
|
||||
});;
|
||||
},
|
||||
complete: function() {
|
||||
top.layer.close(loadingIndex);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var addEvent = function() {
|
||||
// 提交表单
|
||||
form.on('submit(confirmFilter)', function(formData) {
|
||||
top.layer.confirm('确定提交吗?', {title: false}, function(index) {
|
||||
top.layer.close(index);
|
||||
var loadingIndex;
|
||||
$.ajax({
|
||||
url: 'api/data/update/49a150/0b46f6/id/' + id,
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(formData.field),
|
||||
success: function(resp) {
|
||||
var loadLayerIndex;
|
||||
var layerIndex = top.layer.confirm('保存成功,继续添加?', {title: false}, function(index) {
|
||||
top.layer.close(index);
|
||||
window.location.reload();
|
||||
}, function() {
|
||||
close();
|
||||
});
|
||||
},
|
||||
error: function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
top.layer.msg(data.msg);
|
||||
},
|
||||
beforeSend: function() {
|
||||
loadingIndex = top.layer.msg('正在提交...', {
|
||||
icon: 16,
|
||||
shade: 0.01
|
||||
});;
|
||||
},
|
||||
complete: function() {
|
||||
top.layer.close(loadingIndex);
|
||||
}
|
||||
})
|
||||
});
|
||||
return false;
|
||||
});
|
||||
form.on('submit(closeFilter)', function(formData) {
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
addEvent();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user