123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /**
- @Name:layuiAdmin(iframe版) 消息中心
- @Author:贤心
- @Site:http://www.layui.com/admin/
- @License:LPPL
-
- */
- layui.define(['admin', 'table', 'util'], function(exports){
- var $ = layui.$
- ,admin = layui.admin
- ,table = layui.table
- ,element = layui.element;
-
- var DISABLED = 'layui-btn-disabled'
-
- //区分各选项卡中的表格
- ,tabs = {
- all: {
- text: '全部消息'
- ,id: 'LAY-app-message-all'
- }
- ,notice: {
- text: '通知'
- ,id: 'LAY-app-message-notice'
- }
- ,direct: {
- text: '私信'
- ,id: 'LAY-app-message-direct'
- }
- };
-
- //标题内容模板
- var tplTitle = function(d){
- return '<a href="detail.html?id='+ d.id +'">'+ d.title;
- };
-
- //全部消息
- table.render({
- elem: '#LAY-app-message-all'
- ,url: layui.setter.base + 'json/message/all.js' //模拟接口
- ,page: true
- ,cols: [[
- {type: 'checkbox', fixed: 'left'}
- ,{field: 'title', title: '标题内容', minWidth: 300, templet: tplTitle}
- ,{field: 'time', title: '时间', width: 170, templet: '<div>{{ layui.util.timeAgo(d.time) }}</div>'}
- ]]
- ,skin: 'line'
- });
-
- //通知
- table.render({
- elem: '#LAY-app-message-notice'
- ,url: layui.setter.base + 'json/message/notice.js' //模拟接口
- ,page: true
- ,cols: [[
- {type: 'checkbox', fixed: 'left'}
- ,{field: 'title', title: '标题内容', minWidth: 300, templet: tplTitle}
- ,{field: 'time', title: '时间', width: 170, templet: '<div>{{ layui.util.timeAgo(d.time) }}</div>'}
- ]]
- ,skin: 'line'
- });
-
- //私信
- table.render({
- elem: '#LAY-app-message-direct'
- ,url: layui.setter.base + 'json/message/direct.js' //模拟接口
- ,page: true
- ,cols: [[
- {type: 'checkbox', fixed: 'left'}
- ,{field: 'title', title: '标题内容', minWidth: 300, templet: tplTitle}
- ,{field: 'time', title: '时间', width: 170, templet: '<div>{{ layui.util.timeAgo(d.time) }}</div>'}
- ]]
- ,skin: 'line'
- });
-
-
- //事件处理
- var events = {
- del: function(othis, type){
- var thisTabs = tabs[type]
- ,checkStatus = table.checkStatus(thisTabs.id)
- ,data = checkStatus.data; //获得选中的数据
- if(data.length === 0) return layer.msg('未选中行');
- layer.confirm('确定删除选中的数据吗?', function(){
- /*
- admin.req('url', {}, function(){ //请求接口
- //do somethin
- });
- */
- //此处只是演示,实际应用需把下述代码放入上述Ajax回调中
- layer.msg('删除成功', {
- icon: 1
- });
- table.reload(thisTabs.id); //刷新表格
- });
- }
- ,ready: function(othis, type){
- var thisTabs = tabs[type]
- ,checkStatus = table.checkStatus(thisTabs.id)
- ,data = checkStatus.data; //获得选中的数据
- if(data.length === 0) return layer.msg('未选中行');
-
- //此处只是演示
- layer.msg('标记已读成功', {
- icon: 1
- });
- table.reload(thisTabs.id); //刷新表格
- }
- ,readyAll: function(othis, type){
- var thisTabs = tabs[type];
-
- //do somethin
-
- layer.msg(thisTabs.text + ':全部已读', {
- icon: 1
- });
- }
- };
-
- $('.LAY-app-message-btns .layui-btn').on('click', function(){
- var othis = $(this)
- ,thisEvent = othis.data('events')
- ,type = othis.data('type');
- events[thisEvent] && events[thisEvent].call(this, othis, type);
- });
-
- exports('message', {});
- });
|