mirror of https://github.com/veops/cmdb.git
refactor(ui):extract pager components
This commit is contained in:
parent
0b3cad8215
commit
9bdef88eea
|
@ -0,0 +1,2 @@
|
||||||
|
import Pager from './index.vue'
|
||||||
|
export default Pager
|
|
@ -0,0 +1,138 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<a-row class="row" type="flex" justify="end">
|
||||||
|
<a-col>
|
||||||
|
<a-space align="end">
|
||||||
|
<a-button
|
||||||
|
class="left-button"
|
||||||
|
size="small"
|
||||||
|
:disabled="prevIsDisabled"
|
||||||
|
@click="prevPage"
|
||||||
|
><a-icon
|
||||||
|
type="left"
|
||||||
|
/></a-button>
|
||||||
|
<a-button class="page-button" size="small">{{ currentPage }}</a-button>
|
||||||
|
<a-button
|
||||||
|
class="right-button"
|
||||||
|
size="small"
|
||||||
|
:disabled="nextIsDisabled"
|
||||||
|
@click="nextPage"
|
||||||
|
><a-icon
|
||||||
|
type="right"
|
||||||
|
/></a-button>
|
||||||
|
<a-dropdown
|
||||||
|
class="dropdown"
|
||||||
|
size="small"
|
||||||
|
placement="topCenter"
|
||||||
|
:trigger="['click']"
|
||||||
|
:disabled="dropdownIsDisabled"
|
||||||
|
>
|
||||||
|
<a-menu slot="overlay">
|
||||||
|
<a-menu-item v-for="(size, index) in pageSizes" :key="index" @click="handleItemClick(size)">
|
||||||
|
{{ `${size}${$t('itemsPerPage')}` }}
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
<a-button size="small">{{ `${pageSize}${$t('itemsPerPage')}` }}<a-icon type="down" /> </a-button>
|
||||||
|
</a-dropdown>
|
||||||
|
</a-space>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'Pager',
|
||||||
|
props: {
|
||||||
|
currentPage: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
pageSize: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
pageSizes: {
|
||||||
|
type: Array,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
total: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
isLoading: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
dropdownIsDisabled: false,
|
||||||
|
prevIsDisabled: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
nextIsDisabled() {
|
||||||
|
return this.isLoading || this.total < this.pageSize
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
isLoading: {
|
||||||
|
immediate: true,
|
||||||
|
handler: function(val) {
|
||||||
|
if (val) {
|
||||||
|
this.dropdownIsDisabled = true
|
||||||
|
this.prevIsDisabled = true
|
||||||
|
} else {
|
||||||
|
this.dropdownIsDisabled = false
|
||||||
|
if (this.currentPage === 1) {
|
||||||
|
this.prevIsDisabled = true
|
||||||
|
} else {
|
||||||
|
this.prevIsDisabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
currentPage: {
|
||||||
|
immediate: true,
|
||||||
|
handler: function(val) {
|
||||||
|
if (val === 1) {
|
||||||
|
this.prevIsDisabled = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleItemClick(size) {
|
||||||
|
this.$emit('showSizeChange', size)
|
||||||
|
},
|
||||||
|
nextPage() {
|
||||||
|
const pageNum = this.currentPage + 1
|
||||||
|
this.$emit('change', pageNum)
|
||||||
|
},
|
||||||
|
prevPage() {
|
||||||
|
const pageNum = this.currentPage - 1
|
||||||
|
this.$emit('change', pageNum)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.row {
|
||||||
|
margin-top: 5px;
|
||||||
|
.left-button {
|
||||||
|
padding: 0;
|
||||||
|
width: 24px;
|
||||||
|
}
|
||||||
|
.right-button {
|
||||||
|
padding: 0;
|
||||||
|
width: 24px;
|
||||||
|
}
|
||||||
|
.page-button {
|
||||||
|
padding: 0;
|
||||||
|
width: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<a-row class="row" type="flex" justify="end">
|
|
||||||
<a-col>
|
|
||||||
<a-space align="end">
|
|
||||||
<a-button class="left-button" size="small" :disabled="prevIsDisabled" @click="prevPage"><a-icon type="left" /></a-button>
|
|
||||||
<a-button class="page-button" size="small">{{ currentPage }}</a-button>
|
|
||||||
<a-button class="right-button" size="small" :disabled="nextIsDisabled" @click="nextPage"><a-icon type="right" /></a-button>
|
|
||||||
<a-dropdown class="dropdown" size="small" placement="topCenter" :trigger="['click']" :disabled="dropdownIsDisabled">
|
|
||||||
<a-menu slot="overlay">
|
|
||||||
<a-menu-item v-for="(size,index) in pageSizes" :key="index" @click="handleItemClick(size)">
|
|
||||||
{{ size }}{{ $t('itemsPerPage') }}
|
|
||||||
</a-menu-item>
|
|
||||||
</a-menu>
|
|
||||||
<a-button size="small"> {{ pageSize }}{{ $t('itemsPerPage') }}<a-icon type="down" /> </a-button>
|
|
||||||
</a-dropdown>
|
|
||||||
</a-space>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
props: {
|
|
||||||
currentPage: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
pageSize: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
pageSizes: {
|
|
||||||
type: Array,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
total: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
isLoading: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
dropdownIsDisabled: false,
|
|
||||||
prevIsDisabled: true,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
nextIsDisabled() {
|
|
||||||
return this.isLoading || this.total < this.pageSize
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
isLoading: {
|
|
||||||
immediate: true,
|
|
||||||
handler: function (val) {
|
|
||||||
if (val === true) {
|
|
||||||
this.dropdownIsDisabled = true
|
|
||||||
this.prevIsDisabled = true
|
|
||||||
} else {
|
|
||||||
this.dropdownIsDisabled = false
|
|
||||||
if (this.currentPage === 1) {
|
|
||||||
this.prevIsDisabled = true
|
|
||||||
} else {
|
|
||||||
this.prevIsDisabled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
currentPage: {
|
|
||||||
immediate: true,
|
|
||||||
handler: function (val) {
|
|
||||||
if (val === 1) {
|
|
||||||
this.prevIsDisabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleItemClick(size) {
|
|
||||||
this.$emit('showSizeChange', size)
|
|
||||||
},
|
|
||||||
nextPage() {
|
|
||||||
const pageNum = this.currentPage + 1
|
|
||||||
this.$emit('change', pageNum)
|
|
||||||
},
|
|
||||||
prevPage() {
|
|
||||||
const pageNum = this.currentPage - 1
|
|
||||||
this.$emit('change', pageNum)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="less" scoped>
|
|
||||||
.row{
|
|
||||||
margin-top: 5px;
|
|
||||||
.left-button{
|
|
||||||
padding: 0;
|
|
||||||
width: 24px;
|
|
||||||
}
|
|
||||||
.right-button{
|
|
||||||
padding: 0;
|
|
||||||
width: 24px;
|
|
||||||
}
|
|
||||||
.page-button{
|
|
||||||
padding: 0;
|
|
||||||
width: 24px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
|
@ -79,7 +79,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from './searchForm.vue'
|
import SearchForm from './searchForm.vue'
|
||||||
import { searchPermissonHistory } from '@/modules/acl/api/history'
|
import { searchPermissonHistory } from '@/modules/acl/api/history'
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from './searchForm.vue'
|
import SearchForm from './searchForm.vue'
|
||||||
import { searchResourceHistory } from '@/modules/acl/api/history'
|
import { searchResourceHistory } from '@/modules/acl/api/history'
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from './searchForm.vue'
|
import SearchForm from './searchForm.vue'
|
||||||
import { searchResourceHistory } from '@/modules/acl/api/history'
|
import { searchResourceHistory } from '@/modules/acl/api/history'
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from './searchForm.vue'
|
import SearchForm from './searchForm.vue'
|
||||||
import { searchRoleHistory } from '@/modules/acl/api/history'
|
import { searchRoleHistory } from '@/modules/acl/api/history'
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from './searchForm.vue'
|
import SearchForm from './searchForm.vue'
|
||||||
import { searchTriggerHistory } from '@/modules/acl/api/history'
|
import { searchTriggerHistory } from '@/modules/acl/api/history'
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -81,7 +81,7 @@
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
import Pager from '../../module/pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from '../../module/searchForm.vue'
|
import SearchForm from '../../module/searchForm.vue'
|
||||||
import { searchApp } from '@/modules/acl/api/app'
|
import { searchApp } from '@/modules/acl/api/app'
|
||||||
import { searchPermissonHistory } from '@/modules/acl/api/history'
|
import { searchPermissonHistory } from '@/modules/acl/api/history'
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from '../../module/pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from '../../module/searchForm.vue'
|
import SearchForm from '../../module/searchForm.vue'
|
||||||
import { searchResourceHistory } from '@/modules/acl/api/history'
|
import { searchResourceHistory } from '@/modules/acl/api/history'
|
||||||
import { searchUser } from '@/modules/acl/api/user'
|
import { searchUser } from '@/modules/acl/api/user'
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from '../../module/pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from '../../module/searchForm.vue'
|
import SearchForm from '../../module/searchForm.vue'
|
||||||
import { searchResourceHistory } from '@/modules/acl/api/history'
|
import { searchResourceHistory } from '@/modules/acl/api/history'
|
||||||
import { searchUser } from '@/modules/acl/api/user'
|
import { searchUser } from '@/modules/acl/api/user'
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from '../../module/pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from '../../module/searchForm.vue'
|
import SearchForm from '../../module/searchForm.vue'
|
||||||
import { searchRoleHistory } from '@/modules/acl/api/history'
|
import { searchRoleHistory } from '@/modules/acl/api/history'
|
||||||
import { searchApp } from '@/modules/acl/api/app'
|
import { searchApp } from '@/modules/acl/api/app'
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import Pager from '../../module/pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from '../../module/searchForm.vue'
|
import SearchForm from '../../module/searchForm.vue'
|
||||||
import { searchTriggerHistory } from '@/modules/acl/api/history'
|
import { searchTriggerHistory } from '@/modules/acl/api/history'
|
||||||
import { getTriggers } from '@/modules/acl/api/trigger'
|
import { getTriggers } from '@/modules/acl/api/trigger'
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import SearchForm from './searchForm.vue'
|
import SearchForm from './searchForm.vue'
|
||||||
import { getCIHistoryTable, getUsers } from '@/modules/cmdb/api/history'
|
import { getCIHistoryTable, getUsers } from '@/modules/cmdb/api/history'
|
||||||
import { getCITypes } from '@/modules/cmdb/api/CIType'
|
import { getCITypes } from '@/modules/cmdb/api/CIType'
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<a-row class="row" type="flex" justify="end">
|
|
||||||
<a-col>
|
|
||||||
<a-space align="end">
|
|
||||||
<a-button class="left-button" size="small" :disabled="prevIsDisabled" @click="prevPage"><a-icon type="left" /></a-button>
|
|
||||||
<a-button class="page-button" size="small" >{{ currentPage }}</a-button>
|
|
||||||
<a-button class="right-button" size="small" :disabled="nextIsDisabled" @click="nextPage"><a-icon type="right" /></a-button>
|
|
||||||
<a-dropdown class="dropdown" placement="topCenter" :trigger="['click']" :disabled="dropdownIsDisabled">
|
|
||||||
<a-menu slot="overlay">
|
|
||||||
<a-menu-item v-for="(size,index) in pageSizes" :key="index" @click="handleItemClick(size)">
|
|
||||||
{{ size }}{{ $t('cmdb.history.itemsPerPage') }}
|
|
||||||
</a-menu-item>
|
|
||||||
</a-menu>
|
|
||||||
<a-button size="small"> {{ pageSize }}{{ $t('cmdb.history.itemsPerPage') }} <a-icon type="down" /> </a-button>
|
|
||||||
</a-dropdown>
|
|
||||||
</a-space>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
props: {
|
|
||||||
currentPage: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
pageSize: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
pageSizes: {
|
|
||||||
type: Array,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
total: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
isLoading: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
dropdownIsDisabled: false,
|
|
||||||
prevIsDisabled: true,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
nextIsDisabled() {
|
|
||||||
return this.isLoading || this.total < this.pageSize
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
isLoading: {
|
|
||||||
immediate: true,
|
|
||||||
handler: function (val) {
|
|
||||||
if (val === true) {
|
|
||||||
this.dropdownIsDisabled = true
|
|
||||||
this.prevIsDisabled = true
|
|
||||||
} else {
|
|
||||||
this.dropdownIsDisabled = false
|
|
||||||
if (this.currentPage === 1) {
|
|
||||||
this.prevIsDisabled = true
|
|
||||||
} else {
|
|
||||||
this.prevIsDisabled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
currentPage: {
|
|
||||||
immediate: true,
|
|
||||||
handler: function (val) {
|
|
||||||
if (val === 1) {
|
|
||||||
this.prevIsDisabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleItemClick(size) {
|
|
||||||
this.$emit('showSizeChange', size)
|
|
||||||
},
|
|
||||||
nextPage() {
|
|
||||||
const pageNum = this.currentPage + 1
|
|
||||||
this.$emit('change', pageNum)
|
|
||||||
},
|
|
||||||
prevPage() {
|
|
||||||
const pageNum = this.currentPage - 1
|
|
||||||
this.$emit('change', pageNum)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="less" scoped>
|
|
||||||
.row{
|
|
||||||
margin-top: 5px;
|
|
||||||
.left-button{
|
|
||||||
padding: 0;
|
|
||||||
width: 24px;
|
|
||||||
}
|
|
||||||
.right-button{
|
|
||||||
padding: 0;
|
|
||||||
width: 24px;
|
|
||||||
}
|
|
||||||
.page-button{
|
|
||||||
padding: 0;
|
|
||||||
width: 24px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
|
@ -134,7 +134,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import SearchForm from './searchForm'
|
import SearchForm from './searchForm'
|
||||||
import Pager from './pager.vue'
|
import Pager from '@/components/Pager'
|
||||||
import { getCITypes } from '@/modules/cmdb/api/CIType'
|
import { getCITypes } from '@/modules/cmdb/api/CIType'
|
||||||
import { getRelationTable, getUsers } from '@/modules/cmdb/api/history'
|
import { getRelationTable, getUsers } from '@/modules/cmdb/api/history'
|
||||||
import { getRelationTypes } from '@/modules/cmdb/api/relationType'
|
import { getRelationTypes } from '@/modules/cmdb/api/relationType'
|
||||||
|
|
Loading…
Reference in New Issue