@plasosdk/plaso-electron-sdk
Version:
伯索课堂Electron SDK
276 lines (243 loc) • 7.51 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
font-family: "Microsoft YaHei", sans-serif;
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#btn_reload {
width: 120px;
height: 40px;
background: #02c8f2;
border-radius: 4px;
border: none;
margin: 10px auto;
font-size: 20px;
display: block;
color: #fff;
cursor: pointer;
}
.contain {
position: absolute;
width: 80px;
height: 80px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 20px;
}
.animate {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: -25%;
border-radius: 10%;
z-index: 1;
transform: translateZ(0);
background: #8EEFC7;
animation: animate .6s -.1s linear infinite;
}
.shadow {
position: absolute;
left: 0;
width: 100%;
bottom: -9%;
height: 10%;
background: #DFE6EC;
border-radius: 50%;
-webkit-animation: shadow .6s -.1s linear infinite;
-moz-animation: shadow .6s -.1s linear infinite;
-o-animation: shadow .6s -.1s linear infinite;
animation: shadow .6s -.1s linear infinite;
}
@keyframes animate {
17% {
border-bottom-right-radius: 10%;
}
25% {
transform: translateY(25%) rotate(22.5deg);
}
50% {
border-bottom-right-radius: 100%;
transform: translateY(50%) scale(1, .9) rotate(45deg);
}
75% {
transform: translateY(25%) rotate(67.5deg);
}
100% {
transform: translateY(0) rotate(90deg);
}
}
@keyframes shadow {
50% {
transform: scale(1.25, 1);
}
}
</style>
<title></title>
</head>
<body>
<div id="react_body">
<div class="contain" id="loading" style="display:none">
<div class="animate"></div>
<div class="shadow"></div>
</div>
</div>
</body>
<script type="text/javascript">
//配置文件,主要是 thrift 接口地址和一些标识字符串
var globalAppInfo = {};
function getElectronRemote() {
let _remote;
try {
_remote = window.require('electron').remote;
if (!_remote) _remote = window.require('@electron/remote');
} catch (e) {
console.error(err);
}
return _remote;
}
const include = function (url) {
url = globalAppInfo.rhost + url;
let ele;
if (/\.css$/.test(url)) {
ele = document.createElement('link');
ele.rel = "stylesheet";
ele.type = "text/css";
ele.href = url;
} else {
ele = document.createElement('script');
ele.src = url;
}
document.head.appendChild(ele);
}
let hasInit = false;
function init(appinfo) {
if (hasInit) {
return;
} else {
hasInit = true;
}
// from url
var query;
if (window.location.search) {
query = window.location.search.substring(1).split("&");
for (var i = 0, l = query.length; i < l; i++) {
var temp = query[i].split('=');
if (temp.length == 2) {
globalAppInfo[temp[0]] = decodeURIComponent(temp[1]);
} else if (
typeof globalAppInfo[temp[0]] === 'string' &&
globalAppInfo[temp[0]].length > 0 &&
!isNaN(Number(globalAppInfo[temp[0]])) &&
Number(globalAppInfo[temp[0]]) !== undefined &&
!globalAppInfo[temp[0]]?.includes?.('.')
) {
globalAppInfo[temp[0]] = Number(globalAppInfo[temp[0]]);
}
}
}
// from ipc
if (appinfo) {
globalAppInfo = Object.assign({}, globalAppInfo, appinfo)
}
// properties init
if (globalAppInfo.rhost == undefined && location.protocol.indexOf('http') == 0) {
globalAppInfo.rhost = './';
if (!globalAppInfo.dhost) {
if (globalAppInfo.env) {
if (globalAppInfo.env === 'local') {
globalAppInfo.dhost = location.origin;
} else {
globalAppInfo.dhost = `${location.protocol}//${globalAppInfo.env}.plaso.cn/`;
}
} else if (location.origin.indexOf('plaso.cn') > -1) {
globalAppInfo.dhost = location.origin.replace('wwwr', 'www');
globalAppInfo.env = location.host.split('.')[0];
} else if (location.origin.indexOf('127.0.0.1') > -1 || location.origin.indexOf('192.168') > -1) {
globalAppInfo.env = 'dev';
globalAppInfo.dhost = `${location.protocol}//${globalAppInfo.env}.plaso.cn/`;
} else {
globalAppInfo.dhost = `${location.protocol}//www.plaso.cn/`;
}
}
}
if (!globalAppInfo.env) globalAppInfo.env = 'www';
globalAppInfo.markString = globalAppInfo.markString ?? '';
globalAppInfo.needFullScreen = false;
if (globalAppInfo.rhost && globalAppInfo.rhost.substring(globalAppInfo.rhost.length - 1) != '/') {
globalAppInfo.rhost += "/";
}
if (globalAppInfo.dhost && globalAppInfo.dhost.substring(globalAppInfo.dhost.length - 1) != '/') {
globalAppInfo.dhost += "/";
}
// load all.js
path = globalAppInfo.initjs || "js/all.js";
include(path);
}
if (typeof require == "function") {
const { ipcRenderer } = window.require('electron');
const { CLASS_WINDOW_MESG_TYPE } = require('./js/macro');
const queryString = location.href.split('?')[1];
queryString.split('&').forEach((pair) => {
const [key, value] = pair.split('=');
if (key === 'openerId') openerId = Number(value);
});
ipcRenderer.on(CLASS_WINDOW_MESG_TYPE.INIT_GLOBAL_APPINFO, (_, appinfo) => {
if (appinfo) init(appinfo);
});
if(openerId){
const remote = getElectronRemote();
const webContents = remote.getCurrentWebContents();
ipcRenderer.sendTo(openerId, CLASS_WINDOW_MESG_TYPE.HTML_READY, {webContentId: webContents.id});
}
}
/*
* 加载超时函数,立即执行
* param: timeLength :超时时间
*/
(function timeOut(timeLength) {
const timer = setTimeout(
function () {
var loading = document.getElementById('loading');
if (loading) {
loading.style.width = "100%";
loading.style.textAlign = "center";
eval("loading.innerHTML = '加载超时!请点击重新加载<button id=\"btn_reload\" onclick=\"reload()\">重新加载</button>'");
if (typeof require == "function" && globalAppInfo.clientType === 'nw') {
var gui = require('nw.gui');
var win = gui.Window.get();
win.removeAllListeners();
}
}
},
timeLength * 1000
)
})(30);
function reload() {
if (typeof require == "function" && globalAppInfo.clientType === 'electron') {
var remote = getElectronRemote();
var curWindow = remote.getCurrentWindow();
curWindow.webContents.reloadIgnoringCache()
} else {
location.reload();
}
}
</script>
<script type="text/javascript">
if (globalAppInfo.background) {
document.body.style.background = globalAppInfo.background;
document.documentElement.style.background = globalAppInfo.background;
}
if (!globalAppInfo.noLoading) {
var loadingDom = document.getElementById("loading");
if (loadingDom) loadingDom.style.display = "";
}
</script>
</html>