Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-archetype-initializer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tools
schbrain-archetype-initializer
Commits
b8fb0e76
Commit
b8fb0e76
authored
Mar 20, 2022
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support preview
parent
c1bc259c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
5 deletions
+35
-5
initializer-backend/src/main/java/com/schbrain/archetype/initializer/response/PreviewFileTree.java
...brain/archetype/initializer/response/PreviewFileTree.java
+9
-0
initializer-backend/src/main/java/com/schbrain/archetype/initializer/service/ArchetypeService.java
...brain/archetype/initializer/service/ArchetypeService.java
+8
-3
initializer-ui/src/components/BackendStarter.vue
initializer-ui/src/components/BackendStarter.vue
+18
-2
No files found.
initializer-backend/src/main/java/com/schbrain/archetype/initializer/response/PreviewFileTree.java
View file @
b8fb0e76
...
...
@@ -5,6 +5,7 @@ import lombok.Data;
import
lombok.NoArgsConstructor
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Collections
;
import
java.util.List
;
/**
...
...
@@ -18,8 +19,16 @@ public class PreviewFileTree {
private
String
fileName
;
private
String
fileContent
;
private
List
<
PreviewFileTree
>
children
;
public
PreviewFileTree
(
String
fileName
,
String
fileContent
)
{
this
.
fileName
=
fileName
;
this
.
fileContent
=
fileContent
;
this
.
children
=
Collections
.
emptyList
();
}
public
boolean
isFile
()
{
return
CollectionUtils
.
isEmpty
(
children
);
}
...
...
initializer-backend/src/main/java/com/schbrain/archetype/initializer/service/ArchetypeService.java
View file @
b8fb0e76
package
com.schbrain.archetype.initializer.service
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ZipUtil
;
import
com.schbrain.archetype.initializer.maven.MavenUtils
;
...
...
@@ -17,7 +18,10 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Collectors
;
...
...
@@ -53,7 +57,7 @@ public class ArchetypeService {
private
PreviewFileTree
buildFileTree
(
File
root
)
{
File
[]
fileItems
=
root
.
listFiles
();
if
(
ArrayUtil
.
isEmpty
(
fileItems
))
{
return
new
PreviewFileTree
(
root
.
getName
(),
Collections
.
emptyList
()
);
return
new
PreviewFileTree
(
root
.
getName
(),
null
);
}
List
<
PreviewFileTree
>
children
=
Arrays
.
stream
(
fileItems
)
.
map
(
fileItem
->
{
...
...
@@ -61,7 +65,8 @@ public class ArchetypeService {
if
(
fileItem
.
isDirectory
())
{
childrenFileTree
=
buildFileTree
(
fileItem
);
}
else
{
childrenFileTree
=
new
PreviewFileTree
(
fileItem
.
getName
(),
Collections
.
emptyList
());
String
fileContent
=
FileUtil
.
readUtf8String
(
fileItem
);
childrenFileTree
=
new
PreviewFileTree
(
fileItem
.
getName
(),
fileContent
);
}
return
childrenFileTree
;
})
...
...
initializer-ui/src/components/BackendStarter.vue
View file @
b8fb0e76
...
...
@@ -20,7 +20,7 @@
<input
:disabled=
"this.id === null"
class=
"form-submit"
type=
"button"
value=
"下载"
@
click=
"download"
>
<el-dialog
v-model=
"dialogVisible"
title=
"预览"
width=
"30%"
>
<el-tree
ref=
"fileTree"
:data=
"treeData"
:props=
"defaultProps"
@
node-click=
"handleNodeClick"
/>
<el-tree
:data=
"treeData"
:props=
"defaultProps"
@
node-click=
"handleNodeClick"
/>
<template
#footer
>
<span
class=
"dialog-footer"
>
<el-button
type=
"primary"
@
click=
"dialogVisible = false"
>
关闭
</el-button>
...
...
@@ -28,6 +28,15 @@
</
template
>
</el-dialog>
<el-dialog
v-model=
"fileContentDialogVisible"
title=
"预览"
width=
"80%"
>
<div
v-html=
"fileContent"
></div>
<
template
#footer
>
<span
class=
"dialog-footer"
>
<el-button
type=
"primary"
@
click=
"fileContentDialogVisible = false"
>
关闭
</el-button>
</span>
</
template
>
</el-dialog>
</div>
</template>
...
...
@@ -41,6 +50,8 @@ export default {
return
{
id
:
null
,
dialogVisible
:
false
,
fileContentDialogVisible
:
false
,
fileContent
:
''
,
defaultProps
:
{
children
:
'
children
'
,
label
:
'
fileName
'
,
...
...
@@ -87,7 +98,12 @@ export default {
})
},
handleNodeClick
:
function
(
data
)
{
console
.
log
(
data
)
const
{
file
,
fileContent
}
=
data
if
(
!
file
)
{
return
}
this
.
fileContentDialogVisible
=
true
this
.
fileContent
=
fileContent
},
downloadGeneratedProject
:
function
(
data
,
fileName
)
{
const
blob
=
new
Blob
([
data
])
...
...
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