Blame view

components/page/options.vue 2.21 KB
7fa943eb   梁灏   init
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
  <template>
      <div v-if="showSizer || showElevator" :class="optsClasses">
          <div v-if="showSizer" :class="sizerClasses">
              <select v-model="pageSize" @change="changeSize">
                  <option :value="item" v-for="item in pageSizeOpts">{{ item }} 条/页</option>
              </select>
          </div>
          <div v-if="showElevator" :class="ElevatorClasses">
              跳至
              <input type="text" :value="_current" @keyup.enter="changePage">
  
          </div>
      </div>
  </template>
  <script>
      const prefixCls = 'ivu-page';
  
      function isValueNumber (value) {
          return (/^[1-9][0-9]*$/).test(value + '');
      }
  
      export default {
          props: {
              pageSizeOpts: Array,
              showSizer: Boolean,
              showElevator: Boolean,
              current: Number,
              _current: Number,
              pageSize: Number,
              allPages: Number
          },
          computed: {
              optsClasses () {
                  return [
                      `${prefixCls}-options`
                  ]
              },
              sizerClasses () {
                  return [
                      `${prefixCls}-options-sizer`
                  ]
              },
              ElevatorClasses () {
                  return [
                      `${prefixCls}-options-elevator`
                  ]
              }
          },
          methods: {
              changeSize () {
                  this.$emit('on-size', this.pageSize);
              },
              changePage (event) {
                  let val = event.target.value.trim();
                  let page = 0;
  
                  if (isValueNumber(val)) {
                      val = Number(val);
                      if (val != this.current) {
                          const allPages = this.allPages;
  
                          if (val > allPages) {
                              page = allPages;
                          } else {
                              page = val;
                          }
                      }
                  } else {
                      page = 1;
                  }
  
                  if (page) {
                      this.$emit('on-page', page);
                      event.target.value = page;
                  }
              }
          }
      }
  </script>