控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. layui.define(['jquery', 'element'], function(exports) {
  2. "use strict";
  3. var MOD_NAME = 'tab',
  4. $ = layui.jquery,
  5. element = layui.element;
  6. var pearTab = function(opt) {
  7. this.option = opt;
  8. };
  9. var tabData = new Array();
  10. var tabDataCurrent = 0;
  11. var contextTabDOM;
  12. pearTab.prototype.render = function(opt) {
  13. var option = {
  14. elem: opt.elem,
  15. data: opt.data,
  16. tool: opt.tool,
  17. roll: opt.roll,
  18. index: opt.index,
  19. width: opt.width,
  20. height: opt.height,
  21. tabMax: opt.tabMax,
  22. session: opt.session ? opt.session : false,
  23. preload: opt.preload ? opt.preload : false,
  24. closeEvent: opt.closeEvent,
  25. success: opt.success ? opt.success : function(id) {}
  26. }
  27. if (option.session) {
  28. if (sessionStorage.getItem(option.elem + "-pear-tab-data") != null) {
  29. tabData = JSON.parse(sessionStorage.getItem(option.elem + "-pear-tab-data"));
  30. option.data = JSON.parse(sessionStorage.getItem(option.elem + "-pear-tab-data"));
  31. tabDataCurrent = sessionStorage.getItem(option.elem + "-pear-tab-data-current");
  32. tabData.forEach(function(item, index) {
  33. if (item.id == tabDataCurrent) {
  34. option.index = index;
  35. }
  36. })
  37. } else {
  38. tabData = opt.data;
  39. }
  40. }
  41. var lastIndex;
  42. var tab = createTab(option);
  43. $("#" + option.elem).html(tab);
  44. $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-prev").click(function() {
  45. rollPage("left", option);
  46. })
  47. $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-next").click(function() {
  48. rollPage("right", option);
  49. })
  50. element.init();
  51. toolEvent(option);
  52. $("#" + option.elem).width(opt.width);
  53. $("#" + option.elem).height(opt.height);
  54. $("#" + option.elem).css({
  55. position: "relative"
  56. });
  57. closeEvent(option);
  58. option.success(sessionStorage.getItem(option.elem + "-pear-tab-data-current"));
  59. $("body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title").on("contextmenu", "li",
  60. function(e) {
  61. // 获取当前元素位置
  62. var top = e.clientY;
  63. var left = e.clientX;
  64. var menuWidth = 100;
  65. var currentId = $(this).attr("lay-id");
  66. var menu = "<ul><li class='item' id='" + option.elem +
  67. "closeThis'>关闭当前</li><li class='item' id='" + option.elem +
  68. "closeOther'>关闭其他</li><li class='item' id='" + option.elem +
  69. "closeAll'>关闭所有</li></ul>";
  70. contextTabDOM = $(this);
  71. var isOutsideBounds = (left + menuWidth) > $(window).width();
  72. if (isOutsideBounds) {
  73. left = $(window).width() - menuWidth;
  74. }
  75. // 初始化
  76. layer.open({
  77. type: 1,
  78. title: false,
  79. shade: false,
  80. skin: 'pear-tab-menu',
  81. closeBtn: false,
  82. area: [menuWidth + 'px', '108px'],
  83. fixed: true,
  84. anim: false,
  85. isOutAnim: false,
  86. offset: [top, left],
  87. content: menu, //iframe的url,
  88. success: function(layero, index) {
  89. layer.close(lastIndex);
  90. lastIndex = index;
  91. menuEvent(option, index);
  92. var timer;
  93. $(layero).on('mouseout', function() {
  94. timer = setTimeout(function() {
  95. layer.close(index);
  96. }, 30)
  97. });
  98. $(layero).on('mouseover', function() {
  99. clearTimeout(timer);
  100. });
  101. // 清除 item 右击
  102. $(layero).on('contextmenu', function() {
  103. return false;
  104. })
  105. }
  106. });
  107. return false;
  108. })
  109. mousewheelAndTouchmoveHandler(option)
  110. return new pearTab(option);
  111. }
  112. pearTab.prototype.click = function(callback) {
  113. var elem = this.option.elem;
  114. var option = this.option;
  115. element.on('tab(' + this.option.elem + ')', function(data) {
  116. var id = $("#" + elem + " .layui-tab-title .layui-this").attr("lay-id");
  117. sessionStorage.setItem(option.elem + "-pear-tab-data-current", id);
  118. if (!option.preload) {
  119. var $iframe = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content").find(
  120. "iframe[id='" + id + "']");
  121. var iframeUrl = $iframe.attr("src");
  122. if (!iframeUrl || iframeUrl === "about:blank") {
  123. // 获取 url 并重载
  124. tabData.forEach(function(item, index) {
  125. if (item.id === id) {
  126. iframeUrl = item.url;
  127. }
  128. })
  129. tabIframeLoading(elem);
  130. $iframe.attr("src", iframeUrl);
  131. }
  132. }
  133. callback(id);
  134. });
  135. }
  136. pearTab.prototype.positionTab = function() {
  137. var $tabTitle = $('.layui-tab[lay-filter=' + this.option.elem + '] .layui-tab-title');
  138. var autoLeft = 0;
  139. $tabTitle.children("li").each(function() {
  140. if ($(this).hasClass('layui-this')) {
  141. return false;
  142. } else {
  143. autoLeft += $(this).outerWidth();
  144. }
  145. });
  146. $tabTitle.animate({
  147. scrollLeft: autoLeft - $tabTitle.width() / 3
  148. }, 200);
  149. }
  150. pearTab.prototype.clear = function() {
  151. sessionStorage.removeItem(this.option.elem + "-pear-tab-data");
  152. sessionStorage.removeItem(this.option.elem + "-pear-tab-data-current");
  153. }
  154. pearTab.prototype.addTab = function(opt) {
  155. var title = '';
  156. if (opt.close) {
  157. title += '<span class="pear-tab-active"></span><span class="able-close title">' + opt.title +
  158. '</span><i class="layui-icon layui-unselect layui-tab-close">ဆ</i>';
  159. } else {
  160. title += '<span class="pear-tab-active"></span><span class="disable-close title">' + opt.title +
  161. '</span><i class="layui-icon layui-unselect layui-tab-close">ဆ</i>';
  162. }
  163. element.tabAdd(this.option.elem, {
  164. title: title,
  165. content: '<iframe id="' + opt.id + '" data-frameid="' + opt.id +
  166. '" scrolling="auto" frameborder="0" src="' +
  167. opt.url + '" style="width:100%;height:100%;" allowfullscreen="true"></>',
  168. id: opt.id
  169. });
  170. tabData.push(opt);
  171. sessionStorage.setItem(this.option.elem + "-pear-tab-data", JSON.stringify(tabData));
  172. sessionStorage.setItem(this.option.elem + "-pear-tab-data-current", opt.id);
  173. element.tabChange(this.option.elem, opt.id);
  174. }
  175. var index = 0;
  176. // 根据过滤 fliter 标识, 重置选项卡标题
  177. pearTab.prototype.changeTabTitleById = function(elem, id, title) {
  178. var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title [lay-id='" + id +
  179. "'] .title");
  180. currentTab.html(title);
  181. }
  182. // 根据过滤 filter 标识, 删除指定选项卡
  183. pearTab.prototype.delTabByElem = function(elem, id, callback) {
  184. var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title [lay-id='" + id + "']");
  185. if (currentTab.find("span").is(".able-close")) {
  186. tabDelete(elem, id, callback);
  187. }
  188. }
  189. // 根据过滤 filter 标识, 删除其他选项卡
  190. pearTab.prototype.delOtherTabByElem = function(elem, callback) {
  191. var currentId = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this").attr(
  192. "lay-id");
  193. var tabtitle = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li");
  194. $.each(tabtitle, function(i) {
  195. if ($(this).attr("lay-id") != currentId) {
  196. if ($(this).find("span").is(".able-close")) {
  197. tabDelete(elem, $(this).attr("lay-id"), callback);
  198. }
  199. }
  200. })
  201. }
  202. // 根据过滤 filter 标识, 删除全部选项卡
  203. pearTab.prototype.delAllTabByElem = function(elem, callback) {
  204. var currentId = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this").attr(
  205. "lay-id");
  206. var tabtitle = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li");
  207. $.each(tabtitle, function(i) {
  208. if ($(this).find("span").is(".able-close")) {
  209. tabDelete(elem, $(this).attr("lay-id"), callback);
  210. }
  211. })
  212. }
  213. // 根据过滤 filter 标识, 删除当前选项卡
  214. pearTab.prototype.delCurrentTabByElem = function(elem, callback) {
  215. var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this");
  216. if (currentTab.find("span").is(".able-close")) {
  217. var currentId = currentTab.attr("lay-id");
  218. tabDelete(elem, currentId, callback);
  219. }
  220. }
  221. // 通过过滤 filter 标识, 新增标签页
  222. pearTab.prototype.addTabOnlyByElem = function(elem, opt, time) {
  223. var title = '';
  224. if (opt.close) {
  225. title += '<span class="pear-tab-active"></span><span class="able-close title">' + opt.title +
  226. '</span><i class="layui-icon layui-unselect layui-tab-close">ဆ</i>'
  227. } else {
  228. title += '<span class="pear-tab-active"></span><span class="disable-close title">' + opt.title +
  229. '</span><i class="layui-icon layui-unselect layui-tab-close">ဆ</i>'
  230. }
  231. if ($(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li[lay-id]").length <= 0) {
  232. element.tabAdd(elem, {
  233. title: title,
  234. content: '<iframe id="' + opt.id + '" data-frameid="' + opt.id +
  235. '" scrolling="auto" frameborder="0" src="' +
  236. opt.url + '" style="width:100%;height:100%;" allowfullscreen="true"></iframe>',
  237. id: opt.id
  238. });
  239. if (time != false && time != 0) {
  240. tabIframeLoading(elem, opt.id);
  241. }
  242. tabData.push(opt);
  243. sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
  244. } else {
  245. var isData = false;
  246. $.each($(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li[lay-id]"), function() {
  247. if ($(this).attr("lay-id") == opt.id) {
  248. isData = true;
  249. }
  250. })
  251. if (isData == false) {
  252. element.tabAdd(elem, {
  253. title: title,
  254. content: '<iframe id="' + opt.id + '" data-frameid="' + opt.id +
  255. '" scrolling="auto" frameborder="0" src="' +
  256. opt.url + '" style="width:100%;height:100%;" allowfullscreen="true"></iframe>',
  257. id: opt.id
  258. });
  259. if (time != false && time != 0) {
  260. tabIframeLoading(elem, opt.id);
  261. }
  262. tabData.push(opt);
  263. sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
  264. }
  265. }
  266. sessionStorage.setItem(elem + "-pear-tab-data-current", opt.id);
  267. element.tabChange(elem, opt.id);
  268. }
  269. /** 添 加 唯 一 选 项 卡 */
  270. pearTab.prototype.addTabOnly = function(opt, time) {
  271. var title = '';
  272. if (opt.close) {
  273. title += '<span class="pear-tab-active"></span><span class="able-close title">' + opt.title +
  274. '</span><i class="layui-icon layui-unselect layui-tab-close">ဆ</i>';
  275. } else {
  276. title += '<span class="pear-tab-active"></span><span class="disable-close title">' + opt.title +
  277. '</span><i class="layui-icon layui-unselect layui-tab-close">ဆ</i>';
  278. }
  279. if ($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]").length <=
  280. 0) {
  281. element.tabAdd(this.option.elem, {
  282. title: title,
  283. content: '<iframe id="' + opt.id + '" data-frameid="' + opt.id +
  284. '" scrolling="auto" frameborder="0" src="' +
  285. opt.url + '" style="width:100%;height:100%;" allowfullscreen="true"></iframe>',
  286. id: opt.id
  287. });
  288. if (time != false && time != 0) {
  289. tabIframeLoading(this.option.elem, opt.id);
  290. }
  291. tabData.push(opt);
  292. sessionStorage.setItem(this.option.elem + "-pear-tab-data", JSON.stringify(tabData));
  293. sessionStorage.setItem(this.option.elem + "-pear-tab-data-current", opt.id);
  294. } else {
  295. var isData = false;
  296. $.each($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]"),
  297. function() {
  298. if ($(this).attr("lay-id") == opt.id) {
  299. isData = true;
  300. }
  301. })
  302. if (isData == false) {
  303. if (this.option.tabMax != false) {
  304. if ($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]")
  305. .length >= this.option.tabMax) {
  306. layer.msg("最多打开" + this.option.tabMax + "个标签页", {
  307. icon: 2,
  308. time: 1000,
  309. shift: 6
  310. });
  311. return false;
  312. }
  313. }
  314. element.tabAdd(this.option.elem, {
  315. title: title,
  316. content: '<iframe id="' + opt.id + '" data-frameid="' + opt.id +
  317. '" scrolling="auto" frameborder="0" src="' +
  318. opt.url + '" style="width:100%;height:100%;" allowfullscreen="true"></iframe>',
  319. id: opt.id
  320. });
  321. if (time != false && time != 0) {
  322. tabIframeLoading(this.option.elem, opt.id);
  323. }
  324. tabData.push(opt);
  325. sessionStorage.setItem(this.option.elem + "-pear-tab-data", JSON.stringify(tabData));
  326. sessionStorage.setItem(this.option.elem + "-pear-tab-data-current", opt.id);
  327. }
  328. }
  329. element.tabChange(this.option.elem, opt.id);
  330. sessionStorage.setItem(this.option.elem + "-pear-tab-data-current", opt.id);
  331. }
  332. // 刷 新 指 定 的 选 项 卡
  333. pearTab.prototype.refresh = function(time) {
  334. // 刷 新 指 定 的 选 项 卡
  335. var $iframe = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-content .layui-show")
  336. .find("iframe");
  337. if (time != false && time != 0) {
  338. tabIframeLoading(this.option.elem);
  339. }
  340. $iframe.attr("src", $iframe.attr("src"));
  341. }
  342. function tabIframeLoading(elem, id) {
  343. var load = '<div id="pear-tab-loading' + index + '" class="pear-tab-loading">' +
  344. '<div class="ball-loader">' +
  345. '<span></span><span></span><span></span><span></span>' +
  346. '</div>' +
  347. '</div>'
  348. var $iframe = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content .layui-show").find("iframe");
  349. if (id) {
  350. $iframe = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-content").find("iframe[id='" + id +
  351. "']");
  352. }
  353. $iframe.parent().append(load);
  354. var pearLoad = $("#" + elem).find("#pear-tab-loading" + index);
  355. pearLoad.css({
  356. display: "block"
  357. });
  358. index++;
  359. $iframe.on("load", function() {
  360. pearLoad.fadeOut(1000, function() {
  361. pearLoad.remove();
  362. });
  363. })
  364. }
  365. function tabDelete(elem, id, callback, option) {
  366. //根据 elem id 来删除指定的 layui title li
  367. var tabTitle = $(".layui-tab[lay-filter='" + elem + "']").find(".layui-tab-title");
  368. // 删除指定 id 的 title
  369. var removeTab = tabTitle.find("li[lay-id='" + id + "']");
  370. var nextNode = removeTab.next("li");
  371. if (!removeTab.hasClass("layui-this")) {
  372. removeTab.remove();
  373. var tabContent = $(".layui-tab[lay-filter='" + elem + "']").find("iframe[id='" + id + "']")
  374. .parent();
  375. tabContent.remove();
  376. tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-data"));
  377. tabDataCurrent = sessionStorage.getItem(elem + "-pear-tab-data-current");
  378. tabData = tabData.filter(function(item) {
  379. return item.id != id;
  380. })
  381. sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
  382. return false;
  383. }
  384. var currId;
  385. if (nextNode.length) {
  386. nextNode.addClass("layui-this");
  387. currId = nextNode.attr("lay-id");
  388. $("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
  389. } else {
  390. var prevNode = removeTab.prev("li");
  391. prevNode.addClass("layui-this");
  392. currId = prevNode.attr("lay-id");
  393. $("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
  394. }
  395. callback(currId);
  396. tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-data"));
  397. tabDataCurrent = sessionStorage.getItem(elem + "-pear-tab-data-current");
  398. tabData = tabData.filter(function(item) {
  399. return item.id != id;
  400. })
  401. sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
  402. sessionStorage.setItem(elem + "-pear-tab-data-current", currId);
  403. removeTab.remove();
  404. // 删除 content
  405. var tabContent = $(".layui-tab[lay-filter='" + elem + "']").find("iframe[id='" + id + "']").parent();
  406. // 删除
  407. tabContent.remove();
  408. }
  409. function createTab(option) {
  410. var type = "";
  411. if (option.roll == true) {
  412. type = "layui-tab-roll";
  413. }
  414. if (option.tool != false) {
  415. type = "layui-tab-tool";
  416. }
  417. if (option.roll == true && option.tool != false) {
  418. type = "layui-tab-rollTool";
  419. }
  420. var tab = '<div class="pear-tab ' + type + ' layui-tab" lay-filter="' + option.elem +
  421. '" lay-allowClose="true">';
  422. var title = '<ul class="layui-tab-title">';
  423. var content = '<div class="layui-tab-content">';
  424. var control =
  425. '<div class="layui-tab-control"><li class="layui-tab-prev layui-icon layui-icon-left"></li><li class="layui-tab-next layui-icon layui-icon-right"></li><li class="layui-tab-tool layui-icon layui-icon-down"><ul class="layui-nav" lay-filter=""><li class="layui-nav-item"><a href="javascript:;"></a><dl class="layui-nav-child">';
  426. // 处 理 选 项 卡 头 部
  427. var index = 0;
  428. $.each(option.data, function(i, item) {
  429. var TitleItem = '';
  430. if (option.index == index) {
  431. TitleItem += '<li lay-id="' + item.id +
  432. '" class="layui-this"><span class="pear-tab-active"></span>';
  433. } else {
  434. TitleItem += '<li lay-id="' + item.id + '" ><span class="pear-tab-active"></span>';
  435. }
  436. if (item.close) {
  437. // 当 前 选 项 卡 可 以 关 闭
  438. TitleItem += '<span class="able-close title">' + item.title + '</span>';
  439. } else {
  440. // 当 前 选 项 卡 不 允 许 关 闭
  441. TitleItem += '<span class="disable-close title">' + item.title + '</span>';
  442. }
  443. TitleItem += '<i class="layui-icon layui-unselect layui-tab-close">ဆ</i></li>';
  444. title += TitleItem;
  445. if (option.index == index) {
  446. // 处 理 显 示 内 容
  447. content += '<div class="layui-show layui-tab-item"><iframe id="' + item.id +
  448. '" data-frameid="' + item.id +
  449. '" src="' + item.url +
  450. '" frameborder="no" border="0" marginwidth="0" marginheight="0" style="width: 100%;height: 100%;" allowfullscreen="true"></iframe></div>'
  451. } else {
  452. if (!option.preload) {
  453. item.url = "about:blank";
  454. }
  455. // 处 理 显 示 内 容
  456. content += '<div class="layui-tab-item"><iframe id="' + item.id + '" data-frameid="' +
  457. item.id + '" src="' +
  458. item.url +
  459. '" frameborder="no" border="0" marginwidth="0" marginheight="0" style="width: 100%;height: 100%;" allowfullscreen="true"></iframe></div>'
  460. }
  461. index++;
  462. });
  463. title += '</ul>';
  464. content += '</div>';
  465. control += '<dd id="closeThis"><a href="#">关 闭 当 前</a></dd>'
  466. control += '<dd id="closeOther"><a href="#">关 闭 其 他</a></dd>'
  467. control += '<dd id="closeAll"><a href="#">关 闭 全 部</a></dd>'
  468. control += '</dl></li></ul></li></div>';
  469. tab += title;
  470. tab += control;
  471. tab += content;
  472. tab += '</div>';
  473. tab += ''
  474. return tab;
  475. }
  476. function rollPage(d, option) {
  477. var $tabTitle = $('#' + option.elem + ' .layui-tab-title');
  478. var left = $tabTitle.scrollLeft();
  479. if ('left' === d) {
  480. $tabTitle.animate({
  481. scrollLeft: left - 450
  482. }, 200);
  483. } else {
  484. $tabTitle.animate({
  485. scrollLeft: left + 450
  486. }, 200);
  487. }
  488. }
  489. function closeEvent(option) {
  490. $(".layui-tab[lay-filter='" + option.elem + "']").on("click", ".layui-tab-close", function() {
  491. var layid = $(this).parent().attr("lay-id");
  492. tabDelete(option.elem, layid, option.closeEvent, option);
  493. })
  494. }
  495. function menuEvent(option, index) {
  496. $("#" + option.elem + "closeThis").click(function() {
  497. var currentTab = contextTabDOM;
  498. if (currentTab.find("span").is(".able-close")) {
  499. var currentId = currentTab.attr("lay-id");
  500. tabDelete(option.elem, currentId, option.closeEvent, option);
  501. } else {
  502. layer.msg("当前页面不允许关闭", {
  503. icon: 3,
  504. time: 800
  505. })
  506. }
  507. layer.close(index);
  508. })
  509. $("#" + option.elem + "closeOther").click(function() {
  510. var currentId = contextTabDOM.attr("lay-id");
  511. var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
  512. $.each(tabtitle, function(i) {
  513. if ($(this).attr("lay-id") != currentId) {
  514. if ($(this).find("span").is(".able-close")) {
  515. tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
  516. option);
  517. }
  518. }
  519. })
  520. layer.close(index);
  521. })
  522. $("#" + option.elem + "closeAll").click(function() {
  523. var currentId = contextTabDOM.attr("lay-id");
  524. var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
  525. $.each(tabtitle, function(i) {
  526. if ($(this).find("span").is(".able-close")) {
  527. tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
  528. }
  529. })
  530. layer.close(index);
  531. })
  532. }
  533. function toolEvent(option) {
  534. $("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeThis", function() {
  535. var currentTab = $(".layui-tab[lay-filter='" + option.elem +
  536. "'] .layui-tab-title .layui-this");
  537. if (currentTab.find("span").is(".able-close")) {
  538. var currentId = currentTab.attr("lay-id");
  539. tabDelete(option.elem, currentId, option.closeEvent, option);
  540. } else {
  541. layer.msg("当前页面不允许关闭", {
  542. icon: 3,
  543. time: 800
  544. })
  545. }
  546. })
  547. $("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeOther", function() {
  548. var currentId = $(".layui-tab[lay-filter='" + option.elem +
  549. "'] .layui-tab-title .layui-this").attr("lay-id");
  550. var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
  551. $.each(tabtitle, function(i) {
  552. if ($(this).attr("lay-id") != currentId) {
  553. if ($(this).find("span").is(".able-close")) {
  554. tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
  555. option);
  556. }
  557. }
  558. })
  559. })
  560. $("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeAll", function() {
  561. var currentId = $(".layui-tab[lay-filter='" + option.elem +
  562. "'] .layui-tab-title .layui-this").attr("lay-id");
  563. var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
  564. $.each(tabtitle, function(i) {
  565. if ($(this).find("span").is(".able-close")) {
  566. tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
  567. }
  568. })
  569. })
  570. }
  571. function mousewheelAndTouchmoveHandler(option) {
  572. var $bodyTab = $("body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title")
  573. var $tabTitle = $('#' + option.elem + ' .layui-tab-title');
  574. var mouseScrollStep = 100
  575. // 鼠标滚轮
  576. $bodyTab.on("mousewheel DOMMouseScroll", function(e) {
  577. e.originalEvent.preventDefault()
  578. var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? "top" :
  579. "down")) || // chrome & ie
  580. (e.originalEvent.detail && (e.originalEvent.detail > 0 ? "down" : "top")); // firefox
  581. var scrollLeft = $tabTitle.scrollLeft();
  582. if (delta === "top") {
  583. scrollLeft -= mouseScrollStep
  584. } else if (delta === "down") {
  585. scrollLeft += mouseScrollStep
  586. }
  587. $tabTitle.scrollLeft(scrollLeft)
  588. });
  589. // 触摸移动
  590. var touchX = 0;
  591. $bodyTab.on("touchstart", function(e) {
  592. var touch = e.originalEvent.targetTouches[0];
  593. touchX = touch.pageX
  594. })
  595. $bodyTab.on("touchmove", function(e) {
  596. var event = e.originalEvent;
  597. if (event.targetTouches.length > 1) return;
  598. event.preventDefault();
  599. var touch = event.targetTouches[0];
  600. var distanceX = touchX - touch.pageX
  601. var scrollLeft = $tabTitle.scrollLeft();
  602. touchX = touch.pageX
  603. $tabTitle.scrollLeft(scrollLeft += distanceX)
  604. });
  605. }
  606. exports(MOD_NAME, new pearTab());
  607. })