Skip to content

Commit

Permalink
feat: able to custom footer now
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Nov 4, 2022
1 parent f58889c commit e30f89a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var StartTime = time.Now().Unix() // unit: second
var Version = "v0.0.0"
var SystemName = "项目模板"
var ServerAddress = "http://localhost:3000"
var FooterHTML = ""

var SessionSecret = uuid.New().String()
var SQLitePath = ".gin-template.db"
Expand Down
1 change: 1 addition & 0 deletions controller/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func GetStatus(c *gin.Context) {
"github_oauth": common.GitHubOAuthEnabled,
"github_client_id": common.GitHubClientId,
"system_name": common.SystemName,
"footer_html": common.FooterHTML,
},
})
return
Expand Down
3 changes: 3 additions & 0 deletions model/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func InitOptionMap() {
common.OptionMap["SMTPAccount"] = ""
common.OptionMap["SMTPToken"] = ""
common.OptionMap["Notice"] = ""
common.OptionMap["FooterHTML"] = common.FooterHTML
common.OptionMap["ServerAddress"] = ""
common.OptionMap["GitHubClientId"] = ""
common.OptionMap["GitHubClientSecret"] = ""
Expand Down Expand Up @@ -103,5 +104,7 @@ func updateOptionMap(key string, value string) {
common.GitHubClientId = value
case "GitHubClientSecret":
common.GitHubClientSecret = value
case "FooterHTML":
common.FooterHTML = value
}
}
3 changes: 2 additions & 1 deletion web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const About = lazy(() => import('./pages/About'));
function App() {
const loadStatus = async () => {
const res = await API.get('/api/status');
const { success, message, data } = res.data;
const { success, data } = res.data;
if (success) {
localStorage.setItem('status', JSON.stringify(data));
localStorage.setItem('footer_html', data.footer_html);
} else {
showError('无法正常连接至服务器!');
}
Expand Down
48 changes: 39 additions & 9 deletions web/src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import React from 'react';
import React, { useEffect, useState } from 'react';

import { Container, Segment } from 'semantic-ui-react';

const Footer = () => (
<Segment vertical>
<Container textAlign="center">
<div className="custom-footer"><a href="https://github.com/songquanpeng/gin-template" target='_blank'>项目模板 {process.env.REACT_APP_VERSION} </a>
<a href="https://github.com/songquanpeng" target='_blank'>JustSong</a> 构建,源代码遵循 <a href="https://opensource.org/licenses/mit-license.php">MIT 协议</a></div>
</Container>
</Segment>
);
const Footer = () => {
const [footerHTML, setFooterHTML] = useState('');
useEffect(() => {
let savedFooterHTML = localStorage.getItem('footer_html');
if (!savedFooterHTML) savedFooterHTML = '';
setFooterHTML(savedFooterHTML);
});

return (
<Segment vertical>
<Container textAlign="center">
{footerHTML === '' ? (
<div className="custom-footer">
<a
href="https://github.com/songquanpeng/gin-template"
target="_blank"
>
项目模板 {process.env.REACT_APP_VERSION}{' '}
</a>
{' '}
<a href="https://github.com/songquanpeng" target="_blank">
JustSong
</a>{' '}
构建,源代码遵循{' '}
<a href="https://opensource.org/licenses/mit-license.php">
MIT 协议
</a>
</div>
) : (
<div
className="custom-footer"
dangerouslySetInnerHTML={{ __html: footerHTML }}
></div>
)}
</Container>
</Segment>
);
};

export default Footer;
20 changes: 19 additions & 1 deletion web/src/components/SystemSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const SystemSetting = () => {
SMTPAccount: '',
SMTPToken: '',
ServerAddress: '',
FooterHTML: '',
});
let originInputs = {};
let [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -69,7 +70,8 @@ const SystemSetting = () => {
name.startsWith('SMTP') ||
name === 'ServerAddress' ||
name === 'GitHubClientId' ||
name === 'GitHubClientSecret'
name === 'GitHubClientSecret' ||
name === 'FooterHTML'
) {
setInputs((inputs) => ({ ...inputs, [name]: value }));
} else {
Expand Down Expand Up @@ -132,6 +134,22 @@ const SystemSetting = () => {
<Form.Button onClick={submitServerAddress}>
更新服务器地址
</Form.Button>
<Form.Group widths="equal">
<Form.Input
label="页脚 HTML"
placeholder="留空则使用默认页脚"
value={inputs.FooterHTML}
name="FooterHTML"
onChange={handleInputChange}
/>
</Form.Group>
<Form.Button
onClick={() => {
updateOption('FooterHTML', inputs.FooterHTML).then();
}}
>
设置页脚 HTML
</Form.Button>
<Form.Group widths="equal">
<Form.TextArea
label="公告"
Expand Down

0 comments on commit e30f89a

Please sign in to comment.