feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -19,16 +19,12 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import { paginationEvents } from '../src/components/ui/pagination.js';
|
||||
import test from 'node:test';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import React from 'react';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const PaginationFoundation =
|
||||
require('@douyinfe/semi-foundation/lib/cjs/pagination/foundation.js').default;
|
||||
|
||||
async function compile(relativePath) {
|
||||
const filename = new URL(relativePath, import.meta.url);
|
||||
const { code } = await transformWithEsbuild(
|
||||
@@ -54,9 +50,8 @@ async function compile(relativePath) {
|
||||
const loadUtils = await compile('../src/helpers/utils.jsx');
|
||||
const { createCardProPagination } = loadUtils({
|
||||
react: React,
|
||||
'@douyinfe/semi-ui': { Pagination: 'semi-pagination' },
|
||||
'@/components/ui': { Pagination: 'antd-pagination' },
|
||||
'../constants': { toastConstants: {} },
|
||||
'react-toastify': {},
|
||||
i18next: {},
|
||||
'../constants/playground.constants': {},
|
||||
'../hooks/common/useIsMobile': { MOBILE_BREAKPOINT: 768 },
|
||||
@@ -68,40 +63,25 @@ const loadUsersPage = await compile('../src/components/table/users/index.jsx');
|
||||
|
||||
function paginationProps(element) {
|
||||
const pagination = React.Children.toArray(element.props.children).find(
|
||||
(child) => child.type === 'semi-pagination',
|
||||
(child) => child.type === 'antd-pagination',
|
||||
);
|
||||
assert.ok(pagination, 'The helper must render Semi Pagination');
|
||||
assert.ok(pagination, 'The helper must render Ant Design Pagination');
|
||||
return pagination.props;
|
||||
}
|
||||
|
||||
function foundationFor(props) {
|
||||
const state = {
|
||||
currentPage: props.currentPage,
|
||||
pageSize: props.pageSize,
|
||||
total: props.total,
|
||||
const events = paginationEvents(props);
|
||||
return {
|
||||
changePageSize: size => { events.onShowSizeChange(props.currentPage, size); events.onChange(props.currentPage, size); },
|
||||
goPage: page => events.onChange(page, props.pageSize),
|
||||
};
|
||||
// Keep the render snapshot during the event, as with React's batched updates.
|
||||
// Only view-state setters are stubbed; Semi's callback decisions run unchanged.
|
||||
return new PaginationFoundation({
|
||||
getProps: () => props,
|
||||
getStates: () => state,
|
||||
getState: (key) => state[key],
|
||||
updatePageSize: () => {},
|
||||
updateTotal: () => {},
|
||||
setCurrentPage: () => {},
|
||||
setDisabled: () => {},
|
||||
setPageList: () => {},
|
||||
notifyPageSizeChange: (size) => props.onPageSizeChange(size),
|
||||
notifyPageChange: (page) => props.onPageChange(page),
|
||||
notifyChange: () => {},
|
||||
});
|
||||
}
|
||||
|
||||
for (const option of [{}, { preventPageChangeOnPageSizeChange: false }]) {
|
||||
const mode = Object.hasOwn(option, 'preventPageChangeOnPageSizeChange')
|
||||
? 'explicit false'
|
||||
: 'default';
|
||||
test(`other tables retain Semi's resize page callback: ${mode}`, () => {
|
||||
test(`other tables retain existing resize page callback: ${mode}`, () => {
|
||||
const calls = [];
|
||||
const props = paginationProps(
|
||||
createCardProPagination({
|
||||
|
||||
Reference in New Issue
Block a user