Js Factory 设计模式模式的使用

 之前在参考某知名博主大佬的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);/*执行带参数的方法*/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值