Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
juilletVent committed Jun 20, 2021
1 parent 5be47db commit b635ae5
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 65 deletions.
Binary file modified assets/appdmg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon.ico
Binary file not shown.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"mac":"04-D4-C4-EC-D0-37","ip":"192.168.1.80","submask":"255.255.255.0","port":"9","mode":"2","remark":"HOME","id":"id_1"},{"mac":"04-D4-C4-EC-D0-37","ip":"192.168.2.250","submask":"255.255.255.0","port":"9","mode":"1","remark":"公司","id":"id_2"},{"mac":"04-D4-C4-EC-D0-37","ip":"192.168.2.2","submask":"255.255.255.0","port":"9","mode":"1","remark":"测试地址2222","id":"1623979477201"}]
[{"mac":"04-D4-C4-EC-D0-37","ip":"192.168.1.80","submask":"255.255.255.0","port":"9","mode":1,"remark":"HOME","id":"id_1"},{"mac":"04-D4-C4-EC-D0-37","ip":"192.168.2.250","submask":"255.255.255.0","port":"9","mode":2,"remark":"公司","id":"id_2"},{"mac":"04-D4-C4-EC-D0-37","ip":"192.168.2.10","submask":"255.255.255.0","port":"7","mode":1,"id":"1624161186390"}]
11 changes: 10 additions & 1 deletion ele-webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ module.exports = {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
use: [
{
loader: "ts-loader",
options: {
compilerOptions: {
noEmit: false,
},
},
},
],
},
],
},
Expand Down
10 changes: 10 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"verbose": true,
"ignore": ["*.test.js", "fixtures/*", "node_modules/*", "dist/*", "build/*"],
"exec": "webpack --config ele-webpack.config.js",
"watch": ["src/main.ts"],
"env": {
"NODE_ENV": "development"
},
"ext": "js,json,ts"
}
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"background": "assets/appdmg.png",
"icon": "assets/icon.icns",
"iconSize": 100,
"writeUpdateInfo": false,
"contents": [
{
"x": 380,
Expand All @@ -49,13 +50,14 @@
"nsis"
],
"icon": "assets/icon.ico",
"artifactName": "${productName}-Web-Setup-${version}.${ext}",
"publisherName": "Viking Zhang"
"artifactName": "${productName}-Setup-${version}.${ext}",
"publisherName": "juilletVent"
},
"nsis": {
"allowToChangeInstallationDirectory": true,
"oneClick": false,
"perMachine": false
"perMachine": false,
"differentialPackage": false
}
},
"homepage": "./",
Expand Down Expand Up @@ -85,9 +87,13 @@
"test": "react-scripts test",
"eject": "react-scripts eject",
"start-app": "cross-env PORT=7000 BROWSER=none npm start",
"start-ele": "npx wait-on tcp:7000 && tsc ./src/main.ts --outDir ./build && npx electron .",
"dev": "npx concurrently \"wait-on tcp:7000 && tsc ./src/main.ts --outDir ./build && electron .\" \"cross-env PORT=7000 BROWSER=none npm start\"",
"build": "electron-builder"
"start-ele": "npx wait-on tcp:7000 && nodemon && npx electron .",
"start-frame": "electron .",
"dev": "npx concurrently \"wait-on tcp:7000 && npm run build-ele && electron .\" \"cross-env PORT=7000 BROWSER=none npm start\"",
"build": "electron-builder",
"prebuild": "npm run build-ele",
"prebuild-ele": "npm run build-app",
"packet": "electron-builder"
},
"eslintConfig": {
"extends": [
Expand All @@ -114,6 +120,7 @@
"cross-env": "^7.0.3",
"electron": "^13.1.2",
"electron-builder": "^22.11.7",
"nodemon": "^2.0.7",
"ts-loader": "8.2.0",
"wait-on": "^5.3.0",
"webpack-cli": "^4.7.2"
Expand Down
14 changes: 14 additions & 0 deletions src/app/hooks/useI18n.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useMemo } from "react";
import i18n from "../i18n";

export function useI18n(languageKey: string) {
const lanConf = useMemo(() => {
const conf = i18n.find((item) => item.key === languageKey);
if (conf) {
return conf.language;
}
return i18n[0].language;
}, [languageKey]);

return lanConf;
}
Empty file removed src/app/i18n/en.js
Empty file.
31 changes: 31 additions & 0 deletions src/app/i18n/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const languageMap = {
STR_MAC_TIPS: "MAC",
STR_MAC_PLACEHOLDER: "input mac address",
STR_MAC_ERR_MSG: "mac addr,horizontal or colon segmentation",
STR_IP_TIPS: "IP",
STR_IP_PLACEHOLDER: "input ip address",
STR_IP_ERR_MSG: "Invalid IP address",
STR_SUBMASK_TIPS: "SubnetMask",
STR_SUBMASK_PLACEHOLDER: "input subnet-mask",
STR_SUBMASK_ERR_MSG: "Invalid subnet-mask",
STR_PORT_TIPS: "Port",
STR_PORT_PLACEHOLDER: "input port(7 or 9)",
STR_PORT_ERR_MSG: "Invalid port,Allowed values range from 1 to 65535",
STR_MODE_TIPS: "Send Opt",
STR_MODE_PLACEHOLDER: "select network type",
STR_MODE_OPT_1: "internet/vpn",
STR_MODE_OPT_2: "local subnet",
STR_REMARK_TIPS: "Remark",
STR_REMARk_PLACEHOLDER: "input remark,default is IP address",
STR_REMARK_ERR_MSG: "remark too loong,no more than 200",
STR_SAVE_SUCC_MSG: "Save successfully",
STR_SEND_ERR_MSG: "Send failed",
STR_SEND_SUCC_MSG: "Send successfully",
STR_EMPTY: "No configuration",
STR_BTN_DELETE: "Delete",
STR_BTN_ADD: "Add",
STR_BTN_SAVE: "Save",
STR_BTN_WEAKUP: "Weakup",
};

export default languageMap;
28 changes: 28 additions & 0 deletions src/app/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import zhCN from "./zh-CN";
import en from "./en";

export type ConfKey = keyof typeof en;
export type I18nConf = {
[key in ConfKey]: string;
};

type IconConf = {
key: string;
title: string;
language: I18nConf;
};

const i18n: IconConf[] = [
{
key: "en",
title: "English",
language: en,
},
{
key: "zh-CN",
title: "简体中文",
language: zhCN,
},
];

export default i18n;
Empty file removed src/app/i18n/zh-CN.js
Empty file.
31 changes: 31 additions & 0 deletions src/app/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const languageMap = {
STR_MAC_TIPS: "MAC地址",
STR_MAC_PLACEHOLDER: "请输入目标机器MAC地址",
STR_MAC_ERR_MSG: "输入MAC地址,横线或冒号分割",
STR_IP_TIPS: "IP地址",
STR_IP_PLACEHOLDER: "请输入目标机器IP地址",
STR_IP_ERR_MSG: "请有效的IP地址",
STR_SUBMASK_TIPS: "子网掩码",
STR_SUBMASK_PLACEHOLDER: "请输入目标机器子网掩码",
STR_SUBMASK_ERR_MSG: "请输入有效的子网掩码",
STR_PORT_TIPS: "目标端口",
STR_PORT_PLACEHOLDER: "请输入目标端口(通常为7或9)",
STR_PORT_ERR_MSG: "端口无效,请输入1-65535之间的端口号",
STR_MODE_TIPS: "发送模式",
STR_MODE_PLACEHOLDER: "请选择发送模式",
STR_MODE_OPT_1: "广域网/VPN(发送至目标IP)",
STR_MODE_OPT_2: "内网(发送至广播地址)",
STR_REMARK_TIPS: "备注",
STR_REMARk_PLACEHOLDER: "请输入配置备注,默认为IP地址",
STR_REMARK_ERR_MSG: "备注过长,至多200个字符",
STR_SAVE_SUCC_MSG: "保存成功",
STR_SEND_ERR_MSG: "发送失败",
STR_SEND_SUCC_MSG: "唤醒请求已发送",
STR_EMPTY: "暂无配置",
STR_BTN_DELETE: "删除",
STR_BTN_ADD: "新增配置",
STR_BTN_SAVE: "保存",
STR_BTN_WEAKUP: "唤醒",
};

export default languageMap;
65 changes: 34 additions & 31 deletions src/app/ui/ConfigPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@ import { BtnLayout, ConfigPanelLayout } from "./style";
import { SaveOutlined, SendOutlined } from "@ant-design/icons";
import { PATTERN_IP, PATTERN_MAC } from "../constant/regex";
import { ConfigItemI } from "../../types/ConfigItem";
import { useI18n } from "../hooks/useI18n.hooks";

export interface Props {
interface Props {
config?: ConfigItemI;
onSave: (conf: ConfigItemI) => void;
onWeakup: (conf: ConfigItemI) => void;
languageKey: string;
}

const { Option } = Select;
const layout = {
labelCol: { span: 6 },
wrapperCol: { span: 17 },
};
const checkPort = (_: any, value: string | number) => {
const checkPort = (errMsg: string) => (_: any, value: string | number) => {
if (+value < 1 || +value > 65535) {
return Promise.reject(new Error("端口无效,请输入1-65535之间的端口号"));
return Promise.reject(new Error(errMsg));
}
return Promise.resolve();
};

function ConfigPanel(props: Props) {
const { config, onSave, onWeakup } = props;
const { config, onSave, onWeakup, languageKey } = props;
const [form] = Form.useForm();
const { validateFields } = form;
const i18nConf = useI18n(languageKey);
const onSaveInner = useCallback(
(msg?: string) =>
validateFields().then(
Expand Down Expand Up @@ -62,80 +65,80 @@ function ConfigPanel(props: Props) {
initialValues={{ remember: true }}
>
<Form.Item
label="MAC地址"
label={i18nConf.STR_MAC_TIPS}
name="mac"
rules={[
{ required: true, message: "请输入目标机器MAC地址" },
{ required: true, message: i18nConf.STR_MAC_PLACEHOLDER },
{
pattern: PATTERN_MAC,
message: "目标机器MAC地址,横线或冒号分割均可",
message: i18nConf.STR_MAC_ERR_MSG,
},
]}
>
<Input placeholder="请输入目标机器MAC地址" allowClear />
<Input placeholder={i18nConf.STR_MAC_PLACEHOLDER} allowClear />
</Form.Item>

<Form.Item
label="IP地址"
label={i18nConf.STR_IP_TIPS}
name="ip"
rules={[
{ required: true, message: "请输入目标机器IP地址" },
{ required: true, message: i18nConf.STR_IP_PLACEHOLDER },
{
pattern: PATTERN_IP,
message: "请有效的IP地址",
message: i18nConf.STR_IP_ERR_MSG,
},
]}
>
<Input placeholder="请输入目标机器IP地址" allowClear />
<Input placeholder={i18nConf.STR_IP_PLACEHOLDER} allowClear />
</Form.Item>
<Form.Item
label="子网掩码"
label={i18nConf.STR_SUBMASK_TIPS}
name="submask"
rules={[
{ required: true, message: "请输入目标机器子网掩码" },
{ required: true, message: i18nConf.STR_SUBMASK_PLACEHOLDER },
{
pattern: PATTERN_IP,
message: "请有效的子网掩码",
message: i18nConf.STR_SUBMASK_ERR_MSG,
},
]}
>
<Input placeholder="请输入目标机器子网掩码" allowClear />
<Input placeholder={i18nConf.STR_SUBMASK_PLACEHOLDER} allowClear />
</Form.Item>
<Form.Item
label="目标端口"
label={i18nConf.STR_PORT_TIPS}
name="port"
validateFirst
rules={[
{ required: true, message: "请输入目标端口(通常为7或9)" },
{ required: true, message: i18nConf.STR_PORT_PLACEHOLDER },
{
validator: checkPort,
validator: checkPort(i18nConf.STR_PORT_ERR_MSG),
},
]}
>
<Input placeholder="请输入目标端口(通常为7或9)" allowClear />
<Input placeholder={i18nConf.STR_PORT_PLACEHOLDER} allowClear />
</Form.Item>
<Form.Item
label="发送模式"
label={i18nConf.STR_MODE_TIPS}
name="mode"
rules={[{ required: true, message: "请选择发送模式" }]}
rules={[{ required: true, message: i18nConf.STR_MODE_PLACEHOLDER }]}
>
<Select placeholder="请选择发送模式">
<Option value="1">发送至目标IP地址</Option>
<Option value="2">发送至广播地址</Option>
<Select placeholder={i18nConf.STR_MODE_PLACEHOLDER}>
<Option value={1}>{i18nConf.STR_MODE_OPT_1}</Option>
<Option value={2}>{i18nConf.STR_MODE_OPT_2}</Option>
</Select>
</Form.Item>

<Form.Item
label="备注"
label={i18nConf.STR_REMARK_TIPS}
name="remark"
rules={[
{
max: 200,
message: "备注过长,至多200个字符",
message: i18nConf.STR_REMARK_ERR_MSG,
},
]}
>
<Input placeholder="请输入配置备注,默认为IP地址" allowClear />
<Input placeholder={i18nConf.STR_MODE_PLACEHOLDER} allowClear />
</Form.Item>

<BtnLayout>
Expand All @@ -145,13 +148,13 @@ function ConfigPanel(props: Props) {
type="primary"
icon={<SendOutlined />}
>
唤醒
{i18nConf.STR_BTN_WEAKUP}
</Button>
<Button
onClick={() => onSaveInner("保存成功")}
onClick={() => onSaveInner(i18nConf.STR_SAVE_SUCC_MSG)}
icon={<SaveOutlined />}
>
保存
{i18nConf.STR_BTN_SAVE}
</Button>
</BtnLayout>
</Form>
Expand Down
Loading

0 comments on commit b635ae5

Please sign in to comment.