diff --git a/admin/data/card.json b/admin/data/card.json index e531747..e238590 100644 --- a/admin/data/card.json +++ b/admin/data/card.json @@ -1,56 +1,57 @@ { - "code": 0, - "msg": "...", - "count": 3, + "msg": "not data", + "count": 30, "data": [{ - "id": "1", - "image": "https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png", - "title": "Alipay", - "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", - "time": "几秒前" - },{ - "id": "2", - "image": "https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png", - "title": "Layui", - "remark": "生命就像一盒巧克力,结果往往出人意料", - "time": "几秒前" - },{ - "id": "1", - "image": "https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png", - "title": "Angular", - "remark": "希望是一个好东西,也许是最好的,好东西是不会消亡的", - "time": "几秒前" - }, - { - "id": "1", - "image": "https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png", - "title": "React", - "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", - "time": "几秒前" - },{ - "id": "1", - "image": "https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png", - "title": "Alipay", - "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", - "time": "几秒前" - },{ - "id": "2", - "image": "https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png", - "title": "Layui", - "remark": "生命就像一盒巧克力,结果往往出人意料", - "time": "几秒前" - },{ - "id": "1", - "image": "https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png", - "title": "Angular", - "remark": "希望是一个好东西,也许是最好的,好东西是不会消亡的", - "time": "几秒前" - }, - { - "id": "1", - "image": "https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png", - "title": "React", - "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", - "time": "几秒前" - }] + "id": "1", + "image": "https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png", + "title": "Alipay", + "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", + "time": "几秒前" + }, { + "id": "2", + "image": "https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png", + "title": "Layui", + "remark": "生命就像一盒巧克力,结果往往出人意料", + "time": "几秒前" + }, { + "id": "3", + "image": "https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png", + "title": "Angular", + "remark": "希望是一个好东西,也许是最好的,好东西是不会消亡的", + "time": "几秒前" + }, + { + "id": "4", + "image": "https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png", + "title": "React", + "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", + "time": "几秒前" + }, { + "id": "5", + "image": "https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png", + "title": "Alipay", + "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", + "time": "几秒前" + }, { + "id": "6", + "image": "https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png", + "title": "Layui", + "remark": "生命就像一盒巧克力,结果往往出人意料", + "time": "几秒前" + }, { + "id": "7", + "image": "https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png", + "title": "Angular", + "remark": "希望是一个好东西,也许是最好的,好东西是不会消亡的", + "time": "几秒前" + }, + { + "id": "8", + "image": "https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png", + "title": "React", + "remark": "那是一种内在的东西, 他们到达不了,也无法触及的", + "time": "几秒前" + } + ], + "code": 0 } diff --git a/component/pear/css/module/card.css b/component/pear/css/module/card.css index 1a7b68c..39b4ed2 100644 --- a/component/pear/css/module/card.css +++ b/component/pear/css/module/card.css @@ -69,10 +69,25 @@ margin-left: -10px; } -.pear-card-component { +.cloud-card-component { padding: 20px; } -.pear-card-component .layui-laypage .layui-laypage-curr .layui-laypage-em { - border-radius: 0px !important; +.cloud-card-component .layui-table-click { + border-radius: 6px!important; } + +.ew-table-loading { + padding: 10px 0; + text-align: center; +} +.ew-table-loading > i { + color: #999; + font-size: 30px; +} +.ew-table-loading.ew-loading-float { + position: absolute; + top: 0; + left: 0; + right: 0; +} \ No newline at end of file diff --git a/component/pear/module/card.js b/component/pear/module/card.js index 66c2b65..9cb32f1 100644 --- a/component/pear/module/card.js +++ b/component/pear/module/card.js @@ -5,98 +5,263 @@ layui.define(['table', 'laypage','jquery', 'element'], function(exports) { $ = layui.jquery, element = layui.element, laypage = layui.laypage; + + var _instances = {}; // 记录所有实例 + + var defaultOption = { + elem: "#currentTableId",// 构建的模型 + url: "",// 数据 url 连接 + loading: true,//是否加载 + limit: 0, //每页数量默认是每行数量的双倍 + linenum: 4, //每行数量 2,3,4,6 + currentPage: 1,//当前页 + data:[], //静态数据 + limits:[], //页码 + page: true, //是否分页 + layout: ['count', 'prev', 'page', 'next','limit', 'skip'],//分页控件 + request: { + pageName: 'page' //页码的参数名称,默认:page + , limitName: 'limit' //每页数据量的参数名,默认:limit + , idName: 'id' //主键名称,默认:id + , titleName: 'title' //标题名称,默认:title + , imageName: 'image' //图片地址,默认:image + , remarkName: 'remark' //备注名称,默认:remark + , timeName: 'time' //时间名称,默认:time + }, + response: { + statusName: 'code' //规定数据状态的字段名称,默认:code + , statusCode: 0 //规定成功的状态码,默认:0 + , msgName: 'msg' //规定状态信息的字段名称,默认:msg + , countName: 'count' //规定数据总数的字段名称,默认:count + , dataName: 'data' //规定数据列表的字段名称,默认:data + }, + clickItem: function(data){}, + done: function () { - var pearCard = function(opt) { - this.option = opt; + } }; - - pearCard.prototype.render = function(opt) { - var option = { - // 构建的模型 - elem: opt.elem, - // 数据 url 连接 - url: opt.url, - // lineSize 每行的个数 - lineSize: opt.lineSize ? opt.lineSize : 4, - // 共多少个 - pageSize: opt.pageSize ? opt.pageSize : 12, - // 当前页 - currentPage: opt.currentSize ? opt.currentSize : 0, - // 完 成 函 数 - done: opt.done ? opt.done : function() { - alert("跳转页面"); + + var card = function(opt) { + _instances[opt.elem.substring(1)] = this; + this.reload(opt); + }; + card.prototype.initOptions = function (opt) { + this.option = $.extend(true, {}, defaultOption, opt); + if (!this.option.limit || this.option.limit == 0) { + this.option.limit = this.option.linenum * 2; + } + if (!this.option.limits || this.option.limits.length == 0) { + this.option.limits = [this.option.limit]; + } + }; + + card.prototype.init = function () { + var option = this.option; + var url = option.url; + var html = ""; + html += option.loading == true ? '
没有数据
"; + } + $(option.elem).html(html); + if (option.page) { + laypage.render({ + elem: 'cardpage' + , count: option.count, limit: option.limit, limits: option.limits, curr: option.currentPage + , layout: option.layout + , jump: function (obj, first) { + option.limit = obj.limit; + option.currentPage = obj.curr; + if (!first) { + _instances[option.elem.substring(1)].reload(option); + } + } + }); + } + }); + } + else { + if (!option.alldata) { + option.alldata = option.data; + } + if (option.page) { + var data = []; + option.count = option.alldata.length; + for (var i = (option.currentPage - 1) * option.limit; i < option.currentPage * option.limit && i没有数据
"; + } + $(option.elem).html(html); + if (option.page) { + laypage.render({ + elem: 'cardpage' + , count: option.count, limit: option.limit, limits: option.limits, curr: option.currentPage + , layout: option.layout + , jump: function (obj, first) { + option.limit = obj.limit; + option.currentPage = obj.curr; + if (!first) { + _instances[option.elem.substring(1)].reload(option); + } + } + }); } } - // 根 据 请 求 方 式 获 取 数 据 - if (option.url != null) { - // 复制数据 - option.data = getData(option.url).data; - } - - // 根据结果进行相应结构的创建 - var html = createComponent(option.data); - - $(option.elem).html(html); - - // 初始化分页组件 - laypage.render({ - elem: 'cardpage' - ,count: 100 - ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'] - ,jump: function(obj){ - console.log(obj) - } - }); - - return new pearCard(option); } + + card.prototype.reload = function (opt) { + this.initOptions(this.option ? $.extend(true, this.option, opt) : opt); + this.init(); // 初始化表格 + } - function createComponent(data) { - var html = "
diff --git a/view/document/card.html b/view/document/card.html index b64ad9e..4f98816 100644 --- a/view/document/card.html +++ b/view/document/card.html @@ -2,58 +2,77 @@
-
- +
+ -