Bladeren bron

Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev

 Conflicts:
	pom.xml
	ruoyi-common/src/main/java/com/ruoyi/common/annotation/RepeatSubmit.java
	ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
	ruoyi-common/src/main/java/com/ruoyi/common/utils/Threads.java
	ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java
	ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java
	ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
	ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml
	ruoyi-ui/src/layout/components/Settings/index.vue
	ruoyi-ui/src/plugins/download.js
	ruoyi-ui/src/store/modules/permission.js
	ruoyi-ui/src/views/index.vue
	ruoyi-ui/src/views/monitor/server/index.vue
	ruoyi-ui/src/views/system/role/index.vue
	ry.bat
疯狂的狮子Li 3 jaren geleden
bovenliggende
commit
42a3117e2a

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/annotation/RepeatSubmit.java

@@ -24,6 +24,6 @@ public @interface RepeatSubmit {
     /**
      * 提示消息
      */
-    String message() default "不允许重复提交,请稍再试";
+    String message() default "不允许重复提交,请稍再试";
 
 }

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/utils/Threads.java

@@ -28,7 +28,7 @@ public class Threads {
      * 停止线程池
      * 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
      * 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数.
-     * 如果仍超時,則強制退出.
+     * 如果仍超時,則強制退出.
      * 另对在shutdown时线程本身被调用中断做了处理.
      */
     public static void shutdownAndAwaitTermination(ExecutorService pool) {

+ 2 - 3
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java

@@ -22,9 +22,6 @@ public class FileUtils extends FileUtil {
      * @return
      */
     public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException {
-        response.addHeader("Access-Control-Allow-Origin", "*");
-        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
-
         String percentEncodedFileName = percentEncode(realFileName);
 
         StringBuilder contentDispositionValue = new StringBuilder();
@@ -35,6 +32,8 @@ public class FileUtils extends FileUtil {
                 .append("utf-8''")
                 .append(percentEncodedFileName);
 
+        response.addHeader("Access-Control-Allow-Origin", "*");
+        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
         response.setHeader("Content-disposition", contentDispositionValue.toString());
         response.setHeader("download-filename", percentEncodedFileName);
     }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java

@@ -39,7 +39,7 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRole> {
      * @param userId 用户ID
      * @return 选中角色ID列表
      */
-    List<Integer> selectRoleListByUserId(Long userId);
+    List<Long> selectRoleListByUserId(Long userId);
 
     /**
      * 根据用户ID查询角色

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java

@@ -55,7 +55,7 @@ public interface ISysRoleService extends IService<SysRole> {
      * @param userId 用户ID
      * @return 选中角色ID列表
      */
-    List<Integer> selectRoleListByUserId(Long userId);
+    List<Long> selectRoleListByUserId(Long userId);
 
     /**
      * 通过角色ID查询角色

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

@@ -117,7 +117,7 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole,
      * @return 选中角色ID列表
      */
     @Override
-    public List<Integer> selectRoleListByUserId(Long userId) {
+    public List<Long> selectRoleListByUserId(Long userId) {
         return baseMapper.selectRoleListByUserId(userId);
     }
 

+ 2 - 2
ruoyi-ui/src/layout/components/Settings/index.vue

@@ -162,7 +162,7 @@ export default {
       this.sideTheme = val;
     },
     saveSetting() {
-      this.$modal.loading("正在保存到本地,请稍...");
+      this.$modal.loading("正在保存到本地,请稍...");
       this.$cache.local.set(
         "layout-setting",
         `{
@@ -178,7 +178,7 @@ export default {
       setTimeout(this.$modal.closeLoading(), 1000)
     },
     resetSetting() {
-      this.$modal.loading("正在清除设置缓存并刷新,请稍...");
+      this.$modal.loading("正在清除设置缓存并刷新,请稍...");
       this.$cache.local.remove("layout-setting")
       setTimeout("window.location.reload()", 1000)
     }

+ 60 - 0
ruoyi-ui/src/plugins/auth.js

@@ -0,0 +1,60 @@
+import store from '@/store'
+
+function authPermission(permission) {
+  const all_permission = "*:*:*";
+  const permissions = store.getters && store.getters.permissions
+  if (permission && permission.length > 0) {
+    return permissions.some(v => {
+      return all_permission === v || v === permission
+    })
+  } else {
+    return false
+  }
+}
+
+function authRole(role) {
+  const super_admin = "admin";
+  const roles = store.getters && store.getters.roles
+  if (role && role.length > 0) {
+    return roles.some(v => {
+      return super_admin === v || v === role
+    })
+  } else {
+    return false
+  }
+}
+
+export default {
+  // 验证用户是否具备某权限
+  hasPermi(permission) {
+    return authPermission(permission);
+  },
+  // 验证用户是否含有指定权限,只需包含其中一个
+  hasPermiOr(permissions) {
+    return permissions.some(item => {
+      return authPermission(item)
+    })
+  },
+  // 验证用户是否含有指定权限,必须全部拥有
+  hasPermiAnd(permissions) {
+    return permissions.every(item => {
+      return authPermission(item)
+    })
+  },
+  // 验证用户是否具备某角色
+  hasRole(role) {
+    return authRole(role);
+  },
+  // 验证用户是否含有指定角色,只需包含其中一个
+  hasRoleOr(roles) {
+    return roles.some(item => {
+      return authRole(item)
+    })
+  },
+  // 验证用户是否含有指定角色,必须全部拥有
+  hasRoleAnd(roles) {
+    return roles.every(item => {
+      return authRole(item)
+    })
+  }
+}

+ 35 - 10
ruoyi-ui/src/plugins/download.js

@@ -1,6 +1,7 @@
 import { saveAs } from 'file-saver'
 import axios from 'axios'
 import { getToken } from '@/utils/auth'
+import { Message } from 'element-ui'
 
 const baseURL = process.env.VUE_APP_BASE_API
 
@@ -35,9 +36,14 @@ export default {
       url: url,
       responseType: 'blob',
       headers: { 'Authorization': 'Bearer ' + getToken() }
-    }).then(res => {
-      const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
-      this.saveAs(blob, decodeURI(res.headers['download-filename']))
+    }).then(async (res) => {
+      const isLogin = await this.blobValidate(res.data);
+      if (isLogin) {
+        const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
+        this.saveAs(blob, decodeURI(res.headers['download-filename']))
+      } else {
+          Message.error('无效的会话,或者会话已过期,请重新登录。');
+      }
     })
   },
   oss(ossId) {
@@ -47,9 +53,14 @@ export default {
       url: url,
       responseType: 'blob',
       headers: { 'Authorization': 'Bearer ' + getToken() }
-    }).then(res => {
-      const blob = new Blob([res.data], { type: 'application/octet-stream' })
-      this.saveAs(blob, decodeURI(res.headers['download-filename']))
+    }).then(async (res) => {
+      const isLogin = await this.blobValidate(res.data);
+      if (isLogin) {
+        const blob = new Blob([res.data], { type: 'application/octet-stream' })
+        this.saveAs(blob, decodeURI(res.headers['download-filename']))
+      } else {
+        Message.error('无效的会话,或者会话已过期,请重新登录。');
+      }
     })
   },
   zip(url, name) {
@@ -59,13 +70,27 @@ export default {
       url: url,
       responseType: 'blob',
       headers: { 'Authorization': 'Bearer ' + getToken() }
-    }).then(res => {
-      const blob = new Blob([res.data], { type: 'application/zip' })
-      this.saveAs(blob, name)
+    }).then(async (res) => {
+      const isLogin = await this.blobValidate(res.data);
+      if (isLogin) {
+        const blob = new Blob([res.data], { type: 'application/zip' })
+        this.saveAs(blob, name)
+      } else {
+        Message.error('无效的会话,或者会话已过期,请重新登录。');
+      }
     })
   },
   saveAs(text, name, opts) {
     saveAs(text, name, opts);
-  }
+  },
+  async blobValidate(data) {
+    try {
+      const text = await data.text();
+      JSON.parse(text);
+      return false;
+    } catch (error) {
+      return true;
+    }
+  },
 }
 

+ 3 - 0
ruoyi-ui/src/plugins/index.js

@@ -1,9 +1,12 @@
+import auth from './auth'
 import cache from './cache'
 import modal from './modal'
 import download from './download'
 
 export default {
   install(Vue) {
+    // 认证对象
+    Vue.prototype.$auth = auth
     // 缓存对象
     Vue.prototype.$cache = cache
     // 模态框对象

+ 8 - 3
ruoyi-ui/src/store/modules/permission.js

@@ -86,7 +86,7 @@ function filterChildren(childrenMap, lastRouter = false) {
   var children = []
   childrenMap.forEach((el, index) => {
     if (el.children && el.children.length) {
-      if (el.component === 'ParentView') {
+      if (el.component === 'ParentView' && !lastRouter) {
         el.children.forEach(c => {
           c.path = el.path + '/' + c.path
           if (c.children && c.children.length) {
@@ -106,8 +106,13 @@ function filterChildren(childrenMap, lastRouter = false) {
   return children
 }
 
-export const loadView = (view) => { // 路由懒加载
-  return (resolve) => require([`@/views/${view}`], resolve)
+export const loadView = (view) => {
+  if (process.env.NODE_ENV === 'development') {
+    return (resolve) => require([`@/views/${view}`], resolve)
+  } else {
+    // 使用 import 实现生产环境的路由懒加载
+    return () => import(`@/views/${view}`)
+  }
 }
 
 export default permission

+ 0 - 1
ruoyi-ui/src/views/index.vue

@@ -478,7 +478,6 @@
 </template>
 
 <script>
-
 export default {
   name: "Index",
   data() {

+ 1 - 1
ruoyi-ui/src/views/monitor/cache/index.vue

@@ -139,7 +139,7 @@ export default {
     },
     // 打开加载层
     openLoading() {
-      this.$modal.loading("正在加载缓存监控数据,请稍!");
+      this.$modal.loading("正在加载缓存监控数据,请稍!");
     },
   },
 };

+ 2 - 2
ruoyi-ui/src/views/system/role/index.vue

@@ -200,7 +200,7 @@
             ref="menu"
             node-key="id"
             :check-strictly="!form.menuCheckStrictly"
-            empty-text="加载中,请稍"
+            empty-text="加载中,请稍"
             :props="defaultProps"
           ></el-tree>
         </el-form-item>
@@ -245,7 +245,7 @@
             ref="dept"
             node-key="id"
             :check-strictly="!form.deptCheckStrictly"
-            empty-text="加载中,请稍"
+            empty-text="加载中,请稍"
             :props="defaultProps"
           ></el-tree>
         </el-form-item>

+ 23 - 23
ry.bat

@@ -1,45 +1,45 @@
 @echo off
 
-rem jar平目录
+rem jar平锟斤拷目录
 set AppName=ruoyi-admin.jar
 
-rem JVM参数
-set JVM_OPTS="-Dname=%AppName%  -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps  -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
+rem JVM锟斤拷锟斤拷
+set JVM_OPTS="-Dname=%AppName%  -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps  -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
 
 
-ECHO. 
-	ECHO.  [1] 启动%AppName%
-	ECHO.  [2] 关闭%AppName%
-	ECHO.  [3] 重启%AppName%
-	ECHO.  [4] 启动状态 %AppName%
-	ECHO.  [5] 退 出 
-ECHO. 
+ECHO.
+	ECHO.  [1] 锟斤拷锟斤拷%AppName%
+	ECHO.  [2] 锟截憋拷%AppName%
+	ECHO.  [3] 锟斤拷锟斤拷%AppName%
+	ECHO.  [4] 锟斤拷锟斤拷状态 %AppName%
+	ECHO.  [5] 锟斤拷 锟斤拷
+ECHO.
 
-ECHO.请输入选择项目的序号:
+ECHO.锟斤拷锟斤拷锟斤拷选锟斤拷锟斤拷目锟斤拷锟斤拷锟�:
 set /p ID=
-	IF "%id%"=="1" GOTO start 
-	IF "%id%"=="2" GOTO stop 
-	IF "%id%"=="3" GOTO restart 
+	IF "%id%"=="1" GOTO start
+	IF "%id%"=="2" GOTO stop
+	IF "%id%"=="3" GOTO restart
 	IF "%id%"=="4" GOTO status
 	IF "%id%"=="5" EXIT
-PAUSE 
+PAUSE
 :start
     for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
 		set pid=%%a
 		set image_name=%%b
 	)
 	if  defined pid (
-		echo %%is running 
-		PAUSE 
-	) 
+		echo %%is running
+		PAUSE
+	)
 
-start javaw -jar %JAVA_OPTS% ruoyi-admin.jar
+start javaw %JAVA_OPTS% -jar %AppName%
 
-echo  starting……
+echo  starting锟斤拷锟斤拷
 echo  Start %AppName% success...
 goto:eof
 
-rem 函数stop通过jps命令查找pid并结束进程
+rem 锟斤拷锟斤拷stop通锟斤拷jps锟斤拷锟斤拷锟斤拷锟絧id锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
 :stop
 	for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
 		set pid=%%a
@@ -48,7 +48,7 @@ rem 
 	if not defined pid (echo process %AppName% does not exists) else (
 		echo prepare to kill %image_name%
 		echo start kill %pid% ...
-		rem 根据进程ID,kill进程
+		rem 锟斤拷锟捷斤拷锟斤拷ID锟斤拷kill锟斤拷锟斤拷
 		taskkill /f /pid %pid%
 	)
 goto:eof
@@ -64,4 +64,4 @@ goto:eof
 	if not defined pid (echo process %AppName% is dead ) else (
 		echo %image_name% is running
 	)
-goto:eof
+goto:eof

+ 3 - 7
ry.sh

@@ -1,13 +1,9 @@
 #!/bin/sh
-# author ruoyi
-# ./ry.sh start 启动
-# ./ry.sh stop 停止
-# ./ry.sh restart 重启
-# ./ry.sh status 状态
+# ./ry.sh start 启动 stop 停止 restart 重启 status 状态
 AppName=ruoyi-admin.jar
 
 # JVM参数
-JVM_OPTS="-Dname=$AppName  -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps  -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
+JVM_OPTS="-Dname=$AppName  -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps  -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
 APP_HOME=`pwd`
 LOG_PATH=$APP_HOME/logs/$AppName.log
 
@@ -30,7 +26,7 @@ function start()
 	if [ x"$PID" != x"" ]; then
 	    echo "$AppName is running..."
 	else
-		nohup java -jar  $JVM_OPTS target/$AppName > /dev/null 2>&1 &
+		nohup java $JVM_OPTS -jar $AppName > /dev/null 2>&1 &
 		echo "Start $AppName success..."
 	fi
 }