将Electron改为载入本地文件, 修改根据proto生成前端文件的方法
This commit is contained in:
parent
0636568859
commit
b34ab6953d
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
.vs
|
||||
.vscode
|
||||
dist
|
||||
.idea/
|
||||
.DS_Store
|
||||
|
20
app/main.js
20
app/main.js
@ -10,13 +10,21 @@ let win;
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
win = new BrowserWindow({width: 1200, height: 800,webPreferences: {
|
||||
// win = new BrowserWindow({width: 1200, height: 800,webPreferences: {
|
||||
// nodeIntegration: true
|
||||
// }});
|
||||
|
||||
// // and load the index.html of the app.
|
||||
// win.loadURL("http://127.0.0.1:12345/index.html");
|
||||
|
||||
win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
}});
|
||||
|
||||
// and load the index.html of the app.
|
||||
win.loadURL("http://127.0.0.1:12345/index.html");
|
||||
|
||||
}
|
||||
});
|
||||
win.loadFile('../index.html')
|
||||
// Open the DevTools.
|
||||
win.webContents.openDevTools();
|
||||
|
||||
|
70
index.html
Normal file
70
index.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script type="text/javascript" src="dist/Extend.js"></script>
|
||||
<script type="text/javascript" src="dist/FsExtra.js"></script>
|
||||
<script>
|
||||
// 先让node加载punycode,否则url调用punycode时,已经被requirejs加载了punycode
|
||||
require("punycode");
|
||||
if (typeof window.require === "function") {
|
||||
// 重命名 Electron 提供的 require
|
||||
window.nodeRequire = window.require;
|
||||
delete window.require;
|
||||
delete window.exports;
|
||||
delete window.module;
|
||||
}
|
||||
|
||||
function ready(fn) {
|
||||
if (document.readyState != 'loading') {
|
||||
fn();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
font: 14px "Microsoft YaHei";
|
||||
}
|
||||
</style>
|
||||
<script data-main="dist/app2" type="text/javascript" src="libs/require.js"></script>
|
||||
<script type="text/javascript" src="libs/cookie.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="background:#fee; padding-left:10px;padding-right:10px;">
|
||||
客户端项目根目录(src):
|
||||
<input id="txtClientPath" style="width:612px;" type="input" value="/Users/zhl/Desktop/tmp/code_tmp" /><br/>
|
||||
常量ServiceName相对路径:
|
||||
<input id="txtServerServiceNamePath" style="width:612px;" type="input" value="chuanqi/ServiceName.ts" /><br/>
|
||||
PB消息字典的文件相对路径:
|
||||
<input id="txtPBMsgDictName" style="width:612px;" type="input" value="chuanqi/PBMsgDict.ts" />
|
||||
</div>
|
||||
|
||||
<div style="border-top:solid 1px #ccc;padding-top:5px;padding-left:10px;padding-right:10px;background:rgb(235, 208, 226)">
|
||||
Code码WIKI上地址:
|
||||
<input id="txtWikiCodePath" style="width:612px;" type="input" value="http://t.zhl.com/game/MsgConst.ts" /><br/>
|
||||
Code码保存地址地址:
|
||||
<input id="txtLocalCodePath" style="width:612px;" type="input" value="/Users/zhl/Desktop/tmp/code_tmp" />
|
||||
<input id="btnCode" type="button" value="生成Code码" />
|
||||
</div>
|
||||
|
||||
<div style="border-top:solid 1px #ccc;padding-left:10px;padding-right:10px;padding-top:5px;background:#eef">
|
||||
wiki上proto的地址:
|
||||
<input id="txtUrl" style="width:612px;" type="input" value="http://t.zhl.com/proto/AOIMsg.proto" />
|
||||
<input id="btnGen" type="button" value="生成" />
|
||||
</div>
|
||||
<textarea id="txtProto" style="width:49%;height:590px;margin-top:5px;border:#ccc solid 1px;overflow-y:auto;float:left;">
|
||||
</textarea>
|
||||
<div id="txtLog" style="width:49%;height:594px;margin-top:5px;border:#ccc solid 1px;overflow-y:auto;float:left;">
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
41
libs/cookie.js
Normal file
41
libs/cookie.js
Normal file
@ -0,0 +1,41 @@
|
||||
var cookie = {
|
||||
/**
|
||||
* 设置cookie
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
setCookie: function(name, value) {
|
||||
var Days = 30;
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
|
||||
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取cookie
|
||||
*
|
||||
* @param name
|
||||
* @returns
|
||||
*/
|
||||
getCookie: function(name) {
|
||||
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
|
||||
if (arr = document.cookie.match(reg))
|
||||
return unescape(arr[2]);
|
||||
else
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除cookie
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
delCookie: function(name) {
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() - 1);
|
||||
var cval = getCookie(name);
|
||||
if (cval != null)
|
||||
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
|
||||
}
|
||||
}
|
2142
libs/require.js
Normal file
2142
libs/require.js
Normal file
File diff suppressed because it is too large
Load Diff
28
src/app2.ts
28
src/app2.ts
@ -547,21 +547,21 @@ function getHttpData(url: string, gcfg?: GlobalCfg)
|
||||
*/
|
||||
function getProtoData(data: { content: string, gcfg?: GlobalCfg, url: string })
|
||||
{
|
||||
let content = escapeHTML(data.content);
|
||||
// let content = escapeHTML(data.content);
|
||||
// 从HTML流中截取 message {} 或者 option (xxxx) = "xxxx" 这样的数据
|
||||
let reg: RegExp = /<pre class="code">([^>]*?message[ ]+[A-Z][a-zA-Z0-9_$]*[ ]*[{][^]*?[}][^]*?|[^>]*?option[ ]+[(]\w+[)][ ]*=[ ]*".*?";[^]*?)<\/pre>/mg;
|
||||
let proto = "";
|
||||
while (true) {
|
||||
let result = reg.exec(content);
|
||||
if (result) {
|
||||
proto += result[1] + "\n";
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
proto =proto.substring(proto.indexOf("option "));
|
||||
$g("txtProto").value = proto;
|
||||
parseProto(proto, data.gcfg);
|
||||
// let reg: RegExp = /<pre class="code">([^>]*?message[ ]+[A-Z][a-zA-Z0-9_$]*[ ]*[{][^]*?[}][^]*?|[^>]*?option[ ]+[(]\w+[)][ ]*=[ ]*".*?";[^]*?)<\/pre>/mg;
|
||||
// let proto = "";
|
||||
// while (true) {
|
||||
// let result = reg.exec(content);
|
||||
// if (result) {
|
||||
// proto += result[1] + "\n";
|
||||
// } else {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// proto =proto.substring(proto.indexOf("option "));
|
||||
$g("txtProto").value = data.content;
|
||||
parseProto(data.content, data.gcfg);
|
||||
}
|
||||
|
||||
const escChars = { "<": "<", ">": ">", """: "\"", "'": "\'", "&": "&", " ": " ", "
": "\n", "'": "\'", "\\n": "\n"};
|
||||
|
@ -4,7 +4,7 @@
|
||||
"target": "es2015",
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false,
|
||||
"sourceRoot": "src",
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"exclude": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user