Blame view

src/components/page/page.vue 8.95 KB
7fa943eb   梁灏   init
1
  <template>
e0cd7f90   梁灏   fixed #134
2
      <ul :class="simpleWrapClasses" :style="style" v-if="simple">
7fa943eb   梁灏   init
3
          <li
012cbf28   梁灏   update locale
4
              :title="t('i.page.prev')"
7fa943eb   梁灏   init
5
6
              :class="prevClasses"
              @click="prev">
93064e3b   梁灏   add Page UI
7
              <a><i class="ivu-icon ivu-icon-ios-arrow-left"></i></a>
7fa943eb   梁灏   init
8
          </li>
93064e3b   梁灏   add Page UI
9
          <div :class="simplePagerClasses" :title="current + '/' + allPages">
7fa943eb   梁灏   init
10
11
12
13
14
15
16
17
18
19
              <input
                  type="text"
                  :value="current"
                  @keydown="keyDown"
                  @keyup="keyUp"
                  @change="keyUp">
              <span>/</span>
              {{ allPages }}
          </div>
          <li
012cbf28   梁灏   update locale
20
              :title="t('i.page.next')"
7fa943eb   梁灏   init
21
22
              :class="nextClasses"
              @click="next">
93064e3b   梁灏   add Page UI
23
              <a><i class="ivu-icon ivu-icon-ios-arrow-right"></i></a>
7fa943eb   梁灏   init
24
25
          </li>
      </ul>
e0cd7f90   梁灏   fixed #134
26
      <ul :class="wrapClasses" :style="style" v-else>
d6342fe1   jingsam   fixed ie bug
27
          <span :class="[prefixCls + '-total']" v-if="showTotal">
012cbf28   梁灏   update locale
28
              <slot>{{ t('i.page.total') }} {{ total }} <template v-if="total <= 1">{{ t('i.page.item') }}</template><template v-else>{{ t('i.page.items') }}</template></slot>
7fa943eb   梁灏   init
29
30
          </span>
          <li
012cbf28   梁灏   update locale
31
              :title="t('i.page.prev')"
7fa943eb   梁灏   init
32
33
              :class="prevClasses"
              @click="prev">
93064e3b   梁灏   add Page UI
34
              <a><i class="ivu-icon ivu-icon-ios-arrow-left"></i></a>
7fa943eb   梁灏   init
35
          </li>
012cbf28   梁灏   update locale
36
37
          <li title="1" :class="firstPageClasses" @click="changePage(1)"><a>1</a></li>
          <li :title="t('i.page.prev5')" v-if="current - 3 > 1" :class="[prefixCls + '-item-jump-prev']" @click="fastPrev"><a><i class="ivu-icon ivu-icon-ios-arrow-left"></i></a></li>
d6342fe1   jingsam   fixed ie bug
38
39
40
41
42
          <li :title="current - 2" v-if="current - 2 > 1" :class="[prefixCls + '-item']" @click="changePage(current - 2)"><a>{{ current - 2 }}</a></li>
          <li :title="current - 1" v-if="current - 1 > 1" :class="[prefixCls + '-item']" @click="changePage(current - 1)"><a>{{ current - 1 }}</a></li>
          <li :title="current" v-if="current != 1 && current != allPages" :class="[prefixCls + '-item',prefixCls + '-item-active']"><a>{{ current }}</a></li>
          <li :title="current + 1" v-if="current + 1 < allPages" :class="[prefixCls + '-item']" @click="changePage(current + 1)"><a>{{ current + 1 }}</a></li>
          <li :title="current + 2" v-if="current + 2 < allPages" :class="[prefixCls + '-item']" @click="changePage(current + 2)"><a>{{ current + 2 }}</a></li>
012cbf28   梁灏   update locale
43
44
          <li :title="t('i.page.next5')" v-if="current + 3 < allPages" :class="[prefixCls + '-item-jump-next']" @click="fastNext"><a><i class="ivu-icon ivu-icon-ios-arrow-right"></i></a></li>
          <li :title="allPages" v-if="allPages > 1" :class="lastPageClasses" @click="changePage(allPages)"><a>{{ allPages }}</a></li>
7fa943eb   梁灏   init
45
          <li
012cbf28   梁灏   update locale
46
              :title="t('i.page.next')"
7fa943eb   梁灏   init
47
48
              :class="nextClasses"
              @click="next">
93064e3b   梁灏   add Page UI
49
              <a><i class="ivu-icon ivu-icon-ios-arrow-right"></i></a>
7fa943eb   梁灏   init
50
51
52
53
54
55
56
57
58
          </li>
          <Options
              :show-sizer="showSizer"
              :page-size="pageSize"
              :page-size-opts="pageSizeOpts"
              :show-elevator="showElevator"
              :_current.once="current"
              :current.sync="current"
              :all-pages="allPages"
6932b4d7   梁灏   update Page compo...
59
              :is-small="isSmall"
7fa943eb   梁灏   init
60
61
62
63
64
65
66
67
              @on-size="onSize"
              @on-page="onPage">
          </Options>
      </ul>
  </template>
  <script>
      import { oneOf } from '../../utils/assist';
      import Options from './options.vue';
012cbf28   梁灏   update locale
68
      import Locale from '../../mixins/locale';
7fa943eb   梁灏   init
69
70
71
72
  
      const prefixCls = 'ivu-page';
  
      export default {
012cbf28   梁灏   update locale
73
          mixins: [ Locale ],
7fa943eb   梁灏   init
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
          components: { Options },
          props: {
              current: {
                  type: Number,
                  default: 1
              },
              total: {
                  type: Number,
                  default: 0
              },
              pageSize: {
                  type: Number,
                  default: 10
              },
              pageSizeOpts: {
                  type: Array,
                  default () {
b0893113   jingsam   :art: add eslint
91
                      return [10, 20, 30, 40];
7fa943eb   梁灏   init
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
                  }
              },
              size: {
                  validator (value) {
                      return oneOf(value, ['small']);
                  }
              },
              simple: {
                  type: Boolean,
                  default: false
              },
              showTotal: {
                  type: Boolean,
                  default: false
              },
              showElevator: {
                  type: Boolean,
                  default: false
              },
              showSizer: {
                  type: Boolean,
                  default: false
e0cd7f90   梁灏   fixed #134
114
115
116
117
118
119
              },
              class: {
                  type: String
              },
              style: {
                  type: Object
7fa943eb   梁灏   init
120
121
122
123
124
              }
          },
          data () {
              return {
                  prefixCls: prefixCls
b0893113   jingsam   :art: add eslint
125
              };
7fa943eb   梁灏   init
126
127
          },
          computed: {
6932b4d7   梁灏   update Page compo...
128
129
130
              isSmall () {
                  return !!this.size;
              },
7fa943eb   梁灏   init
131
              allPages () {
4935594e   梁灏   fixed #21
132
133
                  const allPage = Math.ceil(this.total / this.pageSize);
                  return (allPage === 0) ? 1 : allPage;
7fa943eb   梁灏   init
134
135
136
137
              },
              simpleWrapClasses () {
                  return [
                      `${prefixCls}`,
e0cd7f90   梁灏   fixed #134
138
139
140
141
                      `${prefixCls}-simple`,
                      {
                          [`${this.class}`]: !!this.class
                      }
b0893113   jingsam   :art: add eslint
142
                  ];
7fa943eb   梁灏   init
143
              },
93064e3b   梁灏   add Page UI
144
145
146
              simplePagerClasses () {
                  return `${prefixCls}-simple-pager`;
              },
7fa943eb   梁灏   init
147
148
149
150
              wrapClasses () {
                  return [
                      `${prefixCls}`,
                      {
e0cd7f90   梁灏   fixed #134
151
                          [`${this.class}`]: !!this.class,
7fa943eb   梁灏   init
152
153
                          'mini': !!this.size
                      }
b0893113   jingsam   :art: add eslint
154
                  ];
7fa943eb   梁灏   init
155
156
157
158
159
              },
              prevClasses () {
                  return [
                      `${prefixCls}-prev`,
                      {
3ac88707   梁灏   optimize Page
160
                          [`${prefixCls}-disabled`]: this.current === 1
7fa943eb   梁灏   init
161
                      }
b0893113   jingsam   :art: add eslint
162
                  ];
7fa943eb   梁灏   init
163
164
165
166
167
              },
              nextClasses () {
                  return [
                      `${prefixCls}-next`,
                      {
3ac88707   梁灏   optimize Page
168
                          [`${prefixCls}-disabled`]: this.current === this.allPages
7fa943eb   梁灏   init
169
                      }
b0893113   jingsam   :art: add eslint
170
                  ];
d6342fe1   jingsam   fixed ie bug
171
172
173
174
175
              },
              firstPageClasses () {
                  return [
                      `${prefixCls}-item`,
                      {
3ac88707   梁灏   optimize Page
176
                          [`${prefixCls}-item-active`]: this.current === 1
d6342fe1   jingsam   fixed ie bug
177
                      }
b0893113   jingsam   :art: add eslint
178
                  ];
d6342fe1   jingsam   fixed ie bug
179
180
181
182
183
              },
              lastPageClasses () {
                  return [
                      `${prefixCls}-item`,
                      {
3ac88707   梁灏   optimize Page
184
                          [`${prefixCls}-item-active`]: this.current === this.allPages
d6342fe1   jingsam   fixed ie bug
185
                      }
b0893113   jingsam   :art: add eslint
186
                  ];
7fa943eb   梁灏   init
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
              }
          },
          methods: {
              changePage (page) {
                  if (this.current != page) {
                      this.current = page;
                      this.$emit('on-change', page);
                  }
              },
              prev () {
                  const current = this.current;
                  if (current <= 1) {
                      return false;
                  }
                  this.changePage(current - 1);
              },
              next () {
                  const current = this.current;
                  if (current >= this.allPages) {
                      return false;
                  }
                  this.changePage(current + 1);
              },
              fastPrev () {
                  const page = this.current - 5;
                  if (page > 0) {
                      this.changePage(page);
                  } else {
                      this.changePage(1);
                  }
              },
              fastNext () {
                  const page = this.current + 5;
                  if (page > this.allPages) {
                      this.changePage(this.allPages);
                  } else {
                      this.changePage(page);
                  }
              },
              onSize (pageSize) {
                  this.pageSize = pageSize;
                  this.changePage(1);
07f400e5   梁灏   fixed #136
229
                  this.$emit('on-page-size-change', pageSize);
7fa943eb   梁灏   init
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
              },
              onPage (page) {
                  this.changePage(page);
              },
              keyDown (e) {
                  const key = e.keyCode;
                  const condition = (key >= 48 && key <= 57) || key == 8 || key == 37 || key == 39;
  
                  if (!condition) {
                      e.preventDefault();
                  }
              },
              keyUp (e) {
                  const key = e.keyCode;
                  const val = parseInt(e.target.value);
  
                  if (key === 38) {
b0893113   jingsam   :art: add eslint
247
                      this.prev();
7fa943eb   梁灏   init
248
                  } else if (key === 40) {
b0893113   jingsam   :art: add eslint
249
                      this.next();
7fa943eb   梁灏   init
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
                  } else if (key == 13) {
                      let page = 1;
  
                      if (val > this.allPages) {
                          page = this.allPages;
                      } else if (val <= 0) {
                          page = 1;
                      } else {
                          page = val;
                      }
  
                      e.target.value = page;
                      this.changePage(page);
                  }
              }
          }
b0893113   jingsam   :art: add eslint
266
      };
d6342fe1   jingsam   fixed ie bug
267
  </script>