之前在参考某知名博主大佬的JS源码时学习一下设计模式源码:
话不多说,详情见以下代码:
///JS Factory
var indexDb = (function () {
var IndexDb = function (ops) {
this.initialize(ops);
},
unitInfo = {
organId: '1d22f688-ac95-4919-871b-61a0c408ee02'
}
, userInfo = {
userId: '暂无'
};
IndexDb.fn = IndexDb.prototype = {
init: function (ops) {
this.unitInfo = extend(unitInfo, ops), this.userInfo = extend(userInfo, ops);
},
initialize: function (ops) {
this.init(ops);
},
LoadVideo: function (ops) {
let playerJson = {};
new Rest({
url: sdk.GetEzponVideoList,
method: "post",
data: {
organId: this.unitInfo.organId,
}
}, function (_resp) {
//console.log(_resp)
if (window.location.href.indexOf('localhost') == 0) {
$("#videoDiv").append(appendVideoFun(_resp) ?? "暂无");
//layui渲染
layui.use(['carousel'], function () {
var carousel = layui.carousel;
carousel.render({
elem: '#videoDiv',
width: '100%',
height: '100%',
autoplay: false,
arrow: 'hover',
indicator: 'none'
});
});
//默认点击播放
//$.each($(`[data-id]`), function ($i, $v) {
// $(this).click(function (e) {
// try {
// let dom = $(`#${$($v).data("id")}`);
// dom.attr("src", dom.attr("data-video"));
// let player = new EZUIKit.EZUIPlayer($($v).data("id"));
// playerJson[$($v).data("id")] = player;
// $.each(playerJson, function (index, data) {
// if (index != $($v).data("id")) {
// data.stop();
// delete playerJson[index];
// } else {
// player.play();
// }
// });
// } catch (e) {
// }
// //console.log(player)
// })
//});
//默认直接播放
$.each($(`[data-id]`), function ($i, $v) {
try {
let dom = $(`#${$($v).data("id")}`);
dom.attr("src", dom.attr("data-video"));
let player = new EZUIKit.EZUIPlayer($($v).data("id"));
} catch (e) {
}
});
}
else {
$("#videoDiv").html(`当前调试页无法浏览`);
}
});
},
LoadBigScreenCount: function (ops) {
new Rest({
url: sdk.GetProblemAreaCount,
method: "post",
data: {
organId: this.unitInfo.organId,
type: null,
layerName: null
}
}, function (_r) {
if (_r > 0) {
$("#wtdk").text(_r);
$("#dxx").text(_r);
$("#wtdk").css("cursor", "pointer");
$("#dxx").css("cursor", "pointer");
$("#wtdk").click(function () {
Opt.publicLayerOpen(false, `/Page/ProblemAreaList`, ["80vw", "57.5vh"], 2);
});
//debugger
}
});
new Rest({
url: sdk.GetOrderListForBsCount,
method: "post",
data: {
organId: this.unitInfo.organId,
queryString: null,
tdbh: null
}
}, function (_r) {
if (_r > 0) {
$("#xczs").text(_r);
$("#xczs").css("cursor", "pointer");
$("#xczs").click(function () {
Opt.publicLayerOpen(false, `/Page/OrderList`, ["80vw", "57.5vh"], 2);
});
//debugger
}
});
}
};
var extend = function (dst, src) {
for (var property in src) {
dst[property] = src[property];
}
return dst;
};
return new IndexDb(arguments);
})();
对于静态字符串调用
let data=indexDb.unitInfo;/*取得对象的值*/
indexDb.LoadVideo();/*执行方法*/
indexDb.LoadVideo(e);/*执行带参数的方法*/