generated from songquanpeng/gin-template
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23bd08b
commit 31654c8
Showing
9 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Form, Grid } from 'semantic-ui-react'; | ||
import { API, showError } from '../helpers'; | ||
|
||
const WeChatSetting = () => { | ||
let [inputs, setInputs] = useState({ | ||
WeChatToken: '', | ||
WeChatAppID: '', | ||
WeChatAppSecret: '', | ||
WeChatEncodingAESKey: '', | ||
WeChatOwnerID: '', | ||
}); | ||
let [loading, setLoading] = useState(false); | ||
|
||
const getOptions = async () => { | ||
const res = await API.get('/api/option'); | ||
const { success, message, data } = res.data; | ||
if (success) { | ||
let newInputs = {}; | ||
data.forEach((item) => { | ||
if (item.key.startsWith('WeChat')) { | ||
newInputs[item.key] = item.value; | ||
} | ||
}); | ||
setInputs(newInputs); | ||
} else { | ||
showError(message); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getOptions().then(); | ||
}, []); | ||
|
||
const updateOption = async (key, value) => { | ||
setLoading(true); | ||
const res = await API.put('/api/option', { | ||
key, | ||
value, | ||
}); | ||
const { success, message } = res.data; | ||
if (success) { | ||
setInputs((inputs) => ({ ...inputs, [key]: value })); | ||
} else { | ||
showError(message); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
const handleInputChange = async (e, { name, value }) => { | ||
await updateOption(name, value); | ||
}; | ||
|
||
return ( | ||
<Grid columns={1}> | ||
<Grid.Column> | ||
<Form loading={loading}> | ||
<Form.Group widths="equal"> | ||
<Form.Input | ||
label="令牌(Token)" | ||
placeholder="" | ||
value={inputs.WeChatToken} | ||
name="WeChatToken" | ||
onChange={handleInputChange} | ||
/> | ||
</Form.Group> | ||
<Form.Group widths="equal"> | ||
<Form.Input | ||
label="开发者 ID(AppID)" | ||
placeholder="" | ||
value={inputs.WeChatAppID} | ||
name="WeChatAppID" | ||
onChange={handleInputChange} | ||
/> | ||
</Form.Group> | ||
<Form.Group widths="equal"> | ||
<Form.Input | ||
label="开发者密码(AppSecret)" | ||
placeholder="" | ||
value={inputs.WeChatAppSecret} | ||
name="WeChatAppSecret" | ||
onChange={handleInputChange} | ||
/> | ||
</Form.Group> | ||
<Form.Group widths="equal"> | ||
<Form.Input | ||
label="消息加解密密钥(EncodingAESKey)" | ||
placeholder="" | ||
value={inputs.WeChatEncodingAESKey} | ||
name="WeChatEncodingAESKey" | ||
onChange={handleInputChange} | ||
/> | ||
</Form.Group> | ||
<Form.Group widths="equal"> | ||
<Form.Input | ||
label="Root 用户微信 ID" | ||
placeholder="" | ||
value={inputs.WeChatOwnerID} | ||
name="WeChatOwnerID" | ||
onChange={handleInputChange} | ||
/> | ||
</Form.Group> | ||
</Form> | ||
</Grid.Column> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default WeChatSetting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters