Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/devui-vue/devui/pagination/__tests__/pagination.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount } from '@vue/test-utils';
import { DOMWrapper, mount } from '@vue/test-utils';
import { reactive } from 'vue';
import { Pagination } from '../index';
import { Select } from '../../select';
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('pagination: ', () => {
expect((wrapper.find('.devui-select-input').element as HTMLInputElement).value).toEqual('20');

const btns = wrapper.findAll('a.devui-pagination-link');
expect(btns.map((ele: any) => ele.text()).join()).toEqual('<,1,...,4,5,6,...,16,>');
expect(btns.map((ele: DOMWrapper<Element>) => ele.text()).join()).toEqual('<,1,...,4,5,6,...,16,>');
expect(wrapper.find('.devui-pagination-list').classes()).toContain('devui-pagination-sm');

// 跳转按钮
Expand All @@ -57,15 +57,15 @@ describe('pagination: ', () => {
await btns[0].trigger('click');
expect(wrapper.find('.devui-pagination-item.active').text()).toEqual('4');
const btns1 = wrapper.findAll('a.devui-pagination-link');
expect(btns1.map((ele: any) => ele.text()).join()).toEqual('<,1,...,3,4,5,...,16,>');
expect(btns1.map((ele: DOMWrapper<Element>) => ele.text()).join()).toEqual('<,1,...,3,4,5,...,16,>');

// 改变每页条数
await wrapper.find('.devui-select-input').trigger('click');
await wrapper.findAll('.devui-select-item')[1].trigger('click');

expect((wrapper.find('.devui-select-input').element as HTMLInputElement).value).toEqual('10');
const btns2 = wrapper.findAll('a.devui-pagination-link');
expect(btns2.map((ele: any) => ele.text()).join()).toEqual('<,1,...,3,4,5,...,31,>');
expect(btns2.map((ele: DOMWrapper<Element>) => ele.text()).join()).toEqual('<,1,...,3,4,5,...,31,>');
});

it('test callback', async () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('pagination: ', () => {

expect(wrapper.find('.devui-pagination-list').classes()).toContain('devui-pagination-lg');
const btns = wrapper.findAll('a.devui-pagination-link');
const pageIndexs = btns.map((ele: any) => ele.text());
const pageIndexs = btns.map((ele: DOMWrapper<Element>) => ele.text());
expect(pageIndexs.join()).toEqual('<,1,...,6,7,8,9,10,11,12,13,...,31,>');

// 当前页改变回调
Expand Down
6 changes: 1 addition & 5 deletions packages/devui-vue/devui/pagination/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { App } from 'vue';
import Pagination from './src/pagination';

Pagination.install = (app: App): void => {
app.component(Pagination.name, Pagination);
};

export { Pagination };

export default {
title: 'Pagination 分页',
category: '导航',
status: '100%',
install(app: App): void {
app.use(Pagination as any);
app.component(Pagination.name, Pagination);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export default defineComponent({
setup() {
const paginationConfig = ref(null);
const isShowConfig = ref(false);
const closeConfigMenu = (e: Event) => {
isShowConfig.value = isShowConfig.value ? false : !!e;
};

onMounted(() => {
on(paginationConfig.value, 'click', closeConfigMenu);
});
onUnmounted(() => {
off(paginationConfig.value, 'click', closeConfigMenu);
});
const closeConfigMenu = (e: Event) => {
isShowConfig.value = isShowConfig.value ? false : !!e;
};

return {
paginationConfig,
Expand Down
6 changes: 3 additions & 3 deletions packages/devui-vue/devui/pagination/src/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, computed, nextTick } from 'vue';
import { ComponentProps, componentProps } from './use-pagination';
import { ComponentProps, componentProps } from './pagination-types';
import { liteSelectOptions } from './utils';

import ConfigMenu from './components/config-menu';
Expand All @@ -18,6 +18,8 @@ export default defineComponent({
props: componentProps,
emits: ['pageIndexChange', 'pageSizeChange', 'update:pageSize', 'update:pageIndex'],
setup(props: ComponentProps, { emit }) {
// 总页数
const totalPages = computed(() => Math.ceil(props.total / props.pageSize));

// 极简模式下,可选的下拉选择页码
const litePageOptions = computed(() => liteSelectOptions(totalPages.value));
Expand Down Expand Up @@ -45,8 +47,6 @@ export default defineComponent({
emit('update:pageSize', val);
}
});
// 总页数
const totalPages = computed(() => Math.ceil(props.total / props.pageSize));

const changeCursorEmit = (val: number) => {
cursor.value = val;
Expand Down