ok-admin/lib/okPlugins/okTab.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-05-16 16:52:43 +00:00
"use strict";
2019-05-18 08:50:45 +00:00
layui.define(["element", "okUtils"], function (exports) {
2019-05-17 07:42:31 +00:00
var element = window.top.layui.element;
2019-05-18 08:50:45 +00:00
var okUtils = layui.okUtils;
2019-05-16 16:52:43 +00:00
var $ = layui.jquery;
var okTab = {
2019-05-18 08:50:45 +00:00
add: function (title, path) {
2019-05-17 16:34:10 +00:00
// 参数校验
2019-05-18 08:50:45 +00:00
if (!okTab.parameterCheck(title, path)) {
2019-05-17 16:34:10 +00:00
return false;
}
2019-05-18 08:50:45 +00:00
// 根据path自动生成tabId值
var tabId = okUtils.str.hash(path)
2019-05-16 16:52:43 +00:00
// 去重复选项卡
2019-05-17 08:07:24 +00:00
var okFrame = $(".ok-frame", window.top.document);
2019-05-16 16:52:43 +00:00
for (var i = 0; i < okFrame.length; i++) {
var _tabId = okFrame.eq(i).attr("tab-id");
if (_tabId == tabId) {
element.tabChange("ok-tab", tabId);
event.stopPropagation();
return;
}
}
// 添加选项卡
element.tabAdd("ok-tab", {
title: title,
content: "<iframe src='" + path + "' tab-id='" + tabId + "' class='ok-frame' frameborder='0' scrolling='yes' width='100%' height='100%'></iframe>",
id: tabId
});
// 切换选项卡
element.tabChange("ok-tab", tabId);
2019-05-17 09:16:54 +00:00
},
2019-05-17 16:34:10 +00:00
/**
* 参数校验
* @param title
* @param path
* @param tabId
* @returns {boolean}
*/
2019-05-18 08:50:45 +00:00
parameterCheck: function (title, path) {
2019-05-17 16:34:10 +00:00
if (title == undefined || title == "") {
console.error("title未定义")
return false;
}
if (path == undefined || path == "") {
console.error("path未定义")
return false;
}
return true;
}
2019-05-16 16:52:43 +00:00
}
exports("okTab", okTab);
});