Skip to content

Commit

Permalink
feat: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
nuintun committed Sep 19, 2024
1 parent 8bf0043 commit 2a990d5
Show file tree
Hide file tree
Showing 27 changed files with 1,154 additions and 782 deletions.
1 change: 1 addition & 0 deletions app/js/components/ActionSwitch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function ActionSwitch<R>({
autoFocus={autoFocus}
className={className}
onChange={onSwitchChange}
disabled={restProps.disabled}
checkedChildren={checkedChildren}
unCheckedChildren={unCheckedChildren}
loading={restProps.confirm ? false : loading}
Expand Down
1 change: 1 addition & 0 deletions app/js/components/Document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @module index
*/

import 'dayjs/locale/zh-cn';
import zhCN from 'antd/locale/zh_CN';
import { ConfigProvider } from 'antd';
import { memo, useMemo } from 'react';
Expand Down
4 changes: 2 additions & 2 deletions app/js/components/FallBack/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import React, { memo } from 'react';
import { Spin, SpinProps } from 'antd';

export interface LoadingFallBackProps extends Pick<SpinProps, 'delay'>, Pick<React.CSSProperties, 'width' | 'height'> {}
export interface LoadingFallbackProps extends Pick<SpinProps, 'delay'>, Pick<React.CSSProperties, 'width' | 'height'> {}

export default memo(function LoadingFallBack({ delay = 128, width, height = 360 }: LoadingFallBackProps) {
export default memo(function LoadingFallback({ delay = 128, width, height = 360 }: LoadingFallbackProps) {
return (
<Spin delay={delay}>
<div style={{ width, height }} />
Expand Down
23 changes: 15 additions & 8 deletions app/js/components/FlexDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@
*/

import { isString } from '/js/utils/utils';
import { memo, useCallback, useRef } from 'react';
import useMediaQuery from '/js/hooks/useMediaQuery';
import { ConfigProvider, Drawer, DrawerProps } from 'antd';
import React, { memo, useCallback, useRef } from 'react';
import { ConfigProvider, Drawer, DrawerProps, GetProp } from 'antd';

export interface FlexDrawerProps extends DrawerProps {
breakWidth?: string | number;
breakHeight?: string | number;
}

const containerStyle: React.CSSProperties = {
minWidth: 'fit-content'
};

const drawerStyles: GetProp<DrawerProps, 'styles'> = {
body: {
outline: 'none',
position: 'relative'
}
};

export default memo(function FlexDrawer({
children,
height = 720,
width = 1440,
keyboard = false,
closeIcon = false,
maskClosable = false,
breakWidth = '100vw',
breakHeight = '100vh',
styles = { body: { position: 'relative' } },
styles = drawerStyles,
...restProps
}: FlexDrawerProps) {
const containerRef = useRef<HTMLDivElement>(null);
Expand All @@ -41,13 +50,11 @@ export default memo(function FlexDrawer({
<Drawer
{...restProps}
styles={styles}
keyboard={keyboard}
closeIcon={closeIcon}
maskClosable={maskClosable}
width={isBreakWidth ? breakWidth : width}
height={isBreakHeight ? breakHeight : height}
>
<div ref={containerRef}>
<div ref={containerRef} style={containerStyle}>
<ConfigProvider getPopupContainer={getPopupContainer} getTargetContainer={getTargetContainer}>
{children}
</ConfigProvider>
Expand Down
1 change: 1 addition & 0 deletions app/js/components/FlexLayout/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default createStyles(

[`.${prefixCls}-content`]: {
height: '100%',
outline: 'none',
overflow: 'auto',
position: 'relative',
msScrollChaining: 'none',
Expand Down
10 changes: 6 additions & 4 deletions app/js/components/FormDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ function createFormName(id: string): string {
return `form_${id.replace(/[^a-z_\d]/gi, '')}`;
}

export type Trigger = React.ReactElement<{
disabled?: boolean;
onClick?: (...args: unknown[]) => void;
}>;

export interface FormDrawerProps<F extends Fields, R>
extends Omit<FormProps<F>, FormOmitted>,
Pick<Options<F, R>, SubmitPicked>,
Pick<FlexDrawerProps, DrawerPicked> {
action: string;
trigger: Trigger;
onOpen?: () => void;
onClose?: () => void;
form?: FormInstance<F>;
trigger: React.ReactElement<{
disabled?: boolean;
onClick?: (...args: unknown[]) => void;
}>;
requestInit?: Omit<Options<F, R>, SubmitPicked>;
extra?: (submitting: boolean, form: FormInstance<F>, onClose: () => void) => React.ReactNode;
footer?: (submitting: boolean, form: FormInstance<F>, onClose: () => void) => React.ReactNode;
Expand Down
2 changes: 0 additions & 2 deletions app/js/components/Paper/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export default createStyles(['components', 'Paper', prefixCls], token => {
[`.${prefixCls}`]: {
margin: token.marginXS,
padding: token.padding,
minWidth: 'fit-content',
minHeight: 'fit-content',
borderRadius: token.borderRadius,
backgroundColor: token.colorBgContainer
}
Expand Down
12 changes: 8 additions & 4 deletions app/js/components/ViewDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { Button } from 'antd';
import FlexDrawer, { FlexDrawerProps } from '/js/components/FlexDrawer';
import React, { cloneElement, memo, useCallback, useEffect, useMemo, useState } from 'react';

export type Trigger = React.ReactElement<{
disabled?: boolean;
onClick?: (...args: unknown[]) => void;
}>;

export interface ViewDrawerProps extends Omit<FlexDrawerProps, 'open' | 'extra' | 'footer'> {
trigger: Trigger;
onOpen?: () => void;
onClose?: () => void;
trigger: React.ReactElement<{
disabled?: boolean;
onClick?: (...args: unknown[]) => void;
}>;
extra?: (onClose: () => void) => React.ReactNode;
footer?: (onClose: () => void) => React.ReactNode;
}
Expand All @@ -27,6 +29,7 @@ export default memo(function ViewDrawer({
trigger,
onClose,
children,
width = 768,
extra = defaultExtra,
...restProps
}: ViewDrawerProps) {
Expand Down Expand Up @@ -64,6 +67,7 @@ export default memo(function ViewDrawer({
<FlexDrawer
{...restProps}
open={open}
width={width}
onClose={onCloseHandler}
extra={extra(onCloseHandler)}
footer={footer?.(onCloseHandler)}
Expand Down
8 changes: 2 additions & 6 deletions app/js/hooks/createStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import {
AbstractCalculator,
CSSInterpolation,
genCalc,
token2CSSVar,
unit,
useCSSVarRegister,
useStyleRegister
} from '@ant-design/cssinjs';
import genMaxMin from 'antd/es/theme/util/maxmin';
import { genCalc } from '@ant-design/cssinjs-utils';
import { isNumber, isString } from '/js/utils/utils';
import { memo, ReactElement, useId, useMemo } from 'react';
import { AliasToken, GlobalToken, OverrideToken } from 'antd/es/theme/interface';
Expand Down Expand Up @@ -48,8 +47,6 @@ export interface UseStyles {
export interface CSSUtils {
unit(value: string | number): string;
calc(value: number | string): AbstractCalculator;
max(...values: (number | string)[]): number | string;
min(...values: (number | string)[]): number | string;
}

export interface Styles<C extends Components = Components> {
Expand Down Expand Up @@ -222,10 +219,9 @@ export default function createStyles<C extends Components = never>(path: string[

const utils = useMemo(() => {
const type = cssVar ? 'css' : 'js';
const { max, min } = genMaxMin(type);
const unitlessCssVar = new Set(Object.keys(unitless));

return { min, max, unit, calc: genCalc(type, unitlessCssVar) };
return { unit, calc: genCalc(type, unitlessCssVar) };
}, [cssVar, unitless]);

const render = useStyleRegister({ path, theme, token, hashId }, () => {
Expand Down
4 changes: 2 additions & 2 deletions app/js/hooks/useAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default function useAction<F extends Fields | null, R>(

if (confirm) {
const { disabled } = options;
const props: PopconfirmProps = isObject(confirm) ? confirm : { title: '警告', description: confirm };
const { okButtonProps, placement = 'topRight', icon = <QuestionCircleOutlined style={{ color: '#f00' }} /> } = props;
const props = isObject(confirm) ? confirm : { title: '警告', description: confirm };
const { okButtonProps, placement = 'topRight', icon = <QuestionCircleOutlined /> } = props;

return (
<Popconfirm
Expand Down
5 changes: 3 additions & 2 deletions app/js/hooks/useControllableValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ export default function useControllableValue<V = undefined>(

const valueRef = useLatestRef(value);

const setValue = useCallback((value: React.SetStateAction<V | undefined>, ...args: any[]): void => {
const setValue = useCallback((value: React.SetStateAction<V | undefined>, ...args: unknown[]): void => {
if (isMounted()) {
const { current: prevState } = valueRef;
const { defaultValue } = optionsRef.current;
const { current: prevState = defaultValue } = valueRef;
const state = isFunction(value) ? value(prevState) : value;

if (state !== prevState) {
Expand Down
1 change: 0 additions & 1 deletion app/js/hooks/usePagingOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default function usePagingOptions(opitons?: Options | false): UsePagingOp
responsive: true,
showSizeChanger: true,
showQuickJumper: true,
hideOnSinglePage: true,
...opitons,
pageSizeOptions: pageSizeOptions.map(item => item.toString())
};
Expand Down
2 changes: 1 addition & 1 deletion app/js/hooks/usePagingRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default function usePagingRequest<I, E = unknown, T = I>(

if (onError) {
onError(error);
} else {
} else if (error.code !== 401) {
message.error(error.message);
}
}
Expand Down
22 changes: 6 additions & 16 deletions app/js/hooks/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface Request {
export interface RequestOptions<R> extends Omit<Options, 'delay'> {
onComplete?: () => void;
onSuccess?: (response: R) => void;
onError?: (error: RequestError<R>) => void;
onError?: (error: RequestError) => void;
}

export interface Options extends Omit<RequestInit, 'onMessage' | 'onUnauthorized'> {
Expand All @@ -32,16 +32,6 @@ export interface Options extends Omit<RequestInit, 'onMessage' | 'onUnauthorized
onUnauthorized?: (navigate: Navigate, location: Location) => void;
}

/**
* @function onUnauthorizedHandler
* @description 默认未授权操作
* @param navigate 导航方法
* @param location 导航信息
*/
export function onUnauthorizedHandler(navigate: Navigate, location: Location): void {
navigate('/login', { state: location });
}

/**
* @function useRequest
* @description [hook] 请求操作
Expand Down Expand Up @@ -76,7 +66,7 @@ export default function useRequest(
if (onUnauthorized) {
onUnauthorized(navigate, location);
} else {
onUnauthorizedHandler(navigate, location);
navigate('/login', { state: location });
}
};

Expand All @@ -90,8 +80,8 @@ export default function useRequest(
}
}

const onMessage = (msg: string) => {
notify && message.success(msg);
const onMessage = (content: string) => {
notify && message.success(content);
};

fetch<R>(url, { ...requestInit, headers, onMessage, onUnauthorized })
Expand All @@ -101,13 +91,13 @@ export default function useRequest(
requestInit.onSuccess?.(response);
}
},
(error: RequestError<R>) => {
(error: RequestError) => {
if (isMounted()) {
const { onError } = requestInit;

if (onError) {
onError(error);
} else {
} else if (error.code !== 401) {
message.error(error.message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/js/hooks/useResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function useResponse<R, T>(
...options
};

request(urlRef.current, {
request<R>(urlRef.current, {
...requestInit,
onSuccess(response) {
const { transform } = requestInit;
Expand Down
2 changes: 1 addition & 1 deletion app/js/hooks/useSearchFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Query as Filter } from '/js/utils/request';
export type { Filter };

export type SearchFilters<T extends Filter[]> = {
[K in keyof T]: T[K] | false;
[K in keyof T]: T[K] extends Filter ? T[K] | false : T[K];
};

/**
Expand Down
2 changes: 1 addition & 1 deletion app/js/hooks/useSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Options<F extends Fields | null, R> extends Omit<RequestOptions
onComplete?: (fields: F) => void;
normalize?: (fields: F) => Fields;
onSuccess?: (response: R, fields: F) => void;
onError?: (error: RequestError<R>, fields: F) => void;
onError?: (error: RequestError, fields: F) => void;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/js/hooks/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default function useTable<I, E = unknown, T = I>(
}
}, []);

const pagination = useMemo(() => {
const pagination = useMemo<GetProp<TableProps<I>, 'pagination'>>(() => {
const originRefsPagination = originRefs.pagination;

if (hasQuery(originRefsPagination)) {
Expand Down
Loading

0 comments on commit 2a990d5

Please sign in to comment.