/* * 版 本 Learun-ADMS V7.0.0 数字化智慧校园(http://www.learun.cn) * Copyright (c) 2013-2018 北京泉江科技有限公司 * 创建人:数字化智慧校园-前端开发组 * 日 期:2017.03.16 * 描 述:window窗口皮肤 */ var bootstrap = function ($, learun) { "use strict"; var isInit = false; // 菜单操作 var meuns = { init: function () { var $menuwarp = $('.lr-frame-menu'); if ($menuwarp != undefined && $('#lr_second_menu_wrap').length == 0) { $menuwarp.append('
'); } this.load(); this.bind(); }, load: function () { var modulesTree = learun.clientdata.get(['modulesTree']); // 第一级菜单 var parentId = '0'; var modules = modulesTree[parentId] || []; var $firstmenus = $(''); for (var i = 0, l = modules.length; i < l; i++) { var item = modules[i]; if (item.F_IsMenu == 1) { var $applistul = $('');// 应用列表 if (item.F_Target != 'expand') { $applistul.append(meuns.getAppItem(item)); } var $firstMenuItem = $('
  • '); if (!!item.F_Description) { $firstMenuItem.attr('title', item.F_Description); } var menuItemHtml = ''; menuItemHtml += ''; menuItemHtml += '' + item.F_FullName + ''; menuItemHtml += ''; $firstMenuItem.append(menuItemHtml); // 第二级菜单 var secondModules = modulesTree[item.F_ModuleId] || []; var $secondMenus = $(''); var secondMenuHad = false; for (var j = 0, sl = secondModules.length; j < sl; j++) { var secondItem = secondModules[j]; if (secondItem.F_IsMenu == 1) { if (secondItem.F_Target != 'expand') { $applistul.append(meuns.getAppItem(secondItem)); } secondMenuHad = true; var $secondMenuItem = $('
  • '); if (!!secondItem.F_Description) { $secondMenuItem.attr('title', secondItem.F_Description); } var secondItemHtml = ''; secondItemHtml += ''; secondItemHtml += '' + secondItem.F_FullName + ''; secondItemHtml += ''; $secondMenuItem.append(secondItemHtml); // 第三级菜单 var threeModules = modulesTree[secondItem.F_ModuleId] || []; var $threeMenus = $(''); var threeMenuHad = false; for (var m = 0, tl = threeModules.length; m < tl; m++) { var threeItem = threeModules[m]; if (threeItem.F_IsMenu == 1) { if (threeItem.F_Target != 'expand') { $applistul.append(meuns.getAppItem(threeItem)); } threeMenuHad = true; var $threeMenuItem = $('
  • '); $threeMenuItem.attr('title', threeItem.F_FullName); var threeItemHtml = ''; threeItemHtml += ''; threeItemHtml += '' + threeItem.F_FullName + ''; threeItemHtml += ''; $threeMenuItem.append(threeItemHtml); $threeMenus.append($threeMenuItem); // 第四级菜单 var fourModules = modulesTree[threeItem.F_ModuleId] || []; var $fourMenus = $(''); var fourMenuHad = false; for (var fi = 0, fl = fourModules.length; fi < fl; fi++) { var fourItem = fourModules[fi]; if (fourItem.F_IsMenu == 1) { if (fourItem.F_Target != 'expand') { $applistul.append(meuns.getAppItem(fourItem)); } fourMenuHad = true; var $fourMenuItem = $('
  • '); $fourMenuItem.attr('title', fourItem.F_FullName); var fourItemHtml = ''; fourItemHtml += ''; fourItemHtml += '' + fourItem.F_FullName + ''; fourItemHtml += ''; $fourMenuItem.append(fourItemHtml); $fourMenus.append($fourMenuItem); } } if (fourMenuHad) { $threeMenuItem.addClass('lr-meun-had'); $threeMenuItem.find('a').append(''); $threeMenuItem.append($fourMenus); } } } if (threeMenuHad) { $secondMenuItem.addClass('lr-meun-had'); $secondMenuItem.find('a').append(''); $secondMenuItem.append($threeMenus); } $secondMenus.append($secondMenuItem); } } if (secondMenuHad) { $secondMenus.attr('data-value', item.F_ModuleId); $('#lr_second_menu_wrap').append($secondMenus); } $firstmenus.append($firstMenuItem); if ($applistul.find('li').length > 0) { $("#lr_applist_slidebox").append($applistul); $(".lr-applist-slidebox-slider-content").append('
  • '); } } } $('#lr_frame_menu').html($firstmenus); // 语言包翻译 $('.lr-menu-item-text').each(function () { var $this = $(this); var text = $this.text(); learun.language.get(text, function (_text) { $this.text(_text); $this.parent().parent().attr('title', _text); }); }); $('.icon-text').each(function () { var $this = $(this); var text = $this.text() || ''; learun.language.get(text.replace(/^\s+|\s+$/g, ""), function (_text) { $this.text(_text); }); }); }, bind: function () { $("#lr_frame_menu").lrscroll(); $("#lr_second_menu_wrap").lrscroll(); $('#lr_windows_start').on('click', meuns.startMenuClick); $('#lr_frame_menu_overlay').on('click', meuns.startMenuClick); // 添加点击事件 $('#lr_frame_menu a').on('click', function () { var $obj = $(this); var id = $obj.attr('id'); var _module = learun.clientdata.get(['modulesMap', id]); switch (_module.F_Target) { case 'iframe':// 窗口 meuns.startMenuClick(); setTimeout(function () { if (learun.validator.isNotNull(_module.F_UrlAddress).code) { learun.frameTab.open(_module); } else { } }, 250); break; case 'expand': var $li = $obj.parent(); if (!$li.hasClass('active')) { $('#lr_frame_menu li.active').removeClass('active'); $li.addClass('active'); $('#lr_second_menu_wrap .lr-second-menu-list').hide(); $('#lr_second_menu_wrap .lr-second-menu-list[data-value="' + _module.F_ModuleId + '"]').show(); } break; } }); $('#lr_second_menu_wrap a').on('click', function () { var $obj = $(this); var id = $obj.attr('id'); var _module = learun.clientdata.get(['modulesMap', id]); switch (_module.F_Target) { case 'iframe':// 窗口 meuns.startMenuClick(); setTimeout(function () { if (learun.validator.isNotNull(_module.F_UrlAddress).code) { learun.frameTab.open(_module); } else { } }, 250); break; case 'expand': var $ul = $obj.next(); if ($ul.is(':visible')) { $ul.slideUp(500, function () { $obj.removeClass('open'); }); } else { if ($ul.hasClass('lr-three-menu-list')) { $ul.parents('.lr-second-menu-list').find('.lr-three-menu-list').slideUp(300, function () { $(this).prev().removeClass('open'); }); } else { $ul.parents('.lr-three-menu-list').find('.lr-four-menu-list').slideUp(300, function () { $(this).prev().removeClass('open'); }); } $ul.slideDown(300, function () { $obj.addClass('open'); }); } break; } }); $('.lr-first-menu-list>li').eq(0).find('a').trigger('click'); $(".lr-applist-slidebox-slider-content li").click(function () { var $this = $(this); if (!$this.hasClass("active")) { var $oldli = $(".lr-applist-slidebox-slider-content li.active"); $oldli.removeClass("active"); $this.addClass("active"); var oldindex = $oldli.index(); var index = $(this).index(); $("#lr_applist_slidebox ul").eq(oldindex).hide(); $("#lr_applist_slidebox ul").eq(index).fadeIn("slow"); } }); $('#lr_applist_btn').on('click', function () { meuns.openApplist(); }); $('#lr_applist_slidebox .appItem').on('click', function () { var $obj = $(this); var id = $obj.attr('data-id'); var _module = learun.clientdata.get(['modulesMap', id]); if (learun.validator.isNotNull(_module.F_UrlAddress).code) { learun.frameTab.open(_module); } }); $('#lr_applist_content').hide(); $(".lr-applist-slidebox-slider-content li").eq(0).trigger('click'); //learun.frameTab.leaveFocus(); }, startMenuClick: function () { debugger; var $lr_frame_menu = $('.lr-frame-menu'); if (!isInit) { isInit = true; $lr_frame_menu.show(); } else { if ($lr_frame_menu.is(':visible')) { $lr_frame_menu.show(); } else { $lr_frame_menu.hide(); } //$lr_frame_menu.slideToggle(300); } }, getAppItem: function (item) { var colorindex = Math.round(Math.random() * 9 + 1); var _html = ''; _html += '
  • '; _html += '
    '; _html += ''; _html += '
    '; _html += '
    '; _html += item.F_FullName; _html += '
    '; _html += '
  • '; return _html; }, closeApplist: function () { var appBtn = $('#lr_applist_btn'); if (!appBtn.hasClass('off')) { $('#lr_applist_btn').addClass('off'); $('#lr_applist_content').hide(); } }, openApplist: function () { var appBtn = $('#lr_applist_btn'); if (appBtn.hasClass('off')) { learun.frameTab.leaveFocus(); $('#lr_applist_btn').removeClass('off'); $('#lr_applist_content').show(); } } }; learun.frameTab.opencallback = function () { meuns.closeApplist(); }; learun.frameTab.closecallback = function () { if (learun.frameTab.iframeId == '') { meuns.openApplist(); } }; meuns.init(); var companyMap = {}; var departmentMap = {}; var userMap = {}; var sysUserMap = {}; var imUserId = ''; var getHeadImg = function (user) { var url = top.$.rootUrl; switch (user.img) { case '0': url += '/Content/images/head/on-girl.jpg'; break; case '1': url += '/Content/images/head/on-boy.jpg'; break; default: url += '/LR_OrganizationModule/User/GetImg?userId=' + user.id; break; } return url; }; // 发送聊天信息 var sendMsg = function (msg, time) { var loginInfo = learun.clientdata.get(['userinfo']); learun.clientdata.getAsync('user', { key: loginInfo.userId, callback: function (data, op) { data.id = op.key; var _html = '\
    '+ (time || '') + '
    \
    \
    \
    \ '+ msg + '\
    '; $('.lr-im-msgcontent .lr-scroll-box').append(_html); $('.lr-im-msgcontent').lrscrollSet('moveBottom'); } }); }; // 接收聊天消息 var revMsg = function (userId, msg, time) { learun.clientdata.getAsync('user', { key: userId, callback: function (data, op) { data.id = op.key; var _html = '\
    '+ (time || '') + '
    \
    \
    \
    \ '+ msg + '\
    '; $('.lr-im-msgcontent .lr-scroll-box').append(_html); $('.lr-im-msgcontent').lrscrollSet('moveBottom'); } }); }; var getTime = function (time) { var d = new Date(); var c = d.DateDiff('d', time); if (c <= 1) { return learun.formatDate(time, 'hh:mm:ss'); } else { return learun.formatDate(time, 'yyyy/MM/dd'); } } // 即时通讯 var im = { init: function () { this.bind(); this.load(); }, load: function () { // 获取下公司列表 learun.clientdata.getAllAsync('company', { callback: function (data) { $.each(data, function (_id, _item) { companyMap[_item.parentId] = companyMap[_item.parentId] || []; _item.id = _id; companyMap[_item.parentId].push(_item); }); var $list = $('#lr_im_content_userlist .lr-scroll-box'); $.each(companyMap["0"], function (_index, _item) { var _html = '\
    \
    \ '+ _item.name + '\
    \
    '; $list.append(_html); }); // 获取部门列表 learun.clientdata.getAllAsync('department', { callback: function (data) { $.each(data, function (_id, _item) { _item.id = _id; if (_item.parentId == "0") { departmentMap[_item.companyId] = departmentMap[_item.companyId] || []; departmentMap[_item.companyId].push(_item); } else { departmentMap[_item.parentId] = departmentMap[_item.parentId] || []; departmentMap[_item.parentId].push(_item); } }); // 获取人员数据 learun.clientdata.getAllAsync('user', { callback: function (data) { $.each(data, function (_id, _item) { _item.id = _id; if (_item.departmentId) { userMap[_item.departmentId] = userMap[_item.departmentId] || []; userMap[_item.departmentId].push(_item); } else if (_item.companyId) { userMap[_item.companyId] = userMap[_item.companyId] || []; userMap[_item.companyId].push(_item); } }); // 获取最近联系人列表 learun.im.getContacts(function (data, sysUserList) { $.each(sysUserList, function (_index, _item) { sysUserMap[_item.F_Code] = _item; }); var $userList = $('#lr_immsg_userlist .lr-scroll-box'); $.each(data, function (_index, _item) { var html = '
    '; html += '
    '; if (sysUserMap[_item.F_OtherUserId]) { html += ''; } else { html += ''; } html += '
    '; html += '
    '; html += '
    '; html += '
    ' + (_item.F_Content || '') + '
    '; html += '
    ' + getTime(_item.F_Time) + '
    '; html += '
    '; $userList.append(html); if (sysUserMap[_item.F_OtherUserId]) { var _$item = $userList.find('[data-value="' + _item.F_OtherUserId + '"]'); _$item.find('.name').text(sysUserMap[_item.F_OtherUserId].F_Name); _$item = null; } else { learun.clientdata.getAsync('user', { key: _item.F_OtherUserId, callback: function (data, op) { var $item = $userList.find('[data-value="' + op.key + '"]'); $item.find('.name').text(data.name); data.id = op.key; $item.find('img').attr('src', getHeadImg(data)); $item = null; } }); } }); }); } }); } }); } }); }, bind: function () { $('#lr_immsg_userlist').lrscroll(); $('#lr_im_content_userlist').lrscroll(); $('.lr-im-msgcontent').lrscroll(); // 打开关闭聊天窗 $('.lr-im-bell').on('click', function () { var $this = $(this); if ($this.hasClass('open')) { $this.removeClass('open'); $('.lr-im-body').removeClass('open'); $('.lr-im-black-overlay').hide(); imUserId = ''; } else { $this.addClass('open'); $('.lr-im-bell .point').hide(); $('.lr-im-body').addClass('open'); } }); // 最近消息 与 联系人之间的切换 $('.lr-im-title .title-item').on('click', function () { var $this = $(this); if (!$this.hasClass('active')) { $('.lr-im-body>.active').removeClass('active'); $('.lr-im-title>.active').removeClass('active'); $this.addClass('active'); var v = $this.attr('data-value'); $('#' + v).addClass('active'); } }); // 联系人 $('#lr_im_content_userlist .lr-scroll-box').on('click', function (e) { e = e || window.event; var et = e.target || e.srcElement; var $et = $(et); if (et.tagName == 'IMG' || et.tagName == 'I') { $et = $et.parent(); } if ($et.hasClass('lr-im-company')) {// 点击公司项 // 判断是否是打开的状态 if ($et.hasClass('open')) { $et.removeClass('open'); $et.parent().find('.lr-im-user-list').remove(); } else { var id = $et.attr('data-value'); var deep = parseInt($et.attr('data-deep')); var $list = $('
    '); $list.css({ 'padding-left': '10px' }); var flag = false; // 加载员工 $.each(userMap[id] || [], function (_index, _item) { var _html = '\
    \
    \ ' + _item.name + '\
    \
    '; $list.append(_html); flag = true; }); // 加载部门 $.each(departmentMap[id] || [], function (_index, _item) { var _html = '\
    \
    \ '+ _item.name + '\
    \
    '; $list.append(_html); flag = true; }); // 加载下属公司 $.each(companyMap[id] || [], function (_index, _item) { var _html = '\
    \
    \ '+ _item.name + '\
    \
    '; $list.append(_html); flag = true; }); if (flag) { $et.parent().append($list); } $et.addClass('open'); } return false; } else if ($et.hasClass('lr-im-department')) { // 判断是否是打开的状态 if ($et.hasClass('open')) { $et.removeClass('open'); $et.parent().find('.lr-im-user-list').remove(); } else { var id = $et.attr('data-value'); var deep = parseInt($et.attr('data-deep')); var $list = $('
    '); $list.css({ 'padding-left': '10px' }); var flag = false; // 加载员工 $.each(userMap[id] || [], function (_index, _item) { var _html = '\
    \
    \ ' + _item.name + '\
    \
    '; $list.append(_html); flag = true; }); // 加载部门 $.each(departmentMap[id] || [], function (_index, _item) { var _html = '\
    \
    \ '+ _item.name + '\
    \
    '; $list.append(_html); flag = true; }); if (flag) { $et.parent().append($list); } $et.addClass('open'); } } else if ($et.hasClass('lr-im-user')) { // 如果是用户列表 // 1.打开聊天窗口 // 2.添加一条最近联系人数据(如果没有添加的话) // 3.获取最近的20条聊天数据或者最近的聊天信息 var id = $et.attr('data-value'); var $userList = $('#lr_immsg_userlist .lr-scroll-box'); var $userItem = $userList.find('[data-value="' + id + '"]'); // 更新下最近的联系人列表数据 $('.lr-im-title .title-item').eq(0).trigger('click'); imUserId = id; if ($userItem.length > 0) { $userList.prepend($userItem); $userItem.trigger('click'); } else { var imgurl = $et.find('img').attr('src'); var _html = '\
    \
    \ \
    \
    \
    \
    \
    \
    '; $userList.prepend(_html); $userItem = $userList.find('[data-value="' + id + '"]'); // 获取人员数据 learun.clientdata.getAsync('user', { key: id, callback: function (data, op) { $userList.find('[data-value="' + op.key + '"] .name').text(data.name); $userItem.trigger('click'); } }); learun.im.addContacts(id); } } }); // 最近联系人列表点击 $('#lr_immsg_userlist .lr-scroll-box').on('click', function (e) { e = e || window.event; var et = e.target || e.srcElement; var $et = $(et); if (!$et.hasClass('msg-item')) { $et = $et.parents('.msg-item'); } if ($et.length > 0) { if (!$et.hasClass('active')) { var name = $et.find('.name').text(); imUserId = $et.attr('data-value'); $('#lr_immsg_userlist .lr-scroll-box .active').removeClass('active'); $et.addClass('active'); $('.lr-im-black-overlay').show(); var $imdialog = $('.lr-im-dialog'); $imdialog.find('.im-title').text("与" + name + "对话中"); $('#lr_im_input').val(''); $('#lr_im_input').select(); $('.lr-im-msgcontent .lr-scroll-box').html(''); // 获取聊天信息 learun.im.getMsgList(imUserId, function (data) { var len = data.length; if (len > 0) { for (var i = len - 1; i >= 0; i--) { var _item = data[i]; learun.clientdata.getAsync('user', { key: _item.userId, msg: _item.content, time: _item.time, callback: function (data, op) { data.id = op.key; var loginInfo = learun.clientdata.get(['userinfo']); var _html = '\
    ' + op.time + '
    \
    \
    \
    \ '+ op.msg + '\
    '; $('.lr-im-msgcontent .lr-scroll-box').prepend(_html); } }); } $('.lr-im-msgcontent').lrscrollSet('moveBottom'); } }, $et.hasClass('imHasMsg')); $et.removeClass('imHasMsg'); learun.im.updateContacts(imUserId); } } }); // 联系人搜索 $('.lr-im-search input').on("keypress", function (e) { e = e || window.event; if (e.keyCode == "13") { var $this = $(this); var keyword = $this.val(); var $list = $('#lr_im_content_userlist .lr-scroll-box'); $list.html(""); if (keyword) { learun.clientdata.getAllAsync('user', { callback: function (data) { $.each(data, function (_index, _item) { if (_item.name.indexOf(keyword) != -1) { _item.id = _index; var _html = '\
    \
    \ ' + _item.name + '\
    \
    '; $list.append(_html); } }); } }); } else { $.each(companyMap["0"], function (_index, _item) { var _html = '\
    \
    \ '+ _item.name + '\
    \
    '; $list.append(_html); }); } } }); // 发送消息 $('#lr_im_input').on("keypress", function (e) { e = e || window.event; if (e.keyCode == "13") { var text = $(this).val(); $(this).val(''); if (text.replace(/(^\s*)|(\s*$)/g, "") != '') { var time = learun.im.sendMsg(imUserId, text); sendMsg(text, time); var $userItem = $('#lr_immsg_userlist .lr-scroll-box [data-value="' + imUserId + '"]'); $userItem.find('.msg').text(text); $userItem.find('.date').text(getTime(learun.getDate('yyyy-MM-dd hh:mm:ss'))); $userItem = null; } return false; } }); // 注册消息接收 learun.im.registerRevMsg(function (userId, msg, dateTime) { var $userList = $('#lr_immsg_userlist .lr-scroll-box'); var $userItem = $userList.find('[data-value="' + userId + '"]'); // 判断当前账号是否打开聊天窗口 if (userId == imUserId) { revMsg(userId, msg, dateTime); learun.im.updateContacts(userId); $userItem.find('.msg').text(msg); $userItem.find('.date').text(getTime(dateTime)); } else { if ($userItem.length > 0) { $userList.prepend($userItem); if (!$userItem.hasClass('imHasMsg')) { $userItem.addClass('imHasMsg'); } $userItem.find('.msg').text(msg); $userItem.find('.date').text(getTime(dateTime)); } else { var html = '
    '; html += '
    '; if (sysUserMap[userId]) { html += ''; } else { html += ''; } html += '
    '; html += '
    '; html += '
    '; html += '
    ' + msg + '
    '; html += '
    ' + getTime(dateTime) + '
    '; html += '
    '; $userList.prepend(html); if (sysUserMap[userId]) { var _$item = $userList.find('[data-value="' + userId + '"]'); _$item.find('.name').text(sysUserMap[userId].F_Name); _$item = null; } else { learun.clientdata.getAsync('user', { key: userId, callback: function (data, op) { var $item = $userList.find('[data-value="' + op.key + '"]'); $item.find('.name').text(data.name); data.id = op.key; $item.find('img').attr('src', getHeadImg(data)); $item = null; } }); } } } if (!$('.lr-im-bell').hasClass('open')) { $('.lr-im-bell .point').show(); } }); // 查看聊天记录 $('#lr_im_look_msg_btn').on('click', function () { learun.layerForm({ id: 'LookMsgIndex', title: '查看聊天记录-' + $('#lr_im_msglist .lr-im-right .lr-im-touser').text(), url: top.$.rootUrl + '/LR_IM/IMMsg/Index?userId=' + imUserId, width: 800, height: 500, maxmin: true, btn: null }); }); $('.im-close').on('click', function () { $('#lr_immsg_userlist .lr-scroll-box [data-value="' + imUserId + '"]').removeClass('active'); $('.lr-im-black-overlay').hide(); imUserId = ''; }); } }; //im.init(); };