Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
sts网站
Commits
e62e8e37
Commit
e62e8e37
authored
Feb 25, 2022
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
组件ImageUpload支持多图同时选择上传
parent
bb65cd19
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
12 deletions
+81
-12
CommonController.java
...ava/com/ruoyi/web/controller/common/CommonController.java
+50
-5
FileUtils.java
.../src/main/java/com/ruoyi/common/utils/file/FileUtils.java
+18
-0
ScheduleUtils.java
...tz/src/main/java/com/ruoyi/quartz/util/ScheduleUtils.java
+1
-4
index.vue
ruoyi-ui/src/components/ImageUpload/index.vue
+12
-3
No files found.
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
View file @
e62e8e37
package
com
.
ruoyi
.
web
.
controller
.
common
;
package
com
.
ruoyi
.
web
.
controller
.
common
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.ruoyi.common.config.RuoYiConfig
;
import
com.ruoyi.common.config.RuoYiConfig
;
...
@@ -24,6 +27,7 @@ import com.ruoyi.framework.config.ServerConfig;
...
@@ -24,6 +27,7 @@ import com.ruoyi.framework.config.ServerConfig;
* @author ruoyi
* @author ruoyi
*/
*/
@RestController
@RestController
@RequestMapping
(
"/common"
)
public
class
CommonController
public
class
CommonController
{
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
CommonController
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
CommonController
.
class
);
...
@@ -31,13 +35,15 @@ public class CommonController
...
@@ -31,13 +35,15 @@ public class CommonController
@Autowired
@Autowired
private
ServerConfig
serverConfig
;
private
ServerConfig
serverConfig
;
private
static
final
String
FILE_DELIMETER
=
","
;
/**
/**
* 通用下载请求
* 通用下载请求
*
*
* @param fileName 文件名称
* @param fileName 文件名称
* @param delete 是否删除
* @param delete 是否删除
*/
*/
@GetMapping
(
"
common
/download"
)
@GetMapping
(
"/download"
)
public
void
fileDownload
(
String
fileName
,
Boolean
delete
,
HttpServletResponse
response
,
HttpServletRequest
request
)
public
void
fileDownload
(
String
fileName
,
Boolean
delete
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
{
try
try
...
@@ -64,9 +70,9 @@ public class CommonController
...
@@ -64,9 +70,9 @@ public class CommonController
}
}
/**
/**
* 通用上传请求
* 通用上传请求
(单个)
*/
*/
@PostMapping
(
"/
common/
upload"
)
@PostMapping
(
"/upload"
)
public
AjaxResult
uploadFile
(
MultipartFile
file
)
throws
Exception
public
AjaxResult
uploadFile
(
MultipartFile
file
)
throws
Exception
{
{
try
try
...
@@ -77,8 +83,47 @@ public class CommonController
...
@@ -77,8 +83,47 @@ public class CommonController
String
fileName
=
FileUploadUtils
.
upload
(
filePath
,
file
);
String
fileName
=
FileUploadUtils
.
upload
(
filePath
,
file
);
String
url
=
serverConfig
.
getUrl
()
+
fileName
;
String
url
=
serverConfig
.
getUrl
()
+
fileName
;
AjaxResult
ajax
=
AjaxResult
.
success
();
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"fileName"
,
fileName
);
ajax
.
put
(
"url"
,
url
);
ajax
.
put
(
"url"
,
url
);
ajax
.
put
(
"fileName"
,
fileName
);
ajax
.
put
(
"newFileName"
,
FileUtils
.
getName
(
fileName
));
ajax
.
put
(
"originalFilename"
,
file
.
getOriginalFilename
());
return
ajax
;
}
catch
(
Exception
e
)
{
return
AjaxResult
.
error
(
e
.
getMessage
());
}
}
/**
* 通用上传请求(多个)
*/
@PostMapping
(
"/uploads"
)
public
AjaxResult
uploadFiles
(
List
<
MultipartFile
>
files
)
throws
Exception
{
try
{
// 上传文件路径
String
filePath
=
RuoYiConfig
.
getUploadPath
();
List
<
String
>
urls
=
new
ArrayList
<
String
>();
List
<
String
>
fileNames
=
new
ArrayList
<
String
>();
List
<
String
>
newFileNames
=
new
ArrayList
<
String
>();
List
<
String
>
originalFilenames
=
new
ArrayList
<
String
>();
for
(
MultipartFile
file
:
files
)
{
// 上传并返回新文件名称
String
fileName
=
FileUploadUtils
.
upload
(
filePath
,
file
);
String
url
=
serverConfig
.
getUrl
()
+
fileName
;
urls
.
add
(
url
);
fileNames
.
add
(
fileName
);
newFileNames
.
add
(
FileUtils
.
getName
(
fileName
));
originalFilenames
.
add
(
file
.
getOriginalFilename
());
}
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"urls"
,
StringUtils
.
join
(
urls
,
FILE_DELIMETER
));
ajax
.
put
(
"fileNames"
,
StringUtils
.
join
(
fileNames
,
FILE_DELIMETER
));
ajax
.
put
(
"newFileNames"
,
StringUtils
.
join
(
newFileNames
,
FILE_DELIMETER
));
ajax
.
put
(
"originalFilenames"
,
StringUtils
.
join
(
originalFilenames
,
FILE_DELIMETER
));
return
ajax
;
return
ajax
;
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
...
@@ -90,7 +135,7 @@ public class CommonController
...
@@ -90,7 +135,7 @@ public class CommonController
/**
/**
* 本地资源通用下载
* 本地资源通用下载
*/
*/
@GetMapping
(
"/
common/
download/resource"
)
@GetMapping
(
"/download/resource"
)
public
void
resourceDownload
(
String
resource
,
HttpServletRequest
request
,
HttpServletResponse
response
)
public
void
resourceDownload
(
String
resource
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
throws
Exception
{
{
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java
View file @
e62e8e37
...
@@ -256,4 +256,22 @@ public class FileUtils
...
@@ -256,4 +256,22 @@ public class FileUtils
}
}
return
strFileExtendName
;
return
strFileExtendName
;
}
}
/**
* 获取名称
*
* @param fileName 路径名称
* @return 没有文件路径的名称
*/
public
static
String
getName
(
String
fileName
)
{
if
(
fileName
==
null
)
{
return
null
;
}
int
lastUnixPos
=
fileName
.
lastIndexOf
(
'/'
);
int
lastWindowsPos
=
fileName
.
lastIndexOf
(
'\\'
);
int
index
=
Math
.
max
(
lastUnixPos
,
lastWindowsPos
);
return
fileName
.
substring
(
index
+
1
);
}
}
}
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/ScheduleUtils.java
View file @
e62e8e37
...
@@ -125,10 +125,7 @@ public class ScheduleUtils
...
@@ -125,10 +125,7 @@ public class ScheduleUtils
int
count
=
StringUtils
.
countMatches
(
packageName
,
"."
);
int
count
=
StringUtils
.
countMatches
(
packageName
,
"."
);
if
(
count
>
1
)
if
(
count
>
1
)
{
{
if
(!
StringUtils
.
containsAnyIgnoreCase
(
invokeTarget
,
Constants
.
JOB_WHITELIST_STR
))
return
StringUtils
.
containsAnyIgnoreCase
(
invokeTarget
,
Constants
.
JOB_WHITELIST_STR
);
{
return
false
;
}
}
}
return
true
;
return
true
;
}
}
...
...
ruoyi-ui/src/components/ImageUpload/index.vue
View file @
e62e8e37
<
template
>
<
template
>
<div
class=
"component-upload-image"
>
<div
class=
"component-upload-image"
>
<el-upload
<el-upload
multiple
:action=
"uploadImgUrl"
:action=
"uploadImgUrl"
list-type=
"picture-card"
list-type=
"picture-card"
:on-success=
"handleUploadSuccess"
:on-success=
"handleUploadSuccess"
...
@@ -70,6 +71,8 @@ export default {
...
@@ -70,6 +71,8 @@ export default {
},
},
data
()
{
data
()
{
return
{
return
{
number
:
0
,
uploadList
:
[],
dialogImageUrl
:
""
,
dialogImageUrl
:
""
,
dialogVisible
:
false
,
dialogVisible
:
false
,
hideUpload
:
false
,
hideUpload
:
false
,
...
@@ -124,9 +127,14 @@ export default {
...
@@ -124,9 +127,14 @@ export default {
},
},
// 上传成功回调
// 上传成功回调
handleUploadSuccess
(
res
)
{
handleUploadSuccess
(
res
)
{
this
.
fileList
.
push
({
name
:
res
.
fileName
,
url
:
res
.
fileName
});
this
.
uploadList
.
push
({
name
:
res
.
fileName
,
url
:
res
.
fileName
});
if
(
this
.
uploadList
.
length
===
this
.
number
)
{
this
.
fileList
=
this
.
fileList
.
concat
(
this
.
uploadList
);
this
.
uploadList
=
[];
this
.
number
=
0
;
this
.
$emit
(
"input"
,
this
.
listToString
(
this
.
fileList
));
this
.
$emit
(
"input"
,
this
.
listToString
(
this
.
fileList
));
this
.
loading
.
close
();
this
.
loading
.
close
();
}
},
},
// 上传前loading加载
// 上传前loading加载
handleBeforeUpload
(
file
)
{
handleBeforeUpload
(
file
)
{
...
@@ -163,6 +171,7 @@ export default {
...
@@ -163,6 +171,7 @@ export default {
text
:
"上传中"
,
text
:
"上传中"
,
background
:
"rgba(0, 0, 0, 0.7)"
,
background
:
"rgba(0, 0, 0, 0.7)"
,
});
});
this
.
number
++
;
},
},
// 文件个数超出
// 文件个数超出
handleExceed
()
{
handleExceed
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment