/**
* 创建锁屏组件
* @param {JQuery} target target是jquery包裹的元素
* @param {Object} urlMap { "urlName":"url" }
*/
/**
* [LockScreen =锁屏功能对象]
* @param {[Element]} target [锁屏界面面板]
* @param {[Element]} backgroundImage [背景图片]
* @param {[Element]} homeTool [桌面右下角的工具栏]
* @param {[Number]} lockTimeout [自动锁定超时]
* @param {[Object]} urlMap [存放url连接token]
*/
function LockScreen(target, backgroundImage, homeTool, lockTimeout, urlMap) {
this.target = target;
this.urlMap = urlMap;
this.homeTool = homeTool;
this.lockTimeout = lockTimeout;
this.backgroundImage = backgroundImage;
this.bindEvent();
this.startClock();
this.showPic();
this.state = LockScreen.STATE_UNLOCK;
this.setupAutoLock(lockTimeout);
this.allztm = false;
this.cwcs = 0;
this._lockScreenElement=null;
}
LockScreen.STATE_UNLOCK = 0;
LockScreen.STATE_LOCK = 1;
LockScreen.prototype.showMsg2 = function(msg) {
var context = this;
if (parent.$("#msgDiv").length == 0){
parent.$("body").append('肥肥6666');
}
var msgLeft = context.target.find(".lock-controll-button").offset().left;
var msgTop = context.target.find(".lock-controll-button").offset().top;
context.target.find(".lock-controll-button").css("margin-left","10px !important")
parent.$("#msgDiv").html(msg);
parent.$("#msgDiv").css({ "left": (msgLeft) + "px", "top": (msgTop-46) + "px" });
setTimeout (function(){
parent.$("#msgDiv").remove();
},3000);
}
LockScreen.prototype.showMsg = function(msg, num, size) {
var context = this;
if (num == 0) {
// parent.$("#msgDiv").html(msg+",剩余"+num+"次机会");
parent.$("#msgDiv").html(msg);
return false;
}
var msgLeft = context.target.find(".login-sca .login-sc[time='" + (size - num + 1) + "']").offset().left;
var msgTop = context.target.find(".login-sca .login-sc[time='" + (size - num + 1) + "']").offset().top;
if (parent.$("#msgDiv").length == 0)
parent.$("body").append('肥肥6666');
parent.$("#msgDiv").html(msg);
// parent.$("#msgDiv").html(msg+",剩余"+num+"次机会");
parent.$("#msgDiv").css({ "left": (msgLeft - 7) + "px", "top": (msgTop - 46) + "px" });
}
LockScreen.prototype.mmandcwts = function(msg, sydlcs, zcs) {
var context = this;
context.target.find(".login-sca").html("");
var kscs = zcs;
var cs = '';
for (let i = 1; i <= kscs; i++) {
if (i <= (zcs - sydlcs)) {
cs = '';
} else {
cs = '';
}
context.target.find(".login-sca").prepend(cs);
}
if (sydlcs == zcs) {
context.target.find(".login-sca").css("visibility", "hidden");
}
if (0 >= sydlcs) {
context.showMsg("密码错误次数过多,帐号已被锁定,请联系管理员!", 0);
return false;
} else {
context.showMsg(msg, sydlcs, zcs);
}
}
LockScreen.prototype.mima = function() {
var context = this;
var showPwd = context.target.find(".login-unlockInput");
context.target.find(".login-eyeIcon").on('click', function() {
if (context.allztm) {
showPwd.attr('type', 'password');
context.allztm = false;
} else {
showPwd.attr('type', 'text');
context.allztm = true;
};
})
}
LockScreen.prototype.lockSession = function() {
var context = this;
this.showPic();
context.allztm = false;
context.isSessionLock = true;
//context.startCheckIsUnlockedByApp();
context.target.find('#lock-msg').html("");
context.target.find('#mm').val("");
context.target.css('z-index', 1);
context.mima();
// context.target.fadeIn();
context.state = LockScreen.STATE_LOCK;
this._lockScreenElement =wd.topWindow.$("body > *").filter(function(){return this.offsetWidth>0;});
this._lockScreenElement.hide();
$(top.document).find('table[align="center"]').fadeOut();
// wd.topWindow.$(".dhtmlx_window_active,.dhtmlx_window_inactive,.wdMaskDiv,.dhx_modal_cover_ifr,.dhx_modal_cover_dv").hide();
$(top.document).find('#background-desktop').css('display', 'block');
$("#lock-screen").css("display","block");
$.ajax({
url: this.urlMap['url8'],
type: 'POST',
success: function (data) {
// console.log(data);
//标记session为锁定状态
// console.log("自动锁屏,服务调用成功。",context.urlMap['url1'])
},
})
}
LockScreen.prototype.setupAutoLock = function() {
if (this.autoLockTask) {
clearTimeout(this.autoLockTask);
}
var context = this;
this.autoLockTask = setTimeout(function(){
console.log("lock session")
context.lockSession();
},this.lockTimeout*1000*60);
//console.log("auto close session")
//console.log(this.lockTimeout.val()*60*1000)
}
LockScreen.prototype.cancelAutoLock = function() {
}
LockScreen.prototype.startCheckIsUnlockedByApp = function() {
var context = this;
context.aaah = wd.c.acquireAppAuthority({
yhm: this.target.find('input[name=zh]').val(),
callback: function(data) {
if (data.code == 0) {
if (data.status == 2) {
context.unlockScreen();
return;
}
}
},
title: '解锁PC系统授权',
content: null,
})
var count = 60; //60s内不能重复触发
var time = context.target.find('.icon-countdownButton')[0];
time.innerHTML = ' ' + count + 's';
time.style.display = 'block';
var _h = setInterval(function() {
if (--count <= 0) {
console.log(count);
clearInterval(_h);
time.innerHTML = '';
time.style.display = 'none';
} else {
time.innerHTML = ' ' + count + 's';
}
}, 1000)
console.log($("#unlockByApp").css("display"),506)
// $.ajax({
// url: this.urlMap['url2'],
// dataType: 'json',
// type: 'POST',
// success: function (data) {
// if (data.code == 0) {
// if (data.status == 2) {
// context.unlockScreen()
// } else if (data.status == 1) {
// alert('移动端拒绝解锁')
// } else if(context.isSessionLock) {
// setTimeout(context.startCheckIsUnlockedByApp.bind(context), 1000);
// }
// }
// },
// });
}
LockScreen.prototype.unlockScreen = function() {
if (!!this.aaah) { //请求定时获取app认证状态得interval
clearInterval(this.aaah);
this.aaah = null;
}
$(top.document).find('#background-desktop').css('display', 'none');
this.state = LockScreen.STATE_LOCK;
this.target.css('z-index', -1);
this.hideInputPanel();
//this.target.fadeOut();
$(top.document).find('table[align="center"]').fadeIn();
this.setupAutoLock(this.lockTimeout);
// if(wd.topWindow.$(".dhtmlx_window_active").length>0)
// wd.topWindow.$(".dhtmlx_window_active,.dhtmlx_window_inactive,.wdMaskDiv,.dhx_modal_cover_ifr,.dhx_modal_cover_dv").show();
if(this._lockScreenElement){
this._lockScreenElement.show();
}
$("#lock-screen").css("display","none");
}
LockScreen.prototype.unlockSessionByPassword = function() {
var context = this;
var mm=this.target.find('#mm').val();
if(!mm){
context.showMsg2("请输入密码");
return;
}
$.ajax({
url: this.urlMap['url3'],
dataType: 'json',
type: 'POST',
data: {
mm: mm,
},
success: function(data) {
// context.target.find('#lock-msg').html(data.msg);
if (data.code == -1) {
context.mmandcwts(data.msg, data.sydlcs, data.zcs);
}
if (data.code == 0) {
context.isSessionLock = false;
context.unlockScreen();
}
},
})
}
LockScreen.prototype.startClock = function() {
var date = new Date();
var dateStr = (date.getHours() < 10 ? ("0" + date.getHours()) : date.getHours()) +
":" +
(date.getMinutes() < 10 ? ("0" + date.getMinutes()) : date.getMinutes());
this.target.find('.home-clock').text(dateStr);
setTimeout(this.startClock.bind(this), (60 - date.getSeconds()) * 1000)
}
LockScreen.prototype.showPic = function() {
var context = this
$.getJSON(this.urlMap['url4'], function(data) {
if (data.code == 0) {
//显示桌面相关部件
context.homeTool.css('display', "block")
context.target.css('display', "block")
// context.backgroundImage.css('display','block')
//设置图片背景
/* 再改,增加 type="img"。Lin
context.backgroundImage.css('background-image', 'url(/service?wdService=dlByHttp&path=' + data.data.filePath + ')'); // ?wdService=getData&。Lin
*/ context.backgroundImage.css('background-image', 'url(/service?ssServ=dlByHttp&type=img&path='+ data.data.filePath +')'); // ?wdService=getData&。Lin
context.homeTool.find('#pl-list a').prop('href', "javascript:" + context.urlMap['url6'].replace(/(\/service\?)/, '$1nrid=' + data.data.nrid + "&"))
// 原来的正则/(token=\d+)/
//nrid
context.nrid = data.data.nrid;
//设置信息
var picInfo = context.homeTool.find('#pic-info');
//picInfo.find('#pic-zz-text').text(data.data.zz);
picInfo.find('#pic-zz-text').text("非繁");
//picInfo.find('#pic-fbsj-text').text(data.data.fbsj);
picInfo.find('#pic-fbsj-text').text("2018.10.18");
picInfo.find('#pic-mc-text').text(data.data.mc);
//点赞数据
var dzCount = context.homeTool.find('#dz-count');
if ("dzs" in data.data) {
if (data.data.dzs != null)
dzCount.find('#dz-count-text').text(data.data.dzs);
else
dzCount.find('#dz-count-text').text("0");
} else
dzCount.find('#dz-count-text').text("0");
//是否已点赞
if ("isLike" in data.data && data.data.isLike)
dzCount.find('a').css('background', 'url(/zzfb_/theme/EasyUses/image/icon_like_alt_red.png)');
//显示评论
context.showNrtz(context.urlMap['url5'] + '&nrid=' + data.data.nrid);
} else {
// context.homeTool.css('display',"block")
context.target.css('display', "block")
context.backgroundImage.css('display', 'block')
}
})
}
LockScreen.prototype.unlockSessionByVoice = function() {
}
LockScreen.prototype.stopPic = function(index, picList) {
if (this.picPlayHandle) {
clearTimeout(this.picPlayHandle)
}
}
LockScreen.prototype.showNrtz = function(url, currentPageNo = 1, rowCountPerPage = 5) {
var context = this;
$.getJSON(url + "¤tPageNo=" + currentPageNo + "&rowCountPerPage=" + rowCountPerPage, function(data) {
var plList = context.homeTool.find('.pl-list');
plList.html("");
for (var i = 0; i < data.data.length; i++) {
var temp = '
' +
'' +
'
' +
'' + data.data[i].bt + '' +
'
' +
'
';
plList.append(temp)
}
//设置分页
context.showNrtzPage(url, data.page)
})
}
// LockScreen.prototype.showNrtz = function(url,page){
// var plPage = this.target.find('#pl-page');
// plPage.html("");
// if(page.currentPageNo <= 1){
// plPage.append('«')
// }else{
// var a = $('«');
// a.click(function(){
// var pageNo = $(this).attr('href').substring(1)
// showNrtz(url,pageNo);
// })
// plPage.append(a)
// }
// var pageCount = parseInt((page.rowCount-1)/page.rowCountPerPage)+1;
// var maxPageNum = 5;
// var startPageNo = Math.max(1,parseInt(page.currentPageNo-maxPageNum/2));
// var endPageNo = Math.min(startPageNo+maxPageNum,parseInt((page.rowCount-1)/page.rowCountPerPage)+1);
// for(var i = startPageNo; i <= endPageNo ; i ++ ){
// if(i == page.currentPageNo){
// plPage.append(''+i+'');
// }else{
// var a = $(''+i+'');
// a.click(function(){
// var pageNo = $(this).attr('href').substring(1)
// showNrtz(url,pageNo);
// })
// plPage.append(a);
// }
// }
// if(page.currentPageNo < pageCount){
// var a = $('»');
// a.click(function(){
// var pageNo = $(this).attr('href').substring(1)
// showNrtz(url,pageNo);
// })
// plPage.append(a)
// }else{
// plPage.append('»')
// }
// }
LockScreen.prototype.showNrtzPage = function(url, page) {
var context = this;
var plPage = this.homeTool.find('#pl-page');
plPage.html("");
if (page.currentPageNo <= 1) {
plPage.append('«')
} else {
var a = $('«');
a.click(function() {
var pageNo = $(this).attr('href').substring(1)
context.showNrtz(url, pageNo);
})
plPage.append(a)
}
var pageCount = parseInt((page.rowCount - 1) / page.rowCountPerPage) + 1;
var maxPageNum = 5;
var startPageNo = Math.max(1, parseInt(page.currentPageNo - maxPageNum / 2));
var endPageNo = Math.min(startPageNo + maxPageNum, parseInt((page.rowCount - 1) / page.rowCountPerPage) + 1);
for (var i = startPageNo; i <= endPageNo; i++) {
if (i == page.currentPageNo) {
plPage.append('' + i + '');
} else {
var a = $('' + i + '');
a.click(function() {
var pageNo = $(this).attr('href').substring(1)
context.showNrtz(url, pageNo);
})
plPage.append(a);
}
}
if (page.currentPageNo < pageCount) {
var a = $('»');
a.click(function() {
var pageNo = $(this).attr('href').substring(1)
context.showNrtz(url, pageNo);
})
plPage.append(a)
} else {
plPage.append('»')
}
}
LockScreen.prototype.showInputPanel = function() {
//this.target.find('#lock-screen').fadeIn();
var display=this.target.find(".lock-controll-panel")["0"].style.display;
if(display=="none"||display==""||!display){
this.target.find(".lock-controll-panel").fadeIn();
parent.$("#msgDiv").fadeIn();
}else{
this.target.find(".lock-controll-panel").fadeOut();
parent.$("#msgDiv").fadeOut();
}
//判断不同系统中摇一摇的显示或隐藏
if($("#unlockByApp").css("display")=="none"){
$("#unlockByPassword").css("margin-left", "46px");
$("#mm").attr("style", "background:none !important;width:217px !important;");
$(".ksmm").css("right","-50px");
}
}
LockScreen.prototype.hideInputPanel = function() {
// this.target.find('#lock-screen').fadeOut();
this.target.find(".lock-controll-panel").fadeOut();
parent.$("#msgDiv").fadeOut();
}
LockScreen.prototype.bindEvent = function() {
var context = this;
this.target.on('click', function(event) {
if (event.target == this) {
//$(this).fadeOut();
clearTimeout(context.autoCloseLockScreen);
}
});
this.target.find('.lock-controll-panel').on('mousemove', function() {
if (new Date().getTime() - context.lastSetACLSTime > 2000) { //距上次设置定时关闭器时的间隔大于2s,重新设置自动关闭器
console.log('滑动触发打开输入')
//自动关闭定时器
clearTimeout(context.autoCloseLockScreen);
context.autoCloseLockScreen = setTimeout(function() {
console.log('滑动触发打开输入:关闭')
context.hideInputPanel();
context.autoCloseLockScreen = null;
}, 60000);
context.lastSetACLSTime = new Date().getTime();
}
})
this.target.find('#lock-screen').on('click', function(event) {
if (event.target != this || context.state == LockScreen.STATE_UNLOCK) { //如果事件的目标不是target对象,则不处理
return;
}
clearTimeout(context.autoCloseLockScreen);
var ls = context.target.find('#lock-screen');
context.showInputPanel();
console.log('点击背景打开输入')
//自动关闭定时器
context.autoCloseLockScreen = setTimeout(function() {
console.log('点击背景打开输入:关闭')
context.hideInputPanel();
context.autoCloseLockScreen = null;
}, 60000);
context.lastSetACLSTime = new Date().getTime();
});
this.target.find('#unlockByPassword').click(this.unlockSessionByPassword.bind(this));
this.target.find('.lock-controll-panel').on("keydown", function(event) {
if (event.keyCode == 13) {
var mm=context.target.find('#mm').val();
if(!mm){
context.showMsg2("请输入密码");
return;
}
$.ajax({
url: context.urlMap['url3'],
dataType: 'json',
type: 'POST',
data: {
mm: mm,
},
success: function(data) {
// context.target.find('#lock-msg').html(data.msg);
if (data.code == -1) {
context.mmandcwts(data.msg, data.sydlcs, data.zcs);
}
if (data.code == 0) {
context.isSessionLock = false;
context.unlockScreen();
}
},
})
}
})
this.target.find('#unlockByApp').click(this.startCheckIsUnlockedByApp.bind(this));
this.target.find('#backToHomepage').click(wd.display.exit);
// 点赞
context.homeTool.find('#dz-count').find('a').on('click', function() {
$.ajax({
url: context.urlMap['url7'],
data: {
'nrid': context.nrid
},
dataType: 'json',
type: 'GET',
success: function(data) {
//根据情况,修改img样式
var result = data;
if (result.result) { //true
//isLike 确认是否为已赞
if (result.isLike) {
//修改样式
context.homeTool.find('#dz-count').find('a').css('background', 'url(/zzfb_/theme/EasyUses/image/icon_like_alt_red.png)');
} else {
//修改样式
context.homeTool.find('#dz-count').find('a').css('background', 'url(/zzfb_/theme/EasyUses/image/icon_like_alt.png)');
}
context.homeTool.find('#dz-count').find('#dz-count-text').text(result.dzs);
} else { //false
console.log('点赞失败');
}
}
});
});
// this.target.find('#pic-info').on('mouseover',function(){
// $(this).find('.pic-info').css('display','block');
// }).on('mouseout',function(){
// $(this).find('.pic-info').css('display','none');
// });
// this.target.find('#dz-count').on('mouseover',function(){
// $(this).find('.dz-count').css('display','block');
// }).on('mouseout',function(){
// $(this).find('.dz-count').css('display','none');
// });
// this.target.find('#pl-list').on('mouseover',function(){
// $(this).find('.pl-list-container').css('display','block');
// }).on('mouseout',function(){
// $(this).find('.pl-list-container').css('display','none');
// })
}
// function lockSession() {
// $.ajax({
// url: '/service?wdApplication=wd&wdService=lockSession',
// dataType: 'json',
// type: 'GET',
// success: function (data) {
// //标记session为锁定状态
// top.isSessionLock = true;
// startCheckIsUnlockedByApp();
// top.document.querySelector('.lock-screen').style.display="block"
// top.document.querySelector('table[align="center"]').style.display='none'//隐藏桌面
// top.document.querySelector('#lock-msg').innerHTML = "";
// top.document.querySelector('#mm').value="";
// },
// })
// }
// function startCheckIsUnlockedByApp() {
// $.ajax({
// url: '/service?wdApplication=wd&wdService=checkIsUnlockedByApp',
// dataType: 'json',
// type: 'POST',
// success: function (data) {
// console.log(data);
// if (data.code == 0) {
// if (data.status == 2) {
// unlockScreen()
// } else if (data.status == 1) {
// alert('移动端拒绝解锁')
// } else if(top.isSessionLock) {
// setTimeout(startCheckIsUnlockedByApp, 1000);
// }
// }
// },
// })
// }
// function unlockScreen(){
// top.document.querySelector('#lock-screen').style.display="none"
// top.document.querySelector('table[align="center"]').style.display="block"
// }
// function unlockSessionByPassword() {
// $.ajax({
// url: '/service?wdApplication=wd&wdService=unlockSessionByPassword',
// dataType: 'json',
// type: 'POST',
// data: {
// mm: top.document.querySelector('#mm').value
// },
// success: function (data) {
// top.document.querySelector('#lock-msg').innerHTML = data.msg;
// if (data.code == 0) {
// top.isSessionLock= false;
// unlockScreen();
// }
// },
// })
// }
// function unlockSessionByVoice() {
// }
// function startClock() {
// var date = new Date();
// var dateStr = (date.getHours() < 10 ? ("0" + date.getHours()) : date.getHours()) +
// ":" +
// (date.getMinutes() < 10 ? ("0" + date.getMinutes()) : date.getMinutes());
// top.document.querySelector('.home-clock').innerHTML = dateStr;
// setTimeout(startClock, 60 - date.getSeconds())
// }
// function showPic(){
// $.getJSON('/service?wdApplication=nr&wdService=getSjtp',function(data){
// if(data.code == 0){
// //设置图片背景
// $(top.document).find('.home-background').css('background-image','url(/service?wdApplication=nr&wdService=getData&path='+data.data.filePath+')');
// //设置信息
// var picInfo = $(top.document).find('#pic-info');
// picInfo.find('#pic-zz-text').text(data.data.zz);
// picInfo.find('#pic-fbsj-text').text(data.data.fbsj);
// picInfo.find('#pic-mc-text').text(data.data.bt);
// //点赞数据
// var dzCount = $(top.document).find('#dz-count');
// dzCount.find('#dz-count-text').text(data.data.dzs);
// //显示评论
// showNrtz('/service?wdApplication=nr&wdService=nr_ck_pl_cx_ajax&nrid='+data.data.nrid);
// }
// })
// }
// function playPic(index,picList){
// if(picList && picList.length > 0){
// $(top.document).find('.home-background').css('background-image','url('+picList[index].url+')');
// //设置信息
// var picInfo = $(top.document).find('#pic-info');
// picInfo.find('#pic-zz-text').text(picList[index].zz);
// picInfo.find('#pic-fbsj-text').text(picList[index].fbsj);
// picInfo.find('#pic-mc-text').text(picList[index].bt);
// //点赞数据
// var dzCount = $(top.document).find('#dz-count');
// dzCount.find('#dz-count-text').text(picList[index].dzs);
// index ++;
// if(index >= picList.length){
// index = 0;
// }
// if(picList.length > 0){
// top.picPlayHandle = setTimeout(function() {
// playPic(index,picList);
// }, 30000);
// }
// }
// }
// function stopPic(index,picList){
// if( top.picPlayHandle ){
// clearTimeout( top.picPlayHandle )
// }
// }
// function showNrtz(url,currentPageNo=1,rowCountPerPage=5){
// $.getJSON(url+"¤tPageNo="+currentPageNo+"&rowCountPerPage="+rowCountPerPage,function(data){
// var plList = $(top.document).find('.pl-list');
// plList.html("");
// for(var i = 0; i < data.data.length ;i++){
// var temp = ''+
// ''+
// '
'+
// ''+data.data[i].bt+''+
// '
'+
// '
';
// plList.append(temp)
// }
// //设置分页
// showNrtzPage(url,data.page)
// })
// }
// function showNrtzPage(url,page){
// var plPage = $(top.document).find('#pl-page');
// plPage.html("");
// if(page.currentPageNo <= 1){
// plPage.append('«')
// }else{
// var a = $('«');
// a.click(function(){
// var pageNo = $(this).attr('href').substring(1)
// showNrtz(url,pageNo);
// })
// plPage.append(a)
// }
// var pageCount = parseInt((page.rowCount-1)/page.rowCountPerPage)+1;
// var maxPageNum = 5;
// var startPageNo = Math.max(1,parseInt(page.currentPageNo-maxPageNum/2));
// var endPageNo = Math.min(startPageNo+maxPageNum,parseInt((page.rowCount-1)/page.rowCountPerPage)+1);
// for(var i = startPageNo; i <= endPageNo ; i ++ ){
// if(i == page.currentPageNo){
// plPage.append(''+i+'');
// }else{
// var a = $(''+i+'');
// a.click(function(){
// var pageNo = $(this).attr('href').substring(1)
// showNrtz(url,pageNo);
// })
// plPage.append(a);
// }
// }
// if(page.currentPageNo < pageCount){
// var a = $('»');
// a.click(function(){
// var pageNo = $(this).attr('href').substring(1)
// showNrtz(url,pageNo);
// })
// plPage.append(a)
// }else{
// plPage.append('»')
// }
// }
// function bindEvent(){
// top.document.querySelector('#unlockByPassword').addEventListener('click',unlockSessionByPassword);
// $(top.document).find('#pic-info').on('mouseover',function(){
// $(this).find('.pic-info').css('display','block');
// }).on('mouseout',function(){
// $(this).find('.pic-info').css('display','none');
// });
// $(top.document).find('#dz-count').on('mouseover',function(){
// $(this).find('.dz-count').css('display','block');
// }).on('mouseout',function(){
// $(this).find('.dz-count').css('display','none');
// });
// $(top.document).find('#pl-list').on('mouseover',function(){
// $(this).find('.pl-list-container').css('display','block');
// }).on('mouseout',function(){
// $(this).find('.pl-list-container').css('display','none');
// })
// }