Kaynağa Gözat

优化代码

RuoYi 6 ay önce
ebeveyn
işleme
3dcee7057d
21 değiştirilmiş dosya ile 79 ekleme ve 123 silme
  1. 4 2
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java
  2. 1 1
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableDataInfo.java
  3. 6 6
      ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java
  4. 11 11
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java
  5. 1 1
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm
  6. 5 5
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm
  7. 6 6
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm
  8. 5 5
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3/index-tree.vue.vm
  9. 6 6
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3/index.vue.vm
  10. 1 1
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
  11. 1 1
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPermissionServiceImpl.java
  12. 0 1
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
  13. 0 4
      ruoyi-ui/src/assets/styles/index.scss
  14. 3 12
      ruoyi-ui/src/assets/styles/ruoyi.scss
  15. 0 1
      ruoyi-ui/src/components/Pagination/index.vue
  16. 2 2
      ruoyi-ui/src/layout/components/Navbar.vue
  17. 6 21
      ruoyi-ui/src/store/modules/permission.js
  18. 19 27
      ruoyi-ui/src/utils/ruoyi.js
  19. 0 8
      ruoyi-ui/src/views/index.vue
  20. 1 1
      ruoyi-ui/src/views/system/logininfor/index.vue
  21. 1 1
      ruoyi-ui/src/views/system/operlog/index.vue

+ 4 - 2
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java

@@ -540,9 +540,9 @@ public class Convert
 
     /**
      * 转换为boolean<br>
-     * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
+     * String支持的值为:true、false、yes、ok、no、1、0、是、否, 如果给定的值为空,或者转换失败,返回默认值<br>
      * 转换失败不会报错
-     * 
+     *
      * @param value 被转换的值
      * @param defaultValue 转换错误时的默认值
      * @return 结果
@@ -569,10 +569,12 @@ public class Convert
             case "yes":
             case "ok":
             case "1":
+            case "是":
                 return true;
             case "false":
             case "no":
             case "0":
+            case "否":
                 return false;
             default:
                 return defaultValue;

+ 1 - 1
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableDataInfo.java

@@ -37,7 +37,7 @@ public class TableDataInfo implements Serializable
      * @param list 列表数据
      * @param total 总记录数
      */
-    public TableDataInfo(List<?> list, int total)
+    public TableDataInfo(List<?> list, long total)
     {
         this.rows = list;
         this.total = total;

+ 6 - 6
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java

@@ -36,11 +36,11 @@ public class TokenService
 
     protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
 
-    private final static long expireTime = CacheConstants.EXPIRATION;
+    private final static long TOKEN_EXPIRE_TIME = CacheConstants.EXPIRATION;
 
     private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
 
-    private final static Long MILLIS_MINUTE_TEN = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
+    private final static Long TOKEN_REFRESH_THRESHOLD_MINUTES = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
 
     /**
      * 创建令牌
@@ -65,7 +65,7 @@ public class TokenService
         // 接口返回信息
         Map<String, Object> rspMap = new HashMap<String, Object>();
         rspMap.put("access_token", JwtUtils.createToken(claimsMap));
-        rspMap.put("expires_in", expireTime);
+        rspMap.put("expires_in", TOKEN_EXPIRE_TIME);
         return rspMap;
     }
 
@@ -147,7 +147,7 @@ public class TokenService
     {
         long expireTime = loginUser.getExpireTime();
         long currentTime = System.currentTimeMillis();
-        if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
+        if (expireTime - currentTime <= TOKEN_REFRESH_THRESHOLD_MINUTES)
         {
             refreshToken(loginUser);
         }
@@ -161,10 +161,10 @@ public class TokenService
     public void refreshToken(LoginUser loginUser)
     {
         loginUser.setLoginTime(System.currentTimeMillis());
-        loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
+        loginUser.setExpireTime(loginUser.getLoginTime() + TOKEN_EXPIRE_TIME * MILLIS_MINUTE);
         // 根据uuid将loginUser缓存
         String userKey = getTokenKey(loginUser.getToken());
-        redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
+        redisService.setCacheObject(userKey, loginUser, TOKEN_EXPIRE_TIME, TimeUnit.MINUTES);
     }
 
     private String getTokenKey(String token)

+ 11 - 11
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java

@@ -129,9 +129,9 @@ public class GenTableServiceImpl implements IGenTableService
         int row = genTableMapper.updateGenTable(genTable);
         if (row > 0)
         {
-            for (GenTableColumn cenTableColumn : genTable.getColumns())
+            for (GenTableColumn genTableColumn : genTable.getColumns())
             {
-                genTableColumnMapper.updateGenTableColumn(cenTableColumn);
+                genTableColumnMapper.updateGenTableColumn(genTableColumn);
             }
         }
     }
@@ -414,16 +414,16 @@ public class GenTableServiceImpl implements IGenTableService
             {
                 throw new ServiceException("树名称字段不能为空");
             }
-            else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
+        }
+        else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
+        {
+            if (StringUtils.isEmpty(genTable.getSubTableName()))
             {
-                if (StringUtils.isEmpty(genTable.getSubTableName()))
-                {
-                    throw new ServiceException("关联子表的表名不能为空");
-                }
-                else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
-                {
-                    throw new ServiceException("子表关联的外键名不能为空");
-                }
+                throw new ServiceException("关联子表的表名不能为空");
+            }
+            else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
+            {
+                throw new ServiceException("子表关联的外键名不能为空");
             }
         }
     }

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm

@@ -71,9 +71,9 @@ public class ${ClassName} extends ${Entity}
     {
         return $column.javaField;
     }
+
 #end
 #end
-
 #if($table.sub)
     public List<${subClassName}> get${subClassName}List()
     {

+ 5 - 5
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm

@@ -75,7 +75,7 @@
           icon="el-icon-plus"
           size="mini"
           @click="handleAdd"
-          v-hasPermi="['${moduleName}:${businessName}:add']"
+          v-hasPermi="['${permissionPrefix}:add']"
         >新增</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -144,21 +144,21 @@
             type="text"
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
-            v-hasPermi="['${moduleName}:${businessName}:edit']"
+            v-hasPermi="['${permissionPrefix}:edit']"
           >修改</el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-plus"
             @click="handleAdd(scope.row)"
-            v-hasPermi="['${moduleName}:${businessName}:add']"
+            v-hasPermi="['${permissionPrefix}:add']"
           >新增</el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
-            v-hasPermi="['${moduleName}:${businessName}:remove']"
+            v-hasPermi="['${permissionPrefix}:remove']"
           >删除</el-button>
         </template>
       </el-table-column>
@@ -453,7 +453,7 @@ export default {
       this.reset();
       this.getTreeselect();
       if (row != null) {
-        this.form.${treeParentCode} = row.${treeCode};
+        this.form.${treeParentCode} = row.${treeParentCode};
       }
       get${BusinessName}(row.${pkColumn.javaField}).then(response => {
         this.form = response.data;

+ 6 - 6
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm

@@ -75,7 +75,7 @@
           icon="el-icon-plus"
           size="mini"
           @click="handleAdd"
-          v-hasPermi="['${moduleName}:${businessName}:add']"
+          v-hasPermi="['${permissionPrefix}:add']"
         >新增</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -86,7 +86,7 @@
           size="mini"
           :disabled="single"
           @click="handleUpdate"
-          v-hasPermi="['${moduleName}:${businessName}:edit']"
+          v-hasPermi="['${permissionPrefix}:edit']"
         >修改</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -97,7 +97,7 @@
           size="mini"
           :disabled="multiple"
           @click="handleDelete"
-          v-hasPermi="['${moduleName}:${businessName}:remove']"
+          v-hasPermi="['${permissionPrefix}:remove']"
         >删除</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -107,7 +107,7 @@
           icon="el-icon-download"
           size="mini"
           @click="handleExport"
-          v-hasPermi="['${moduleName}:${businessName}:export']"
+          v-hasPermi="['${permissionPrefix}:export']"
         >导出</el-button>
       </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@@ -158,14 +158,14 @@
             type="text"
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
-            v-hasPermi="['${moduleName}:${businessName}:edit']"
+            v-hasPermi="['${permissionPrefix}:edit']"
           >修改</el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
-            v-hasPermi="['${moduleName}:${businessName}:remove']"
+            v-hasPermi="['${permissionPrefix}:remove']"
           >删除</el-button>
         </template>
       </el-table-column>

+ 5 - 5
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3/index-tree.vue.vm

@@ -73,7 +73,7 @@
           plain
           icon="Plus"
           @click="handleAdd"
-          v-hasPermi="['${moduleName}:${businessName}:add']"
+          v-hasPermi="['${permissionPrefix}:add']"
         >新增</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -136,9 +136,9 @@
 #end
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template #default="scope">
-          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
-          <el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
-          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
+          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${permissionPrefix}:edit']">修改</el-button>
+          <el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['${permissionPrefix}:add']">新增</el-button>
+          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${permissionPrefix}:remove']">删除</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -420,7 +420,7 @@ async function handleUpdate(row) {
   reset();
   await getTreeselect();
   if (row != null) {
-    form.value.${treeParentCode} = row.${treeCode};
+    form.value.${treeParentCode} = row.${treeParentCode};
   }
   get${BusinessName}(row.${pkColumn.javaField}).then(response => {
     form.value = response.data;

+ 6 - 6
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3/index.vue.vm

@@ -73,7 +73,7 @@
           plain
           icon="Plus"
           @click="handleAdd"
-          v-hasPermi="['${moduleName}:${businessName}:add']"
+          v-hasPermi="['${permissionPrefix}:add']"
         >新增</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -83,7 +83,7 @@
           icon="Edit"
           :disabled="single"
           @click="handleUpdate"
-          v-hasPermi="['${moduleName}:${businessName}:edit']"
+          v-hasPermi="['${permissionPrefix}:edit']"
         >修改</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -93,7 +93,7 @@
           icon="Delete"
           :disabled="multiple"
           @click="handleDelete"
-          v-hasPermi="['${moduleName}:${businessName}:remove']"
+          v-hasPermi="['${permissionPrefix}:remove']"
         >删除</el-button>
       </el-col>
       <el-col :span="1.5">
@@ -102,7 +102,7 @@
           plain
           icon="Download"
           @click="handleExport"
-          v-hasPermi="['${moduleName}:${businessName}:export']"
+          v-hasPermi="['${permissionPrefix}:export']"
         >导出</el-button>
       </el-col>
       <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
@@ -148,8 +148,8 @@
 #end
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template #default="scope">
-          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
-          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
+          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${permissionPrefix}:edit']">修改</el-button>
+          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${permissionPrefix}:remove']">删除</el-button>
         </template>
       </el-table-column>
     </el-table>

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

@@ -365,7 +365,7 @@ public class SysMenuServiceImpl implements ISysMenuService
     /**
      * 获取路由名称,如没有配置路由名称则取路由地址
      * 
-     * @param routerName 路由名称
+     * @param name 路由名称
      * @param path 路由地址
      * @return 路由名称(驼峰格式)
      */

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

@@ -73,7 +73,7 @@ public class SysPermissionServiceImpl implements ISysPermissionService
                 // 多角色设置permissions属性,以便数据权限匹配权限
                 for (SysRole role : roles)
                 {
-                    if (StringUtils.equals(role.getStatus(), UserConstants.ROLE_NORMAL))
+                    if (StringUtils.equals(role.getStatus(), UserConstants.ROLE_NORMAL) && !role.isAdmin())
                     {
                         Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId());
                         role.setPermissions(rolePerms);

+ 0 - 1
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -146,7 +146,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  		insert into sys_user(
  			<if test="userId != null and userId != 0">user_id,</if>
  			<if test="deptId != null and deptId != 0">dept_id,</if>
- 			<if test="userName != null and userName != ''">user_name,</if>
  			<if test="nickName != null and nickName != ''">nick_name,</if>
  			<if test="email != null and email != ''">email,</if>
  			<if test="avatar != null and avatar != ''">avatar,</if>

+ 0 - 4
ruoyi-ui/src/assets/styles/index.scss

@@ -129,10 +129,6 @@ aside {
   position: relative;
 }
 
-.pagination-container {
-  margin-top: 30px;
-}
-
 .text-center {
   text-align: center
 }

+ 3 - 12
ruoyi-ui/src/assets/styles/ruoyi.scss

@@ -117,11 +117,9 @@
 
 /** 表格布局 **/
 .pagination-container {
-  position: relative;
-  height: 32px;
-  margin-bottom: 10px;
-  margin-top: 15px;
-  padding: 10px 20px !important;
+  display: flex;
+  justify-content: flex-end;
+  margin-top: 20px;
 }
 
 /* tree border */
@@ -132,11 +130,6 @@
   border-radius: 4px;
 }
 
-.pagination-container .el-pagination {
-  right: 0;
-  position: absolute;
-}
-
 @media (max-width: 768px) {
   .pagination-container .el-pagination > .el-pagination__jump {
     display: none !important;
@@ -201,8 +194,6 @@
 }
 
 .card-box {
-  padding-right: 15px;
-  padding-left: 15px;
   margin-bottom: 10px;
 }
 

+ 0 - 1
ruoyi-ui/src/components/Pagination/index.vue

@@ -106,7 +106,6 @@ export default {
 <style scoped>
 .pagination-container {
   background: #fff;
-  padding: 32px 16px;
 }
 .pagination-container.hidden {
   display: none;

+ 2 - 2
ruoyi-ui/src/layout/components/Navbar.vue

@@ -2,8 +2,8 @@
   <div class="navbar">
     <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
 
-    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav"/>
-    <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/>
+    <breadcrumb v-if="!topNav" id="breadcrumb-container" class="breadcrumb-container" />
+    <top-nav v-if="topNav" id="topmenu-container" class="topmenu-container" />
 
     <div class="right-menu">
       <template v-if="device!=='mobile'">

+ 6 - 21
ruoyi-ui/src/store/modules/permission.js

@@ -82,28 +82,13 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
 
 function filterChildren(childrenMap, lastRouter = false) {
   var children = []
-  childrenMap.forEach((el, index) => {
-    if (el.children && el.children.length) {
-      if (el.component === 'ParentView' && !lastRouter) {
-        el.children.forEach(c => {
-          c.path = el.path + '/' + c.path
-          if (c.children && c.children.length) {
-            children = children.concat(filterChildren(c.children, c))
-            return
-          }
-          children.push(c)
-        })
-        return
-      }
-    }
-    if (lastRouter) {
-      el.path = lastRouter.path + '/' + el.path
-      if (el.children && el.children.length) {
-        children = children.concat(filterChildren(el.children, el))
-        return
-      }
+  childrenMap.forEach(el => {
+    el.path = lastRouter ? lastRouter.path + '/' + el.path : el.path
+    if (el.children && el.children.length && el.component === 'ParentView') {
+      children = children.concat(filterChildren(el.children, el))
+    } else {
+      children.push(el)
     }
-    children = children.concat(el)
   })
   return children
 }

+ 19 - 27
ruoyi-ui/src/utils/ruoyi.js

@@ -1,5 +1,3 @@
-
-
 /**
  * 通用js方法封装处理
  * Copyright (c) 2019 ruoyi
@@ -165,37 +163,19 @@ export function handleTree(data, id, parentId, children) {
   };
 
   var childrenListMap = {};
-  var nodeIds = {};
   var tree = [];
-
   for (let d of data) {
-    let parentId = d[config.parentId];
-    if (childrenListMap[parentId] == null) {
-      childrenListMap[parentId] = [];
-    }
-    nodeIds[d[config.id]] = d;
-    childrenListMap[parentId].push(d);
+    let id = d[config.id];
+    childrenListMap[id] = d;
   }
 
   for (let d of data) {
-    let parentId = d[config.parentId];
-    if (nodeIds[parentId] == null) {
+    let parentId = d[config.parentId]
+    let parentObj = childrenListMap[parentId]
+    if (!parentObj) {
       tree.push(d);
-    }
-  }
-
-  for (let t of tree) {
-    adaptToChildrenList(t);
-  }
-
-  function adaptToChildrenList(o) {
-    if (childrenListMap[o[config.id]] !== null) {
-      o[config.childrenList] = childrenListMap[o[config.id]];
-    }
-    if (o[config.childrenList]) {
-      for (let c of o[config.childrenList]) {
-        adaptToChildrenList(c);
-      }
+    } else {
+      parentObj[config.childrenList].push(d)
     }
   }
   return tree;
@@ -227,6 +207,18 @@ export function tansParams(params) {
   return result
 }
 
+// 返回项目路径
+export function getNormalPath(p) {
+  if (p.length === 0 || !p || p == 'undefined') {
+    return p
+  };
+  let res = p.replace('//', '/')
+  if (res[res.length - 1] === '/') {
+    return res.slice(0, res.length - 1)
+  }
+  return res
+}
+
 // 验证是否为blob格式
 export function blobValidate(data) {
   return data.type !== 'application/json'

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

@@ -1,13 +1,5 @@
 <template>
   <div class="app-container home">
-    <el-row :gutter="20">
-      <el-col :sm="24" :lg="24">
-        <blockquote class="text-warning" style="font-size: 14px">
-          阿里云服务器折扣区<el-link href="http://aly.ruoyi.vip" type="primary" target="_blank">☛☛点我进入☚☚</el-link> &nbsp;&nbsp;&nbsp; 腾讯云服务器秒杀区<el-link href="http://txy.ruoyi.vip" type="primary" target="_blank">☛☛点我进入☚☚</el-link>
-        </blockquote>
-        <hr />
-      </el-col>
-    </el-row>
     <el-row :gutter="20">
       <el-col :sm="24" :lg="12" style="padding-left: 20px">
         <h2>若依后台管理框架</h2>

+ 1 - 1
ruoyi-ui/src/views/system/logininfor/index.vue

@@ -153,7 +153,7 @@ export default {
       // 日期范围
       dateRange: [],
       // 默认排序
-      defaultSort: {prop: 'accessTime', order: 'descending'},
+      defaultSort: { prop: "accessTime", order: "descending" },
       // 查询参数
       queryParams: {
         pageNum: 1,

+ 1 - 1
ruoyi-ui/src/views/system/operlog/index.vue

@@ -231,7 +231,7 @@ export default {
       // 日期范围
       dateRange: [],
       // 默认排序
-      defaultSort: {prop: 'operTime', order: 'descending'},
+      defaultSort: { prop: "operTime", order: "descending" },
       // 表单参数
       form: {},
       // 查询参数