WidgetManager.js 22.2 KB
// eval(function (p, a, c, k, e, r) {
//     e = function (c) {
//         return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
//     };
//     if (!''.replace(/^/, String)) {
//         while (c--)r[e(c)] = k[c] || e(c);
//         k = [function (e) {
//             return r[e]
//         }];
//         e = function () {
//             return '\\w+'
//         };
//         c = 1
//     }
//     ;
//     while (c--)if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]);
//     return p
// }('36("o/15/2W o/15/2X o/15/30 o/15/2m o/15/3n o/3u o/3H 3X/3Z o/44 o/2S o/V o/1S-W o/1S-34 o/1S-1M o/39/3b o/3d/3f o/3l".3m(" "),6(u,c,f,m,v,k,e,w,r,z,A,g,t,B,n,l,x){j p=O,q=u(w,{2p:"1k,2Q,1Y,22,26,27,2b,2d",N:O,32:6(){5.P=[];e.U("37",c.8(5,5.2t));e.U("3a",c.8(5,5.2v));e.U("3c",c.8(5,5.2w));e.U("12/3i/3j",c.8(5,5.2J));e.U("12/1w/1v",c.8(5,5.1Z));e.U("12/1w/3E",c.8(5,5.20));e.U("12/1w/3S",c.8(5,5.1u))},23:6(){$(".1t-1r").1p();j a=c.8(5,6(){j a=5.1F("1o"),b=5.1F("33");l([a,b]).H(c.8(5,6(a){e.2o("35",5.P);$(".1t-1r").1y();$(".2q-2s").1p()}),6(a){38&&17.1j(a);$(".1t-1r").1y();$(".2q-2s").1p()})});E(2x&&"2A"!=r("2B")){j b=5.2E(5.2F("3k"),1z.2H({1i:5.2p})),d=5.2E(5.2F("3v"),1z.2H({3w:5.3y().7}));l([b,d]).H(c.8(5,6(b){E(0!=b[0].1E||0!=b[1].1E&&4!=b[1].1E)17.1j(1T);1h{5.N=b[0].1T;E((5.19=b[1].1T)&&0<5.19.1e)2c{f.1b(5.19,c.8(5,6(a,b){a.2R=1z.31(a.2R)}))}2f(y){17.1j(y)}a()}}))}1h a()},1F:6(a){j b=G k,d=[];5.2l(a).H(c.8(5,6(h){f.1b(5.18[a].F,c.8(5,6(b,e){e=5.1X(b.S,h[e].2r).H(c.8(5,6(d){5.1A(b,d,a)}));d.R(e)}));l(d).H(c.8(5,6(a){b.Q(a)}),6(a){b.1a(a)})}));s b},2z:6(a){j b=O,b=-1!=a.1x.1s("</i>")?!0:!1,d=-1!=a.9.1m.1s("K")?!0:!1,h=O,h=b?a.1x:\'<3o 3q="\'+a.1x+\'">\',b=d?\'<L 7="\'+a.7+\'1q" 1M="K-F-M">\'+h+"<L></L><1l>"+a.16+"</1l></L>":\'<L 7="\'+a.7+\'1q" 1M="C-F-M">\'+h+"<L></L><1l>"+a.16+"</1l></L>",b=t.3J(b);t.3N(b,a.9.1m+"F","3O");b.3Q=c.8(5,6(){j b="21"==$("#14").Y("K")?0:24($("#14").Y("K")),d="21"==$("#14").Y("C")?0:24($("#14").Y("C"));40.41({25:1,46:a.16,48:0,4a:!0,4b:[b+10+"Z",d+2T+"Z"],2U:$("#"+a.7),2V:6(b){$(".C-F-M-1d").28("C-F-M-1d");e.2o("12/2Y/1v",a.7);s!0}});$(".C-F-M-1d").28("C-F-M-1d");$("#"+a.7+"1q").2Z("C-F-M-1d")})},29:6(a){"2a"==D a.9&&("J"!=D a.9.K&&0!=a.9.K&&g.T(a.7,"K",a.9.K+"Z"),"J"!=D a.9.C&&0!=a.9.C&&g.T(a.7,"C",a.9.C+"Z"),"J"!=D a.9.1B&&g.T(a.7,"1B",a.9.1B+"Z"),"J"!=D a.9.1C&&g.T(a.7,"1C",a.9.1C+"Z"))},2l:6(a){j b=G k,d=[];f.1b(5.18[a].F,c.8(5,6(a,b){a=5.1D(a.S);d.R(a)}));l(d).H(c.8(5,6(a){b.Q(a)}),6(a){b.1a(a)});s b},1X:6(a,b){j d=G k,h,e,g,f=[];h=5.2g(a,b);e=5.2h(a,b);g=5.2i(a,b);a=5.2j(a,b);f.R(h);f.R(e);f.R(g);f.R(a);l(f).H(c.8(5,6(a){j b={};b.11=a[0];b.W=a[1];b.2k=a[2];b.1c=a[3];d.Q(b)}),6(a){d.1a(a)});s d},2w:6(a){5.18=a},2t:6(a,b){5.1g=a;5.1G=b;5.23()},2v:6(a){5.1g=a},2j:6(a,b){j d=G k;3e([a+"/2n.3g?.v="+b],c.8(5,6(a){d.Q(a)}));s d},1D:6(a){s n(a+"/3h.V",{1H:"V",1I:{"X-1J-1K":O}})},2g:6(a,b){E(2x&&"2A"!=r("2B")){j d=G k;n(a+"/11.V?v="+b,{1H:"V",1I:{"X-1J-1K":O}}).H(c.8(5,6(b){j c=a.1L("F/","");2u(c){I"2Q":I"1Y":I"22":I"26":I"27":I"2b":I"2d":5.N[c]&&0<5.N[c].1e&&(b.3p=5.N[c]);1N;I"3r":5.N.1k&&0<5.N.1k.1e&&(b.3s.M=5.N.1k)}d.Q(b)}));s d}s n(a+"/11.V?v="+b,{1H:"V",1I:{"X-1J-1K":O}})},2i:6(a,b){b=G k;(a=x(G v(a+"/2n.2m"),{3t:!0}))?b.Q(a):b.1a("1O");s b},2h:6(a,b){a=5.2y({1P:"3x",7:5.1Q("1c/W/"+a),3z:"3A",25:"3B/Y",3C:a+"/Y/W.Y?v="+b,3D:6(){},1R:"3F"});b=G k;a?b.Q("3G"):b.1a("1O");s b},2y:6(a){j b=2C.3I(a.1P),d;2D(d 3K a)"1P"!==d&&"1R"!==d&&(b[d]=a[d]);s"2a"===D 2C.3L(a.1R)[0].3M(b)},2J:6(a,b){E("J"!==D a)2u(a){I"1y":a=5.13(b.7);"J"!=D a&&g.T(a.7,"1f","3P");"J"!=D b.2G&&g.T("3R"+b.2G,"1f","1U");1N;I"3T":a=5.13(b.7),"J"!=D a?0<a.7.1s("3U")?m.3V(a.7,"1f","3W-1U"):g.T(a.7,"1f","1U"):"J"!==D b&&5.1V(b)}},1V:6(a){5.1D(a.S).H(c.8(5,6(b){5.1X(a.S,b.2r).H(c.8(5,6(b){5.1A(a,b,a.2I)}))}))},1A:6(a,b,d){j c={};c.11=b.11;c.W=b.W;c.1g=5.1g;c.1G=5.1G;c.3Y=b.2k;c.7=a.7;c.1i=a.1i;c.16=a.16;c.S=a.S;c.9=a.9;c.18=5.18;c.19=5.19;b=G b.1c(c);"1o"==d?(b.1W(c.9.1m),5.29(b)):"J"!==D a.2K&&a.2K?b.1W(a.9.1m):(b.1W("14"),5.2z(a));b.2L||(b.42(),b.2L=!0);5.P.R(b)},13:6(a){j b;f.43(5.P,6(c){E(c.7===a)s b=c,!0},5);s b},1Z:6(a){j b=5.13(a.7);E(b)E(a.1v)5.1u([a]);1h b.2M()},20:6(a){f.1b(a,c.8(5,6(a,c){E(c=5.13(a.7))c.45();1h a.2I="1o",5.1V(a)}))},1u:6(a){f.1b(a,c.8(5,6(a,c){2D(c=0;c<5.P.1e;c++)E(a.7==5.P[c].7){5.2N(5.P[c]);5.P.47(c,1);1N}}))},2N:6(a){E(a.2O&&"49"!==a.2O)a.2M();5.2P(a);2c{a.1n(),m.1n(a.7)}2f(b){17.1j(17.1O("4c 4d 1n 1c "+a.1i+". "+b.4e))}},2P:6(a){m.1n(5.1Q("1c/W/"+a.S))},1Q:6(a){s a.1L(/\\//g,"2e").1L(/\\./g,"2e")}});q.4f=6(){O===p&&(p=G q);s p};s q});', 62, 264, '|||||this|function|id|hitch|position||||||||||var|||||dojo||||return||||||||||left|typeof|if|widgets|new|then|case|undefined|top|div|item|widgetConfigs|null|loaded|resolve|push|uri|set|subscribe|json|style||css|px||config|app|_findWidgetById|thememappanel|_base|label|console|appConfig|userCollect|reject|forEach|widget|selected|length|display|map|else|name|log|charquery|span|relativeTo|destroy|widgetOnMapScreen|show|_btn|loading|indexOf|hole|_onAppWidgetRemove|close|widgetcontrol|icon|hide|JSON|_createWidgetItem|right|bottom|_tryLoadwidgetmanifest|status|_loadWidgetFromType|view|handleAs|headers|Requested|With|replace|class|break|error|element|_replaceId|appendTo|dom|result|block|_reLoadWidget|placeAt|loadWidgetResources|Pipelines|_onAppWidgetColse|_onAppModelOpen|auto|Approval|loadwidget|parseInt|type|Archives|Traffic|removeClass|_widgetSetMarginBox|object|Database|try|SplitScreen|_|catch|_tryLoadwidgetconfig|_loadCss|_tryLoadwidgetTemplete|_tryLoadwidget|template|loadwidgetmanifest|html|Widget|publish|widgetConfigsString|esri|version|zoom|_onMapLoaded|switch|_onMapChanged|_onAppConfigLoaded|netServer|_createElement|_createPanelWidgetItem|admin|username|document|for|requestDefaultByUrlAndParam|getRequestUrlByLabel|toolIndex|stringify|widgetType|_onAppServerWidgetchanged|contentpanel|started|onClose|_onDestroyWidget|state|removeWidgetStyle|SpecialTopic|items|aspect|55|content|cancel|declare|lang|wedget|addClass|array|parse|constructor|widgetOnPanel|construct|appWidgetLoaded|define|mapLoaded|isDebug_L|request|mapChanged|xhr|appConfigLoaded|promise|require|all|js|manifest|serverchang|widgetchang|widget_configs|cache|split|url|img|layers|src|ChartQuery|chartLayer|sanitize|Deferred|collect_get|userid|link|getUserInfo|rel|stylesheet|text|href|onload|modelopen|head|load|topic|createElement|toDom|in|getElementsByTagName|appendChild|place|last|none|onclick|iconwidgets_|remove|visible|ZoomSlider|setStyle|inline|lib|templateString|BaseWidget|layer|open|startup|some|cookie|onOpen|title|splice|shade|closed|maxmin|offset|fail|to|stack|getInstance'.split('|'), 0, {}))

define("dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/html dojo/_base/url dojo/Deferred dojo/topic lib/BaseWidget dojo/cookie dojo/aspect dojo/json dojo/dom-style dojo/dom-construct dojo/dom-class dojo/request/xhr dojo/promise/all dojo/cache".split(" "), function(u, c, f, m, v, k, e, w, r, z, A, g, t, B, n, l, x) {
    var p = null,
        q = u(w, {
            widgetConfigsString: "charquery,SpecialTopic,Pipelines,Approval,Archives,Traffic,Database,SplitScreen",
            widgetConfigs: null,
            constructor: function() {
                this.loaded = [];
                // 原设计逻辑为 map 加载完毕之后,再通过 publish 调用所有 subscribe 为 mapLoaded 的方法
                // 此处不再将 widget 的加载 subscribe 为 mapLoaded ,即让 widget 的加载不再等待 map 的加载完成
                // e.subscribe("mapLoaded", c.hitch(this, this._onMapLoaded));
                e.subscribe("loadwidget", c.hitch(this, this._onMapLoaded));
                e.subscribe("mapChanged", c.hitch(this, this._onMapChanged));
                e.subscribe("appConfigLoaded", c.hitch(this, this._onAppConfigLoaded));
                e.subscribe("app/serverchang/widgetchang", c.hitch(this, this._onAppServerWidgetchanged));
                e.subscribe("app/widgetcontrol/close", c.hitch(this, this._onAppWidgetColse));
                e.subscribe("app/widgetcontrol/modelopen", c.hitch(this, this._onAppModelOpen));
                e.subscribe("app/widgetcontrol/remove", c.hitch(this, this._onAppWidgetRemove))
            },
            loadwidget: function() {
                $(".hole-loading").show();
                var a = c.hitch(this, function() {
                    var a = this._loadWidgetFromType("widgetOnMapScreen"),
                        b = this._loadWidgetFromType("widgetOnPanel");
                    l([a, b]).then(c.hitch(this, function(a) {
                        e.publish("appWidgetLoaded", this.loaded);
                        // 默认显示第一模块
                        var items = $(".btn-default.nnsz-leftmenu-item");
                        items.length > 0 && items[0].click();
                        // 关闭loading, 显示地图
                        $(".hole-loading").hide();
                        $(".esri-zoom").show()
                    }), function(a) {
                        isDebug_L && console.log(a);
                        $(".hole-loading").hide();
                        $(".esri-zoom").show();
                        // 默认显示第一模块
                        var showModule = function () {
                            var items = $(".btn-default.nnsz-leftmenu-item");
                            items.length == 0 ? setTimeout(showModule, 1000) : items[0].click();
                        };
                        showModule();
                    })
                });
                //if (netServer && r("username")) {
                if (netServer && this.getUserInfo()) {
                    var b = this.requestDefaultByUrlAndParam(this.getRequestUrlByLabel("widget_configs"), JSON.stringify({
                            name: this.widgetConfigsString
                        })),
                        d = this.requestDefaultByUrlAndParam(this.getRequestUrlByLabel("collect_get"), JSON.stringify({
                            userid: this.getUserInfo().id
                        }));
                    l([b, d]).then(c.hitch(this, function(b) {
                        if (0 != b[0].status || 0 != b[1].status && 4 != b[1].status) console.log(result);
                        else {
                            this.widgetConfigs = b[0].result;
                            if ((this.userCollect = b[1].result) && 0 < this.userCollect.length) try {
                                f.forEach(this.userCollect, c.hitch(this, function(a, b) {
                                    a.items = JSON.parse(a.items)
                                }))
                            } catch (y) {
                                console.log(y)
                            }
                            a()
                        }
                    }))
                } else a()
            },
            _loadWidgetFromType: function(a) {
                var b = new k,
                    d = [];
                this.loadwidgetmanifest(a).then(c.hitch(this, function(h) {
                    f.forEach(this.appConfig[a].widgets, c.hitch(this, function(b, e) {
                        e = this.loadWidgetResources(b.uri, h[e].version).then(c.hitch(this, function(d) {
                            this._createWidgetItem(b, d, a)
                        }));
                        d.push(e)
                    }));
                    l(d).then(c.hitch(this, function(a) {
                        b.resolve(a)
                    }), function(a) {
                        b.reject(a)
                    })
                }));
                return b
            },
            _createPanelWidgetItem: function(a) {
                var b = null,
                    b = -1 != a.icon.indexOf("</i>") ? !0 : !1,
                    d = -1 != a.position.relativeTo.indexOf("top") ? !0 : !1,
                    h = null,
                    h = b ? a.icon : '<img src="' + a.icon + '">',
                    b = d ? '<div id="' + a.id + '_btn" class="top-widgets-item">' + h + "<div></div><span>" + a.label + "</span></div>" : '<div id="' + a.id + '_btn" class="left-widgets-item">' + h + "<div></div><span>" + a.label + "</span></div>",
                    b = t.toDom(b);
                t.place(b, a.position.relativeTo + "widgets", "last");
                b.onclick = c.hitch(this, function() {
                    var b = "auto" == $("#thememappanel").css("top") ? 0 : parseInt($("#thememappanel").css("top")),
                        d = "auto" == $("#thememappanel").css("left") ? 0 : parseInt($("#thememappanel").css("left"));
                    layer.open({
                        type: 1,
                        title: a.label,
                        shade: 0,
                        maxmin: !0,
                        offset: [b + 10 + "px", d + 55 + "px"],
                        content: $("#" + a.id),
                        cancel: function(b) {
                            $(".left-widgets-item-selected").removeClass("left-widgets-item-selected");
                            e.publish("app/wedget/close", a.id);
                            return !0
                        }
                    });
                    $(".left-widgets-item-selected").removeClass("left-widgets-item-selected");
                    $("#" + a.id + "_btn").addClass("left-widgets-item-selected")
                })
            },
            _widgetSetMarginBox: function(a) {
                "object" == typeof a.position && ("undefined" != typeof a.position.top && 0 != a.position.top && g.set(a.id, "top", a.position.top + "px"), "undefined" != typeof a.position.left && 0 != a.position.left && g.set(a.id, "left", a.position.left + "px"), "undefined" != typeof a.position.right && g.set(a.id, "right", a.position.right + "px"), "undefined" != typeof a.position.bottom && g.set(a.id, "bottom", a.position.bottom + "px"))
            },
            loadwidgetmanifest: function(a) {
                var b = new k,
                    d = [];
                f.forEach(this.appConfig[a].widgets, c.hitch(this, function(a, b) {
                    a = this._tryLoadwidgetmanifest(a.uri);
                    d.push(a)
                }));
                l(d).then(c.hitch(this, function(a) {
                    b.resolve(a)
                }), function(a) {
                    b.reject(a)
                });
                return b
            },
            loadWidgetResources: function(a, b) {
                var d = new k,
                    h, e, g, f = [];
                h = this._tryLoadwidgetconfig(a, b);
                e = this._loadCss(a, b);
                g = this._tryLoadwidgetTemplete(a, b);
                a = this._tryLoadwidget(a, b);
                f.push(h);
                f.push(e);
                f.push(g);
                f.push(a);
                l(f).then(c.hitch(this, function(a) {
                    var b = {};
                    b.config = a[0];
                    b.style = a[1];
                    b.template = a[2];
                    b.widget = a[3];
                    d.resolve(b)
                }), function(a) {
                    d.reject(a)
                });
                return d
            },
            _onAppConfigLoaded: function(a) {
                this.appConfig = a
            },
            _onMapLoaded: function(a, b) {
                this.map = a;
                this.view = b;
                this.loadwidget();
            },
            _onMapChanged: function(a) {
                this.map = a
            },
            _tryLoadwidget: function(a, b) {
                var d = new k;
                require([a + "/Widget.js?.v=" + b], c.hitch(this, function(a) {
                    d.resolve(a)
                }));
                return d
            },
            _tryLoadwidgetmanifest: function(a) {
                return n(a + "/manifest.json", {
                    handleAs: "json",
                    headers: {
                        "X-Requested-With": null
                    }
                })
            },
            _tryLoadwidgetconfig: function(a, b) {
                if (false) {
                    var d = new k;
                    n(a + "/config.json?v=" + b, {
                        handleAs: "json",
                        headers: {
                            "X-Requested-With": null
                        }
                    }).then(c.hitch(this, function(b) {
                        var c = a.replace("widgets/", "");
                        switch (c) {
                            case "SpecialTopic":
                            case "Pipelines":
                            case "Approval":
                            case "Archives":
                            case "Traffic":
                            case "Database":
                            case "SplitScreen":
                                this.widgetConfigs[c] && 0 < this.widgetConfigs[c].length && (b.layers = this.widgetConfigs[c]);
                                break;
                            case "ChartQuery":
                                this.widgetConfigs.charquery && 0 < this.widgetConfigs.charquery.length && (b.chartLayer.item = this.widgetConfigs.charquery)
                        }
                        d.resolve(b)
                    }));
                    return d
                }
                return n(a + "/config.json?v=" + b, {
                    handleAs: "json",
                    headers: {
                        "X-Requested-With": null
                    }
                })
            },
            _tryLoadwidgetTemplete: function(a, b) {
                b = new k;
                (a = x(new v(a + "/Widget.html"), {
                    sanitize: !0
                })) ? b.resolve(a) : b.reject("error");
                return b
            },
            _loadCss: function(a, b) {
                a = this._createElement({
                    element: "link",
                    id: this._replaceId("widget/style/" + a),
                    rel: "stylesheet",
                    type: "text/css",
                    href: a + "/css/style.css?v=" + b,
                    onload: function() {},
                    appendTo: "head"
                });
                b = new k;
                a ? b.resolve("load") : b.reject("error");
                return b
            },
            _createElement: function(a) {
                var b = document.createElement(a.element),
                    d;
                for (d in a)"element" !== d && "appendTo" !== d && (b[d] = a[d]);
                return "object" === typeof document.getElementsByTagName(a.appendTo)[0].appendChild(b)
            },
            _onAppServerWidgetchanged: function(a, b) {
                if ("undefined" !== typeof a) switch (a) {
                    case "hide":
                        a = this._findWidgetById(b.id);
                        "undefined" != typeof a && g.set(a.id, "display", "none");
                        "undefined" != typeof b.toolIndex && g.set("iconwidgets_" + b.toolIndex, "display", "block");
                        break;
                    case "visible":
                        a = this._findWidgetById(b.id), "undefined" != typeof a ? 0 < a.id.indexOf("ZoomSlider") ? m.setStyle(a.id, "display", "inline-block") : g.set(a.id, "display", "block") : "undefined" !== typeof b && this._reLoadWidget(b)
                }
            },
            _reLoadWidget: function(a) {
                this._tryLoadwidgetmanifest(a.uri).then(c.hitch(this, function(b) {
                    this.loadWidgetResources(a.uri, b.version).then(c.hitch(this, function(b) {
                        this._createWidgetItem(a, b, a.widgetType)
                    }))
                }))
            },
            _createWidgetItem: function(a, b, d) {
                var c = {};
                c.config = b.config;
                c.style = b.style;
                c.map = this.map;
                c.view = this.view;
                c.templateString = b.template;
                c.id = a.id;
                c.name = a.name;
                c.label = a.label;
                c.uri = a.uri;
                c.position = a.position;
                c.appConfig = this.appConfig;
                c.userCollect = this.userCollect;
                b = new b.widget(c);
                "widgetOnMapScreen" == d ? (b.placeAt(c.position.relativeTo), this._widgetSetMarginBox(b)) : "undefined" !== typeof a.contentpanel && a.contentpanel ? b.placeAt(a.position.relativeTo) : (b.placeAt("thememappanel"), this._createPanelWidgetItem(a));
                b.started || (b.startup(), b.started = !0);
                this.loaded.push(b)
            },
            _findWidgetById: function(a) {
                var b;
                f.some(this.loaded, function(c) {
                    if (c.id === a) return b = c, !0
                }, this);
                return b
            },
            _onAppWidgetColse: function(a) {
                var b = this._findWidgetById(a.id);
                if (b) if (a.close) this._onAppWidgetRemove([a]);
                else b.onClose()
            },
            _onAppModelOpen: function(a) {
                f.forEach(a, c.hitch(this, function(a, c) {
                    if (c = this._findWidgetById(a.id)) c.onOpen();
                    else a.widgetType = "widgetOnMapScreen", this._reLoadWidget(a)
                }))
            },
            _onAppWidgetRemove: function(a) {
                f.forEach(a, c.hitch(this, function(a, c) {
                    for (c = 0; c < this.loaded.length; c++) if (a.id == this.loaded[c].id) {
                        this._onDestroyWidget(this.loaded[c]);
                        this.loaded.splice(c, 1);
                        break
                    }
                }))
            },
            _onDestroyWidget: function(a) {
                if (a.state && "closed" !== a.state) a.onClose();
                this.removeWidgetStyle(a);
                try {
                    a.destroy(), m.destroy(a.id)
                } catch (b) {
                    console.log(console.error("fail to destroy widget " + a.name + ". " + b.stack))
                }
            },
            removeWidgetStyle: function(a) {
                m.destroy(this._replaceId("widget/style/" + a.uri))
            },
            _replaceId: function(a) {
                return a.replace(/\//g, "_").replace(/\./g, "_")
            }
        });
    q.getInstance = function() {
        null === p && (p = new q);
        return p
    };
    return q
});