Skip to content

Commit b130a26

Browse files
authored
添加资助页面。 (#2)
1 parent b8cd246 commit b130a26

File tree

9 files changed

+106
-12
lines changed

9 files changed

+106
-12
lines changed

gulpfile.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const task_html = done => {
1212
build_html();
1313
done();
1414
}
15+
const task_images = done => {
16+
build_images();
17+
done();
18+
}
1519
const task_gen_package_json = done => {
1620
gen_package_json();
1721
done();
@@ -34,14 +38,26 @@ const task_copy_release_note = done => {
3438
done();
3539
}
3640

37-
exports.default = gulp.parallel(task_html, task_ui, task_styles, task_worker, task_copy_release_note);
41+
exports.default = gulp.parallel(
42+
task_html,
43+
task_images,
44+
task_ui,
45+
task_styles,
46+
task_worker,
47+
task_copy_release_note);
3848

3949
function build_html() {
4050
return gulp
4151
.src(PATH_SRC_HTML + "index.html")
4252
.pipe(gulp.dest(PATH_OUT));
4353
}
4454

55+
function build_images() {
56+
return gulp
57+
.src(PATH_SRC_IMG + "*")
58+
.pipe(gulp.dest(PATH_OUT));
59+
}
60+
4561
function build_scripts(src) {
4662
let cfg = require(src + "webpack.config.js")();
4763
const entry = cfg.entry;
@@ -92,6 +108,7 @@ function copy_release_note() {
92108

93109
const PATH_SRC = "./src/";
94110
const PATH_SRC_HTML = PATH_SRC + "ui/html/";
111+
const PATH_SRC_IMG = PATH_SRC + "ui/images/";
95112
const PATH_SRC_UI = PATH_SRC + "ui/scripts/";
96113
const PATH_SRC_WORKER = PATH_SRC + "worker/";
97114
const PATH_SRC_STYLES = PATH_SRC + "ui/styles/";

src/ui/images/donate-alipay.jpg

41.3 KB
Loading

src/ui/images/donate-wechat.jpg

39.3 KB
Loading

src/ui/scripts/components/page-content.tsx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,74 @@ import { DataBytesView } from "./data-bytes-view";
88
import { AsmView } from "./asm-view";
99

1010
interface ConnectedProps {
11+
pageId: S.PageIdType;
12+
showDonationPrompt: boolean;
1113
}
1214

1315
function mapStateToProps(state: S.AppState): ConnectedProps {
16+
const { hexView } = state;
17+
const { pageId } = state.appInfo;
18+
1419
return {
20+
pageId,
21+
showDonationPrompt: hexView == null
1522
};
1623
}
1724

1825
class PageContentClass extends React.Component<ConnectedProps> {
1926
public render(): JSX.Element {
27+
const { pageId } = this.props;
28+
29+
let pageContent: JSX.Element | null = null;
30+
switch (pageId) {
31+
case "MAIN": pageContent = this.renderMainPageContent(); break;
32+
case "DONATE": pageContent = this.renderDonatePageContent(); break;
33+
}
34+
2035
return (
2136
<section id="app-content">
37+
{pageContent}
38+
</section>
39+
);
40+
}
41+
42+
public renderMainPageContent(): JSX.Element {
43+
const { showDonationPrompt } = this.props;
44+
45+
return (
46+
<React.Fragment>
2247
<FileOpener />
2348
<section id="view-container">
2449
<AsmView />
2550
<DataBytesView />
2651
<HexView />
2752
</section>
28-
</section>
29-
)
53+
{showDonationPrompt && (
54+
<div id="donation-prompt">
55+
{"如果这个应用对您有所帮助,欢迎采取资助的方式进行鼓励 (。◕‿◕。) ↓"}
56+
</div>
57+
)}
58+
</React.Fragment>
59+
);
60+
}
61+
62+
private renderDonatePageContent(): JSX.Element {
63+
return (
64+
<React.Fragment>
65+
<h2>资助作者</h2>
66+
<p>这个小工具能对您有所帮助,是作者的荣幸。对于您的资助,作者表示万分感激!</p>
67+
<table>
68+
<thead>
69+
<tr><th>微信</th><th>支付宝</th></tr>
70+
</thead>
71+
<tbody>
72+
<tr><td><img src="donate-wechat.jpg" /></td><td><img src="donate-alipay.jpg" /></td></tr>
73+
</tbody>
74+
</table>
75+
<p>如有兴致,请在备注/留言中注明用于资助STC51反汇编器。</p>
76+
<p>另外,作者计划不定期在此页面列出资助者以示感谢,如果您做好事不想留名,或希望留一个别致的名号,也请在留言/备注中告知;作者默认列出收款信息中看到的名字。</p>
77+
</React.Fragment>
78+
);
3079
}
3180
}
3281

src/ui/scripts/components/page-footer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function mapStateToProps(state: S.AppState): ConnectedProps {
1717
class PageFooterClass extends React.Component<ConnectedProps> {
1818
public render(): JSX.Element {
1919
const { appInfo } = this.props;
20-
const { title, version, author, homepage, bugsUrl, releaseNotesUrl, buildTimeLocal, year } = appInfo;
20+
const { title, version, author, homepage, bugsUrl, releaseNotesUrl, buildTimeLocal, year, pageId } = appInfo;
21+
const showDonate = pageId !== "DONATE";
2122

2223
return (
2324
<footer id="app-footer">
@@ -29,6 +30,9 @@ class PageFooterClass extends React.Component<ConnectedProps> {
2930
<div><a href="/latest" target="_blank">尝试新版</a></div>
3031
<div><a href={homepage} target="_blank">GitHub</a></div>
3132
<div><a href={bugsUrl} target="_blank">报bug</a></div>
33+
{showDonate && (
34+
<div className="right"><a href={"?donate"} target="_blank">资助作者</a></div>
35+
)}
3236
</footer>
3337
)
3438
}

src/ui/scripts/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ const appInfo: S.AppInfo = {
1919
releaseNotesUrl: packageJson.release_notes,
2020
buildTimeLocal: new Date(Date.parse(packageJson.build_time)).toLocaleString(),
2121
year: new Date().getFullYear().toString(),
22+
pageId: document.location.search === "?donate" ? "DONATE" : "MAIN"
2223
};
2324

2425
const defaultState: S.AppState = {
2526
appInfo,
2627
};
2728

2829
document.title = `${appInfo.title}`;
29-
window.addEventListener("beforeunload", (evt) =>{
30-
if(!window.confirm("即将离开此页面,打开的文件将丢失。确定离开吗?")) {
31-
evt.preventDefault();
32-
evt.returnValue = "";
33-
}
34-
});
3530

3631
const _w = window as any;
3732
const composeEnhancers = _w.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || Redux.compose;
@@ -41,7 +36,9 @@ const store = Redux.createStore(R.appReducer, defaultState, composeEnhancers(
4136
workerClientMiddleware)
4237
));
4338

44-
initWorkerClient(store);
39+
if (appInfo.pageId === "MAIN") {
40+
initWorkerClient(store);
41+
}
4542

4643
ReactDOM.render(
4744
<ReactRedux.Provider store={store}>

src/ui/scripts/store/action-listener.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as A from "./actions";
44
import * as S from "./state";
55

66
export const actionListenerMiddleware = ((store: Redux.MiddlewareAPI<S.AppState>) => (next: Redux.Dispatch<S.AppState>) => (action: Redux.Action) => {
7-
switch (action.type) {
7+
switch (action.type as A.ActionType) {
88
case "OPEN_FILE": {
99
const { appInfo } = store.getState();
1010
const { file } = action as A.OpenFileAction;
@@ -19,6 +19,14 @@ export const actionListenerMiddleware = ((store: Redux.MiddlewareAPI<S.AppState>
1919
}
2020
break;
2121
}
22+
case "SET_HEX": {
23+
window.addEventListener("beforeunload", (evt) => {
24+
if (!window.confirm("即将离开此页面,打开的文件将丢失。确定离开吗?")) {
25+
evt.preventDefault();
26+
evt.returnValue = "";
27+
}
28+
});
29+
}
2230
}
2331
return next(action);
2432
}) as Redux.Middleware;

src/ui/scripts/store/state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export interface AppState {
1010
asmView?: AsmView;
1111
}
1212

13+
export type PageIdType = "MAIN" | "DONATE";
14+
1315
export interface AppInfo {
1416
title: string;
1517
version: string;
@@ -19,6 +21,7 @@ export interface AppInfo {
1921
releaseNotesUrl: string;
2022
buildTimeLocal: string;
2123
year: string;
24+
pageId: PageIdType;
2225
}
2326

2427
export interface FileInfo {

src/ui/styles/ui.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ body, input, select, th {
3535
padding: $size-pad-lg;
3636
white-space: nowrap;
3737
font-size: $size-txt-sm;
38+
line-height: 24px;
3839

3940
a {
4041
color: $color-txt-lt;
@@ -48,12 +49,27 @@ body, input, select, th {
4849
margin-left: 2 * $size-pad-lg;
4950
}
5051

52+
&.right {
53+
float: right;
54+
}
55+
5156
&>strong {
5257
font-size: $size-txt-mid-lg;
5358
}
5459
}
5560
}
5661

62+
#donation-prompt {
63+
position: fixed;
64+
right: $size-pad-lg;
65+
bottom: 60px;
66+
width: 155px;
67+
color: $color-bg-dk;
68+
background: $color-txt-lt;
69+
padding: $size-pad-lg $size-pad-lg+2;
70+
border-radius: $size-pad-lg+2;
71+
}
72+
5773
#app-content {
5874
overflow: auto;
5975
padding: $size-pad-lg;

0 commit comments

Comments
 (0)