1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciexport class PageNation { 17fb726d48Sopenharmony_ci element: unknown; 18fb726d48Sopenharmony_ci pageInfo: unknown; 19fb726d48Sopenharmony_ci first: unknown; 20fb726d48Sopenharmony_ci prev: unknown; 21fb726d48Sopenharmony_ci next: unknown; 22fb726d48Sopenharmony_ci last: unknown; 23fb726d48Sopenharmony_ci inputBox: unknown; 24fb726d48Sopenharmony_ci btn: unknown; 25fb726d48Sopenharmony_ci list: unknown; 26fb726d48Sopenharmony_ci origin: HTMLElement | undefined; 27fb726d48Sopenharmony_ci static BtnBackColor = '#6C9BFA'; 28fb726d48Sopenharmony_ci static BtnColor = '#fff'; 29fb726d48Sopenharmony_ci constructor(selector: unknown, options = {}) { 30fb726d48Sopenharmony_ci // @ts-ignore 31fb726d48Sopenharmony_ci selector!.innerHTML = ''; 32fb726d48Sopenharmony_ci //最大容器 33fb726d48Sopenharmony_ci this.element = selector; 34fb726d48Sopenharmony_ci // 默认值 35fb726d48Sopenharmony_ci this.pageInfo = { 36fb726d48Sopenharmony_ci current: 1, 37fb726d48Sopenharmony_ci total: 100, 38fb726d48Sopenharmony_ci pageSize: 15, 39fb726d48Sopenharmony_ci }; 40fb726d48Sopenharmony_ci //等待创建的元素 41fb726d48Sopenharmony_ci this.first = null; 42fb726d48Sopenharmony_ci this.prev = null; 43fb726d48Sopenharmony_ci this.next = null; 44fb726d48Sopenharmony_ci this.last = null; 45fb726d48Sopenharmony_ci // 输入框 46fb726d48Sopenharmony_ci this.inputBox = null; 47fb726d48Sopenharmony_ci // 跳转按钮 48fb726d48Sopenharmony_ci this.btn = null; 49fb726d48Sopenharmony_ci // 中间的按钮组 50fb726d48Sopenharmony_ci this.list = null; 51fb726d48Sopenharmony_ci this.setPageOptions(options); 52fb726d48Sopenharmony_ci this.setItemStyles(); 53fb726d48Sopenharmony_ci this.createPageElement(); 54fb726d48Sopenharmony_ci this.bindPageHtml(); 55fb726d48Sopenharmony_ci this.bindPageEvent(); 56fb726d48Sopenharmony_ci } 57fb726d48Sopenharmony_ci 58fb726d48Sopenharmony_ci setPageOptions(options: unknown): void { 59fb726d48Sopenharmony_ci // 当前页 60fb726d48Sopenharmony_ci // @ts-ignore 61fb726d48Sopenharmony_ci this.pageInfo.current = options.current || 1; 62fb726d48Sopenharmony_ci // 一页显示多少条 63fb726d48Sopenharmony_ci // @ts-ignore 64fb726d48Sopenharmony_ci this.pageInfo.pageSize = options.pageSize || 15; // @ts-ignore 65fb726d48Sopenharmony_ci if (options.totalpage) { 66fb726d48Sopenharmony_ci //用户传递了多少页 67fb726d48Sopenharmony_ci // @ts-ignore 68fb726d48Sopenharmony_ci this.pageInfo.totalpage = options.totalpage; 69fb726d48Sopenharmony_ci } else { 70fb726d48Sopenharmony_ci //没有传递多少页 71fb726d48Sopenharmony_ci // @ts-ignore 72fb726d48Sopenharmony_ci if (options.total) { 73fb726d48Sopenharmony_ci // 如果传递了总条数 74fb726d48Sopenharmony_ci // @ts-ignore 75fb726d48Sopenharmony_ci this.pageInfo.totalpage = Math.ceil(options.total / this.pageInfo.pageSize); 76fb726d48Sopenharmony_ci } else { 77fb726d48Sopenharmony_ci // 如果没有传递总条数 78fb726d48Sopenharmony_ci // @ts-ignore 79fb726d48Sopenharmony_ci this.pageInfo.totalpage = 9; 80fb726d48Sopenharmony_ci } 81fb726d48Sopenharmony_ci } // @ts-ignore 82fb726d48Sopenharmony_ci this.pageInfo.first = options.first || '<<'; 83fb726d48Sopenharmony_ci // @ts-ignore 84fb726d48Sopenharmony_ci this.pageInfo.change = options.change || function (): void {}; 85fb726d48Sopenharmony_ci } 86fb726d48Sopenharmony_ci 87fb726d48Sopenharmony_ci setElementStyles(ele: unknown, styles: unknown): void { 88fb726d48Sopenharmony_ci // @ts-ignore 89fb726d48Sopenharmony_ci for (let key in styles) { 90fb726d48Sopenharmony_ci // @ts-ignore 91fb726d48Sopenharmony_ci ele.style[key] = styles[key]; 92fb726d48Sopenharmony_ci } 93fb726d48Sopenharmony_ci } 94fb726d48Sopenharmony_ci 95fb726d48Sopenharmony_ci setItemStyles(): void { 96fb726d48Sopenharmony_ci this.setElementStyles(this.element, { 97fb726d48Sopenharmony_ci margin: '18px auto', 98fb726d48Sopenharmony_ci display: 'flex', 99fb726d48Sopenharmony_ci alignItems: 'center', 100fb726d48Sopenharmony_ci justifyContent: 'center', 101fb726d48Sopenharmony_ci }); 102fb726d48Sopenharmony_ci } 103fb726d48Sopenharmony_ci 104fb726d48Sopenharmony_ci createElement(jumpDiv: HTMLElement): void { 105fb726d48Sopenharmony_ci // Create input field 106fb726d48Sopenharmony_ci this.inputBox = document.createElement('input'); // @ts-ignore 107fb726d48Sopenharmony_ci this.inputBox.value = this.pageInfo.current; 108fb726d48Sopenharmony_ci this.setElementStyles(this.inputBox, { 109fb726d48Sopenharmony_ci width: '35px', 110fb726d48Sopenharmony_ci height: '30px', 111fb726d48Sopenharmony_ci textAlign: 'center', 112fb726d48Sopenharmony_ci outline: 'none', 113fb726d48Sopenharmony_ci padding: '0', 114fb726d48Sopenharmony_ci border: '0', 115fb726d48Sopenharmony_ci 'border-radius': '5px', 116fb726d48Sopenharmony_ci }); // @ts-ignore 117fb726d48Sopenharmony_ci jumpDiv.appendChild(this.inputBox); 118fb726d48Sopenharmony_ci let span = document.createElement('span'); 119fb726d48Sopenharmony_ci span.style.width = '1px'; 120fb726d48Sopenharmony_ci span.style.height = '24px'; 121fb726d48Sopenharmony_ci span.style.alignSelf = 'center'; 122fb726d48Sopenharmony_ci span.style.backgroundColor = '#999999'; 123fb726d48Sopenharmony_ci jumpDiv.appendChild(span); 124fb726d48Sopenharmony_ci // Create button 125fb726d48Sopenharmony_ci this.btn = document.createElement('button'); // @ts-ignore 126fb726d48Sopenharmony_ci this.btn.innerText = ''; // @ts-ignore 127fb726d48Sopenharmony_ci this.btn.name = 'goto'; 128fb726d48Sopenharmony_ci this.setElementStyles(this.btn, { 129fb726d48Sopenharmony_ci height: '32px', 130fb726d48Sopenharmony_ci width: '30px', 131fb726d48Sopenharmony_ci cursor: 'pointer', 132fb726d48Sopenharmony_ci backgroundColor: '#FFF', 133fb726d48Sopenharmony_ci border: '0', 134fb726d48Sopenharmony_ci 'border-radius': '5px', 135fb726d48Sopenharmony_ci }); // @ts-ignore 136fb726d48Sopenharmony_ci this.btn.style.background = 'url("img/arrowright.png") no-repeat 98% center var(--dark-background3,#FFFFFF)'; // @ts-ignore 137fb726d48Sopenharmony_ci this.btn.style.backgroundPosition = 'center'; // @ts-ignore 138fb726d48Sopenharmony_ci jumpDiv.appendChild(this.btn); // @ts-ignore 139fb726d48Sopenharmony_ci this.element.appendChild(jumpDiv); 140fb726d48Sopenharmony_ci } 141fb726d48Sopenharmony_ci 142fb726d48Sopenharmony_ci // 创建元素 首页 上一页 按钮组 下一页 尾页 输入框 按钮 143fb726d48Sopenharmony_ci createPageElement(): void { 144fb726d48Sopenharmony_ci //首页 145fb726d48Sopenharmony_ci this.origin = document.createElement('p'); 146fb726d48Sopenharmony_ci this.setElementStyles(this.origin, { 147fb726d48Sopenharmony_ci 'border-radius': '4px', 148fb726d48Sopenharmony_ci padding: '5px', 149fb726d48Sopenharmony_ci border: '1px solid rgba(0,0,0,0.6)', 150fb726d48Sopenharmony_ci cursor: 'pointer', 151fb726d48Sopenharmony_ci margin: '0 5px', 152fb726d48Sopenharmony_ci }); 153fb726d48Sopenharmony_ci this.first = this.origin.cloneNode(true); // @ts-ignore 154fb726d48Sopenharmony_ci this.first.innerText = this.pageInfo.first; // @ts-ignore 155fb726d48Sopenharmony_ci this.first.name = 'first'; // @ts-ignore 156fb726d48Sopenharmony_ci this.element.appendChild(this.first); 157fb726d48Sopenharmony_ci this.prev = this.origin.cloneNode(true); // @ts-ignore 158fb726d48Sopenharmony_ci this.prev.innerText = '<'; // @ts-ignore 159fb726d48Sopenharmony_ci this.prev.name = 'prev'; // @ts-ignore 160fb726d48Sopenharmony_ci this.prev.style.padding = '5px 10px'; // @ts-ignore 161fb726d48Sopenharmony_ci this.element.appendChild(this.prev); 162fb726d48Sopenharmony_ci // 创建ul 163fb726d48Sopenharmony_ci this.list = document.createElement('ul'); 164fb726d48Sopenharmony_ci this.setElementStyles(this.list, { 165fb726d48Sopenharmony_ci display: 'flex', 166fb726d48Sopenharmony_ci padding: '0', 167fb726d48Sopenharmony_ci }); // @ts-ignore 168fb726d48Sopenharmony_ci this.element.appendChild(this.list); 169fb726d48Sopenharmony_ci this.next = this.origin.cloneNode(true); // @ts-ignore 170fb726d48Sopenharmony_ci this.next.innerText = '>'; // @ts-ignore 171fb726d48Sopenharmony_ci this.next.name = 'next'; // @ts-ignore 172fb726d48Sopenharmony_ci this.next.style.padding = '5px 10px'; // @ts-ignore 173fb726d48Sopenharmony_ci this.next.style.margin = '0px 5px'; // @ts-ignore 174fb726d48Sopenharmony_ci this.element.appendChild(this.next); 175fb726d48Sopenharmony_ci this.last = this.origin.cloneNode(true); // @ts-ignore 176fb726d48Sopenharmony_ci this.last.innerText = '>>'; // @ts-ignore 177fb726d48Sopenharmony_ci this.last.name = 'last'; // @ts-ignore 178fb726d48Sopenharmony_ci this.last.style.padding = '5px'; // @ts-ignore 179fb726d48Sopenharmony_ci this.last.style.margin = '0px 5px'; // @ts-ignore 180fb726d48Sopenharmony_ci this.element.appendChild(this.last); 181fb726d48Sopenharmony_ci let jumpDiv = document.createElement('div'); 182fb726d48Sopenharmony_ci jumpDiv.style.display = 'flex'; 183fb726d48Sopenharmony_ci jumpDiv.style.border = '1px solid rgba(0,0,0,0.6)'; 184fb726d48Sopenharmony_ci jumpDiv.style.borderRadius = '4px'; 185fb726d48Sopenharmony_ci jumpDiv.style.width = '70px'; 186fb726d48Sopenharmony_ci jumpDiv.style.height = '32px'; 187fb726d48Sopenharmony_ci jumpDiv.style.marginLeft = '10px'; 188fb726d48Sopenharmony_ci 189fb726d48Sopenharmony_ci this.createElement(jumpDiv); 190fb726d48Sopenharmony_ci } 191fb726d48Sopenharmony_ci 192fb726d48Sopenharmony_ci // 判断首页 上一页 下一页 尾页 是否可以点击 193fb726d48Sopenharmony_ci bindPageHtml(): void { 194fb726d48Sopenharmony_ci // @ts-ignore 195fb726d48Sopenharmony_ci const { current, totalpage } = this.pageInfo; 196fb726d48Sopenharmony_ci const disable = { color: '#999999', cursor: 'not-allowed' }; 197fb726d48Sopenharmony_ci const enable = { 198fb726d48Sopenharmony_ci color: '#000', 199fb726d48Sopenharmony_ci cursor: 'pointer', 200fb726d48Sopenharmony_ci }; 201fb726d48Sopenharmony_ci // 判断当前页是否是第一页 如果是第一页 那么首页和上一页就不能点击 202fb726d48Sopenharmony_ci if (current <= 1) { 203fb726d48Sopenharmony_ci this.setElementStyles(this.first, disable); 204fb726d48Sopenharmony_ci this.setElementStyles(this.prev, disable); 205fb726d48Sopenharmony_ci } else { 206fb726d48Sopenharmony_ci this.setElementStyles(this.first, enable); 207fb726d48Sopenharmony_ci this.setElementStyles(this.prev, enable); 208fb726d48Sopenharmony_ci } 209fb726d48Sopenharmony_ci // 判断当前页是否是最后一页 如果是最后一页 那么下一页和尾页就不能点击 210fb726d48Sopenharmony_ci if (current >= totalpage) { 211fb726d48Sopenharmony_ci this.setElementStyles(this.next, disable); 212fb726d48Sopenharmony_ci this.setElementStyles(this.last, disable); 213fb726d48Sopenharmony_ci } else { 214fb726d48Sopenharmony_ci this.setElementStyles(this.next, enable); 215fb726d48Sopenharmony_ci this.setElementStyles(this.last, enable); 216fb726d48Sopenharmony_ci } // @ts-ignore 217fb726d48Sopenharmony_ci this.inputBox.value = current; 218fb726d48Sopenharmony_ci //渲染的时候判断ul列表的显示情况 219fb726d48Sopenharmony_ci this.bindPageList(); // @ts-ignore 220fb726d48Sopenharmony_ci this.pageInfo.change(this.pageInfo.current); 221fb726d48Sopenharmony_ci } 222fb726d48Sopenharmony_ci 223fb726d48Sopenharmony_ci bindPageList(): void { 224fb726d48Sopenharmony_ci // @ts-ignore 225fb726d48Sopenharmony_ci this.list.innerHTML = ''; // clear ul its contents 226fb726d48Sopenharmony_ci // @ts-ignore 227fb726d48Sopenharmony_ci const { pageSize, current, totalpage } = this.pageInfo; //Clean the ul before each load 228fb726d48Sopenharmony_ci const origin = document.createElement('li'); 229fb726d48Sopenharmony_ci origin.dataset.name = 'item'; 230fb726d48Sopenharmony_ci this.setElementStyles(origin, { 231fb726d48Sopenharmony_ci listStyle: 'none', 232fb726d48Sopenharmony_ci 'border-radius': '4px', 233fb726d48Sopenharmony_ci border: '1px solid rgba(0,0,0,0.6)', 234fb726d48Sopenharmony_ci padding: '5px 10px', 235fb726d48Sopenharmony_ci margin: '0 5px', 236fb726d48Sopenharmony_ci cursor: 'pointer', 237fb726d48Sopenharmony_ci }); 238fb726d48Sopenharmony_ci if (totalpage <= 9) { 239fb726d48Sopenharmony_ci for (let i = 0; i < totalpage; i++) { 240fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 241fb726d48Sopenharmony_ci } 242fb726d48Sopenharmony_ci return; 243fb726d48Sopenharmony_ci } 244fb726d48Sopenharmony_ci // Five on the left... Two on the right 245fb726d48Sopenharmony_ci if (this.bindLeftList(current, totalpage, origin)) { 246fb726d48Sopenharmony_ci return; 247fb726d48Sopenharmony_ci } 248fb726d48Sopenharmony_ci // The current page is larger than 5 pages and smaller than the last 5 pages 249fb726d48Sopenharmony_ci for (let index = 0; index < 2; index++) { 250fb726d48Sopenharmony_ci this.buildLi(origin, index, current); 251fb726d48Sopenharmony_ci } 252fb726d48Sopenharmony_ci let span = document.createElement('span'); 253fb726d48Sopenharmony_ci span.innerText = '...'; // @ts-ignore 254fb726d48Sopenharmony_ci this.list.appendChild(span); 255fb726d48Sopenharmony_ci for (let i = current - 3; i < current + 2; i++) { 256fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 257fb726d48Sopenharmony_ci } 258fb726d48Sopenharmony_ci span = document.createElement('span'); 259fb726d48Sopenharmony_ci span.innerText = '...'; // @ts-ignore 260fb726d48Sopenharmony_ci this.list.appendChild(span); 261fb726d48Sopenharmony_ci for (let i = totalpage - 2; i < totalpage; i++) { 262fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 263fb726d48Sopenharmony_ci } 264fb726d48Sopenharmony_ci } 265fb726d48Sopenharmony_ci 266fb726d48Sopenharmony_ci private buildLi(origin: HTMLElement, i: number, current: number): void { 267fb726d48Sopenharmony_ci const li = origin.cloneNode(true); 268fb726d48Sopenharmony_ci // @ts-ignore 269fb726d48Sopenharmony_ci li.innerText = i + 1; 270fb726d48Sopenharmony_ci if (i + 1 === current) { 271fb726d48Sopenharmony_ci this.setElementStyles(li, { 272fb726d48Sopenharmony_ci backgroundColor: PageNation.BtnBackColor, 273fb726d48Sopenharmony_ci color: PageNation.BtnColor, 274fb726d48Sopenharmony_ci }); 275fb726d48Sopenharmony_ci } // @ts-ignore 276fb726d48Sopenharmony_ci this.list.appendChild(li); 277fb726d48Sopenharmony_ci } 278fb726d48Sopenharmony_ci 279fb726d48Sopenharmony_ci bindLeftList(current: number, totalpage: number, origin: HTMLElement): boolean { 280fb726d48Sopenharmony_ci let span; 281fb726d48Sopenharmony_ci if (current < 5) { 282fb726d48Sopenharmony_ci // 左边5个 中间 ... 右边2个 283fb726d48Sopenharmony_ci for (let index = 0; index < 5; index++) { 284fb726d48Sopenharmony_ci this.buildLi(origin, index, current); 285fb726d48Sopenharmony_ci } 286fb726d48Sopenharmony_ci span = document.createElement('span'); 287fb726d48Sopenharmony_ci span.innerText = '...'; // @ts-ignore 288fb726d48Sopenharmony_ci this.list.appendChild(span); 289fb726d48Sopenharmony_ci for (let index = totalpage - 2; index < totalpage; index++) { 290fb726d48Sopenharmony_ci this.buildLi(origin, index, current); 291fb726d48Sopenharmony_ci } 292fb726d48Sopenharmony_ci return true; 293fb726d48Sopenharmony_ci } 294fb726d48Sopenharmony_ci if (current === 5) { 295fb726d48Sopenharmony_ci // 左边5个 中间 ... 右边2个 296fb726d48Sopenharmony_ci for (let i = 0; i < 7; i++) { 297fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 298fb726d48Sopenharmony_ci } 299fb726d48Sopenharmony_ci span = document.createElement('span'); 300fb726d48Sopenharmony_ci span.innerText = '...'; // @ts-ignore 301fb726d48Sopenharmony_ci this.list.appendChild(span); 302fb726d48Sopenharmony_ci 303fb726d48Sopenharmony_ci for (let index = totalpage - 2; index < totalpage; index++) { 304fb726d48Sopenharmony_ci this.buildLi(origin, index, current); 305fb726d48Sopenharmony_ci } 306fb726d48Sopenharmony_ci return true; 307fb726d48Sopenharmony_ci } 308fb726d48Sopenharmony_ci // 当前页面 大于倒数第5页 309fb726d48Sopenharmony_ci if (current > totalpage - 4) { 310fb726d48Sopenharmony_ci // 左边5个 中间 ... 右边2个 311fb726d48Sopenharmony_ci for (let index = 0; index < 2; index++) { 312fb726d48Sopenharmony_ci this.buildLi(origin, index, current); 313fb726d48Sopenharmony_ci } 314fb726d48Sopenharmony_ci span = document.createElement('span'); 315fb726d48Sopenharmony_ci span.innerText = '...'; // @ts-ignore 316fb726d48Sopenharmony_ci this.list.appendChild(span); 317fb726d48Sopenharmony_ci for (let i = totalpage - 5; i < totalpage; i++) { 318fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 319fb726d48Sopenharmony_ci } 320fb726d48Sopenharmony_ci return true; 321fb726d48Sopenharmony_ci } 322fb726d48Sopenharmony_ci if (current === totalpage - 4) { 323fb726d48Sopenharmony_ci // 左边5个 中间 ... 右边2个 324fb726d48Sopenharmony_ci this.nodeAppendChild(origin, current, span, totalpage); 325fb726d48Sopenharmony_ci return true; 326fb726d48Sopenharmony_ci } 327fb726d48Sopenharmony_ci return false; 328fb726d48Sopenharmony_ci } 329fb726d48Sopenharmony_ci 330fb726d48Sopenharmony_ci nodeAppendChild(origin: HTMLElement, current: number, span: unknown, totalpage: number): void { 331fb726d48Sopenharmony_ci for (let i = 0; i < 2; i++) { 332fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 333fb726d48Sopenharmony_ci } 334fb726d48Sopenharmony_ci span = document.createElement('span'); // @ts-ignore 335fb726d48Sopenharmony_ci span.innerText = '...'; // @ts-ignore 336fb726d48Sopenharmony_ci this.list.appendChild(span); 337fb726d48Sopenharmony_ci for (let i = totalpage - 7; i < totalpage; i++) { 338fb726d48Sopenharmony_ci this.buildLi(origin, i, current); 339fb726d48Sopenharmony_ci } 340fb726d48Sopenharmony_ci } 341fb726d48Sopenharmony_ci 342fb726d48Sopenharmony_ci bindPageEvent(): void { 343fb726d48Sopenharmony_ci // @ts-ignore 344fb726d48Sopenharmony_ci this.element.addEventListener( 345fb726d48Sopenharmony_ci 'click', 346fb726d48Sopenharmony_ci (event: { 347fb726d48Sopenharmony_ci target: { 348fb726d48Sopenharmony_ci name: string; 349fb726d48Sopenharmony_ci dataset: { name: string }; 350fb726d48Sopenharmony_ci innerText: number; 351fb726d48Sopenharmony_ci }; 352fb726d48Sopenharmony_ci }) => { 353fb726d48Sopenharmony_ci this.targetName(event); 354fb726d48Sopenharmony_ci if (event.target.name === 'goto') { 355fb726d48Sopenharmony_ci // 拿到你文本的内容 356fb726d48Sopenharmony_ci // @ts-ignore 357fb726d48Sopenharmony_ci let page = this.inputBox.value - 0; 358fb726d48Sopenharmony_ci if (isNaN(page)) { 359fb726d48Sopenharmony_ci page = 1; 360fb726d48Sopenharmony_ci } 361fb726d48Sopenharmony_ci if (page <= 1) { 362fb726d48Sopenharmony_ci page = 1; 363fb726d48Sopenharmony_ci } // @ts-ignore 364fb726d48Sopenharmony_ci if (page >= this.pageInfo.totalpage) { 365fb726d48Sopenharmony_ci // @ts-ignore 366fb726d48Sopenharmony_ci page = this.pageInfo.totalpage; 367fb726d48Sopenharmony_ci } // @ts-ignore 368fb726d48Sopenharmony_ci this.pageInfo.current = page; 369fb726d48Sopenharmony_ci this.bindPageHtml(); 370fb726d48Sopenharmony_ci } 371fb726d48Sopenharmony_ci if (event.target.dataset.name === 'item') { 372fb726d48Sopenharmony_ci // @ts-ignore 373fb726d48Sopenharmony_ci this.pageInfo.current = event.target.innerText - 0; 374fb726d48Sopenharmony_ci this.bindPageHtml(); 375fb726d48Sopenharmony_ci } 376fb726d48Sopenharmony_ci } 377fb726d48Sopenharmony_ci ); 378fb726d48Sopenharmony_ci } 379fb726d48Sopenharmony_ci 380fb726d48Sopenharmony_ci targetName(event: { 381fb726d48Sopenharmony_ci target: { 382fb726d48Sopenharmony_ci name: string; 383fb726d48Sopenharmony_ci dataset: { name: string }; 384fb726d48Sopenharmony_ci innerText: number; 385fb726d48Sopenharmony_ci }; 386fb726d48Sopenharmony_ci }): void { 387fb726d48Sopenharmony_ci if (event.target.name === 'first') { 388fb726d48Sopenharmony_ci // @ts-ignore 389fb726d48Sopenharmony_ci if (this.pageInfo.current === 1) { 390fb726d48Sopenharmony_ci return; 391fb726d48Sopenharmony_ci } // @ts-ignore 392fb726d48Sopenharmony_ci this.pageInfo.current = 1; 393fb726d48Sopenharmony_ci this.bindPageHtml(); 394fb726d48Sopenharmony_ci } 395fb726d48Sopenharmony_ci if (event.target.name === 'prev') { 396fb726d48Sopenharmony_ci // @ts-ignore 397fb726d48Sopenharmony_ci if (this.pageInfo.current === 1) { 398fb726d48Sopenharmony_ci return; 399fb726d48Sopenharmony_ci } // @ts-ignore 400fb726d48Sopenharmony_ci this.pageInfo.current--; 401fb726d48Sopenharmony_ci this.bindPageHtml(); 402fb726d48Sopenharmony_ci } 403fb726d48Sopenharmony_ci if (event.target.name === 'next') { 404fb726d48Sopenharmony_ci // @ts-ignore 405fb726d48Sopenharmony_ci if (this.pageInfo.current === this.pageInfo.totalpage) { 406fb726d48Sopenharmony_ci return; 407fb726d48Sopenharmony_ci } // @ts-ignore 408fb726d48Sopenharmony_ci this.pageInfo.current++; 409fb726d48Sopenharmony_ci this.bindPageHtml(); 410fb726d48Sopenharmony_ci } 411fb726d48Sopenharmony_ci if (event.target.name === 'last') { 412fb726d48Sopenharmony_ci // @ts-ignore 413fb726d48Sopenharmony_ci if (this.pageInfo.current === this.pageInfo.totalpage) { 414fb726d48Sopenharmony_ci return; 415fb726d48Sopenharmony_ci } // @ts-ignore 416fb726d48Sopenharmony_ci this.pageInfo.current = this.pageInfo.totalpage; 417fb726d48Sopenharmony_ci this.bindPageHtml(); 418fb726d48Sopenharmony_ci } 419fb726d48Sopenharmony_ci } 420fb726d48Sopenharmony_ci} 421