pull/1761/head
lyswhut 2023-11-22 12:59:30 +08:00
parent 87bd27f814
commit 6f22c73d99
2 changed files with 30 additions and 23 deletions

View File

@ -51,6 +51,7 @@
</template> </template>
<script> <script>
import { computed } from '@common/utils/vueTools'
export default { export default {
props: { props: {
@ -72,29 +73,34 @@ export default {
}, },
}, },
emits: ['btn-click'], emits: ['btn-click'],
computed: { setup(props, { emit }) {
maxPage() { const maxPage = computed(() => {
return Math.ceil(this.count / this.limit) || 1 return Math.ceil(props.count / props.limit) || 1
}, })
pageEvg() { const pageEvg = computed(() => {
return Math.floor(this.btnLength / 2) return Math.floor(props.btnLength / 2)
}, })
pages() { const pages = computed(() => {
if (this.maxPage <= this.btnLength) return Array.from({ length: this.maxPage }, (_, i) => i + 1) if (maxPage <= props.btnLength) return Array.from({ length: maxPage }, (_, i) => i + 1)
let start = let start = props.page - pageEvg > 1
this.page - this.pageEvg > 1 // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands ? maxPage - props.page < pageEvg + 1
? this.maxPage - this.page < this.pageEvg + 1 ? maxPage - (props.btnLength - 1)
? this.maxPage - (this.btnLength - 1) : props.page - pageEvg
: this.page - this.pageEvg : 1
: 1 return Array.from({ length: props.btnLength }, (_, i) => start + i)
return Array.from({ length: this.btnLength }, (_, i) => start + i) })
},
}, const handleClick = (page) => {
methods: { emit('btn-click', page)
handleClick(page) { }
this.$emit('btn-click', page)
}, return {
maxPage,
pageEvg,
pages,
handleClick,
}
}, },
} }
</script> </script>

View File

@ -120,6 +120,7 @@ export default {
handleRegisterEvent(action) { handleRegisterEvent(action) {
let eventHub = window.key_event let eventHub = window.key_event
let name = action == 'on' ? 'on' : 'off' let name = action == 'on' ? 'on' : 'off'
// eslint-disable-next-line @typescript-eslint/unbound-method
eventHub[name](HOTKEY_COMMON.focusSearchInput.action, this.handleFocusInput) eventHub[name](HOTKEY_COMMON.focusSearchInput.action, this.handleFocusInput)
}, },
handleFocusInput() { handleFocusInput() {