e8d3ba0e5a5b5d75faf16b34bc47259da6cf45e6.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. layui.define(['layer'], function (exports) {
  2. var $ = layui.jquery;
  3. var obj = {
  4. ajax: function (url, type, dataType, data, callback) {
  5. $.ajax({
  6. url: url,
  7. type: type,
  8. dataType: dataType,
  9. data: data,
  10. success: function (data, startic) {
  11. if (data.code == 1) {
  12. parent.layer.alert(data.msg, {
  13. title: "提示", icon: 1, resize: false, zIndex: layer.zIndex
  14. }, function () {
  15. location.href = location.href;
  16. });
  17. //obj.layerAlertS(data.msg, '提示');
  18. }
  19. else {
  20. obj.layerAlertE(data.msg, '提示');
  21. }
  22. },
  23. error: function () {
  24. }
  25. });
  26. },
  27. Ajaxpage:function(curr){
  28. var key = $('#key').val();
  29. $.getJSON(url, {
  30. page: curr || 1,key:key
  31. }, function(data){ //data是后台返回过来的JSON数据
  32. $(".spiner-example").css('display','none'); //数据加载完关闭动画
  33. if(data==''){
  34. $("#article_list").html('<tr><td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td></tr>');
  35. }else{
  36. // article_list(data); //模板赋值
  37. var tpl = document.getElementById('arlist').innerHTML;
  38. laytpl(tpl).render(data, function(html){
  39. $("#article_list").html(html);
  40. //document.getElementById('article_list').innerHTML = html;
  41. });
  42. laypage({
  43. cont: $('#AjaxPage'),//容器。值支持id名、原生dom对象,jquery对象,
  44. pages:allpages,//总页数
  45. skip: true,//是否开启跳页
  46. skin: '#28b5d6',//分页组件颜色
  47. curr: curr || 1,
  48. groups: 5,//连续显示分页数
  49. jump: function(ob, first){
  50. if(!first){
  51. obj.Ajaxpage(ob.curr)
  52. }
  53. $('#allpage').html('第 '+ ob.curr +' 页,共 '+ ob.pages +' 页');
  54. }
  55. });
  56. }
  57. });
  58. },
  59. layerDel: function (title, text, url, type, dataType, data, callback) {
  60. parent.layer.confirm(text, {
  61. title: title,
  62. btnAlign: 'c',
  63. resize: false,
  64. icon: 3,
  65. btn: ['确定删除', '我再想想'],
  66. yes: function () {
  67. obj.ajax(url, type, dataType, data, callback);
  68. }
  69. });
  70. },
  71. layerState: function (title, text, url, type, dataType, data, callback) {
  72. parent.layer.confirm(text, {
  73. title: title,
  74. btnAlign: 'c',
  75. resize: false,
  76. icon: 3,
  77. btn: ['确定操作', '我再想想'],
  78. yes: function () {
  79. obj.ajax(url, type, dataType, data, callback);
  80. }
  81. });
  82. },
  83. //成功提示
  84. layerAlertS: function (text, title) {
  85. parent.layer.alert(text, { title: title, icon: 1, time: 5000, resize: false, zIndex: layer.zIndex });
  86. },
  87. //成功提示
  88. layerAlertSHref: function (text, title, url) {
  89. parent.layer.alert(text, { title: title, icon: 1, closeBtn:0, resize: false, zIndex: layer.zIndex }, function(){
  90. window.location.href = url;
  91. });
  92. },
  93. //错误提示
  94. layerAlertE: function (text, title) {
  95. parent.layer.alert(text, { title: title, icon: 2, time: 5000, resize: false, zIndex: layer.zIndex });
  96. },
  97. //信息提示
  98. layerAlertI: function (text) {
  99. parent.layer.alert(text, { time: 5000, resize: false, zIndex: layer.zIndex });
  100. return;
  101. },
  102. layerPrompt: function () {
  103. },
  104. //询问层
  105. layerConfirm: function () {
  106. },
  107. //退出系统
  108. signOut: function (title, text, url,rturl,type, dataType, data, callback) {
  109. parent.layer.confirm(text, {
  110. title: title,
  111. resize: false,
  112. btn: ['确定退出', '我再想想'],
  113. btnAlign: 'c',
  114. icon: 3
  115. }, function () {
  116. $.ajax({
  117. url: url,
  118. type: type,
  119. dataType: dataType,
  120. data: data,
  121. success: function (data, startic) {
  122. if (data.code == 1) {
  123. location.href = rturl;
  124. obj.layerAlertS(data.message, '提示');
  125. }
  126. else {
  127. obj.layerAlertE(data.message, '提示');
  128. }
  129. },
  130. error: function () {
  131. }
  132. });
  133. }, function () {
  134. });
  135. }
  136. }
  137. exports("common", obj);
  138. });