MCSManager/public/common/js/viewmodel.js

188 lines
5.2 KiB
JavaScript
Raw Normal View History

2017-11-13 12:26:31 +08:00
//ViewModel层
//用于各类数据模型的双向绑定和控制区域
2018-01-18 11:00:54 +08:00
(function () {
2017-11-13 12:26:31 +08:00
2018-01-18 11:00:54 +08:00
var DEBUG = false;
2018-01-19 14:40:11 +08:00
//ws 链接事件
2018-01-18 11:00:54 +08:00
MI.listener('ws/open', function (ws) {
2017-11-13 12:26:31 +08:00
VIEW_MODEL['websocketStatus'] = {};
var webscoketStatus = VIEW_MODEL['websocketStatus'];
2018-02-17 19:06:38 +08:00
webscoketStatus['status'] = '服务器连接正常';
2017-11-13 12:26:31 +08:00
webscoketStatus['is'] = true;
2018-02-17 19:06:38 +08:00
webscoketStatus['tcolor'] = '#12ea19';
2017-11-13 12:26:31 +08:00
VIEW_MODEL.newVue('websocketStatus', {
el: '#websocket'
});
VIEW_MODEL.newVue('websocketStatus', {
el: '#websocket2'
});
});
2018-01-18 11:00:54 +08:00
MI.listener('ws/close', function (ws) {
2017-11-13 12:26:31 +08:00
var webscoketStatus = VIEW_MODEL['websocketStatus'];
2018-02-17 19:06:38 +08:00
webscoketStatus['status'] = '!!! 连接断开 !!!';
2017-11-13 12:26:31 +08:00
webscoketStatus['is'] = false;
2018-02-17 19:06:38 +08:00
webscoketStatus['tcolor'] = '#ffffff';
2017-11-13 12:26:31 +08:00
});
2018-01-18 11:00:54 +08:00
MI.listener('ws/error', function (ws) {
2017-11-13 12:26:31 +08:00
var webscoketStatus = VIEW_MODEL['websocketStatus'];
2018-02-17 19:06:38 +08:00
webscoketStatus['status'] = '!!! 连接错误 !!!';
2017-11-13 12:26:31 +08:00
webscoketStatus['is'] = false;
2018-02-17 19:06:38 +08:00
webscoketStatus['tcolor'] = '#ffffff';
2017-11-13 12:26:31 +08:00
});
2018-01-19 14:40:11 +08:00
//单页生命周期替换事件
2018-01-18 11:00:54 +08:00
MI.listener('page/live', function (ws) {
for (var tmp in PAGE) delete PAGE[tmp];
2017-11-13 12:26:31 +08:00
delete PAGE;
PAGE = new Object();
});
2018-03-04 20:32:56 +08:00
2018-01-19 14:40:11 +08:00
//菜单获取
2018-01-18 11:00:54 +08:00
MI.routeListener('ws/muem', function (data) {
2018-03-04 20:32:56 +08:00
//菜单选项选择
MI.listener("SideMeumClick", function () {
console.log("--- 菜单选项被选择 ---");
// MCSERVER.autoColmDo();
});
DEBUG && console.log('--- 系统菜单获取成功 ---');
2017-11-13 12:26:31 +08:00
MCSERVER.username = data.obj.username;
//虚拟的数据接受,让前端数据得到,菜单在前端建筑
2018-01-18 11:00:54 +08:00
if (TOOLS.isMaster(MCSERVER.username)) {
2017-11-13 12:26:31 +08:00
data.obj.items = MCSERVER.meumObject.masterMeum;
2018-01-18 11:00:54 +08:00
} else {
2017-11-13 12:26:31 +08:00
data.obj.items = MCSERVER.meumObject.notMasterMeum;
}
//copy
MI.routeCopy('col-muem', data.obj);
VIEW_MODEL.newVueOnce('col-muem', {
el: '#SideColFor',
data: {
isOnMouse: false
},
methods: {
2018-01-18 11:00:54 +08:00
onRedirect: function (link, api) {
DEBUG && console.log('菜单处网页开始跳转:' + link);
2018-03-04 20:32:56 +08:00
//触发菜单选项点击事件
MI.on("SideMeumClick", null);
2017-11-13 12:26:31 +08:00
RES.redirectPage(link, api, 'update_page');
},
2018-01-18 11:00:54 +08:00
onMouse: function ($event, flag) {
2018-03-12 14:11:21 +08:00
// var $elem = $event.target;
// if (flag) {
// //进入
// $($elem).stop(true, true).animate({
// 'padding-left': '24px'
// }, 200);
// } else {
// //移出
// $($elem).stop(true, true).animate({
// 'padding-left': '20px'
// }, 200);
// }
2017-11-13 12:26:31 +08:00
}
}
});
});
2018-01-18 11:00:54 +08:00
MI.routeListener('index/update', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('SystemUp', data.obj);
});
2018-01-18 11:00:54 +08:00
MI.routeListener('center/show', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('centerShow', data.obj);
});
2018-01-18 11:00:54 +08:00
MI.routeListener('server/view', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('ServerList', data.obj);
});
//UsersetList
2018-01-18 11:00:54 +08:00
MI.routeListener('userset/update', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('UsersetList', data.obj);
});
//单个服务器的资料显示
2018-01-18 11:00:54 +08:00
MI.routeListener('server/get', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('ServerPanel', data.obj);
});
//服务器控制台
2018-01-18 11:00:54 +08:00
MI.routeListener('server/console', function (data) {
if (data.obj == null) {
2018-01-19 14:40:11 +08:00
TOOLS.pushMsgWindow('您并不拥有这个服务器的所有权,需要管理员设定');
2017-11-13 12:26:31 +08:00
VIEW_MODEL['ConsolePanel'].serverData.name = null;
}
MI.routeCopy('ConsolePanel', data.obj);
});
2018-01-18 11:00:54 +08:00
MI.routeListener('userset/view', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('OneUserView', data.obj);
});
//Minecraft 服务器终端插入
2018-01-18 11:00:54 +08:00
var terminalEncode = function (text) {
2017-11-13 12:26:31 +08:00
var ify = '[_b_r_]';
var txt = text;
txt = txt.replace(/<br \/>/igm, '[_b_r_]');
var consoleSafe = TOOLS.encode(txt);
consoleSafe = consoleSafe.replace(/\[_b_r_\]/igm, '<br>');
return consoleSafe;
}
2018-01-18 11:00:54 +08:00
MI.routeListener('server/console/ws', function (data) {
2017-11-13 12:26:31 +08:00
var consoleSafe = terminalEncode(data.body);
var MinecraftConsole = document.getElementById('TerminalMinecraft');
2018-01-18 11:00:54 +08:00
if (MinecraftConsole == undefined) {
2017-11-13 12:26:31 +08:00
console.log('NULL')
}
MinecraftConsole.innerHTML += consoleSafe;
var BUFF_FONTIER_SIZE_DOWN = MinecraftConsole.scrollHeight - MinecraftConsole.clientHeight;
2018-01-18 11:00:54 +08:00
if (MinecraftConsole.scrollTop + 354 >= BUFF_FONTIER_SIZE_DOWN) {
2017-11-13 12:26:31 +08:00
MinecraftConsole.scrollTop = MinecraftConsole.scrollHeight;
}
});
2018-01-19 14:40:11 +08:00
//获取控制台历史记录
2018-01-18 11:00:54 +08:00
MI.routeListener('server/console/history', function (data) {
2017-11-13 12:26:31 +08:00
var consoleSafe = terminalEncode(data.body);
var MinecraftConsole = document.getElementById('TerminalMinecraft');
var ifyLoad =
'<span style="color:#3af138;">[历史日志] </span>' +
'<span style="color:rgb(212, 136, 30);">================<br></span>';
var oldTopV = 0;
var oldHeightV = MinecraftConsole.scrollHeight;
//incude
MinecraftConsole.innerHTML = consoleSafe + ifyLoad + MinecraftConsole.innerHTML;
var newTopV = MinecraftConsole.scrollTop;
var newHeightV = MinecraftConsole.scrollHeight;
var resVTopLac = newHeightV - oldHeightV;
MinecraftConsole.scrollTop = resVTopLac - 60;
});
//普通用户主页
2018-01-18 11:00:54 +08:00
MI.routeListener('genuser/home', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('GenHome', data.obj);
});
//配置项试图
2018-01-18 11:00:54 +08:00
MI.routeListener('server/properties', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('ServerProperties', data.obj);
});
//配置项试图
2018-01-18 11:00:54 +08:00
MI.routeListener('soft/view', function (data) {
2017-11-13 12:26:31 +08:00
MI.routeCopy('SoftProperties', data.obj);
});
})();