缓存(默认 false)
title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
@@ -35,28 +37,28 @@ export const constantRoutes = [
children: [
{
path: '/redirect/:path(.*)',
- component: (resolve) => require(['@/views/redirect'], resolve)
+ component: () => import('@/views/redirect')
}
]
},
{
path: '/login',
- component: (resolve) => require(['@/views/login'], resolve),
+ component: () => import('@/views/login'),
hidden: true
},
{
path: '/register',
- component: (resolve) => require(['@/views/register'], resolve),
+ component: () => import('@/views/register'),
hidden: true
},
{
path: '/404',
- component: (resolve) => require(['@/views/error/404'], resolve),
+ component: () => import('@/views/error/404'),
hidden: true
},
{
path: '/401',
- component: (resolve) => require(['@/views/error/401'], resolve),
+ component: () => import('@/views/error/401'),
hidden: true
},
{
@@ -66,7 +68,7 @@ export const constantRoutes = [
children: [
{
path: 'index',
- component: (resolve) => require(['@/views/index'], resolve),
+ component: () => import('@/views/index'),
name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true }
}
@@ -80,20 +82,25 @@ export const constantRoutes = [
children: [
{
path: 'profile',
- component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
+ component: () => import('@/views/system/user/profile/index'),
name: 'Profile',
meta: { title: '个人中心', icon: 'user' }
}
]
- },
+ }
+]
+
+// 动态路由,基于用户权限动态去加载
+export const dynamicRoutes = [
{
path: '/system/user-auth',
component: Layout,
hidden: true,
+ permissions: ['system:user:edit'],
children: [
{
path: 'role/:userId(\\d+)',
- component: (resolve) => require(['@/views/system/user/authRole'], resolve),
+ component: () => import('@/views/system/user/authRole'),
name: 'AuthRole',
meta: { title: '分配角色', activeMenu: '/system/user' }
}
@@ -103,10 +110,11 @@ export const constantRoutes = [
path: '/system/role-auth',
component: Layout,
hidden: true,
+ permissions: ['system:role:edit'],
children: [
{
path: 'user/:roleId(\\d+)',
- component: (resolve) => require(['@/views/system/role/authUser'], resolve),
+ component: () => import('@/views/system/role/authUser'),
name: 'AuthUser',
meta: { title: '分配用户', activeMenu: '/system/role' }
}
@@ -116,10 +124,11 @@ export const constantRoutes = [
path: '/system/dict-data',
component: Layout,
hidden: true,
+ permissions: ['system:dict:list'],
children: [
{
path: 'index/:dictId(\\d+)',
- component: (resolve) => require(['@/views/system/dict/data'], resolve),
+ component: () => import('@/views/system/dict/data'),
name: 'Data',
meta: { title: '字典数据', activeMenu: '/system/dict' }
}
@@ -129,10 +138,11 @@ export const constantRoutes = [
path: '/monitor/job-log',
component: Layout,
hidden: true,
+ permissions: ['monitor:job:list'],
children: [
{
path: 'index',
- component: (resolve) => require(['@/views/monitor/job/log'], resolve),
+ component: () => import('@/views/monitor/job/log'),
name: 'JobLog',
meta: { title: '调度日志', activeMenu: '/monitor/job' }
}
@@ -142,10 +152,11 @@ export const constantRoutes = [
path: '/tool/gen-edit',
component: Layout,
hidden: true,
+ permissions: ['tool:gen:edit'],
children: [
{
path: 'index',
- component: (resolve) => require(['@/views/tool/gen/editTable'], resolve),
+ component: () => import('@/views/tool/gen/editTable'),
name: 'GenEdit',
meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
}
diff --git a/ruoyi-ui/src/store/modules/permission.js b/ruoyi-ui/src/store/modules/permission.js
index 2c2120a8f..8c3c33909 100644
--- a/ruoyi-ui/src/store/modules/permission.js
+++ b/ruoyi-ui/src/store/modules/permission.js
@@ -1,4 +1,5 @@
-import { constantRoutes } from '@/router'
+import auth from '@/plugins/auth'
+import router, { constantRoutes, dynamicRoutes } from '@/router'
import { getRouters } from '@/api/menu'
import Layout from '@/layout/index'
import ParentView from '@/components/ParentView'
@@ -42,7 +43,9 @@ const permission = {
const rdata = JSON.parse(JSON.stringify(res.data))
const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
+ const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
+ router.addRoutes(asyncRoutes);
commit('SET_ROUTES', rewriteRoutes)
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
@@ -106,6 +109,23 @@ function filterChildren(childrenMap, lastRouter = false) {
return children
}
+// 动态路由遍历,验证是否具备权限
+export function filterDynamicRoutes(routes) {
+ const res = []
+ routes.forEach(route => {
+ if (route.permissions) {
+ if (auth.hasPermiOr(route.permissions)) {
+ res.push(route)
+ }
+ } else if (route.roles) {
+ if (auth.hasRoleOr(route.roles)) {
+ res.push(route)
+ }
+ }
+ })
+ return res
+}
+
export const loadView = (view) => {
if (process.env.NODE_ENV === 'development') {
return (resolve) => require([`@/views/${view}`], resolve)
diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js
index 8ee43ccb4..107a28d67 100644
--- a/ruoyi-ui/src/utils/request.js
+++ b/ruoyi-ui/src/utils/request.js
@@ -4,9 +4,12 @@ import store from '@/store'
import { getToken } from '@/utils/auth'
import errorCode from '@/utils/errorCode'
import { tansParams, blobValidate } from "@/utils/ruoyi";
+import cache from '@/plugins/cache'
import { saveAs } from 'file-saver'
let downloadLoadingInstance;
+// 是否显示重新登录
+let isReloginShow;
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// 创建axios实例
@@ -21,6 +24,8 @@ const service = axios.create({
service.interceptors.request.use(config => {
// 是否需要设置 token
const isToken = (config.headers || {}).isToken === false
+ // 是否需要防止数据重复提交
+ const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
if (getToken() && !isToken) {
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
}
@@ -31,6 +36,29 @@ service.interceptors.request.use(config => {
config.params = {};
config.url = url;
}
+ if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
+ const requestObj = {
+ url: config.url,
+ data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
+ time: new Date().getTime()
+ }
+ const sessionObj = cache.session.getJSON('sessionObj')
+ if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
+ cache.session.setJSON('sessionObj', requestObj)
+ } else {
+ const s_url = sessionObj.url; // 请求地址
+ const s_data = sessionObj.data; // 请求数据
+ const s_time = sessionObj.time; // 请求时间
+ const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交
+ if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
+ const message = '数据正在处理,请勿重复提交';
+ console.warn(`[${s_url}]: ` + message)
+ return Promise.reject(new Error(message))
+ } else {
+ cache.session.setJSON('sessionObj', requestObj)
+ }
+ }
+ }
return config
}, error => {
console.log(error)
@@ -48,16 +76,25 @@ service.interceptors.response.use(res => {
return res.data
}
if (code === 401) {
- MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
+ if (!isReloginShow) {
+ isReloginShow = true;
+ MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
+ isReloginShow = false;
store.dispatch('LogOut').then(() => {
- location.href = '/index';
+ // 如果是登录页面不需要重新加载
+ if (window.location.hash.indexOf("#/login") != 0) {
+ location.href = '/index';
+ }
})
- }).catch(() => {});
+ }).catch(() => {
+ isReloginShow = false;
+ });
+ }
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) {
Message({
diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js
index 4cc5e24ea..8e3cb0cea 100644
--- a/ruoyi-ui/src/utils/ruoyi.js
+++ b/ruoyi-ui/src/utils/ruoyi.js
@@ -1,3 +1,5 @@
+
+
/**
* 通用js方法封装处理
* Copyright (c) 2019 ruoyi
@@ -5,130 +7,133 @@
// 日期格式化
export function parseTime(time, pattern) {
- if (arguments.length === 0 || !time) {
- return null
- }
- const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'object') {
- date = time
- } else {
- if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
- time = parseInt(time)
- } else if (typeof time === 'string') {
- time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm),'');
- }
- if ((typeof time === 'number') && (time.toString().length === 10)) {
- time = time * 1000
- }
- date = new Date(time)
- }
- const formatObj = {
- y: date.getFullYear(),
- m: date.getMonth() + 1,
- d: date.getDate(),
- h: date.getHours(),
- i: date.getMinutes(),
- s: date.getSeconds(),
- a: date.getDay()
- }
- const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
- let value = formatObj[key]
- // Note: getDay() returns 0 on Sunday
- if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
- if (result.length > 0 && value < 10) {
- value = '0' + value
- }
- return value || 0
- })
- return time_str
+ if (arguments.length === 0 || !time) {
+ return null
+ }
+ const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
+ let date
+ if (typeof time === 'object') {
+ date = time
+ } else {
+ if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
+ time = parseInt(time)
+ } else if (typeof time === 'string') {
+ time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
+ }
+ if ((typeof time === 'number') && (time.toString().length === 10)) {
+ time = time * 1000
+ }
+ date = new Date(time)
+ }
+ const formatObj = {
+ y: date.getFullYear(),
+ m: date.getMonth() + 1,
+ d: date.getDate(),
+ h: date.getHours(),
+ i: date.getMinutes(),
+ s: date.getSeconds(),
+ a: date.getDay()
+ }
+ const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
+ let value = formatObj[key]
+ // Note: getDay() returns 0 on Sunday
+ if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
+ if (result.length > 0 && value < 10) {
+ value = '0' + value
+ }
+ return value || 0
+ })
+ return time_str
}
// 表单重置
export function resetForm(refName) {
- if (this.$refs[refName]) {
- this.$refs[refName].resetFields();
- }
+ if (this.$refs[refName]) {
+ this.$refs[refName].resetFields();
+ }
}
// 添加日期范围
export function addDateRange(params, dateRange, propName) {
- let search = params;
- search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {};
- dateRange = Array.isArray(dateRange) ? dateRange : [];
- if (typeof (propName) === 'undefined') {
- search.params['beginTime'] = dateRange[0];
- search.params['endTime'] = dateRange[1];
- } else {
- search.params['begin' + propName] = dateRange[0];
- search.params['end' + propName] = dateRange[1];
- }
- return search;
+ let search = params;
+ search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {};
+ dateRange = Array.isArray(dateRange) ? dateRange : [];
+ if (typeof (propName) === 'undefined') {
+ search.params['beginTime'] = dateRange[0];
+ search.params['endTime'] = dateRange[1];
+ } else {
+ search.params['begin' + propName] = dateRange[0];
+ search.params['end' + propName] = dateRange[1];
+ }
+ return search;
}
-// 回显数据字典
+// 回显数据字典
export function selectDictLabel(datas, value) {
- var actions = [];
- Object.keys(datas).some((key) => {
- if (datas[key].value == ('' + value)) {
- actions.push(datas[key].label);
- return true;
- }
- })
- return actions.join('');
+ var actions = [];
+ Object.keys(datas).some((key) => {
+ if (datas[key].value == ('' + value)) {
+ actions.push(datas[key].label);
+ return true;
+ }
+ })
+ return actions.join('');
}
// 回显数据字典(字符串数组)
export function selectDictLabels(datas, value, separator) {
- var actions = [];
- var currentSeparator = undefined === separator ? "," : separator;
- var temp = value.split(currentSeparator);
- Object.keys(value.split(currentSeparator)).some((val) => {
- Object.keys(datas).some((key) => {
- if (datas[key].value == ('' + temp[val])) {
- actions.push(datas[key].label + currentSeparator);
- }
- })
- })
- return actions.join('').substring(0, actions.join('').length - 1);
+ if(value === undefined) {
+ return "";
+ }
+ var actions = [];
+ var currentSeparator = undefined === separator ? "," : separator;
+ var temp = value.split(currentSeparator);
+ Object.keys(value.split(currentSeparator)).some((val) => {
+ Object.keys(datas).some((key) => {
+ if (datas[key].value == ('' + temp[val])) {
+ actions.push(datas[key].label + currentSeparator);
+ }
+ })
+ })
+ return actions.join('').substring(0, actions.join('').length - 1);
}
// 字符串格式化(%s )
export function sprintf(str) {
- var args = arguments, flag = true, i = 1;
- str = str.replace(/%s/g, function () {
- var arg = args[i++];
- if (typeof arg === 'undefined') {
- flag = false;
- return '';
- }
- return arg;
- });
- return flag ? str : '';
+ var args = arguments, flag = true, i = 1;
+ str = str.replace(/%s/g, function () {
+ var arg = args[i++];
+ if (typeof arg === 'undefined') {
+ flag = false;
+ return '';
+ }
+ return arg;
+ });
+ return flag ? str : '';
}
// 转换字符串,undefined,null等转化为""
-export function praseStrEmpty(str) {
- if (!str || str == "undefined" || str == "null") {
- return "";
- }
- return str;
+export function parseStrEmpty(str) {
+ if (!str || str == "undefined" || str == "null") {
+ return "";
+ }
+ return str;
}
// 数据合并
export function mergeRecursive(source, target) {
- for (var p in target) {
- try {
- if (target[p].constructor == Object) {
- source[p] = mergeRecursive(source[p], target[p]);
- } else {
- source[p] = target[p];
- }
- } catch(e) {
- source[p] = target[p];
- }
+ for (var p in target) {
+ try {
+ if (target[p].constructor == Object) {
+ source[p] = mergeRecursive(source[p], target[p]);
+ } else {
+ source[p] = target[p];
+ }
+ } catch (e) {
+ source[p] = target[p];
}
- return source;
+ }
+ return source;
};
/**
@@ -139,47 +144,47 @@ export function mergeRecursive(source, target) {
* @param {*} children 孩子节点字段 默认 'children'
*/
export function handleTree(data, id, parentId, children) {
- let config = {
- id: id || 'id',
- parentId: parentId || 'parentId',
- childrenList: children || 'children'
- };
+ let config = {
+ id: id || 'id',
+ parentId: parentId || 'parentId',
+ childrenList: children || 'children'
+ };
- var childrenListMap = {};
- var nodeIds = {};
- var tree = [];
+ 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);
- }
+ 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);
+ }
- for (let d of data) {
- let parentId = d[config.parentId];
- if (nodeIds[parentId] == null) {
- tree.push(d);
- }
- }
+ for (let d of data) {
+ let parentId = d[config.parentId];
+ if (nodeIds[parentId] == null) {
+ tree.push(d);
+ }
+ }
- for (let t of tree) {
- adaptToChildrenList(t);
- }
+ 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);
- }
- }
- }
- return tree;
+ 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);
+ }
+ }
+ }
+ return tree;
}
/**
@@ -187,34 +192,34 @@ export function handleTree(data, id, parentId, children) {
* @param {*} params 参数
*/
export function tansParams(params) {
- let result = ''
- for (const propName of Object.keys(params)) {
- const value = params[propName];
- var part = encodeURIComponent(propName) + "=";
- if (value !== null && typeof (value) !== "undefined") {
- if (typeof value === 'object') {
- for (const key of Object.keys(value)) {
- if (value[key] !== null && typeof (value[key]) !== 'undefined') {
- let params = propName + '[' + key + ']';
- var subPart = encodeURIComponent(params) + "=";
- result += subPart + encodeURIComponent(value[key]) + "&";
- }
- }
- } else {
- result += part + encodeURIComponent(value) + "&";
- }
- }
- }
- return result
+ let result = ''
+ for (const propName of Object.keys(params)) {
+ const value = params[propName];
+ var part = encodeURIComponent(propName) + "=";
+ if (value !== null && typeof (value) !== "undefined") {
+ if (typeof value === 'object') {
+ for (const key of Object.keys(value)) {
+ if (value[key] !== null && typeof (value[key]) !== 'undefined') {
+ let params = propName + '[' + key + ']';
+ var subPart = encodeURIComponent(params) + "=";
+ result += subPart + encodeURIComponent(value[key]) + "&";
+ }
+ }
+ } else {
+ result += part + encodeURIComponent(value) + "&";
+ }
+ }
+ }
+ return result
}
// 验证是否为blob格式
export async function blobValidate(data) {
- try {
- const text = await data.text();
- JSON.parse(text);
- return false;
- } catch (error) {
- return true;
- }
-}
+ try {
+ const text = await data.text();
+ JSON.parse(text);
+ return false;
+ } catch (error) {
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue
index 75761cb75..1cf7954be 100644
--- a/ruoyi-ui/src/views/index.vue
+++ b/ruoyi-ui/src/views/index.vue
@@ -120,9 +120,9 @@
QQ群:满937441
满887144332 满180251782 满104180207
- 满186866453 满201396349 满101456076
-
- 101539465满186866453 满201396349 满101456076 满101539465
+
+ 264312783
@@ -147,6 +147,39 @@
更新日志
+
+
+ - 新增Vue3前端代码生成模板
+ - 新增图片预览组件
+ - 新增压缩插件实现打包Gzip
+ - 自定义xss校验注解实现
+ - 自定义文字复制剪贴指令
+ - 代码生成预览支持复制内容
+ - 路由支持单独配置菜单或角色权限
+ - 用户管理部门查询选择节点后分页参数初始
+ - 修复用户分配角色属性错误
+ - 修复打包后字体图标偶现的乱码问题
+ - 修复菜单管理重置表单出现的错误
+ - 修复版本差异导致的懒加载报错问题
+ - 修复Cron组件中周回显问题
+ - 修复定时任务多参数逗号分隔的问题
+ - 修复根据ID查询列表可能出现的主键溢出问题
+ - 修复tomcat配置参数已过期问题
+ - 升级clipboard到最新版本2.0.8
+ - 升级oshi到最新版本v5.8.6
+ - 升级fastjson到最新版1.2.79
+ - 升级spring-boot到最新版本2.5.8
+ - 升级log4j2到2.17.1,防止漏洞风险
+ - 优化下载解析blob异常提示
+ - 优化代码生成字典组重复问题
+ - 优化查询用户的角色组&岗位组代码
+ - 优化定时任务cron表达式小时设置24
+ - 优化用户导入提示溢出则显示滚动条
+ - 优化防重复提交标识组合为(key+url+header)
+ - 优化分页方法设置成通用方便灵活调用
+ - 其他细节优化
+
+
- 新增配套并同步的Vue3前端版本
@@ -717,7 +750,7 @@ export default {
data() {
return {
// 版本号
- version: "3.8.0",
+ version: "3.8.1",
};
},
methods: {
diff --git a/ruoyi-ui/src/views/login.vue b/ruoyi-ui/src/views/login.vue
index 3baaf2432..6e240dd24 100644
--- a/ruoyi-ui/src/views/login.vue
+++ b/ruoyi-ui/src/views/login.vue
@@ -56,7 +56,7 @@