From b6dbe7b5a5727d048724d9e86b2519cf599ded41 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 31 十月 2022 10:33:29 +0800
Subject: [PATCH] update 优化 新增返回警告消息提示
---
ruoyi-ui/src/utils/request.js | 6 ++
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java | 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java | 4
ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java | 93 +++++++++++++++++++++++++++++++
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java | 22 +++++++
5 files changed, 125 insertions(+), 4 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java
index 411eee9..fa763df 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java
@@ -108,10 +108,10 @@
@DeleteMapping("/{deptId}")
public R<Void> remove(@PathVariable Long deptId) {
if (deptService.hasChildByDeptId(deptId)) {
- return R.fail("瀛樺湪涓嬬骇閮ㄩ棬,涓嶅厑璁稿垹闄�");
+ return R.warn("瀛樺湪涓嬬骇閮ㄩ棬,涓嶅厑璁稿垹闄�");
}
if (deptService.checkDeptExistUser(deptId)) {
- return R.fail("閮ㄩ棬瀛樺湪鐢ㄦ埛,涓嶅厑璁稿垹闄�");
+ return R.warn("閮ㄩ棬瀛樺湪鐢ㄦ埛,涓嶅厑璁稿垹闄�");
}
deptService.checkDeptDataScope(deptId);
return toAjax(deptService.deleteDeptById(deptId));
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java
index 2000fd0..e80f0ee 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java
@@ -117,10 +117,10 @@
@DeleteMapping("/{menuId}")
public R<Void> remove(@PathVariable("menuId") Long menuId) {
if (menuService.hasChildByMenuId(menuId)) {
- return R.fail("瀛樺湪瀛愯彍鍗�,涓嶅厑璁稿垹闄�");
+ return R.warn("瀛樺湪瀛愯彍鍗�,涓嶅厑璁稿垹闄�");
}
if (menuService.checkMenuExistRole(menuId)) {
- return R.fail("鑿滃崟宸插垎閰�,涓嶅厑璁稿垹闄�");
+ return R.warn("鑿滃崟宸插垎閰�,涓嶅厑璁稿垹闄�");
}
return toAjax(menuService.deleteMenuById(menuId));
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java
new file mode 100644
index 0000000..f007b8c
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java
@@ -0,0 +1,93 @@
+package com.ruoyi.common.constant;
+
+/**
+ * 杩斿洖鐘舵�佺爜
+ *
+ * @author Lion Li
+ */
+public interface HttpStatus {
+ /**
+ * 鎿嶄綔鎴愬姛
+ */
+ int SUCCESS = 200;
+
+ /**
+ * 瀵硅薄鍒涘缓鎴愬姛
+ */
+ int CREATED = 201;
+
+ /**
+ * 璇锋眰宸茬粡琚帴鍙�
+ */
+ int ACCEPTED = 202;
+
+ /**
+ * 鎿嶄綔宸茬粡鎵ц鎴愬姛锛屼絾鏄病鏈夎繑鍥炴暟鎹�
+ */
+ int NO_CONTENT = 204;
+
+ /**
+ * 璧勬簮宸茶绉婚櫎
+ */
+ int MOVED_PERM = 301;
+
+ /**
+ * 閲嶅畾鍚�
+ */
+ int SEE_OTHER = 303;
+
+ /**
+ * 璧勬簮娌℃湁琚慨鏀�
+ */
+ int NOT_MODIFIED = 304;
+
+ /**
+ * 鍙傛暟鍒楄〃閿欒锛堢己灏戯紝鏍煎紡涓嶅尮閰嶏級
+ */
+ int BAD_REQUEST = 400;
+
+ /**
+ * 鏈巿鏉�
+ */
+ int UNAUTHORIZED = 401;
+
+ /**
+ * 璁块棶鍙楅檺锛屾巿鏉冭繃鏈�
+ */
+ int FORBIDDEN = 403;
+
+ /**
+ * 璧勬簮锛屾湇鍔℃湭鎵惧埌
+ */
+ int NOT_FOUND = 404;
+
+ /**
+ * 涓嶅厑璁哥殑http鏂规硶
+ */
+ int BAD_METHOD = 405;
+
+ /**
+ * 璧勬簮鍐茬獊锛屾垨鑰呰祫婧愯閿�
+ */
+ int CONFLICT = 409;
+
+ /**
+ * 涓嶆敮鎸佺殑鏁版嵁锛屽獟浣撶被鍨�
+ */
+ int UNSUPPORTED_TYPE = 415;
+
+ /**
+ * 绯荤粺鍐呴儴閿欒
+ */
+ int ERROR = 500;
+
+ /**
+ * 鎺ュ彛鏈疄鐜�
+ */
+ int NOT_IMPLEMENTED = 501;
+
+ /**
+ * 绯荤粺璀﹀憡娑堟伅
+ */
+ int WARN = 601;
+}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java
index 1c7b1d8..381a6f6 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java
@@ -1,5 +1,6 @@
package com.ruoyi.common.core.domain;
+import com.ruoyi.common.constant.HttpStatus;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -67,6 +68,27 @@
return restResult(null, code, msg);
}
+ /**
+ * 杩斿洖璀﹀憡娑堟伅
+ *
+ * @param msg 杩斿洖鍐呭
+ * @return 璀﹀憡娑堟伅
+ */
+ public static <T> R<T> warn(String msg) {
+ return restResult(null, HttpStatus.WARN, msg);
+ }
+
+ /**
+ * 杩斿洖璀﹀憡娑堟伅
+ *
+ * @param msg 杩斿洖鍐呭
+ * @param data 鏁版嵁瀵硅薄
+ * @return 璀﹀憡娑堟伅
+ */
+ public static <T> R<T> warn(String msg, T data) {
+ return restResult(data, HttpStatus.WARN, msg);
+ }
+
private static <T> R<T> restResult(T data, int code, String msg) {
R<T> r = new R<>();
r.setCode(code);
diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js
index 2473bc1..39d5c26 100644
--- a/ruoyi-ui/src/utils/request.js
+++ b/ruoyi-ui/src/utils/request.js
@@ -101,6 +101,12 @@
type: 'error'
})
return Promise.reject(new Error(msg))
+ } else if (code === 601) {
+ Message({
+ message: msg,
+ type: 'warning'
+ })
+ return Promise.reject('error')
} else if (code !== 200) {
Notification.error({
title: msg
--
Gitblit v1.9.3