11import React , { useEffect , useState } from 'react' ;
22import { Button , Form , Header , Segment } from 'semantic-ui-react' ;
33import { useParams } from 'react-router-dom' ;
4- import { API , isAdmin , showError , showSuccess , quotatamp2string } from '../../helpers' ;
4+ import { API , downloadTextAsFile , showError , showSuccess } from '../../helpers' ;
55
66const EditRedemption = ( ) => {
77 const params = useParams ( ) ;
@@ -11,7 +11,7 @@ const EditRedemption = () => {
1111 const originInputs = {
1212 name : '' ,
1313 quota : 100 ,
14- count : 1 ,
14+ count : 1
1515 } ;
1616 const [ inputs , setInputs ] = useState ( originInputs ) ;
1717 const { name, quota, count } = inputs ;
@@ -46,10 +46,10 @@ const EditRedemption = () => {
4646 res = await API . put ( `/api/redemption/` , { ...localInputs , id : parseInt ( redemptionId ) } ) ;
4747 } else {
4848 res = await API . post ( `/api/redemption/` , {
49- ...localInputs ,
49+ ...localInputs
5050 } ) ;
5151 }
52- const { success, message } = res . data ;
52+ const { success, message, data } = res . data ;
5353 if ( success ) {
5454 if ( isEdit ) {
5555 showSuccess ( '兑换码更新成功!' ) ;
@@ -60,6 +60,13 @@ const EditRedemption = () => {
6060 } else {
6161 showError ( message ) ;
6262 }
63+ if ( ! isEdit && data ) {
64+ let text = "" ;
65+ for ( let i = 0 ; i < data . length ; i ++ ) {
66+ text += data [ i ] + "\n" ;
67+ }
68+ downloadTextAsFile ( text , `${ inputs . name } .txt` ) ;
69+ }
6370 } ;
6471
6572 return (
0 commit comments