vip_table.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Created by Administrator on 2017/08/25.
  3. * @name: vip-admin 后台模板 表格JS功能
  4. * @author: 随丶
  5. */
  6. layui.define(['layer', 'element'], function (exports) {
  7. var $ = layui.jquery;
  8. // 封装方法
  9. var mod = {
  10. // 删除公共方法 deleteAll(ids,请求的url,操作成功跳转url,操作失败跳转url)
  11. deleteAll: function (ids, url, sUrl, eUrl) {
  12. // ids不能为空
  13. if (ids == null || ids == '') {
  14. layer.msg('请选择要删除的数据', {time: 2000});
  15. return false;
  16. } else {
  17. layer.confirm('确认删除选中数据?', {
  18. title: '删除',
  19. btn: ['确认', '取消'] // 按钮
  20. }, function (index, layero) {
  21. // 确认
  22. $.post(url, {ids: ids}, function (res) {
  23. // 大于0表示删除成功
  24. if (res.status > 0) {
  25. // 提示信息并跳转
  26. layer.msg(res.msg, {time: 1500}, function () {
  27. location.href = sUrl;
  28. })
  29. } else {
  30. // 提示信息并跳转
  31. layer.msg(res.msg, {time: 1500}, function () {
  32. location.href = eUrl;
  33. })
  34. }
  35. });
  36. }, function (index) {
  37. // 关闭
  38. layer.close(index);
  39. });
  40. }
  41. }
  42. // 转换时间戳为日期时间(时间戳,是否只显示年月日时分,8)
  43. ,unixToDate: function (unixTime, isFull, timeZone) {
  44. if (unixTime == '' || unixTime == null) {
  45. return '';
  46. }
  47. if (typeof (timeZone) == 'number') {
  48. unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
  49. }
  50. var time = new Date(unixTime * 1000);
  51. var ymdhis = "";
  52. var year, month, date, hours, minutes, seconds;
  53. if (time.getUTCFullYear() < 10) {
  54. year = '0' + time.getUTCFullYear();
  55. } else {
  56. year = time.getUTCFullYear();
  57. }
  58. if ((time.getUTCMonth() + 1) < 10) {
  59. month = '0' + (time.getUTCMonth() + 1);
  60. } else {
  61. month = (time.getUTCMonth() + 1);
  62. }
  63. if (time.getUTCDate() < 10) {
  64. date = '0' + time.getUTCDate();
  65. } else {
  66. date = time.getUTCDate();
  67. }
  68. ymdhis += year + "-";
  69. ymdhis += month + "-";
  70. ymdhis += date;
  71. if (isFull === true) {
  72. if (time.getUTCHours() < 10) {
  73. hours = '0' + time.getUTCHours();
  74. } else {
  75. hours = time.getUTCHours();
  76. }
  77. if (time.getUTCMinutes() < 10) {
  78. minutes = '0' + time.getUTCMinutes();
  79. } else {
  80. minutes = time.getUTCMinutes();
  81. }
  82. if (time.getUTCSeconds() < 10) {
  83. seconds = '0' + time.getUTCSeconds();
  84. } else {
  85. seconds = time.getUTCSeconds();
  86. }
  87. ymdhis += " " + hours + ":";
  88. ymdhis += minutes;
  89. // ymdhis += seconds;
  90. }
  91. return ymdhis;
  92. }
  93. // 批量删除 返回需要的 ids
  94. ,getIds: function (o, str) {
  95. var obj = o.find('tbody tr td:first-child input[type="checkbox"]:checked');
  96. var list = '';
  97. obj.each(function (index, elem) {
  98. list += $(elem).attr(str) + ',';
  99. });
  100. // 去除最后一位逗号
  101. list = list.substr(0, (list.length - 1));
  102. return list;
  103. }
  104. // 获取高度
  105. ,getFullHeight: function(){
  106. return $(window).height() - ( $('.my-btn-box').outerHeight(true) ? $('.my-btn-box').outerHeight(true) + 35 : 40 );
  107. }
  108. };
  109. // 输出
  110. exports('vip_table', mod);
  111. });