Notice 关闭 false 问题
parent
5f1d4a080d
commit
8e525f5d6a
|
|
@ -1,44 +1,47 @@
|
||||||
layui.define(['table', 'jquery', 'element'], function (exports) {
|
layui.define(['table', 'jquery', 'element'], function(exports) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var MOD_NAME = 'pearNotice',
|
var MOD_NAME = 'pearNotice',
|
||||||
$ = layui.jquery,
|
$ = layui.jquery,
|
||||||
element = layui.element;
|
element = layui.element;
|
||||||
|
|
||||||
var pearNotice = function (opt) {
|
var pearNotice = function(opt) {
|
||||||
this.option = opt;
|
this.option = opt;
|
||||||
};
|
};
|
||||||
|
|
||||||
pearNotice.prototype.render = function (opt) {
|
pearNotice.prototype.render = function(opt) {
|
||||||
//默认配置值
|
//默认配置值
|
||||||
var option = {
|
var option = {
|
||||||
elem:opt.elem,
|
elem: opt.elem,
|
||||||
url:opt.url,
|
url: opt.url ? opt.url : false,
|
||||||
height:opt.height,
|
height: opt.height,
|
||||||
data:opt.data,
|
data: opt.data,
|
||||||
click:opt.click
|
click: opt.click
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (option.url != false) {
|
||||||
|
|
||||||
option.data = getData(option.url);
|
option.data = getData(option.url);
|
||||||
|
|
||||||
var notice = createHtml(option);
|
var notice = createHtml(option);
|
||||||
|
|
||||||
$("#"+option.elem).html(notice);
|
$("#" + option.elem).html(notice);
|
||||||
|
|
||||||
// 添加监听
|
// 添加监听
|
||||||
$("*[notice-id]").click(function(){
|
$("*[notice-id]").click(function() {
|
||||||
var id = $(this).attr("notice-id");
|
var id = $(this).attr("notice-id");
|
||||||
var title = $(this).attr("notice-title");
|
var title = $(this).attr("notice-title");
|
||||||
var context = $(this).attr("notice-context");
|
var context = $(this).attr("notice-context");
|
||||||
var form = $(this).attr("notice-form");
|
var form = $(this).attr("notice-form");
|
||||||
option.click(id,title,context,form);
|
option.click(id, title, context, form);
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return new pearNotice(option);
|
return new pearNotice(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 同 步 请 求 获 取 数 据 */
|
/** 同 步 请 求 获 取 数 据 */
|
||||||
function getData(url){
|
function getData(url) {
|
||||||
|
|
||||||
$.ajaxSettings.async = false;
|
$.ajaxSettings.async = false;
|
||||||
var data = null;
|
var data = null;
|
||||||
|
|
@ -51,17 +54,17 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createHtml(option){
|
function createHtml(option) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var notice = '<li class="layui-nav-item" lay-unselect="">'+
|
var notice = '<li class="layui-nav-item" lay-unselect="">' +
|
||||||
'<a href="#" class="notice layui-icon layui-icon-notice"><span class="layui-badge-dot"></span></a>'+
|
'<a href="#" class="notice layui-icon layui-icon-notice"><span class="layui-badge-dot"></span></a>' +
|
||||||
'<div class="layui-nav-child layui-tab pear-notice" style="left: -200px;">';
|
'<div class="layui-nav-child layui-tab pear-notice" style="left: -200px;">';
|
||||||
|
|
||||||
var noticeTitle = '<ul class="layui-tab-title">';
|
var noticeTitle = '<ul class="layui-tab-title">';
|
||||||
|
|
||||||
var noticeContent = '<div class="layui-tab-content" style="height:'+option.height+';overflow-x: hidden;">'
|
var noticeContent = '<div class="layui-tab-content" style="height:' + option.height + ';overflow-x: hidden;">'
|
||||||
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
|
|
@ -70,15 +73,15 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(index === 0){
|
if (index === 0) {
|
||||||
|
|
||||||
noticeTitle += '<li class="layui-this">'+item.title+'</li>';
|
noticeTitle += '<li class="layui-this">' + item.title + '</li>';
|
||||||
|
|
||||||
noticeContent += '<div class="layui-tab-item layui-show">';
|
noticeContent += '<div class="layui-tab-item layui-show">';
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
noticeTitle += '<li>'+item.title+'</li>';
|
noticeTitle += '<li>' + item.title + '</li>';
|
||||||
|
|
||||||
noticeContent += '<div class="layui-tab-item">';
|
noticeContent += '<div class="layui-tab-item">';
|
||||||
|
|
||||||
|
|
@ -86,10 +89,11 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||||
|
|
||||||
$.each(item.children, function(i, note) {
|
$.each(item.children, function(i, note) {
|
||||||
|
|
||||||
noticeContent += '<div class="pear-notice-item" notice-form="'+note.form+'" notice-context="'+note.context+'" notice-title="'+note.title+'" notice-id="'+note.id+'">'+
|
noticeContent += '<div class="pear-notice-item" notice-form="' + note.form + '" notice-context="' + note.context +
|
||||||
'<img src="'+note.avatar+'">'+
|
'" notice-title="' + note.title + '" notice-id="' + note.id + '">' +
|
||||||
'<span>'+note.title+'</span>'+
|
'<img src="' + note.avatar + '">' +
|
||||||
'<span>'+note.time+'</span>'+
|
'<span>' + note.title + '</span>' +
|
||||||
|
'<span>' + note.time + '</span>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
@ -115,5 +119,5 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports(MOD_NAME,new pearNotice());
|
exports(MOD_NAME, new pearNotice());
|
||||||
})
|
})
|
||||||
Loading…
Reference in New Issue