赣州市洪水风险预警系统二维版本
xiebin
2023-03-02 b39483c96ae572121d3c619c0b9d37634e682cc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
 * infoWindow的template
 * @author Wenyb
 * @date 2015/11/4
 */
define([
    "base/BaseControl",
    "dojo",
    "dojo/_base/declare",
    "dojo/text!controls/tab/TabControl.html",
    "dojo/_base/lang",
    "dojo/query",
    "dojo/dom-construct",
    "dojo/dom-style",
    "dojo/dom-attr",
    "dojo/on",
    "dojo/dom-class",
    "dojo/domReady!"
], function(
    BaseControl,
    dojo,
    declare,
    template,
    lang,
    query,
    domConstruct,
    domStyle,
    domAttr,
    on,
    domClass
) {
    var Widget = declare("TabControl", [BaseControl], {
        templateString: template,
        baseClass: "tabcontrol",
        //{tab:[{type:"tab1",label:"TAB1",active:true},{type:"tab1",label:"TAB2"}]}
        constructor: function(options, srcRefNode) {
            this.activeTabType = null;
            this.tabIndex = {};
        },
        startup: function() {
            for (var i = 0; i < this.tab.length; i++) {
                this._createTab(this.tab[i]);
            }
            this.inherited(arguments);
        },
        _createTab: function(tab) {
            var className = this.baseClass + "-tabbutton ";
            if (tab.active) {
                className += this.baseClass + "-tabbutton-actived";
            }
            tab.span = domConstruct.create("div", {
                className: className,
                innerHTML: tab.label,
                "data-type": tab.type
            }, this.tabContainer);
            on(tab.span, "click", lang.hitch(this, this._tabButtonClick));
            this.tabIndex[tab.type] = tab;
        },
        postCreate: function() {
            this.inherited(arguments);
        },
        changeActiveTab: function(type) {
            if (this.activeTabType) {
                var tab = this.tabIndex[this.activeTabType];
                domClass.remove(tab.span, this.baseClass + "-tabbutton-actived");
                if (tab.content) {
                    domStyle.set(tab.content, "display", "none");
                }
                this.activeTabType = null;
            }
            if (type) {
                var tab = this.tabIndex[type];
                domClass.add(tab.span, this.baseClass + "-tabbutton-actived");
                if (tab.content) {
                    domStyle.set(tab.content, "display", "block");
                }
                this.activeTabType = type;
            }
        },
        onChangeActiveTab: function(type) {
            return type;
        },
        //将两个type的Content关联,即设为同一个dom,使得切换到两个tab时,显示状态一致的相同内容。如需根据type改变content内部行为,可对onChangeActiveTab进行拦截。
        //type2需要已设置content,linkContent后type1的content将与type2的保持一致
        linkContent: function(type1, type2) {
            if (this.tabIndex[type2] && this.tabIndex[type2].content && this.tabIndex[type1]) {
                this.tabIndex[type1].content = this.tabIndex[type2].content;
            }
        },
        setContent: function(type, content) {
            var tab = this.tabIndex[type];
            if (tab.content) {
                domConstruct.destroy(tab.content);
                tab.content = null;
            }
            var style = "display:none";
            if (this.activeTabType == type) {
                style = "display:block";
            }
            tab.content = domConstruct.create("div", {
                className: this.baseClass + "-tabcontent-box",
                "data-type": type,
                style: style
            }, this.tabContent);
            domConstruct.place(content, tab.content);
        },
        _tabButtonClick: function(evt) {
            var type = domAttr.get(evt.currentTarget, "data-type");
            if (this.activeTabType == type) {
                if (!this.disableNoActiveTab) {
                    this.changeActiveTab(null);
                    this.onChangeActiveTab(null);
                }
            } else {
                this.changeActiveTab(type);
                this.onChangeActiveTab(type);
            }
 
        },
        hideContent: function() {
            this.changeActiveTab(null);
        },
        hideTab: function() {
            domStyle.set(this.tabcontainer, "display", "none");
            domStyle.set(this.content, "bottom", "0px");
        },
        show: function() {
            domStyle.set(this.domNode, "display", "block");
        },
        hide: function() {
            domStyle.set(this.domNode, "display", "none");
        }
    });
    return Widget;
});