diff --git a/js/okadmin.js b/js/okadmin.js
index 6647a4f..a06f50b 100644
--- a/js/okadmin.js
+++ b/js/okadmin.js
@@ -1,7 +1,11 @@
-layui.use(["element", "layer"], function () {
- var element = layui.element;
+layui.config({
+ base: "lib/okPlugins/"
+}).extend({
+ okTab: "okTab",
+}).use(["element", "layer", "okTab"], function () {
var $ = layui.jquery;
var layer = layui.layer;
+ var okTab = layui.okTab;
/**
* localhost运行提示
@@ -37,90 +41,9 @@ layui.use(["element", "layer"], function () {
// var title = $(this).find("a").html();
var path = $(this).children("a").attr("path");
var tabId = $(this).children("a").attr("tab-id");
- tabAdd(title, path, tabId);
+ okTab.add(title, path, tabId);
});
- /**
- * 添加tab
- * @param title 标题
- * @param path 路径
- * @param tabId tabId必须唯一
- */
-// window.tabAdd = function (title, path, tabId) {
-// if (self == top) {
-// // console.log("不在iframe中")
-// tabAdd1(title, path, tabId)
-// } else {
-// // console.log("在iframe中")
-// tabAdd2(title, path, tabId)
-// }
-// }
-
- function tabAdd(title, path, tabId) {
- // 参数校验
- if (!parameterCheck(title, path, tabId)) {
- return false;
- }
- // 去重复选项卡
- var okFrame = $(".ok-frame");
- 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: "",
- id: tabId
- });
- // 切换选项卡
- element.tabChange("ok-tab", tabId);
- }
-
-// function tabAdd2(title, path, tabId) {
-// // 参数校验
-// parameterCheck(title, path, tabId);
-// // 去重复选项卡
-// var parentOkFrame = $(".ok-frame", parent.document);
-// for (var i = 0; i < parentOkFrame.length; i++) {
-// var _tabId = parentOkFrame.eq(i).attr("tab-id");
-// if (_tabId == tabId) {
-// console.warn("tabId=" + tabId + "有重复元素,请检查!")
-// parent.layui.element.tabChange("ok-tab", tabId);
-// event.stopPropagation();
-// return;
-// }
-// }
-// // 添加选项卡
-// parent.layui.element.tabAdd("ok-tab", {
-// title: title,
-// content: "",
-// id: tabId
-// });
-// // 切换选项卡
-// parent.layui.element.tabChange("ok-tab", tabId);
-// }
-
- function parameterCheck(title, path, tabId) {
- if (title == undefined || title == "") {
- console.error("title未定义")
- return false;
- }
- if (path == undefined || path == "") {
- console.error("path未定义")
- return false;
- }
- if (tabId == undefined || tabId == "") {
- console.error("tabId未定义")
- return false;
- }
- return true;
- }
-
/**
* 修改copyright结束时间
*/
diff --git a/lib/okPlugins/okTab.js b/lib/okPlugins/okTab.js
index 2ce4207..201d8b0 100644
--- a/lib/okPlugins/okTab.js
+++ b/lib/okPlugins/okTab.js
@@ -1,16 +1,14 @@
"use strict";
-layui.define(["element", "layer"], function (exports) {
+layui.define(["element"], function (exports) {
var element = window.top.layui.element;
- var layer = layui.layer;
var $ = layui.jquery;
var okTab = {
add: function (title, path, tabId) {
- console.log("title:", title, "path:", path, "tabId:", tabId);
- // 参数校验
- if (!okTab.parameterCheck(title, path, tabId)) {
- return false;
- }
+ // 参数校验
+ if (!okTab.parameterCheck(title, path, tabId)) {
+ return false;
+ }
// 去重复选项卡
var okFrame = $(".ok-frame", window.top.document);
for (var i = 0; i < okFrame.length; i++) {
@@ -30,21 +28,28 @@ layui.define(["element", "layer"], function (exports) {
// 切换选项卡
element.tabChange("ok-tab", tabId);
},
- parameterCheck: function(title, path, tabId) {
- if (title == undefined || title == "") {
- console.error("title未定义")
- return false;
- }
- if (path == undefined || path == "") {
- console.error("path未定义")
- return false;
- }
- if (tabId == undefined || tabId == "") {
- console.error("tabId未定义")
- return false;
- }
- return true;
- }
+ /**
+ * 参数校验
+ * @param title
+ * @param path
+ * @param tabId
+ * @returns {boolean}
+ */
+ parameterCheck: function (title, path, tabId) {
+ if (title == undefined || title == "") {
+ console.error("title未定义")
+ return false;
+ }
+ if (path == undefined || path == "") {
+ console.error("path未定义")
+ return false;
+ }
+ if (tabId == undefined || tabId == "") {
+ console.error("tabId未定义")
+ return false;
+ }
+ return true;
+ }
}
exports("okTab", okTab);
diff --git a/lib/okPlugins/okUtils.js b/lib/okPlugins/okUtils.js
index 12855b8..06302df 100644
--- a/lib/okPlugins/okUtils.js
+++ b/lib/okPlugins/okUtils.js
@@ -99,7 +99,7 @@ layui.define("layer", function (exports) {
},
date: {
/**
- * 格式化时间
+ * 格式化日期时间
* @param date
* @param fmt
* @returns {*}
diff --git a/pages/use/use-okLayer.html b/pages/use/use-okLayer.html
index d54a0f2..533e43e 100644
--- a/pages/use/use-okLayer.html
+++ b/pages/use/use-okLayer.html
@@ -71,7 +71,6 @@ okLayer.open("添加用户", "user-add.html", "90%", "90%", function() {})
-
diff --git a/pages/use/use-okTab.html b/pages/use/use-okTab.html
index d09ff2d..0989a2b 100644
--- a/pages/use/use-okTab.html
+++ b/pages/use/use-okTab.html
@@ -67,7 +67,8 @@ okTab.tabAdd("ok-tool", "http://www.xlbweb.cn", "11-1")
-
+
+
@@ -87,14 +88,22 @@ okTab.tabAdd("ok-tool", "http://www.xlbweb.cn", "11-1")
$("#addTab1").click(function () {
okTab.add("okLayer", "pages/use/use-okLayer.html", "11-1");
});
-
+
$("#addTab2").click(function () {
okTab.add("ok-tool", "http://tool.xlbweb.cn", "11-2");
});
-
+
$("#addTab3").click(function () {
- okLayer.open("子页面", "use-okTab-sub.html", "90%", "90%", function() {})
+ // 参数漏写
+ // okTab.add("test");
+ // okTab.add("test", "");
+ // okTab.add("test", "http://tool.xlbweb.cn");
+ okTab.add("test", "http://tool.xlbweb.cn", "");
});
+
+ $("#addTab4").click(function () {
+ okLayer.open("子页面", "use-okTab-sub.html", "90%", "90%", function() {})
+ });
})