Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
863d8424
authored
Apr 26, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: download redemption codes as file (#12)
parent
be2b3f3f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
web/src/helpers/utils.js
+10
-0
web/src/pages/Redemption/EditRedemption.js
+11
-4
No files found.
web/src/helpers/utils.js
View file @
863d8424
...
...
@@ -143,4 +143,13 @@ export function timestamp2string(timestamp) {
':'
+
second
);
}
export
function
downloadTextAsFile
(
text
,
filename
)
{
let
blob
=
new
Blob
([
text
],
{
type
:
'text/plain;charset=utf-8'
});
let
url
=
URL
.
createObjectURL
(
blob
);
let
a
=
document
.
createElement
(
'a'
);
a
.
href
=
url
;
a
.
download
=
filename
;
a
.
click
();
}
\ No newline at end of file
web/src/pages/Redemption/EditRedemption.js
View file @
863d8424
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Button
,
Form
,
Header
,
Segment
}
from
'semantic-ui-react'
;
import
{
useParams
}
from
'react-router-dom'
;
import
{
API
,
isAdmin
,
showError
,
showSuccess
,
quotatamp2string
}
from
'../../helpers'
;
import
{
API
,
downloadTextAsFile
,
showError
,
showSuccess
}
from
'../../helpers'
;
const
EditRedemption
=
()
=>
{
const
params
=
useParams
();
...
...
@@ -11,7 +11,7 @@ const EditRedemption = () => {
const
originInputs
=
{
name
:
''
,
quota
:
100
,
count
:
1
,
count
:
1
};
const
[
inputs
,
setInputs
]
=
useState
(
originInputs
);
const
{
name
,
quota
,
count
}
=
inputs
;
...
...
@@ -46,10 +46,10 @@ const EditRedemption = () => {
res
=
await
API
.
put
(
`/api/redemption/`
,
{
...
localInputs
,
id
:
parseInt
(
redemptionId
)
});
}
else
{
res
=
await
API
.
post
(
`/api/redemption/`
,
{
...
localInputs
,
...
localInputs
});
}
const
{
success
,
message
}
=
res
.
data
;
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
if
(
isEdit
)
{
showSuccess
(
'兑换码更新成功!'
);
...
...
@@ -60,6 +60,13 @@ const EditRedemption = () => {
}
else
{
showError
(
message
);
}
if
(
!
isEdit
&&
data
)
{
let
text
=
""
;
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
text
+=
data
[
i
]
+
"\n"
;
}
downloadTextAsFile
(
text
,
`
${
inputs
.
name
}
.txt`
);
}
};
return
(
...
...
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