Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
MyCard
Neos
Commits
fd8162b5
Commit
fd8162b5
authored
Aug 13, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add DeckUploder
parent
770af6f9
Pipeline
#23050
passed with stages
in 13 minutes and 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
2 deletions
+76
-2
src/ui/BuildDeck/DeckSelect.tsx
src/ui/BuildDeck/DeckSelect.tsx
+76
-2
No files found.
src/ui/BuildDeck/DeckSelect.tsx
View file @
fd8162b5
...
@@ -3,8 +3,13 @@ import {
...
@@ -3,8 +3,13 @@ import {
DownloadOutlined
,
DownloadOutlined
,
FileAddOutlined
,
FileAddOutlined
,
PlusOutlined
,
PlusOutlined
,
UploadOutlined
,
}
from
"
@ant-design/icons
"
;
}
from
"
@ant-design/icons
"
;
import
{
Button
,
Dropdown
,
MenuProps
}
from
"
antd
"
;
import
{
App
,
Button
,
Dropdown
,
MenuProps
,
Upload
,
UploadProps
}
from
"
antd
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
YGOProDeck
from
"
ygopro-deck-encode
"
;
import
{
deckStore
,
IDeck
}
from
"
@/stores
"
;
import
styles
from
"
./DeckSelect.module.scss
"
;
import
styles
from
"
./DeckSelect.module.scss
"
;
...
@@ -16,6 +21,32 @@ export const DeckSelect: React.FC<{
...
@@ -16,6 +21,32 @@ export const DeckSelect: React.FC<{
onDownload
:
(
deckName
:
string
)
=>
void
;
onDownload
:
(
deckName
:
string
)
=>
void
;
onAdd
:
()
=>
void
;
onAdd
:
()
=>
void
;
}
>
=
({
decks
,
selected
,
onSelect
,
onDelete
,
onDownload
,
onAdd
})
=>
{
}
>
=
({
decks
,
selected
,
onSelect
,
onDelete
,
onDownload
,
onAdd
})
=>
{
const
[
newDeck
,
setNewDeck
]
=
useState
<
IDeck
|
undefined
>
(
undefined
);
const
{
modal
}
=
App
.
useApp
();
const
showUploadModal
=
()
=>
{
const
{
destroy
}
=
modal
.
info
({
width
:
500
,
centered
:
true
,
title
:
"
请上传YDK文件
"
,
icon
:
null
,
content
:
(
<
DeckUploader
onLoaded=
{
(
deck
)
=>
{
// 这里不生效,很奇怪
setNewDeck
(
deck
);
}
}
/>
),
okText
:
"
上传
"
,
onCancel
:
()
=>
destroy
(),
onOk
:
async
()
=>
{
if
(
newDeck
)
{
await
deckStore
.
add
(
newDeck
);
}
},
});
};
const
items
:
MenuProps
[
"
items
"
]
=
[
const
items
:
MenuProps
[
"
items
"
]
=
[
{
{
key
:
"
1
"
,
key
:
"
1
"
,
...
@@ -27,9 +58,10 @@ export const DeckSelect: React.FC<{
...
@@ -27,9 +58,10 @@ export const DeckSelect: React.FC<{
key
:
"
2
"
,
key
:
"
2
"
,
label
:
"
导入卡组
"
,
label
:
"
导入卡组
"
,
icon
:
<
FileAddOutlined
/>,
icon
:
<
FileAddOutlined
/>,
onClick
:
()
=>
{}
,
onClick
:
showUploadModal
,
},
},
];
];
return
(
return
(
<>
<>
<
div
className=
{
styles
[
"
deck-select
"
]
}
>
<
div
className=
{
styles
[
"
deck-select
"
]
}
>
...
@@ -73,6 +105,48 @@ export const DeckSelect: React.FC<{
...
@@ -73,6 +105,48 @@ export const DeckSelect: React.FC<{
);
);
};
};
const
DeckUploader
:
React
.
FC
<
{
onLoaded
:
(
deck
:
IDeck
)
=>
void
}
>
=
({
onLoaded
,
})
=>
{
const
[
uploadState
,
setUploadState
]
=
useState
(
""
);
const
uploadProps
:
UploadProps
=
{
name
:
"
file
"
,
onChange
(
info
)
{
if
(
uploadState
!=
"
ERROR
"
)
{
info
.
file
.
status
=
"
done
"
;
}
},
beforeUpload
(
file
,
_
)
{
const
reader
=
new
FileReader
();
reader
.
readAsText
(
file
);
reader
.
onload
=
(
e
)
=>
{
const
ydk
=
e
.
target
?.
result
as
string
;
const
deck
=
YGOProDeck
.
fromYdkString
(
ydk
);
if
(
!
(
deck
.
main
.
length
===
0
&&
deck
.
extra
.
length
===
0
&&
deck
.
side
.
length
===
0
)
)
{
// YDK解析成功
onLoaded
({
deckName
:
file
.
name
,
...
deck
});
}
else
{
alert
(
`
${
file
.
name
}
解析失败,请检查格式是否正确。`
);
setUploadState
(
"
ERROR
"
);
}
};
},
};
return
(
<
Upload
{
...
uploadProps
}
>
<
Button
icon=
{
<
UploadOutlined
/>
}
>
点击上传
</
Button
>
</
Upload
>
);
};
/** 阻止事件冒泡 */
/** 阻止事件冒泡 */
const
cancelBubble
=
const
cancelBubble
=
<
T
,
>
(fn: (e: React.SyntheticEvent) =
>
T) =
>
<
T
,
>
(fn: (e: React.SyntheticEvent) =
>
T) =
>
...
...
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