zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/**
    @name Edo.navigators.PagingBar
    @class
    @description 分页组件,配合表格组件使用
    @extend Edo.containers.Box
*/
Edo.navigators.PagingBar = function(config){   
    
    Edo.navigators.PagingBar.superclass.constructor.call(this);     
    /**
        @name Edo.navigators.PagingBar#beforepaging
        @event        
        @description 分页前事件
        @property {Number} index 分页索引
        @property {Number} size 每页分页数
        @property {Object} params 分页参数对象
    */   
    /**
        @name Edo.navigators.PagingBar#paging
        @event        
        @description 分页前事件
        @property {Number} index 分页索引
        @property {Number} size 每页分页数
        @property {Object} params 分页参数对象
    */    
};
Edo.navigators.PagingBar.extend(Edo.containers.Box,{
    elCls: 'e-pagingbar e-box e-ct e-div',
    /**
        @name Edo.navigators.PagingBar#size
        @property
        @type Number
        @default 20
        @description 每页多少行记录
    */
    size: 20,
    /**
        @name Edo.navigators.PagingBar#index
        @property
        @type Number
        @default 0
        @description 页码
    */
    index: 0,
    /**
        @name Edo.navigators.PagingBar#total
        @property
        @type Number
        @description 总记录数
    */
    total: -1,
    /**
        @name Edo.navigators.PagingBar#totalPage
        @property
        @type Number
        @description 总页码数
    */
    totalPage: -1,
    loading: false,
    /**
        @name Edo.navigators.PagingBar#autoPaging
        @property
        @type Boolean
        @default false
        @description 创建后是否自动激发分页动作
    */
    autoPaging: false,   //创建成功,自动激发分页
    
    totalTpl: '第 <input class="e-pagingbar-input" onchange="<%=this.id%>.change(parseInt(this.value)-1, <%=this.size%>);" onkeydown="if(event.keyCode==13) <%=this.id%>.change(parseInt(this.value)-1, <%=this.size%>);" type="text" value="<%=this.index+1%>"/> / <%=this.totalPage%>页, 每页<input onchange="<%=this.id%>.change(<%=this.index%>, this.value);" onkeydown="if(event.keyCode==13) <%=this.id%>.change(<%=this.index%>, this.value);" class="e-pagingbar-input"  type="text" value="<%=this.size%>"/>条, 共<%=this.total%>条',
 
    layout: 'horizontal',
    layout: 'horizontal',
    border: [0,0,0,0],
    padding: [0,0,0,0],
    /**
        @name Edo.navigators.PagingBar#barVisible
        @property
        @type Boolean
        @default true
        @description 是否显示分页操作按钮
    */
    barVisible: true,
    /**
        @name Edo.navigators.PagingBar#infoVisible
        @property
        @type Boolean
        @default true
        @description 是否显示分页信息
    */
    infoVisible: true,
    
    _setSize: function(v){
        this.size = v;
    },
    init: function(){
        var pager = this;
        this.set({
            verticalAlign: 'middle',
            'children': [
                {
                    name: 'barct', type: 'ct',layout: 'horizontal', horizontalGap: 0,verticalAlign: 'middle', height:'100%',
                    children: [
                        {
                            type: 'button',
                            name: 'first',
                            defaultHeight: 16,                            
                            icon: 'e-page-first',                  
                            onclick: this.doFirst.bind(this)
                        },
                        {
                            type: 'button',
                            name: 'pre',
                            defaultHeight: 16,
                            icon: 'e-page-pre',
                            onclick: this.doPre.bind(this)
                        },  
                        {
                            type: 'button',
                            name: 'next',
                            defaultHeight: 16,
                            icon: 'e-page-next',
                            onclick: this.doNext.bind(this)
                        },
                        {
                            type: 'button',
                            name: 'last',
                            defaultHeight: 16,
                            icon: 'e-page-last',
                            onclick: this.doLast.bind(this)
                        }                
                    ]
                },
                {
                    type: 'button',
                    name: 'refresh',
                    defaultHeight: 16,
                    icon: 'e-icon-refresh',
                    onclick: this.doRefresh.bind(this)
                },
                {
                    type: 'button',
                    name: 'nowait',
                    defaultHeight: 16,
                    icon: 'e-page-nowait'
                },
                {
                    type: 'space', name: 'space', width: '100%'
                },
                {
                    name: 'infoct', type: 'ct',layout: 'horizontal', verticalAlign: 'middle',
                    children: [
//                        {
//                            type: 'text',
//                            name: 'index',
//                            textStyle: 'text-align:center',
//                            text: '1',
//                            width: 25,
//                            ontextchange: function(e){
//        //                        var index = parseInt(this.text);
//        //                        if(isNaN(index)){
//        //                            alert("只能输入数字");
//        //                            this.set('text', pager.index);
//        //                            return;
//        //                        }
//        //                        pager.change(index);
//                            }
//                        },
                        {
                            type: 'label',
                            name: 'view'                
                        }                     
                    ]
                }
            ]
        });
        Edo.navigators.PagingBar.superclass.init.apply(this, arguments);
        
        var sf = this;
        function get(name){
            return Edo.getByName(name, sf)[0];
        }
        
        var btns = this.children;
        this.firstBtn = get("first");
        this.preBtn = get("pre");
        this.nextBtn = get("next");
        this.lastBtn = get("last");
        
        this.refreshBtn =  get("refresh");
        this.loadBtn =  get("nowait");
        
        //this.indexText = get("index");
        //this.sizeText = get("size");
        this.viewText = get("view");
        //
        this.barCt = get('barct');
        this.infoCt = get('infoct');
        
        this.space = get('space');
        
        this.barCt.set('visible', this.barVisible);
        this.infoCt.set('visible', this.infoVisible);
        
        if(this.autoPaging){
            this.change.defer(this.padingDelay, this);
        }
    },
    padingDelay: 100,
    doFirst: function(e){
        this.change(0);
    },
    doPre: function(e){
        this.change(this.index-1);
    },
    doNext: function(e){
        this.change(this.index+1);
    },
    doLast: function(e){    
        this.change(this.totalPage-1);
    },
    doRefresh: function(e){
        this.change();
    },
    /**
        @name Edo.navigators.PagingBar#change
        @function 
        @param {Number} index 页码
        @param {Number} size 每页记录数
        @param {Object} params 分页参数
        @description 列配置
    */
    change: function(index, size, params){       
        index = parseInt(index);
        size = parseInt(size);
        var e = {
            type: 'beforepaging',
            source: this,
            index: Edo.isValue(index) ? index : this.index,
            size: Edo.isValue(size) ? size : this.size,
            params: params
        }
        
        if(this.fireEvent('beforepaging', e) !== false){
        
            this.index = e.index;
            this.size = e.size;
                        
            this.compute();
            
            this.loading = true;
            this.refresh();
            
            e.type = 'paging';
            this.fireEvent('paging', e);
        }
        
    },
    compute: function(index, size, total){
        if(Edo.isValue(index)) this.index = index;
        if(Edo.isValue(size)) this.size = size;
        if(Edo.isValue(total)) this.total = total;
        this.totalPage = parseInt(this.total / this.size) + (this.total % this.size ? 1 : 0);
        //this.totalPage -= 1;
        
        if(this.index >= this.totalPage-1){
            this.index = this.totalPage - 1;
        }
        if(this.index < 0) this.index = 0;
    },
    /**
        @name Edo.navigators.PagingBar#refresh
        @function 
        @param {Number} total 总记录数        
        @description 更新分页状态信息
    */
    refresh: function(total){
        if(Edo.isValue(total)){
            this.total = total;
        }
        //根据当前的分页数据,更新按钮状态(可用/不可用等..)
        
        this.compute();
        
        //loading
        if(this.inited) {        
            this.firstBtn.set('enable', this.index != 0);
            this.preBtn.set('enable', this.index != 0);
            
            this.nextBtn.set('enable', !(this.totalPage == 0) && this.index != this.totalPage-1);
            this.lastBtn.set('enable', !(this.totalPage == 0) && this.index != this.totalPage-1);
                        
            this.viewText.set('text', '');
            this.viewText.set('text', new Edo.util.Template(this.totalTpl).run(this));
            
            this.loadBtn.set('icon', this.loading ? 'e-page-wait' : 'e-page-nowait');
            
            this.loading = false;
        }
    }
});
 
Edo.navigators.PagingBar.regType('pagingbar');
Edo.navigators.PagingBar.prototype.refreshView = Edo.navigators.PagingBar.prototype.refresh;