2026-01-07
1.优化代码
This commit is contained in:
@@ -1,23 +1,22 @@
|
|||||||
package cn.lailab.toolbox.beans.domain;
|
package cn.lailab.toolbox.beans.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Parameter {
|
public class Parameter {
|
||||||
private int id;//参数ID
|
private int id;// 参数ID
|
||||||
private int sortId;//排序号
|
private int sortId;// 排序号
|
||||||
private int isSystem;//是否系统参数(0-用户参数 1-系统参数)
|
private int isSystem;// 是否系统参数(0-用户参数 1-系统参数)
|
||||||
private String category;//分类分组
|
private String category;// 分类分组
|
||||||
private String type;//参数类型: string, number, boolean, json, text
|
private String type;// 参数类型: string, number, boolean, json, text
|
||||||
private String parameterName;//参数名称
|
private String parameterName;// 参数名称
|
||||||
private String parameterValue;//参数值
|
private String parameterValue;// 参数值
|
||||||
private String description ;//参数描述
|
private String description;// 参数描述
|
||||||
private int status;//状态: 0-禁用 1-启用
|
private int status;// 状态: 0-禁用 1-启用
|
||||||
private String createUser;//创建人
|
private String createUser;// 创建人
|
||||||
private Date createTime;//创建时间
|
private Date createTime;// 创建时间
|
||||||
private String updateUser;//更新人
|
private String updateUser;// 更新人
|
||||||
private Date updateTime ;//更新时间
|
private Date updateTime;// 更新时间
|
||||||
private String authCode;
|
private String authCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.lailab.toolbox.beans.domain;
|
package cn.lailab.toolbox.beans.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class AuthController {
|
public class AuthController {
|
||||||
|
|
||||||
@@ -27,10 +26,10 @@ public class AuthController {
|
|||||||
String rst;
|
String rst;
|
||||||
logger.info("调用方法getAuthCode()开始 入参:{}", user);
|
logger.info("调用方法getAuthCode()开始 入参:{}", user);
|
||||||
String code = authService.getAuthCode(user);
|
String code = authService.getAuthCode(user);
|
||||||
if (code == null|| code.isEmpty()) {
|
if (code == null || code.isEmpty()) {
|
||||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!","");
|
rst = resultService.error("获取授权码失败,请确认登录信息无误!", "");
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.success("获取授权码成功!",code);
|
rst = resultService.success("获取授权码成功!", code);
|
||||||
}
|
}
|
||||||
logger.info("调用方法getAuthCode()结束 返回:{}", code);
|
logger.info("调用方法getAuthCode()结束 返回:{}", code);
|
||||||
return rst;
|
return rst;
|
||||||
@@ -41,10 +40,10 @@ public class AuthController {
|
|||||||
String rst;
|
String rst;
|
||||||
logger.info("调用方法getAuthMd5Code()开始 入参:{}", user);
|
logger.info("调用方法getAuthMd5Code()开始 入参:{}", user);
|
||||||
String code = authService.getAuthMd5Code(user);
|
String code = authService.getAuthMd5Code(user);
|
||||||
if (code == null|| code.isEmpty()) {
|
if (code == null || code.isEmpty()) {
|
||||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!","");
|
rst = resultService.error("获取授权码失败,请确认登录信息无误!", "");
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.success("获取授权码成功!",code);
|
rst = resultService.success("获取授权码成功!", code);
|
||||||
}
|
}
|
||||||
logger.info("调用方法getAuthMd5Code()结束 返回:{}", code);
|
logger.info("调用方法getAuthMd5Code()结束 返回:{}", code);
|
||||||
return rst;
|
return rst;
|
||||||
|
|||||||
@@ -31,58 +31,56 @@ public class ParameterController {
|
|||||||
String defaultAuthCode;
|
String defaultAuthCode;
|
||||||
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/api/parameter/getAllParameter")
|
@RequestMapping("/api/parameter/getAllParameter")
|
||||||
public String getAllParameter(@RequestBody Parameter parameter) {
|
public String getAllParameter(@RequestBody Parameter parameter) {
|
||||||
logger.info("调用方法getAllParameter()开始 入参:{}", parameter);
|
logger.info("调用方法getAllParameter()开始 入参:{}", parameter);
|
||||||
String rst;
|
String rst;
|
||||||
if(this.checkAuth(parameter.getAuthCode())){
|
if (this.checkAuth(parameter.getAuthCode())) {
|
||||||
List<Parameter> parameters = parameterService.getAllParameter(parameter);
|
List<Parameter> parameters = parameterService.getAllParameter(parameter);
|
||||||
if(!parameters.isEmpty()) {
|
if (!parameters.isEmpty()) {
|
||||||
rst = resultService.success("获取所有参数信息成功!", parameters);
|
rst = resultService.success("获取所有参数信息成功!", parameters);
|
||||||
} else {
|
} else {
|
||||||
rst = resultService.success("获取所有参数信息失败!", "");
|
rst = resultService.success("获取所有参数信息失败!", "");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法getAllParameter()结束 返回:{}", rst);
|
logger.info("调用方法getAllParameter()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/api/parameter/getParameterByName")
|
@RequestMapping("/api/parameter/getParameterByName")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String getParameterByName(@RequestBody Parameter parameter){
|
public String getParameterByName(@RequestBody Parameter parameter) {
|
||||||
logger.info("调用方法getParameterByName()开始 入参:{}", parameter);
|
logger.info("调用方法getParameterByName()开始 入参:{}", parameter);
|
||||||
String parameterName = parameter.getParameterName();
|
String parameterName = parameter.getParameterName();
|
||||||
String rst;
|
String rst;
|
||||||
if(parameterName == null|| parameterName.isEmpty()){
|
if (parameterName == null || parameterName.isEmpty()) {
|
||||||
rst = resultService.error("参数parameterName不存在,请检查入参!");
|
rst = resultService.error("参数parameterName不存在,请检查入参!");
|
||||||
}else {
|
} else {
|
||||||
if(this.checkAuth(parameter.getAuthCode())){
|
if (this.checkAuth(parameter.getAuthCode())) {
|
||||||
Parameter rstParameter = parameterService.getParameterByName(parameter);
|
Parameter rstParameter = parameterService.getParameterByName(parameter);
|
||||||
if (rstParameter == null) {
|
if (rstParameter == null) {
|
||||||
rst = resultService.error("未获取参数信息!", "");
|
rst = resultService.error("未获取参数信息!", "");
|
||||||
} else {
|
} else {
|
||||||
rst = resultService.success("获取参数信息成功!", rstParameter);
|
rst = resultService.success("获取参数信息成功!", rstParameter);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.info("调用方法getParameterByName()结束 返回:{}", rst);
|
logger.info("调用方法getParameterByName()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkAuth(String auth_code){
|
public boolean checkAuth(String auth_code) {
|
||||||
logger.info("调用方法checkAuth()开始 入参:{}",auth_code);
|
logger.info("调用方法checkAuth()开始 入参:{}", auth_code);
|
||||||
String auth_new = authService.getAuthMd5CodeInside();
|
String auth_new = authService.getAuthMd5CodeInside();
|
||||||
logger.info("最新授权码 {}",auth_new);
|
logger.info("最新授权码 {}", auth_new);
|
||||||
authService.addUseCount(auth_new);
|
authService.addUseCount(auth_new);
|
||||||
logger.info("授权码 {} 使用次数加1",auth_new);
|
logger.info("授权码 {} 使用次数加1", auth_new);
|
||||||
boolean is_match = auth_new.equals(auth_code)||defaultAuthCode.equals(auth_code);
|
boolean is_match = auth_new.equals(auth_code) || defaultAuthCode.equals(auth_code);
|
||||||
logger.info("调用方法checkAuth()结束 返回:{}",is_match);
|
logger.info("调用方法checkAuth()结束 返回:{}", is_match);
|
||||||
return is_match;
|
return is_match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
public class ToolController {
|
public class ToolController {
|
||||||
|
|
||||||
@RequestMapping("/JiSuanQi")
|
@RequestMapping("/JiSuanQi")
|
||||||
public String JiSuanQi(){
|
public String JiSuanQi() {
|
||||||
return "tools/JiSuanQi/JiSuanQi.html";
|
return "tools/JiSuanQi/JiSuanQi.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public String index(){
|
public String index() {
|
||||||
return "index.html";
|
return "index.html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserServiceImpl userService ;
|
UserServiceImpl userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ResultServiceImpl resultService;
|
ResultServiceImpl resultService;
|
||||||
@@ -33,15 +32,15 @@ public class UserController {
|
|||||||
public String getAllUser(@RequestBody User user) {
|
public String getAllUser(@RequestBody User user) {
|
||||||
String rst;
|
String rst;
|
||||||
logger.info("调用方法getAllUser()开始 入参:{}", user);
|
logger.info("调用方法getAllUser()开始 入参:{}", user);
|
||||||
if(this.checkAuth(user.getAuthCode())){
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
List<User> users = userService.getAllUser(user);
|
List<User> users = userService.getAllUser(user);
|
||||||
if(!users.isEmpty()) {
|
if (!users.isEmpty()) {
|
||||||
rst = resultService.success("获取所有用户信息成功!", users);
|
rst = resultService.success("获取所有用户信息成功!", users);
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.error("获取所有用户信息失败!", "");
|
rst = resultService.error("获取所有用户信息失败!", "");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法getAllUser()结束 返回:{}", rst);
|
logger.info("调用方法getAllUser()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
@@ -49,22 +48,22 @@ public class UserController {
|
|||||||
|
|
||||||
@RequestMapping("/api/user/getUserByOpenId")
|
@RequestMapping("/api/user/getUserByOpenId")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String getUserByOpenId(@RequestBody User user){
|
public String getUserByOpenId(@RequestBody User user) {
|
||||||
logger.info("调用方法getUserByOpenId()开始 入参:{}", user);
|
logger.info("调用方法getUserByOpenId()开始 入参:{}", user);
|
||||||
String openId = user.getOpenId();
|
String openId = user.getOpenId();
|
||||||
String rst;
|
String rst;
|
||||||
if(openId == null|| openId.isEmpty()){
|
if (openId == null || openId.isEmpty()) {
|
||||||
rst = resultService.error("参数code不存在,请检查入参!");
|
rst = resultService.error("参数code不存在,请检查入参!");
|
||||||
}else {
|
} else {
|
||||||
if(this.checkAuth(user.getAuthCode())){
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
User rstUser = userService.getUserByOpenId(user);
|
User rstUser = userService.getUserByOpenId(user);
|
||||||
if (rstUser == null) {
|
if (rstUser == null) {
|
||||||
rst = resultService.error("未获取用户信息!", "");
|
rst = resultService.error("未获取用户信息!", "");
|
||||||
} else {
|
} else {
|
||||||
rst = resultService.success("获取用户信息成功!", rstUser);
|
rst = resultService.success("获取用户信息成功!", rstUser);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.info("调用方法getUserByOpenId()结束 返回:{}", rst);
|
logger.info("调用方法getUserByOpenId()结束 返回:{}", rst);
|
||||||
@@ -72,15 +71,15 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/api/user/addUser")
|
@RequestMapping("/api/user/addUser")
|
||||||
public String addUser(@RequestBody User user){
|
public String addUser(@RequestBody User user) {
|
||||||
logger.info("调用方法addUser()开始 入参:{}",user);
|
logger.info("调用方法addUser()开始 入参:{}", user);
|
||||||
logger.info("1.检测用户是否存在(addUser)");
|
logger.info("1.检测用户是否存在(addUser)");
|
||||||
int exist = userService.userExist(user);
|
int exist = userService.userExist(user);
|
||||||
String rst;
|
String rst;
|
||||||
if(exist>0) {
|
if (exist > 0) {
|
||||||
logger.info("2.用户已存在,不能新建用户(addUser)");
|
logger.info("2.用户已存在,不能新建用户(addUser)");
|
||||||
rst = resultService.other(-2,"用户已存在!","");
|
rst = resultService.other(-2, "用户已存在!", "");
|
||||||
}else{
|
} else {
|
||||||
logger.info("2.用户不存在,新建用户(addUser)");
|
logger.info("2.用户不存在,新建用户(addUser)");
|
||||||
int code = userService.addUser(user);
|
int code = userService.addUser(user);
|
||||||
if (code > 0) {
|
if (code > 0) {
|
||||||
@@ -94,10 +93,10 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/api/user/login")
|
@RequestMapping("/api/user/login")
|
||||||
public String login(@RequestBody User user){
|
public String login(@RequestBody User user) {
|
||||||
logger.info("调用方法login()开始 入参:{}",user);
|
logger.info("调用方法login()开始 入参:{}", user);
|
||||||
String rst;
|
String rst;
|
||||||
if(this.checkAuth(user.getAuthCode())) {
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
logger.info("1.检测用户是否存在(login)");
|
logger.info("1.检测用户是否存在(login)");
|
||||||
int exist = userService.userExist(user);
|
int exist = userService.userExist(user);
|
||||||
if (exist > 0) {
|
if (exist > 0) {
|
||||||
@@ -119,59 +118,58 @@ public class UserController {
|
|||||||
logger.info("2.用户不存在,需要注册(login)");
|
logger.info("2.用户不存在,需要注册(login)");
|
||||||
rst = resultService.other(-2, "用户不存在,请进行注册!", "");
|
rst = resultService.other(-2, "用户不存在,请进行注册!", "");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法login()结束 返回:{}", rst);
|
logger.info("调用方法login()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/api/user/loginByOpenId")
|
@RequestMapping("/api/user/loginByOpenId")
|
||||||
public String loginByOpenId(@RequestBody User user){
|
public String loginByOpenId(@RequestBody User user) {
|
||||||
logger.info("loginByOpenId()开始 入参:{}",user);
|
logger.info("loginByOpenId()开始 入参:{}", user);
|
||||||
if (user.getOpenId() == null || user.getOpenId().trim().isEmpty()) {
|
if (user.getOpenId() == null || user.getOpenId().trim().isEmpty()) {
|
||||||
logger.info("参数OpenId不存在,请检查入参!");
|
logger.info("参数OpenId不存在,请检查入参!");
|
||||||
return resultService.error("参数OpenId不存在,请检查入参!");
|
return resultService.error("参数OpenId不存在,请检查入参!");
|
||||||
}
|
}
|
||||||
String rst;
|
String rst;
|
||||||
if(this.checkAuth(user.getAuthCode())) {
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
User rstUser = userService.loginByOpenId(user);
|
User rstUser = userService.loginByOpenId(user);
|
||||||
if (rstUser == null) {
|
if (rstUser == null) {
|
||||||
rst = resultService.error("登录失败!");
|
rst = resultService.error("登录失败!");
|
||||||
} else {
|
} else {
|
||||||
rst = resultService.success("登录成功!", rstUser);
|
rst = resultService.success("登录成功!", rstUser);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法loginByOpenId()结束 返回:{}", rst);
|
logger.info("调用方法loginByOpenId()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/api/user/updateUser")
|
@RequestMapping("/api/user/updateUser")
|
||||||
public String updateUser(@RequestBody User user){
|
public String updateUser(@RequestBody User user) {
|
||||||
logger.info("调用方法updateUser()开始 入参:{}",user);
|
logger.info("调用方法updateUser()开始 入参:{}", user);
|
||||||
String rst;
|
String rst;
|
||||||
if(this.checkAuth(user.getAuthCode())) {
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
int code = userService.updateUser(user);
|
int code = userService.updateUser(user);
|
||||||
if (code > 0) {
|
if (code > 0) {
|
||||||
rst = resultService.success("修改用户信息成功!");
|
rst = resultService.success("修改用户信息成功!");
|
||||||
} else {
|
} else {
|
||||||
rst = resultService.error("修改用户信息失败!");
|
rst = resultService.error("修改用户信息失败!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法updateUser()结束 返回:{}", rst);
|
logger.info("调用方法updateUser()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/api/user/deleteUser")
|
@RequestMapping("/api/user/deleteUser")
|
||||||
public String deleteUser(@RequestBody User user){
|
public String deleteUser(@RequestBody User user) {
|
||||||
logger.info("调用方法deleteUser()开始 入参:{}",user);
|
logger.info("调用方法deleteUser()开始 入参:{}", user);
|
||||||
String rst;
|
String rst;
|
||||||
if(this.checkAuth(user.getAuthCode())) {
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
logger.info("1.检测用户是否存在(deleteUser)");
|
logger.info("1.检测用户是否存在(deleteUser)");
|
||||||
int exist = userService.userExist(user);
|
int exist = userService.userExist(user);
|
||||||
if (exist > 0) {
|
if (exist > 0) {
|
||||||
@@ -186,39 +184,39 @@ public class UserController {
|
|||||||
logger.info("2.用户不存在(deleteUser)");
|
logger.info("2.用户不存在(deleteUser)");
|
||||||
rst = resultService.error("用户不存在!");
|
rst = resultService.error("用户不存在!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法deleteUser()结束 返回:{}",rst);
|
logger.info("调用方法deleteUser()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/api/user/deleteUserByOpenId")
|
@RequestMapping("/api/user/deleteUserByOpenId")
|
||||||
public String deleteUserByOpenId(@RequestBody User user){
|
public String deleteUserByOpenId(@RequestBody User user) {
|
||||||
logger.info("调用方法deleteUserByOpenId()开始 入参:{}",user);
|
logger.info("调用方法deleteUserByOpenId()开始 入参:{}", user);
|
||||||
String rst;
|
String rst;
|
||||||
if(this.checkAuth(user.getAuthCode())) {
|
if (this.checkAuth(user.getAuthCode())) {
|
||||||
int code = userService.deleteUserByOpenId(user);
|
int code = userService.deleteUserByOpenId(user);
|
||||||
if (code > 0) {
|
if (code > 0) {
|
||||||
rst = resultService.success("删除用户成功!");
|
rst = resultService.success("删除用户成功!");
|
||||||
} else {
|
} else {
|
||||||
rst = resultService.error("删除用户失败!");
|
rst = resultService.error("删除用户失败!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||||
}
|
}
|
||||||
logger.info("调用方法deleteUserByOpenId()结束 返回:{}",rst);
|
logger.info("调用方法deleteUserByOpenId()结束 返回:{}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkAuth(String auth_code){
|
public boolean checkAuth(String auth_code) {
|
||||||
logger.info("调用方法checkAuth()开始 入参:{}",auth_code);
|
logger.info("调用方法checkAuth()开始 入参:{}", auth_code);
|
||||||
String auth_new = authService.getAuthMd5CodeInside();
|
String auth_new = authService.getAuthMd5CodeInside();
|
||||||
logger.info("最新授权码 {}",auth_new);
|
logger.info("最新授权码 {}", auth_new);
|
||||||
authService.addUseCount(auth_new);
|
authService.addUseCount(auth_new);
|
||||||
logger.info("授权码 {} 使用次数加1",auth_new);
|
logger.info("授权码 {} 使用次数加1", auth_new);
|
||||||
boolean is_match = auth_new.equals(auth_code)||defaultAuthCode.equals(auth_code);
|
boolean is_match = auth_new.equals(auth_code) || defaultAuthCode.equals(auth_code);
|
||||||
logger.info("调用方法checkAuth()结束 返回:{}",is_match);
|
logger.info("调用方法checkAuth()结束 返回:{}", is_match);
|
||||||
return is_match;
|
return is_match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,16 @@ public class WXController {
|
|||||||
ResultServiceImpl resultService;
|
ResultServiceImpl resultService;
|
||||||
// 定义日志打印类
|
// 定义日志打印类
|
||||||
private final Logger logger = LoggerFactory.getLogger(WXController.class);
|
private final Logger logger = LoggerFactory.getLogger(WXController.class);
|
||||||
|
|
||||||
// 获取微信OpenId
|
// 获取微信OpenId
|
||||||
@RequestMapping("/api/wx/getOpenId")
|
@RequestMapping("/api/wx/getOpenId")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String getOpenId(@RequestParam(required=false,name = "code") String code) {
|
public String getOpenId(@RequestParam(required = false, name = "code") String code) {
|
||||||
logger.info("调用方法getOpenId()开始 {}",code);
|
logger.info("调用方法getOpenId()开始 {}", code);
|
||||||
// 拼接所需字符串
|
// 拼接所需字符串
|
||||||
String url = "https://api.weixin.qq.com/sns/jscode2session" +
|
String url = "https://api.weixin.qq.com/sns/jscode2session" +
|
||||||
"?appid=" +appid +
|
"?appid=" + appid +
|
||||||
"&secret=" + secret + //自己的appSecret
|
"&secret=" + secret + // 自己的appSecret
|
||||||
"&js_code=" + code +
|
"&js_code=" + code +
|
||||||
"&grant_type=authorization_code" +
|
"&grant_type=authorization_code" +
|
||||||
"&connect_redirect=1";
|
"&connect_redirect=1";
|
||||||
@@ -43,8 +44,8 @@ public class WXController {
|
|||||||
return resultService.error("参数code不存在,请检查入参!");
|
return resultService.error("参数code不存在,请检查入参!");
|
||||||
}
|
}
|
||||||
String result = HttpUtil.get(url, CharsetUtil.CHARSET_UTF_8);
|
String result = HttpUtil.get(url, CharsetUtil.CHARSET_UTF_8);
|
||||||
String rst = resultService.success("调用完成",result);
|
String rst = resultService.success("调用完成", result);
|
||||||
logger.info("调用方法getOpenId()结束 {}",rst);
|
logger.info("调用方法getOpenId()结束 {}", rst);
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
public interface AuthMapper {
|
public interface AuthMapper {
|
||||||
|
|
||||||
String getAuthCode(User user);
|
String getAuthCode(User user);
|
||||||
|
|
||||||
String getAuthMd5Code(User user);
|
String getAuthMd5Code(User user);
|
||||||
|
|
||||||
String getAuthMd5CodeInside();
|
String getAuthMd5CodeInside();
|
||||||
|
|
||||||
int addUseCount(String authCode);
|
int addUseCount(String authCode);
|
||||||
|
|
||||||
int addAuth(Auth auth);
|
int addAuth(Auth auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package cn.lailab.toolbox.mapper;
|
|||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ParameterMapper {
|
public interface ParameterMapper {
|
||||||
List<Parameter> getAllParameter(Parameter parameter);
|
List<Parameter> getAllParameter(Parameter parameter);
|
||||||
|
|
||||||
Parameter getParameterByName(Parameter parameter);
|
Parameter getParameterByName(Parameter parameter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package cn.lailab.toolbox.mapper;
|
|||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.User;
|
import cn.lailab.toolbox.beans.domain.User;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
|
|
||||||
int addUser(User user);
|
int addUser(User user);
|
||||||
|
|
||||||
User getUserByOpenId(User user);
|
User getUserByOpenId(User user);
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ import cn.lailab.toolbox.beans.domain.User;
|
|||||||
|
|
||||||
public interface AuthService {
|
public interface AuthService {
|
||||||
String getAuthCode(User user);
|
String getAuthCode(User user);
|
||||||
|
|
||||||
String getAuthMd5Code(User user);
|
String getAuthMd5Code(User user);
|
||||||
|
|
||||||
String getAuthMd5CodeInside();
|
String getAuthMd5CodeInside();
|
||||||
|
|
||||||
int addUseCount(String auth_code);
|
int addUseCount(String auth_code);
|
||||||
|
|
||||||
int addAuth(Auth auth);
|
int addAuth(Auth auth);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package cn.lailab.toolbox.service;
|
package cn.lailab.toolbox.service;
|
||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ParameterService {
|
public interface ParameterService {
|
||||||
List<Parameter> getAllParameter(Parameter parameter);
|
List<Parameter> getAllParameter(Parameter parameter);
|
||||||
|
|
||||||
Parameter getParameterByName(Parameter parameter);
|
Parameter getParameterByName(Parameter parameter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package cn.lailab.toolbox.service;
|
package cn.lailab.toolbox.service;
|
||||||
|
|
||||||
public interface ResultService {
|
public interface ResultService {
|
||||||
|
|
||||||
String success();
|
String success();
|
||||||
|
|
||||||
String success(String message);
|
String success(String message);
|
||||||
String success(String message,Object data);
|
|
||||||
|
String success(String message, Object data);
|
||||||
|
|
||||||
String error();
|
String error();
|
||||||
|
|
||||||
String error(String message);
|
String error(String message);
|
||||||
String error(String message,Object data);
|
|
||||||
String other(int code,String message,Object data);
|
String error(String message, Object data);
|
||||||
|
|
||||||
|
String other(int code, String message, Object data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.lailab.toolbox.service;
|
package cn.lailab.toolbox.service;
|
||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.User;
|
import cn.lailab.toolbox.beans.domain.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import cn.lailab.toolbox.mapper.ParameterMapper;
|
|||||||
import cn.lailab.toolbox.service.ParameterService;
|
import cn.lailab.toolbox.service.ParameterService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@@ -12,39 +12,41 @@ public class ResultServiceImpl implements ResultService {
|
|||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.setCode(code);
|
result.setCode(code);
|
||||||
result.setMessage(message);
|
result.setMessage(message);
|
||||||
if(data == null) result.setData("");
|
if (data == null)
|
||||||
|
result.setData("");
|
||||||
result.setData(data);
|
result.setData(data);
|
||||||
result.setTimestamp(System.currentTimeMillis());
|
result.setTimestamp(System.currentTimeMillis());
|
||||||
//return JSONUtil.toJsonPrettyStr(result);
|
// return JSONUtil.toJsonPrettyStr(result);
|
||||||
return JSONUtil.toJsonStr(result);
|
return JSONUtil.toJsonStr(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String success() {
|
public String success() {
|
||||||
return other(0,"success","");
|
return other(0, "success", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String success(String message) {
|
public String success(String message) {
|
||||||
return other(0,message,"");
|
return other(0, message, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String success(String message, Object data) {
|
public String success(String message, Object data) {
|
||||||
return other(0,message,data);
|
return other(0, message, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String error() {
|
public String error() {
|
||||||
return other(-1,"error","");
|
return other(-1, "error", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String error(String message) {
|
public String error(String message) {
|
||||||
return other(-1,message,"");
|
return other(-1, message, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String error(String message, Object data) {
|
public String error(String message, Object data) {
|
||||||
return other(-1,message,data);
|
return other(-1, message, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import cn.lailab.toolbox.service.UserService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -27,15 +26,15 @@ public class UserServiceImpl implements UserService {
|
|||||||
public int addUser(User user) {
|
public int addUser(User user) {
|
||||||
int maxId;
|
int maxId;
|
||||||
maxId = userMapper.getMaxId();
|
maxId = userMapper.getMaxId();
|
||||||
maxId +=1;
|
maxId += 1;
|
||||||
// 自动生成用户名
|
// 自动生成用户名
|
||||||
if(user.getUsername().isEmpty()){
|
if (user.getUsername().isEmpty()) {
|
||||||
user.setUsername(String.format("%05d",maxId));
|
user.setUsername(String.format("%05d", maxId));
|
||||||
}
|
}
|
||||||
// 对用户输入的密码进行MD5加密
|
// 对用户输入的密码进行MD5加密
|
||||||
if(user.getPassword().isEmpty()) {
|
if (user.getPassword().isEmpty()) {
|
||||||
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
||||||
}else{
|
} else {
|
||||||
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
||||||
}
|
}
|
||||||
// 创建时间赋值
|
// 创建时间赋值
|
||||||
@@ -71,9 +70,9 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
public int updateUser(User user) {
|
public int updateUser(User user) {
|
||||||
// 对用户输入的密码进行MD5加密
|
// 对用户输入的密码进行MD5加密
|
||||||
if(user.getPassword().isEmpty()) {
|
if (user.getPassword().isEmpty()) {
|
||||||
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
||||||
}else{
|
} else {
|
||||||
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
||||||
}
|
}
|
||||||
return userMapper.updateUser(user);
|
return userMapper.updateUser(user);
|
||||||
@@ -103,5 +102,4 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userMapper.getMaxId();
|
return userMapper.getMaxId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -40,7 +39,7 @@ public class AuthTask {
|
|||||||
|
|
||||||
if (code > 0) {
|
if (code > 0) {
|
||||||
logger.info("调用方法authTask()结束 添加成功!");
|
logger.info("调用方法authTask()结束 添加成功!");
|
||||||
}else{
|
} else {
|
||||||
logger.info("调用方法authTask()结束 添加失败!");
|
logger.info("调用方法authTask()结束 添加失败!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{"properties": [{
|
||||||
|
"name": "mybatis.mapper-locations",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "A description for 'mybatis.mapper-locations'"
|
||||||
|
}]}{"properties": [{
|
||||||
|
"name": "mybatis.mapper-locations",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "A description for 'mybatis.mapper-locations'"
|
||||||
|
}]}
|
||||||
@@ -15,7 +15,7 @@ mini-program:
|
|||||||
secret: "3d20927085d4eabc7e600201fe97642c"
|
secret: "3d20927085d4eabc7e600201fe97642c"
|
||||||
|
|
||||||
lailab:
|
lailab:
|
||||||
default-password: "123456" #新建用户默认密码
|
default-password: "123456" #新建用户默认密码
|
||||||
auth-task:
|
auth-task:
|
||||||
cron: "0 0/10 * * * ?"
|
cron: "0 0/10 * * * ?"
|
||||||
random-length: 6
|
random-length: 6
|
||||||
@@ -33,7 +33,7 @@ logging:
|
|||||||
level:
|
level:
|
||||||
org.springframework.web: info
|
org.springframework.web: info
|
||||||
org.hibernate.SQL: debug
|
org.hibernate.SQL: debug
|
||||||
cn.lailab: info
|
cn.lailab.toolbox: info
|
||||||
logback:
|
logback:
|
||||||
rollingpolicy:
|
rollingpolicy:
|
||||||
max-file-size: 10MB
|
max-file-size: 10MB
|
||||||
@@ -21,7 +21,7 @@ mini-program:
|
|||||||
secret: "3d20927085d4eabc7e600201fe97642c"
|
secret: "3d20927085d4eabc7e600201fe97642c"
|
||||||
|
|
||||||
lailab:
|
lailab:
|
||||||
default-password: "123456" #新建用户默认密码
|
default-password: "123456" #新建用户默认密码
|
||||||
auth-task:
|
auth-task:
|
||||||
cron: "0 0/30 * * * ?"
|
cron: "0 0/30 * * * ?"
|
||||||
random-length: 6
|
random-length: 6
|
||||||
@@ -37,7 +37,7 @@ mybatis:
|
|||||||
# 3. 开启驼峰命名自动转换(比如数据库字段 user_name 自动映射到实体类属性 userName)
|
# 3. 开启驼峰命名自动转换(比如数据库字段 user_name 自动映射到实体类属性 userName)
|
||||||
# configuration:
|
# configuration:
|
||||||
# map-underscore-to-camel-case: true
|
# map-underscore-to-camel-case: true
|
||||||
# 可选:开启日志打印,方便调试 SQL
|
# 可选:开启日志打印,方便调试 SQL
|
||||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<h1>hello word!!!</h1>
|
<h1>hello word!!!</h1>
|
||||||
<p>this is a html page</p>
|
<p>this is a html page</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,202 +1,217 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>计算器</title>
|
<title>计算器</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
font-family:
|
||||||
}
|
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 显示区域 */
|
/* 显示区域 */
|
||||||
.display {
|
.display {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
padding: 20px 10px;
|
padding: 20px 10px;
|
||||||
font-size: 8rem;
|
font-size: 8rem;
|
||||||
font-weight: 200;
|
font-weight: 200;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 按钮区域 */
|
/* 按钮区域 */
|
||||||
.buttons {
|
.buttons {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(4, 1fr);
|
||||||
gap: 15px;
|
gap: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 按钮基础样式 */
|
/* 按钮基础样式 */
|
||||||
button {
|
button {
|
||||||
height: 80px;
|
height: 80px;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 50px; /* 圆角按钮 */
|
border-radius: 50px; /* 圆角按钮 */
|
||||||
font-size: 1.8rem;
|
font-size: 1.8rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 0.2s ease;
|
transition: background-color 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 功能按钮(AC、+/-、%) */
|
/* 功能按钮(AC、+/-、%) */
|
||||||
.func-btn {
|
.func-btn {
|
||||||
background-color: #e6f7ff;
|
background-color: #e6f7ff;
|
||||||
color: #1890ff;
|
color: #1890ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.func-btn:active {
|
.func-btn:active {
|
||||||
background-color: #bae7ff;
|
background-color: #bae7ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 数字按钮 */
|
/* 数字按钮 */
|
||||||
.num-btn {
|
.num-btn {
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.num-btn:active {
|
.num-btn:active {
|
||||||
background-color: #e0e0e0;
|
background-color: #e0e0e0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 运算符按钮(天蓝色主题) */
|
/* 运算符按钮(天蓝色主题) */
|
||||||
.op-btn {
|
.op-btn {
|
||||||
background-color: #1890ff;
|
background-color: #1890ff;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.op-btn:active {
|
.op-btn:active {
|
||||||
background-color: #096dd9;
|
background-color: #096dd9;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 0号按钮占两列 */
|
/* 0号按钮占两列 */
|
||||||
#zero {
|
#zero {
|
||||||
grid-column: span 2;
|
grid-column: span 2;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="display">0</div>
|
<div class="display">0</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="func-btn" id="ac">AC</button>
|
<button class="func-btn" id="ac">AC</button>
|
||||||
<button class="func-btn" id="plus-minus">+/-</button>
|
<button class="func-btn" id="plus-minus">+/-</button>
|
||||||
<button class="func-btn" id="percent">%</button>
|
<button class="func-btn" id="percent">%</button>
|
||||||
<button class="op-btn" id="divide">÷</button>
|
<button class="op-btn" id="divide">÷</button>
|
||||||
|
|
||||||
<button class="num-btn" id="7">7</button>
|
<button class="num-btn" id="7">7</button>
|
||||||
<button class="num-btn" id="8">8</button>
|
<button class="num-btn" id="8">8</button>
|
||||||
<button class="num-btn" id="9">9</button>
|
<button class="num-btn" id="9">9</button>
|
||||||
<button class="op-btn" id="multiply">×</button>
|
<button class="op-btn" id="multiply">×</button>
|
||||||
|
|
||||||
<button class="num-btn" id="4">4</button>
|
<button class="num-btn" id="4">4</button>
|
||||||
<button class="num-btn" id="5">5</button>
|
<button class="num-btn" id="5">5</button>
|
||||||
<button class="num-btn" id="6">6</button>
|
<button class="num-btn" id="6">6</button>
|
||||||
<button class="op-btn" id="subtract">-</button>
|
<button class="op-btn" id="subtract">-</button>
|
||||||
|
|
||||||
<button class="num-btn" id="1">1</button>
|
<button class="num-btn" id="1">1</button>
|
||||||
<button class="num-btn" id="2">2</button>
|
<button class="num-btn" id="2">2</button>
|
||||||
<button class="num-btn" id="3">3</button>
|
<button class="num-btn" id="3">3</button>
|
||||||
<button class="op-btn" id="add">+</button>
|
<button class="op-btn" id="add">+</button>
|
||||||
|
|
||||||
<button class="num-btn" id="zero">0</button>
|
<button class="num-btn" id="zero">0</button>
|
||||||
<button class="num-btn" id="decimal">.</button>
|
<button class="num-btn" id="decimal">.</button>
|
||||||
<button class="op-btn" id="equals">=</button>
|
<button class="op-btn" id="equals">=</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const display = document.querySelector('.display');
|
const display = document.querySelector(".display");
|
||||||
let currentValue = '0';
|
let currentValue = "0";
|
||||||
let previousValue = '';
|
let previousValue = "";
|
||||||
let operator = '';
|
let operator = "";
|
||||||
let resetDisplay = false;
|
let resetDisplay = false;
|
||||||
|
|
||||||
// 更新显示
|
// 更新显示
|
||||||
function updateDisplay() {
|
function updateDisplay() {
|
||||||
display.textContent = currentValue;
|
display.textContent = currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数字按钮
|
// 数字按钮
|
||||||
document.querySelectorAll('.num-btn').forEach(btn => {
|
document.querySelectorAll(".num-btn").forEach((btn) => {
|
||||||
btn.addEventListener('click', () => {
|
btn.addEventListener("click", () => {
|
||||||
const value = btn.textContent;
|
const value = btn.textContent;
|
||||||
if (currentValue === '0' || resetDisplay) {
|
if (currentValue === "0" || resetDisplay) {
|
||||||
currentValue = value;
|
currentValue = value;
|
||||||
resetDisplay = false;
|
|
||||||
} else {
|
|
||||||
if (value === '.' && currentValue.includes('.')) return;
|
|
||||||
currentValue += value;
|
|
||||||
}
|
|
||||||
updateDisplay();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 运算符按钮
|
|
||||||
document.querySelectorAll('.op-btn').forEach(btn => {
|
|
||||||
btn.addEventListener('click', () => {
|
|
||||||
if (btn.id === 'equals') return;
|
|
||||||
if (previousValue && operator && !resetDisplay) calculate();
|
|
||||||
previousValue = currentValue;
|
|
||||||
operator = btn.id;
|
|
||||||
resetDisplay = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 等号按钮
|
|
||||||
document.getElementById('equals').addEventListener('click', calculate);
|
|
||||||
|
|
||||||
// 功能按钮
|
|
||||||
document.getElementById('ac').addEventListener('click', () => {
|
|
||||||
currentValue = '0';
|
|
||||||
previousValue = '';
|
|
||||||
operator = '';
|
|
||||||
resetDisplay = false;
|
resetDisplay = false;
|
||||||
updateDisplay();
|
} else {
|
||||||
|
if (value === "." && currentValue.includes(".")) return;
|
||||||
|
currentValue += value;
|
||||||
|
}
|
||||||
|
updateDisplay();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('plus-minus').addEventListener('click', () => {
|
// 运算符按钮
|
||||||
currentValue = currentValue.startsWith('-') ? currentValue.slice(1) : '-' + currentValue;
|
document.querySelectorAll(".op-btn").forEach((btn) => {
|
||||||
updateDisplay();
|
btn.addEventListener("click", () => {
|
||||||
|
if (btn.id === "equals") return;
|
||||||
|
if (previousValue && operator && !resetDisplay) calculate();
|
||||||
|
previousValue = currentValue;
|
||||||
|
operator = btn.id;
|
||||||
|
resetDisplay = true;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('percent').addEventListener('click', () => {
|
// 等号按钮
|
||||||
currentValue = (parseFloat(currentValue) / 100).toString();
|
document.getElementById("equals").addEventListener("click", calculate);
|
||||||
updateDisplay();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 计算逻辑
|
// 功能按钮
|
||||||
function calculate() {
|
document.getElementById("ac").addEventListener("click", () => {
|
||||||
if (!previousValue || !operator) return;
|
currentValue = "0";
|
||||||
let result;
|
previousValue = "";
|
||||||
const prev = parseFloat(previousValue);
|
operator = "";
|
||||||
const curr = parseFloat(currentValue);
|
resetDisplay = false;
|
||||||
|
updateDisplay();
|
||||||
|
});
|
||||||
|
|
||||||
switch (operator) {
|
document.getElementById("plus-minus").addEventListener("click", () => {
|
||||||
case 'add': result = prev + curr; break;
|
currentValue = currentValue.startsWith("-")
|
||||||
case 'subtract': result = prev - curr; break;
|
? currentValue.slice(1)
|
||||||
case 'multiply': result = prev * curr; break;
|
: "-" + currentValue;
|
||||||
case 'divide': result = curr === 0 ? '错误' : prev / curr; break;
|
updateDisplay();
|
||||||
default: return;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
currentValue = typeof result === 'number'
|
document.getElementById("percent").addEventListener("click", () => {
|
||||||
? (result % 1 === 0 ? result.toString() : result.toFixed(6).replace(/\.?0*$/, ''))
|
currentValue = (parseFloat(currentValue) / 100).toString();
|
||||||
: result;
|
updateDisplay();
|
||||||
previousValue = '';
|
});
|
||||||
operator = '';
|
|
||||||
resetDisplay = true;
|
// 计算逻辑
|
||||||
updateDisplay();
|
function calculate() {
|
||||||
|
if (!previousValue || !operator) return;
|
||||||
|
let result;
|
||||||
|
const prev = parseFloat(previousValue);
|
||||||
|
const curr = parseFloat(currentValue);
|
||||||
|
|
||||||
|
switch (operator) {
|
||||||
|
case "add":
|
||||||
|
result = prev + curr;
|
||||||
|
break;
|
||||||
|
case "subtract":
|
||||||
|
result = prev - curr;
|
||||||
|
break;
|
||||||
|
case "multiply":
|
||||||
|
result = prev * curr;
|
||||||
|
break;
|
||||||
|
case "divide":
|
||||||
|
result = curr === 0 ? "错误" : prev / curr;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentValue =
|
||||||
|
typeof result === "number"
|
||||||
|
? result % 1 === 0
|
||||||
|
? result.toString()
|
||||||
|
: result.toFixed(6).replace(/\.?0*$/, "")
|
||||||
|
: result;
|
||||||
|
previousValue = "";
|
||||||
|
operator = "";
|
||||||
|
resetDisplay = true;
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user