xadmin.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. $(function() {
  2. //加载弹出层
  3. layui.use(["form", "element"], function() {
  4. layer = layui.layer;
  5. element = layui.element;
  6. });
  7. var userAccount =sessionStorage.getItem("userAccount")
  8. $("#username").text(userAccount)
  9. //触发事件
  10. var tab = {
  11. tabAdd: function(title, url, id) {
  12. //新增一个Tab项
  13. element.tabAdd("xbs_tab", {
  14. title: title,
  15. content:
  16. '<iframe tab-id="' +
  17. id +
  18. '" frameborder="0" src="' +
  19. url +
  20. '" scrolling="yes" class="x-iframe"></iframe>',
  21. id: id
  22. });
  23. // 向上级窗口传值
  24. window.xframe = $(".x-iframe");
  25. },
  26. tabDelete: function(othis) {
  27. //删除指定Tab项
  28. element.tabDelete("xbs_tab", "44"); //删除:“商品管理”
  29. othis.addClass("layui-btn-disabled");
  30. },
  31. tabChange: function(id) {
  32. //切换到指定Tab项
  33. element.tabChange("xbs_tab", id); //切换到:用户管理
  34. }
  35. };
  36. tableCheck = {
  37. init: function() {
  38. $(".layui-form-checkbox").click(function(event) {
  39. if ($(this).hasClass("layui-form-checked")) {
  40. $(this).removeClass("layui-form-checked");
  41. if ($(this).hasClass("header")) {
  42. $(".layui-form-checkbox").removeClass("layui-form-checked");
  43. }
  44. } else {
  45. $(this).addClass("layui-form-checked");
  46. if ($(this).hasClass("header")) {
  47. $(".layui-form-checkbox").addClass("layui-form-checked");
  48. }
  49. }
  50. });
  51. },
  52. getData: function() {
  53. var obj = $(".layui-form-checked").not(".header");
  54. var arr = [];
  55. obj.each(function(index, el) {
  56. arr.push(obj.eq(index).attr("data-id"));
  57. });
  58. return arr;
  59. }
  60. };
  61. //开启表格多选
  62. tableCheck.init();
  63. $(".container .left_open i").click(function(event) {
  64. if ($(".left-nav").css("left") == "0px") {
  65. $(".left-nav").animate({ left: "-221px" }, 100);
  66. $(".page-content").animate({ left: "0px" }, 100);
  67. $(".page-content-bg").hide();
  68. } else {
  69. $(".left-nav").animate({ left: "0px" }, 100);
  70. $(".page-content").animate({ left: "221px" }, 100);
  71. if ($(window).width() < 768) {
  72. $(".page-content-bg").show();
  73. }
  74. }
  75. });
  76. $(".page-content-bg").click(function(event) {
  77. $(".left-nav").animate({ left: "-221px" }, 100);
  78. $(".page-content").animate({ left: "0px" }, 100);
  79. $(this).hide();
  80. });
  81. $(".layui-tab-close").click(function(event) {
  82. $(".layui-tab-title li")
  83. .eq(0)
  84. .find("i")
  85. .remove();
  86. });
  87. $("tbody.x-cate tr[fid!='0']").hide();
  88. // 栏目多级显示效果
  89. $(".x-show").click(function() {
  90. if ($(this).attr("status") == "true") {
  91. $(this).html("&#xe625;");
  92. $(this).attr("status", "false");
  93. cateId = $(this)
  94. .parents("tr")
  95. .attr("cate-id");
  96. $("tbody tr[fid=" + cateId + "]").show();
  97. } else {
  98. cateIds = [];
  99. $(this).html("&#xe623;");
  100. $(this).attr("status", "true");
  101. cateId = $(this)
  102. .parents("tr")
  103. .attr("cate-id");
  104. getCateId(cateId);
  105. for (var i in cateIds) {
  106. $("tbody tr[cate-id=" + cateIds[i] + "]")
  107. .hide()
  108. .find(".x-show")
  109. .html("&#xe623;")
  110. .attr("status", "true");
  111. }
  112. }
  113. });
  114. //左侧菜单效果
  115. // $('#content').bind("click",function(event){
  116. // 向上级窗口传值
  117. window.windowTab = tab;
  118. window.xframe = $(".x-iframe");
  119. $(".left-nav #nav li").click(function(event) {
  120. if ($(this).children(".sub-menu").length) {
  121. if ($(this).hasClass("open")) {
  122. $(this).removeClass("open");
  123. $(this)
  124. .find(".nav_right")
  125. .html("&#xe697;");
  126. $(this)
  127. .children(".sub-menu")
  128. .stop()
  129. .slideUp();
  130. $(this)
  131. .siblings()
  132. .children(".sub-menu")
  133. .slideUp();
  134. } else {
  135. $(this).addClass("open");
  136. $(this)
  137. .children("a")
  138. .find(".nav_right")
  139. .html("&#xe6a6;");
  140. $(this)
  141. .children(".sub-menu")
  142. .stop()
  143. .slideDown();
  144. $(this)
  145. .siblings()
  146. .children(".sub-menu")
  147. .stop()
  148. .slideUp();
  149. $(this)
  150. .siblings()
  151. .find(".nav_right")
  152. .html("&#xe697;");
  153. $(this)
  154. .siblings()
  155. .removeClass("open");
  156. }
  157. } else {
  158. var url = $(this)
  159. .children("a")
  160. .attr("_href");
  161. var title = $(this)
  162. .find("cite")
  163. .html();
  164. var index = $(".left-nav #nav li").index($(this));
  165. for (var i = 0; i < $(".x-iframe").length; i++) {
  166. if (
  167. $(".x-iframe")
  168. .eq(i)
  169. .attr("tab-id") ==
  170. index + 1
  171. ) {
  172. tab.tabChange(index + 1);
  173. event.stopPropagation();
  174. return;
  175. }
  176. }
  177. tab.tabAdd(title, url, index + 1);
  178. tab.tabChange(index + 1);
  179. }
  180. event.stopPropagation();
  181. });
  182. });
  183. var cateIds = [];
  184. function getCateId(cateId) {
  185. $("tbody tr[fid=" + cateId + "]").each(function(index, el) {
  186. id = $(el).attr("cate-id");
  187. cateIds.push(id);
  188. getCateId(id);
  189. });
  190. }
  191. /*弹出层*/
  192. /*
  193. 参数解释:
  194. title 标题
  195. url 请求的url
  196. id 需要操作的数据id
  197. w 弹出层宽度(缺省调默认值)
  198. h 弹出层高度(缺省调默认值)
  199. */
  200. function x_admin_show(title, url, w, h, endCallback) {
  201. if (title == null || title == "") {
  202. title = false;
  203. }
  204. if (url == null || url == "") {
  205. url = "404.html";
  206. }
  207. if (w == null || w == "") {
  208. w = $(window).width() * 0.9;
  209. }
  210. if (h == null || h == "") {
  211. h = $(window).height() - 50;
  212. }
  213. layer.open({
  214. type: 2,
  215. area: [w + "px", h + "px"],
  216. fix: false, //不固定
  217. maxmin: true,
  218. shadeClose: true,
  219. shade: 0.4,
  220. title: title,
  221. content: url,
  222. end: endCallback
  223. });
  224. }
  225. /*关闭弹出框口*/
  226. function x_admin_close() {
  227. var index = parent.layer.getFrameIndex(window.name);
  228. parent.layer.close(index);
  229. }