Compare commits
2 Commits
aaa
...
82d043a414
| Author | SHA1 | Date | |
|---|---|---|---|
| 82d043a414 | |||
| 12495b6d85 |
@@ -4,8 +4,8 @@ NODE_ENV=development
|
|||||||
VITE_DEV=true
|
VITE_DEV=true
|
||||||
|
|
||||||
# 请求路径
|
# 请求路径
|
||||||
# VITE_BASE_URL='http://114.132.60.20:48080'
|
VITE_BASE_URL='http://114.132.60.20:48080'
|
||||||
VITE_BASE_URL='http://192.168.1.114:48080' # 理君
|
# VITE_BASE_URL='http://192.168.1.114:48080' # 理君
|
||||||
|
|
||||||
|
|
||||||
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
|
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
"@ant-design/icons": "^5.6.1",
|
"@ant-design/icons": "^5.6.1",
|
||||||
"@ant-design/pro-components": "^2.8.9",
|
"@ant-design/pro-components": "^2.8.9",
|
||||||
"@ant-design/v5-patch-for-react-19": "^1.0.3",
|
"@ant-design/v5-patch-for-react-19": "^1.0.3",
|
||||||
|
"@tinymce/tinymce-react": "^6.3.0",
|
||||||
"antd": "^5.26.4",
|
"antd": "^5.26.4",
|
||||||
"antd-style": "^3.7.0",
|
"antd-style": "^3.7.0",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
"jsencrypt": "^3.5.4",
|
"jsencrypt": "^3.5.4",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.0",
|
||||||
|
"tinymce": "^8.1.2",
|
||||||
"web-storage-cache": "^1.1.1"
|
"web-storage-cache": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
29
pnpm-lock.yaml
generated
29
pnpm-lock.yaml
generated
@@ -17,6 +17,9 @@ importers:
|
|||||||
'@ant-design/v5-patch-for-react-19':
|
'@ant-design/v5-patch-for-react-19':
|
||||||
specifier: ^1.0.3
|
specifier: ^1.0.3
|
||||||
version: 1.0.3(antd@5.27.3(date-fns@2.30.0)(moment@2.30.1)(react-dom@19.1.1(react@19.1.1))(react@19.1.1))(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
version: 1.0.3(antd@5.27.3(date-fns@2.30.0)(moment@2.30.1)(react-dom@19.1.1(react@19.1.1))(react@19.1.1))(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||||
|
'@tinymce/tinymce-react':
|
||||||
|
specifier: ^6.3.0
|
||||||
|
version: 6.3.0(react-dom@19.1.1(react@19.1.1))(react@19.1.1)(tinymce@8.1.2)
|
||||||
antd:
|
antd:
|
||||||
specifier: ^5.26.4
|
specifier: ^5.26.4
|
||||||
version: 5.27.3(date-fns@2.30.0)(moment@2.30.1)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
version: 5.27.3(date-fns@2.30.0)(moment@2.30.1)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||||
@@ -38,6 +41,9 @@ importers:
|
|||||||
react-dom:
|
react-dom:
|
||||||
specifier: ^19.1.0
|
specifier: ^19.1.0
|
||||||
version: 19.1.1(react@19.1.1)
|
version: 19.1.1(react@19.1.1)
|
||||||
|
tinymce:
|
||||||
|
specifier: ^8.1.2
|
||||||
|
version: 8.1.2
|
||||||
web-storage-cache:
|
web-storage-cache:
|
||||||
specifier: ^1.1.1
|
specifier: ^1.1.1
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
@@ -2551,6 +2557,16 @@ packages:
|
|||||||
'@types/react-dom':
|
'@types/react-dom':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
'@tinymce/tinymce-react@6.3.0':
|
||||||
|
resolution: {integrity: sha512-E++xnn0XzDzpKr40jno2Kj7umfAE6XfINZULEBBeNjTMvbACWzA6CjiR6V8eTDc9yVmdVhIPqVzV4PqD5TZ/4g==}
|
||||||
|
peerDependencies:
|
||||||
|
react: ^19.0.0 || ^18.0.0 || ^17.0.1 || ^16.7.0
|
||||||
|
react-dom: ^19.0.0 || ^18.0.0 || ^17.0.1 || ^16.7.0
|
||||||
|
tinymce: ^8.0.0 || ^7.0.0 || ^6.0.0 || ^5.5.1
|
||||||
|
peerDependenciesMeta:
|
||||||
|
tinymce:
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@tootallnate/once@1.1.2':
|
'@tootallnate/once@1.1.2':
|
||||||
resolution: {integrity: sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==}
|
resolution: {integrity: sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
@@ -10246,6 +10262,9 @@ packages:
|
|||||||
tinyexec@1.0.1:
|
tinyexec@1.0.1:
|
||||||
resolution: {integrity: sha512-5uC6DDlmeqiOwCPmK9jMSdOuZTh8bU39Ys6yidB+UTt5hfZUPGAypSgFRiEp+jbi9qH40BLDvy85jIU88wKSqw==}
|
resolution: {integrity: sha512-5uC6DDlmeqiOwCPmK9jMSdOuZTh8bU39Ys6yidB+UTt5hfZUPGAypSgFRiEp+jbi9qH40BLDvy85jIU88wKSqw==}
|
||||||
|
|
||||||
|
tinymce@8.1.2:
|
||||||
|
resolution: {integrity: sha512-KITxHEEHRlxC5xOnxA123eAJ67NgsWxNphtItWt9TRu07DiTZrWIqJeIKRX9euE51/l3kJO4WQiqoBXKTJJGsA==}
|
||||||
|
|
||||||
titleize@3.0.0:
|
titleize@3.0.0:
|
||||||
resolution: {integrity: sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==}
|
resolution: {integrity: sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
@@ -14715,6 +14734,14 @@ snapshots:
|
|||||||
'@types/react': 19.1.12
|
'@types/react': 19.1.12
|
||||||
'@types/react-dom': 19.1.9(@types/react@19.1.12)
|
'@types/react-dom': 19.1.9(@types/react@19.1.12)
|
||||||
|
|
||||||
|
'@tinymce/tinymce-react@6.3.0(react-dom@19.1.1(react@19.1.1))(react@19.1.1)(tinymce@8.1.2)':
|
||||||
|
dependencies:
|
||||||
|
prop-types: 15.8.1
|
||||||
|
react: 19.1.1
|
||||||
|
react-dom: 19.1.1(react@19.1.1)
|
||||||
|
optionalDependencies:
|
||||||
|
tinymce: 8.1.2
|
||||||
|
|
||||||
'@tootallnate/once@1.1.2': {}
|
'@tootallnate/once@1.1.2': {}
|
||||||
|
|
||||||
'@tootallnate/once@2.0.0': {}
|
'@tootallnate/once@2.0.0': {}
|
||||||
@@ -24850,6 +24877,8 @@ snapshots:
|
|||||||
|
|
||||||
tinyexec@1.0.1: {}
|
tinyexec@1.0.1: {}
|
||||||
|
|
||||||
|
tinymce@8.1.2: {}
|
||||||
|
|
||||||
titleize@3.0.0: {}
|
titleize@3.0.0: {}
|
||||||
|
|
||||||
tldts-core@6.1.86: {}
|
tldts-core@6.1.86: {}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import { CloseOutlined } from '@ant-design/icons';
|
|
||||||
import type { ProFormColumnsType } from '@ant-design/pro-components';
|
import type { ProFormColumnsType } from '@ant-design/pro-components';
|
||||||
import { BetaSchemaForm, DrawerForm } from '@ant-design/pro-components';
|
import { BetaSchemaForm } from '@ant-design/pro-components';
|
||||||
import { Button, type ColProps, Drawer, Space, Typography } from 'antd';
|
import { Button, type ColProps, Drawer, Space, Typography } from 'antd';
|
||||||
import React, { forwardRef, useImperativeHandle } from 'react';
|
import React, { forwardRef, useImperativeHandle } from 'react';
|
||||||
|
|
||||||
const { Title } = Typography;
|
|
||||||
interface ConfigurableDrawerFormProps {
|
interface ConfigurableDrawerFormProps {
|
||||||
title?: string;
|
title?: string;
|
||||||
columns: ProFormColumnsType[];
|
columns: ProFormColumnsType[];
|
||||||
onSubmit?: (values: any) => Promise<boolean>;
|
onSubmit?: (values: any) => Promise<boolean>;
|
||||||
initialValues?: Record<string, any>;
|
initialValues?: Record<string, any>;
|
||||||
width?: number;
|
width?: number | string;
|
||||||
labelCol?: ColProps;
|
labelCol?: ColProps;
|
||||||
wrapperCol?: ColProps;
|
wrapperCol?: ColProps;
|
||||||
}
|
}
|
||||||
@@ -70,31 +68,31 @@ const ConfigurableDrawerForm = forwardRef<
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const customHeader = (
|
// const customHeader = (
|
||||||
<div
|
// <div
|
||||||
style={{
|
// style={{
|
||||||
display: 'flex',
|
// display: "flex",
|
||||||
justifyContent: 'space-between',
|
// justifyContent: "space-between",
|
||||||
alignItems: 'center',
|
// alignItems: "center",
|
||||||
padding: '0 0px 16px 0px',
|
// padding: "0 0px 16px 0px",
|
||||||
borderBottom: '1px solid #f0f0f0',
|
// borderBottom: "1px solid #f0f0f0",
|
||||||
marginBottom: '16px',
|
// marginBottom: "16px",
|
||||||
}}
|
// }}
|
||||||
>
|
// >
|
||||||
<Title level={4} style={{ margin: 0 }}>
|
// <Title level={4} style={{ margin: 0 }}>
|
||||||
{title}
|
// {title}
|
||||||
</Title>
|
// </Title>
|
||||||
<Button
|
// <Button
|
||||||
type="text"
|
// type="text"
|
||||||
icon={<CloseOutlined />}
|
// icon={<CloseOutlined />}
|
||||||
onClick={() => setOpen(false)}
|
// onClick={() => setOpen(false)}
|
||||||
style={{
|
// style={{
|
||||||
border: 'none',
|
// border: "none",
|
||||||
boxShadow: 'none',
|
// boxShadow: "none",
|
||||||
}}
|
// }}
|
||||||
/>
|
// />
|
||||||
</div>
|
// </div>
|
||||||
);
|
// );
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
title={title}
|
title={title}
|
||||||
|
|||||||
@@ -4,30 +4,12 @@ import { PlusOutlined } from '@ant-design/icons';
|
|||||||
import {
|
import {
|
||||||
type ActionType,
|
type ActionType,
|
||||||
type ParamsType,
|
type ParamsType,
|
||||||
ProColumns,
|
|
||||||
ProTable,
|
ProTable,
|
||||||
TableDropdown,
|
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Button, Space } from 'antd';
|
import { Button, Space } from 'antd';
|
||||||
import React, {
|
import React, { forwardRef, useCallback, useMemo, useState } from 'react';
|
||||||
act,
|
import { formatPaginationTotal } from '@/utils/antd/tableHelpers';
|
||||||
forwardRef,
|
import type { BaseRecord, EnhancedProTableProps } from './types';
|
||||||
useCallback,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
import {
|
|
||||||
buildTableDropdownMenuItems,
|
|
||||||
formatPaginationTotal,
|
|
||||||
handleTableDropdownSelect,
|
|
||||||
} from '@/utils/antd/tableHelpers';
|
|
||||||
import {
|
|
||||||
type BaseRecord,
|
|
||||||
type EnhancedProTableProps,
|
|
||||||
TableAction,
|
|
||||||
ToolbarAction,
|
|
||||||
} from './types';
|
|
||||||
|
|
||||||
function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
||||||
props: EnhancedProTableProps<T, U>,
|
props: EnhancedProTableProps<T, U>,
|
||||||
@@ -36,21 +18,22 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
|||||||
const {
|
const {
|
||||||
columns,
|
columns,
|
||||||
request,
|
request,
|
||||||
actions = [],
|
// actions = [],
|
||||||
permissions = [],
|
// permissions = [],
|
||||||
checkPermission = () => true,
|
checkPermission = () => true,
|
||||||
toolbarActions,
|
toolbarActions,
|
||||||
showIndex = true,
|
showIndex = true,
|
||||||
showSelection = true,
|
showSelection = true,
|
||||||
showActions = true,
|
// showActions = true,
|
||||||
maxActionCount = 2,
|
// maxActionCount = 2,
|
||||||
onAdd,
|
// onAdd,
|
||||||
onEdit,
|
// onEdit,
|
||||||
onDelete,
|
// onDelete,
|
||||||
onView,
|
// onView,
|
||||||
onExport,
|
// onExport,
|
||||||
customToolbarRender,
|
// customToolbarRender,
|
||||||
customActionRender,
|
customActionRender,
|
||||||
|
rowKey,
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
@@ -91,14 +74,13 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
|||||||
[showSelection],
|
[showSelection],
|
||||||
);
|
);
|
||||||
|
|
||||||
const toolBarRender = useCallback(
|
const toolBarRender = useCallback(() =>
|
||||||
(
|
// action: ActionType | undefined,
|
||||||
action: ActionType | undefined,
|
// rows: {
|
||||||
rows: {
|
// selectedRowKeys?: (string | number)[] | undefined;
|
||||||
selectedRowKeys?: (string | number)[] | undefined;
|
// selectedRows?: T[] | undefined;
|
||||||
selectedRows?: T[] | undefined;
|
// }
|
||||||
},
|
{
|
||||||
) => {
|
|
||||||
const toolbarElements =
|
const toolbarElements =
|
||||||
toolbarActions?.map((action) => {
|
toolbarActions?.map((action) => {
|
||||||
return (
|
return (
|
||||||
@@ -125,22 +107,19 @@ function EnhancedProTable<T extends BaseRecord, U extends ParamsType = any>(
|
|||||||
// </Button>,
|
// </Button>,
|
||||||
// ];
|
// ];
|
||||||
return toolbarElements;
|
return toolbarElements;
|
||||||
},
|
}, [toolbarActions]);
|
||||||
[toolbarActions],
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<ProTable<T, U>
|
<ProTable<T, U>
|
||||||
{...restProps}
|
{...restProps}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
actionRef={ref}
|
actionRef={ref}
|
||||||
request={request}
|
request={request}
|
||||||
rowKey="id"
|
rowKey={rowKey || 'id'}
|
||||||
rowSelection={rowSelection}
|
rowSelection={rowSelection}
|
||||||
toolBarRender={toolBarRender}
|
toolBarRender={toolBarRender}
|
||||||
manualRequest={false}
|
manualRequest={false}
|
||||||
showSorterTooltip
|
showSorterTooltip
|
||||||
tableAlertRender={tableAlertRender}
|
tableAlertRender={tableAlertRender}
|
||||||
// tableAlertOptionRender={tableAlertOptionRender}
|
|
||||||
scroll={{ x: 'max-content' }}
|
scroll={{ x: 'max-content' }}
|
||||||
search={{
|
search={{
|
||||||
labelWidth: 'auto',
|
labelWidth: 'auto',
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
// components/EnhancedProTable/types.ts
|
// components/EnhancedProTable/types.ts
|
||||||
import {
|
import type {
|
||||||
ProTableProps,
|
|
||||||
ProColumns,
|
|
||||||
ActionType,
|
ActionType,
|
||||||
} from "@ant-design/pro-components";
|
ProColumns,
|
||||||
import { ButtonProps } from "antd";
|
ProTableProps,
|
||||||
import React from "react";
|
} from '@ant-design/pro-components';
|
||||||
|
import type { ButtonProps } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
export interface BaseRecord {
|
export interface BaseRecord {
|
||||||
id: number;
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiResponse<T> {
|
export interface ApiResponse<T> {
|
||||||
data: T[];
|
data: T[];
|
||||||
total: number;
|
total?: number;
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
@@ -32,7 +31,7 @@ export interface TableAction<T = any> {
|
|||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
type?: ButtonProps["type"];
|
type?: ButtonProps['type'];
|
||||||
danger?: boolean;
|
danger?: boolean;
|
||||||
disabled?: (record: T) => boolean;
|
disabled?: (record: T) => boolean;
|
||||||
visible?: (record: T) => boolean;
|
visible?: (record: T) => boolean;
|
||||||
@@ -44,7 +43,7 @@ export interface ToolbarAction {
|
|||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
type?: ButtonProps["type"];
|
type?: ButtonProps['type'];
|
||||||
danger?: boolean;
|
danger?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onClick: (selectedKeys?: React.Key[], selectedRows?: any[]) => void;
|
onClick: (selectedKeys?: React.Key[], selectedRows?: any[]) => void;
|
||||||
@@ -53,10 +52,10 @@ export interface ToolbarAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface EnhancedProTableProps<T extends BaseRecord, U = any>
|
export interface EnhancedProTableProps<T extends BaseRecord, U = any>
|
||||||
extends Omit<ProTableProps<T, U>, "columns" | "request" | "toolBarRender"> {
|
extends Omit<ProTableProps<T, U>, 'columns' | 'request' | 'toolBarRender'> {
|
||||||
columns: ProColumns<T>[];
|
columns: ProColumns<T>[];
|
||||||
request?: (
|
request?: (
|
||||||
params: U & { current?: number; pageSize?: number }
|
params: U & { current?: number; pageSize?: number },
|
||||||
) => Promise<ApiResponse<T>>;
|
) => Promise<ApiResponse<T>>;
|
||||||
loading?: boolean; // 添加 loading 属性
|
loading?: boolean; // 添加 loading 属性
|
||||||
actions?: TableAction<T>[];
|
actions?: TableAction<T>[];
|
||||||
@@ -73,11 +72,11 @@ export interface EnhancedProTableProps<T extends BaseRecord, U = any>
|
|||||||
onView?: (record: T) => void;
|
onView?: (record: T) => void;
|
||||||
onExport?: (selectedRows: T[]) => void;
|
onExport?: (selectedRows: T[]) => void;
|
||||||
customToolbarRender?: (
|
customToolbarRender?: (
|
||||||
defaultActions: React.ReactNode[]
|
defaultActions: React.ReactNode[],
|
||||||
) => React.ReactNode[];
|
) => React.ReactNode[];
|
||||||
customActionRender?: (
|
customActionRender?: (
|
||||||
record: T,
|
record: T,
|
||||||
defaultActions: React.ReactNode[]
|
defaultActions: React.ReactNode[],
|
||||||
) => React.ReactNode[];
|
) => React.ReactNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
105
src/components/TagEditor/index.tsx
Normal file
105
src/components/TagEditor/index.tsx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
// src/components/TagEditor/index.tsx
|
||||||
|
|
||||||
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
|
import type { TagProps } from 'antd';
|
||||||
|
import { Input, Space, Tag } from 'antd';
|
||||||
|
import React, { useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
interface TagEditorProps {
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (value: string[]) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
maxCount?: number;
|
||||||
|
tagProps?: TagProps;
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TagEditor: React.FC<TagEditorProps> = ({
|
||||||
|
value = [],
|
||||||
|
onChange,
|
||||||
|
placeholder = '请输入标签',
|
||||||
|
maxCount,
|
||||||
|
tagProps,
|
||||||
|
disabled = false,
|
||||||
|
}) => {
|
||||||
|
// const [tags, setTags] = useState<string[]>(value);
|
||||||
|
const [inputVisible, setInputVisible] = useState(false);
|
||||||
|
const [inputValue, setInputValue] = useState('');
|
||||||
|
|
||||||
|
const tags = useMemo(() => {
|
||||||
|
return value || [];
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
const handleClose = (removedTag: string) => {
|
||||||
|
const newTags = tags.filter((tag) => tag !== removedTag);
|
||||||
|
onChange?.(newTags);
|
||||||
|
};
|
||||||
|
|
||||||
|
const showInput = () => {
|
||||||
|
setInputVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setInputValue(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputConfirm = () => {
|
||||||
|
if (inputValue && !tags.includes(inputValue)) {
|
||||||
|
const newTags = [...tags, inputValue];
|
||||||
|
onChange?.(newTags);
|
||||||
|
}
|
||||||
|
setInputVisible(false);
|
||||||
|
setInputValue('');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputBlur = () => {
|
||||||
|
handleInputConfirm();
|
||||||
|
};
|
||||||
|
|
||||||
|
const canAddMore = !maxCount || tags.length < maxCount;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Space wrap>
|
||||||
|
{tags.map((tag) => (
|
||||||
|
<Tag
|
||||||
|
key={tag}
|
||||||
|
closable={!disabled}
|
||||||
|
onClose={() => handleClose(tag)}
|
||||||
|
{...tagProps}
|
||||||
|
>
|
||||||
|
{tag}
|
||||||
|
</Tag>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{inputVisible ? (
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
style={{ width: 110 }}
|
||||||
|
value={inputValue}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
onBlur={handleInputBlur}
|
||||||
|
onPressEnter={handleInputConfirm}
|
||||||
|
placeholder={placeholder}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
canAddMore &&
|
||||||
|
!disabled && (
|
||||||
|
<Tag
|
||||||
|
onClick={showInput}
|
||||||
|
style={{
|
||||||
|
background: '#fff',
|
||||||
|
borderStyle: 'dashed',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PlusOutlined /> 添加标签
|
||||||
|
</Tag>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TagEditor;
|
||||||
691
src/components/Tinymce/demo.tsx
Normal file
691
src/components/Tinymce/demo.tsx
Normal file
@@ -0,0 +1,691 @@
|
|||||||
|
// components/RichEditor/index.tsx
|
||||||
|
|
||||||
|
import { Editor } from '@tinymce/tinymce-react';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
|
import type { Editor as TinyMCEEditor } from 'tinymce';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
export interface RichEditorProps {
|
||||||
|
value?: string;
|
||||||
|
onChange?: (content: string) => void;
|
||||||
|
height?: number;
|
||||||
|
placeholder?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
uploadConfig?: {
|
||||||
|
action: string;
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
maxSize?: number;
|
||||||
|
acceptTypes?: string[];
|
||||||
|
data?: Record<string, any>;
|
||||||
|
};
|
||||||
|
showWordCount?: boolean;
|
||||||
|
maxWords?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RichEditor: React.FC<RichEditorProps> = ({
|
||||||
|
value = '',
|
||||||
|
onChange,
|
||||||
|
height = 400,
|
||||||
|
placeholder = '请输入内容...',
|
||||||
|
disabled = false,
|
||||||
|
showWordCount = true,
|
||||||
|
maxWords,
|
||||||
|
uploadConfig = {
|
||||||
|
action: '/api/upload/image',
|
||||||
|
maxSize: 5,
|
||||||
|
acceptTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
||||||
|
},
|
||||||
|
}) => {
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const [wordCount, setWordCount] = useState(0);
|
||||||
|
const [charCount, setCharCount] = useState(0);
|
||||||
|
|
||||||
|
// 自定义字数统计函数
|
||||||
|
const countWords = (text: string) => {
|
||||||
|
const plainText = text.replace(/<[^>]*>/g, '');
|
||||||
|
const cleanText = plainText.replace(/\s+/g, ' ').trim();
|
||||||
|
|
||||||
|
if (!cleanText) return { words: 0, characters: 0 };
|
||||||
|
|
||||||
|
const chineseChars = cleanText.match(/[\u4e00-\u9fa5]/g) || [];
|
||||||
|
const englishWords = cleanText.match(/[a-zA-Z]+/g) || [];
|
||||||
|
const numbers = cleanText.match(/\d+/g) || [];
|
||||||
|
|
||||||
|
const words = chineseChars.length + englishWords.length + numbers.length;
|
||||||
|
const characters = cleanText.length;
|
||||||
|
|
||||||
|
return { words, characters };
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditorChange = (content: string) => {
|
||||||
|
onChange?.(content);
|
||||||
|
|
||||||
|
if (showWordCount) {
|
||||||
|
const { words, characters } = countWords(content);
|
||||||
|
setWordCount(words);
|
||||||
|
setCharCount(characters);
|
||||||
|
|
||||||
|
if (maxWords && words > maxWords) {
|
||||||
|
message.warning(
|
||||||
|
`内容超出字数限制,当前 ${words} 字,限制 ${maxWords} 字`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (showWordCount && value) {
|
||||||
|
const { words, characters } = countWords(value);
|
||||||
|
setWordCount(words);
|
||||||
|
setCharCount(characters);
|
||||||
|
}
|
||||||
|
}, [value, showWordCount]);
|
||||||
|
|
||||||
|
const uploadFile = useCallback(
|
||||||
|
async (file: File): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
if (uploadConfig.data) {
|
||||||
|
Object.keys(uploadConfig.data).forEach((key) => {
|
||||||
|
if (uploadConfig.data) formData.append(key, uploadConfig.data[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhr.upload.addEventListener('progress', (e) => {
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
const percent = Math.round((e.loaded / e.total) * 100);
|
||||||
|
console.log(`上传进度: ${percent}%`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.addEventListener('load', () => {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
try {
|
||||||
|
const response = JSON.parse(xhr.responseText);
|
||||||
|
if (response.code === 200 && response.data?.url) {
|
||||||
|
resolve(response.data.url);
|
||||||
|
} else {
|
||||||
|
reject(response.message || '上传失败');
|
||||||
|
}
|
||||||
|
} catch (_error) {
|
||||||
|
reject('响应解析失败');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(`上传失败: ${xhr.status}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.addEventListener('error', () => {
|
||||||
|
reject('网络错误');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (uploadConfig.headers) {
|
||||||
|
Object.keys(uploadConfig.headers).forEach((key) => {
|
||||||
|
if (uploadConfig.headers)
|
||||||
|
xhr.setRequestHeader(key, uploadConfig.headers[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.open('POST', uploadConfig.action);
|
||||||
|
xhr.send(formData);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[uploadConfig],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleImageUpload = useCallback(
|
||||||
|
(blobInfo: any, _: (percent: number) => void): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
setUploading(true);
|
||||||
|
const file = blobInfo.blob();
|
||||||
|
uploadFile(file).then((url) => {
|
||||||
|
resolve(url);
|
||||||
|
message.success('图片上传成功');
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
message.error(typeof error === 'string' ? error : '上传失败');
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[uploadFile],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCustomUpload = useCallback(
|
||||||
|
(editor: TinyMCEEditor) => {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = uploadConfig.acceptTypes?.join(',') || 'image/*';
|
||||||
|
input.multiple = true;
|
||||||
|
|
||||||
|
const handleFileChange = async (event: Event) => {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const files = Array.from(target.files || []);
|
||||||
|
|
||||||
|
if (files.length === 0) return;
|
||||||
|
|
||||||
|
setUploading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const file of files) {
|
||||||
|
const isValidType = uploadConfig.acceptTypes?.includes(file.type);
|
||||||
|
if (!isValidType) {
|
||||||
|
message.error(`文件 ${file.name} 类型不支持`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isValidSize =
|
||||||
|
file.size / 1024 / 1024 < (uploadConfig.maxSize || 5);
|
||||||
|
if (!isValidSize) {
|
||||||
|
message.error(
|
||||||
|
`文件 ${file.name} 大小超过 ${uploadConfig.maxSize || 5}MB`,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = await uploadFile(file);
|
||||||
|
const imgHtml = `<img src="${url}" alt="${file.name}" style="max-width: 100%; height: auto;" />`;
|
||||||
|
editor.insertContent(imgHtml);
|
||||||
|
message.success(`${file.name} 上传成功`);
|
||||||
|
} catch (error) {
|
||||||
|
message.error(`${file.name} 上传失败: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
input.addEventListener('change', handleFileChange);
|
||||||
|
input.click();
|
||||||
|
},
|
||||||
|
[uploadConfig, uploadFile],
|
||||||
|
);
|
||||||
|
|
||||||
|
// 全展开的工具栏配置
|
||||||
|
const editorConfig = {
|
||||||
|
height,
|
||||||
|
menubar: 'file edit view insert format tools table help',
|
||||||
|
plugins: [
|
||||||
|
'advlist',
|
||||||
|
'autolink',
|
||||||
|
'lists',
|
||||||
|
'link',
|
||||||
|
'image',
|
||||||
|
'charmap',
|
||||||
|
'preview',
|
||||||
|
'anchor',
|
||||||
|
'searchreplace',
|
||||||
|
'visualblocks',
|
||||||
|
'code',
|
||||||
|
'fullscreen',
|
||||||
|
'insertdatetime',
|
||||||
|
'media',
|
||||||
|
'table',
|
||||||
|
'help',
|
||||||
|
'wordcount',
|
||||||
|
'emoticons',
|
||||||
|
'template',
|
||||||
|
'codesample',
|
||||||
|
'hr',
|
||||||
|
'pagebreak',
|
||||||
|
'nonbreaking',
|
||||||
|
'toc',
|
||||||
|
'imagetools',
|
||||||
|
'textpattern',
|
||||||
|
'noneditable',
|
||||||
|
'quickbars',
|
||||||
|
'accordion',
|
||||||
|
],
|
||||||
|
|
||||||
|
// 修改为全展开的工具栏配置
|
||||||
|
toolbar: [
|
||||||
|
// 第一行:撤销重做 + 格式选择 + 字体
|
||||||
|
'undo redo | blocks fontfamily fontsize',
|
||||||
|
|
||||||
|
// 第二行:文本格式
|
||||||
|
'bold italic underline strikethrough subscript superscript | forecolor backcolor',
|
||||||
|
|
||||||
|
// 第三行:对齐和列表
|
||||||
|
'alignleft aligncenter alignright alignjustify | bullist numlist outdent indent',
|
||||||
|
|
||||||
|
// 第四行:插入功能
|
||||||
|
'link customupload image media table emoticons charmap insertdatetime hr pagebreak',
|
||||||
|
|
||||||
|
// 第五行:高级功能
|
||||||
|
'codesample accordion blockquote | searchreplace visualblocks code',
|
||||||
|
|
||||||
|
// 第六行:其他工具
|
||||||
|
'removeformat | fullscreen preview help',
|
||||||
|
].join(' | '),
|
||||||
|
|
||||||
|
// 设置工具栏模式为换行显示,而不是滑动
|
||||||
|
toolbar_mode: 'wrap' as const, // 改为 wrap 模式,全部展开
|
||||||
|
|
||||||
|
// 工具栏分组,每组之间有分隔符
|
||||||
|
toolbar_groups: {
|
||||||
|
history: { icon: 'undo', tooltip: '历史操作' },
|
||||||
|
formatting: { icon: 'bold', tooltip: '文本格式' },
|
||||||
|
alignment: { icon: 'align-left', tooltip: '对齐方式' },
|
||||||
|
indentation: { icon: 'indent', tooltip: '缩进' },
|
||||||
|
insert: { icon: 'plus', tooltip: '插入' },
|
||||||
|
tools: { icon: 'preferences', tooltip: '工具' },
|
||||||
|
},
|
||||||
|
|
||||||
|
font_family_formats: [
|
||||||
|
'微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif',
|
||||||
|
'苹方=PingFang SC,Microsoft YaHei,sans-serif',
|
||||||
|
'宋体=SimSun,serif',
|
||||||
|
'黑体=SimHei,sans-serif',
|
||||||
|
'楷体=KaiTi,serif',
|
||||||
|
'Arial=arial,helvetica,sans-serif',
|
||||||
|
'Times New Roman=times new roman,times,serif',
|
||||||
|
'Courier New=courier new,courier,monospace',
|
||||||
|
].join(';'),
|
||||||
|
|
||||||
|
fontsize_formats:
|
||||||
|
'8px 9px 10px 11px 12px 14px 16px 18px 20px 22px 24px 26px 28px 36px 48px 72px',
|
||||||
|
|
||||||
|
block_formats: [
|
||||||
|
'段落=p',
|
||||||
|
'标题1=h1',
|
||||||
|
'标题2=h2',
|
||||||
|
'标题3=h3',
|
||||||
|
'标题4=h4',
|
||||||
|
'标题5=h5',
|
||||||
|
'标题6=h6',
|
||||||
|
'预格式化=pre',
|
||||||
|
'地址=address',
|
||||||
|
'代码=code',
|
||||||
|
].join(';'),
|
||||||
|
|
||||||
|
// 字数统计配置
|
||||||
|
wordcount_countregex: /[\w\u2019\u4e00-\u9fa5]+/g,
|
||||||
|
wordcount_cleanregex: /[0-9.(),;:!?%#$?\x27\x22_+=\\/-]*/g,
|
||||||
|
|
||||||
|
// 颜色配置
|
||||||
|
color_map: [
|
||||||
|
'000000',
|
||||||
|
'黑色',
|
||||||
|
'993300',
|
||||||
|
'深红色',
|
||||||
|
'333300',
|
||||||
|
'深黄色',
|
||||||
|
'003300',
|
||||||
|
'深绿色',
|
||||||
|
'003366',
|
||||||
|
'深青色',
|
||||||
|
'000080',
|
||||||
|
'深蓝色',
|
||||||
|
'333399',
|
||||||
|
'蓝色',
|
||||||
|
'333333',
|
||||||
|
'深灰色',
|
||||||
|
'800000',
|
||||||
|
'栗色',
|
||||||
|
'FF6600',
|
||||||
|
'橙色',
|
||||||
|
'808000',
|
||||||
|
'橄榄色',
|
||||||
|
'008000',
|
||||||
|
'绿色',
|
||||||
|
'008080',
|
||||||
|
'青色',
|
||||||
|
'0000FF',
|
||||||
|
'蓝色',
|
||||||
|
'666699',
|
||||||
|
'灰蓝色',
|
||||||
|
'808080',
|
||||||
|
'灰色',
|
||||||
|
'FF0000',
|
||||||
|
'红色',
|
||||||
|
'FF9900',
|
||||||
|
'琥珀色',
|
||||||
|
'99CC00',
|
||||||
|
'黄绿色',
|
||||||
|
'339966',
|
||||||
|
'海绿色',
|
||||||
|
'33CCCC',
|
||||||
|
'青绿色',
|
||||||
|
'3366FF',
|
||||||
|
'蓝色',
|
||||||
|
'800080',
|
||||||
|
'紫色',
|
||||||
|
'999999',
|
||||||
|
'中灰色',
|
||||||
|
'FF00FF',
|
||||||
|
'洋红色',
|
||||||
|
'FFCC00',
|
||||||
|
'金色',
|
||||||
|
'FFFF00',
|
||||||
|
'黄色',
|
||||||
|
'00FF00',
|
||||||
|
'酸橙色',
|
||||||
|
'00FFFF',
|
||||||
|
'水蓝色',
|
||||||
|
'00CCFF',
|
||||||
|
'天蓝色',
|
||||||
|
'993366',
|
||||||
|
'红紫色',
|
||||||
|
'FFFFFF',
|
||||||
|
'白色',
|
||||||
|
],
|
||||||
|
|
||||||
|
// 代码高亮配置
|
||||||
|
codesample_languages: [
|
||||||
|
{ text: 'HTML/XML', value: 'markup' },
|
||||||
|
{ text: 'JavaScript', value: 'javascript' },
|
||||||
|
{ text: 'TypeScript', value: 'typescript' },
|
||||||
|
{ text: 'CSS', value: 'css' },
|
||||||
|
{ text: 'SCSS', value: 'scss' },
|
||||||
|
{ text: 'Python', value: 'python' },
|
||||||
|
{ text: 'Java', value: 'java' },
|
||||||
|
{ text: 'C++', value: 'cpp' },
|
||||||
|
{ text: 'C#', value: 'csharp' },
|
||||||
|
{ text: 'PHP', value: 'php' },
|
||||||
|
{ text: 'Ruby', value: 'ruby' },
|
||||||
|
{ text: 'Go', value: 'go' },
|
||||||
|
{ text: 'Rust', value: 'rust' },
|
||||||
|
{ text: 'SQL', value: 'sql' },
|
||||||
|
{ text: 'JSON', value: 'json' },
|
||||||
|
{ text: 'Bash', value: 'bash' },
|
||||||
|
],
|
||||||
|
|
||||||
|
// 表格配置
|
||||||
|
table_default_attributes: {
|
||||||
|
border: '1',
|
||||||
|
},
|
||||||
|
table_default_styles: {
|
||||||
|
'border-collapse': 'collapse',
|
||||||
|
width: '100%',
|
||||||
|
},
|
||||||
|
table_class_list: [
|
||||||
|
{ title: '无样式', value: '' },
|
||||||
|
{ title: '简单表格', value: 'simple-table' },
|
||||||
|
{ title: '条纹表格', value: 'striped-table' },
|
||||||
|
{ title: '边框表格', value: 'bordered-table' },
|
||||||
|
],
|
||||||
|
|
||||||
|
// 链接配置
|
||||||
|
link_default_target: '_blank',
|
||||||
|
link_assume_external_targets: true,
|
||||||
|
link_context_toolbar: true,
|
||||||
|
|
||||||
|
// 图片配置
|
||||||
|
image_advtab: true,
|
||||||
|
image_caption: true,
|
||||||
|
|
||||||
|
// 媒体配置
|
||||||
|
media_live_embeds: true,
|
||||||
|
media_filter_html: false,
|
||||||
|
|
||||||
|
content_style: `
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
margin: 16px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
margin-top: 24px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 { font-size: 2em; color: #1a1a1a; }
|
||||||
|
h2 { font-size: 1.5em; color: #2a2a2a; }
|
||||||
|
h3 { font-size: 1.25em; color: #3a3a3a; }
|
||||||
|
|
||||||
|
p { margin-bottom: 16px; }
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||||
|
margin: 8px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
margin: 16px 0;
|
||||||
|
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
table td, table th {
|
||||||
|
border: 1px solid #e8e8e8;
|
||||||
|
padding: 12px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
table th {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
border-left: 4px solid #1890ff;
|
||||||
|
margin: 16px 0;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background-color: #f6f8fa;
|
||||||
|
color: #666;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: #f1f3f4;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #d73a49;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #f8f8f8;
|
||||||
|
border: 1px solid #e1e4e8;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 16px;
|
||||||
|
overflow-x: auto;
|
||||||
|
margin: 16px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
background: none;
|
||||||
|
padding: 0;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
|
||||||
|
placeholder,
|
||||||
|
branding: false,
|
||||||
|
elementpath: true,
|
||||||
|
resize: 'both' as const,
|
||||||
|
statusbar: showWordCount,
|
||||||
|
|
||||||
|
// 图片上传配置
|
||||||
|
images_upload_handler: handleImageUpload,
|
||||||
|
automatic_uploads: true,
|
||||||
|
images_reuse_filename: true,
|
||||||
|
images_upload_url: uploadConfig.action,
|
||||||
|
images_upload_base_path: '',
|
||||||
|
images_upload_credentials: true,
|
||||||
|
|
||||||
|
// 粘贴配置
|
||||||
|
paste_data_images: true,
|
||||||
|
paste_as_text: false,
|
||||||
|
paste_webkit_styles: 'none',
|
||||||
|
paste_merge_formats: true,
|
||||||
|
paste_remove_styles_if_webkit: true,
|
||||||
|
|
||||||
|
// 文件选择器配置
|
||||||
|
file_picker_types: 'image media',
|
||||||
|
file_picker_callback: (
|
||||||
|
callback: (url: string, meta?: any) => void,
|
||||||
|
// value: string,
|
||||||
|
meta: any,
|
||||||
|
) => {
|
||||||
|
if (meta.filetype === 'image') {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = uploadConfig.acceptTypes?.join(',') || 'image/*';
|
||||||
|
|
||||||
|
const handleChange = async (event: Event) => {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const file = target.files?.[0];
|
||||||
|
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
|
const isValidType = uploadConfig.acceptTypes?.includes(file.type);
|
||||||
|
const isValidSize =
|
||||||
|
file.size / 1024 / 1024 < (uploadConfig.maxSize || 5);
|
||||||
|
|
||||||
|
if (!isValidType) {
|
||||||
|
message.error('文件类型不支持');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidSize) {
|
||||||
|
message.error(`文件大小不能超过 ${uploadConfig.maxSize || 5}MB`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setUploading(true);
|
||||||
|
const url = await uploadFile(file);
|
||||||
|
callback(url, { alt: file.name });
|
||||||
|
message.success('图片上传成功');
|
||||||
|
} catch (error) {
|
||||||
|
message.error('上传失败');
|
||||||
|
console.error('Upload error:', error);
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
input.addEventListener('change', handleChange);
|
||||||
|
input.click();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 快速工具栏
|
||||||
|
quickbars_selection_toolbar:
|
||||||
|
'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
|
||||||
|
quickbars_insert_toolbar: 'quickimage quicktable',
|
||||||
|
|
||||||
|
// 文本模式
|
||||||
|
textpattern_patterns: [
|
||||||
|
{ start: '*', end: '*', format: 'italic' },
|
||||||
|
{ start: '**', end: '**', format: 'bold' },
|
||||||
|
{ start: '#', format: 'h1' },
|
||||||
|
{ start: '##', format: 'h2' },
|
||||||
|
{ start: '###', format: 'h3' },
|
||||||
|
{ start: '####', format: 'h4' },
|
||||||
|
{ start: '#####', format: 'h5' },
|
||||||
|
{ start: '######', format: 'h6' },
|
||||||
|
{ start: '1. ', cmd: 'InsertOrderedList' },
|
||||||
|
{ start: '* ', cmd: 'InsertUnorderedList' },
|
||||||
|
{ start: '- ', cmd: 'InsertUnorderedList' },
|
||||||
|
],
|
||||||
|
|
||||||
|
// 初始化设置
|
||||||
|
setup: (editor: TinyMCEEditor) => {
|
||||||
|
// 注册自定义上传按钮
|
||||||
|
editor.ui.registry.addButton('customupload', {
|
||||||
|
text: uploading ? '上传中...' : '上传',
|
||||||
|
icon: 'upload',
|
||||||
|
tooltip: '上传图片(支持多选)',
|
||||||
|
enabled: !disabled && !uploading,
|
||||||
|
onAction: () => {
|
||||||
|
handleCustomUpload(editor);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听内容变化,实时更新字数统计
|
||||||
|
editor.on('input change undo redo', () => {
|
||||||
|
if (showWordCount) {
|
||||||
|
const content = editor.getContent();
|
||||||
|
const { words, characters } = countWords(content);
|
||||||
|
setWordCount(words);
|
||||||
|
setCharCount(characters);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
editor.on('init', () => {
|
||||||
|
console.log('编辑器初始化完成');
|
||||||
|
|
||||||
|
// 初始化字数统计
|
||||||
|
if (showWordCount && value) {
|
||||||
|
const { words, characters } = countWords(value);
|
||||||
|
setWordCount(words);
|
||||||
|
setCharCount(characters);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 其他配置
|
||||||
|
convert_urls: false,
|
||||||
|
remove_script_host: false,
|
||||||
|
relative_urls: false,
|
||||||
|
language: 'zh_CN',
|
||||||
|
directionality: 'ltr' as const,
|
||||||
|
|
||||||
|
// 高级配置
|
||||||
|
extended_valid_elements: 'script[src|async|defer|type|charset]',
|
||||||
|
|
||||||
|
// 性能配置
|
||||||
|
browser_spellcheck: true,
|
||||||
|
contextmenu: 'link image table',
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rich-editor-wrapper">
|
||||||
|
<Editor
|
||||||
|
value={value}
|
||||||
|
onEditorChange={handleEditorChange}
|
||||||
|
init={editorConfig}
|
||||||
|
disabled={disabled}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 自定义字数统计显示 */}
|
||||||
|
{showWordCount && (
|
||||||
|
<div className="word-count-display">
|
||||||
|
<span className="word-count">
|
||||||
|
字数: {wordCount}
|
||||||
|
{maxWords && (
|
||||||
|
<span className={wordCount > maxWords ? 'over-limit' : ''}>
|
||||||
|
/{maxWords}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
<span className="char-count">字符: {charCount}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{uploading && (
|
||||||
|
<div className="upload-overlay">
|
||||||
|
<div className="upload-spinner">
|
||||||
|
<div className="spinner"></div>
|
||||||
|
<span>上传中...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RichEditor;
|
||||||
145
src/components/Tinymce/index.less
Normal file
145
src/components/Tinymce/index.less
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
/* components/RichEditor/index.css */
|
||||||
|
.rich-editor-wrapper {
|
||||||
|
position: relative;
|
||||||
|
border: 1px solid #d9d9d9;
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: all 0.3s;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper:hover {
|
||||||
|
border-color: #4096ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper:focus-within {
|
||||||
|
border-color: #4096ff;
|
||||||
|
box-shadow: 0 0 0 2px rgba(64, 150, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-tinymce {
|
||||||
|
border: none !important;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-editor-header {
|
||||||
|
border-bottom: 1px solid #e8e8e8 !important;
|
||||||
|
background: #fafafa !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-toolbar__primary {
|
||||||
|
background: #fafafa !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-statusbar {
|
||||||
|
border-top: 1px solid #e8e8e8 !important;
|
||||||
|
background: #fafafa !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 自定义按钮样式 */
|
||||||
|
.rich-editor-wrapper .tox-tbtn--enabled {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-tbtn--enabled:hover {
|
||||||
|
background: #e6f7ff !important;
|
||||||
|
border-color: #91d5ff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-tbtn--enabled:active {
|
||||||
|
background: #bae7ff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 上传状态覆盖层 */
|
||||||
|
.upload-overlay {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: rgba(255, 255, 255, 0.8);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1000;
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-spinner {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 20px;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border: 3px solid #f3f3f3;
|
||||||
|
border-top: 3px solid #1890ff;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-spinner span {
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 响应式设计 */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.rich-editor-wrapper .tox-toolbar__primary {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-toolbar__group {
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 图片样式优化 */
|
||||||
|
.rich-editor-wrapper .tox-edit-area img {
|
||||||
|
max-width: 100% !important;
|
||||||
|
height: auto !important;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
margin: 4px 0;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-edit-area img:hover {
|
||||||
|
transform: scale(1.02);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 表格样式优化 */
|
||||||
|
.rich-editor-wrapper .tox-edit-area table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
margin: 8px 0;
|
||||||
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-edit-area table td,
|
||||||
|
.rich-editor-wrapper .tox-edit-area table th {
|
||||||
|
border: 1px solid #e8e8e8;
|
||||||
|
padding: 8px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-wrapper .tox-edit-area table th {
|
||||||
|
background-color: #fafafa;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
262
src/components/Tinymce/index.tsx
Normal file
262
src/components/Tinymce/index.tsx
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
import { Editor } from '@tinymce/tinymce-react';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import React, { useCallback, useState } from 'react';
|
||||||
|
import type { Editor as TinyMCEEditor } from 'tinymce';
|
||||||
|
export interface RichEditorProps {
|
||||||
|
value?: string;
|
||||||
|
onChange?: (content: string) => void;
|
||||||
|
height?: number;
|
||||||
|
placeholder?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
uploadConfig?: {
|
||||||
|
action: string;
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
maxSize?: number;
|
||||||
|
acceptTypes?: string[];
|
||||||
|
data?: Record<string, any>;
|
||||||
|
};
|
||||||
|
showWordCount?: boolean;
|
||||||
|
maxWords?: number;
|
||||||
|
}
|
||||||
|
const RichEditor: React.FC<RichEditorProps> = ({
|
||||||
|
// value = "",
|
||||||
|
// onChange,
|
||||||
|
// height = 400,
|
||||||
|
// placeholder = "请输入内容...",
|
||||||
|
disabled = false,
|
||||||
|
// showWordCount = true,
|
||||||
|
// maxWords,
|
||||||
|
uploadConfig = {
|
||||||
|
action: '/api/upload/image',
|
||||||
|
maxSize: 5,
|
||||||
|
acceptTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
||||||
|
},
|
||||||
|
}) => {
|
||||||
|
const [uploading, setUploading] = useState<boolean>(false);
|
||||||
|
const uploadFile = useCallback(
|
||||||
|
async (file: File): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
if (uploadConfig.data) {
|
||||||
|
Object.keys(uploadConfig.data).forEach((key) => {
|
||||||
|
formData.append(key, uploadConfig.data?.[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhr.upload.addEventListener('progress', (e) => {
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
const percent = Math.round((e.loaded / e.total) * 100);
|
||||||
|
console.log(`上传进度: ${percent}%`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.addEventListener('load', () => {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
try {
|
||||||
|
const response = JSON.parse(xhr.responseText);
|
||||||
|
if (response.code === 200 && response.data?.url) {
|
||||||
|
resolve(response.data.url);
|
||||||
|
} else {
|
||||||
|
reject(response.message || '上传失败');
|
||||||
|
}
|
||||||
|
} catch (_error) {
|
||||||
|
reject('响应解析失败');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(`上传失败: ${xhr.status}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.addEventListener('error', () => {
|
||||||
|
reject('网络错误');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (uploadConfig.headers) {
|
||||||
|
Object.keys(uploadConfig.headers).forEach((key) => {
|
||||||
|
xhr.setRequestHeader(key, uploadConfig.headers![key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.open('POST', uploadConfig.action);
|
||||||
|
xhr.send(formData);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[uploadConfig],
|
||||||
|
);
|
||||||
|
const handleImageUpload = useCallback(
|
||||||
|
(blobInfo: any, _: (percent: number) => void): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
setUploading(true);
|
||||||
|
const file = blobInfo.blob();
|
||||||
|
uploadFile(file).then((url) => {
|
||||||
|
resolve(url);
|
||||||
|
});
|
||||||
|
|
||||||
|
message.success('图片上传成功');
|
||||||
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
message.error(typeof error === 'string' ? error : '上传失败');
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[uploadFile],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCustomUpload = useCallback(
|
||||||
|
(editor: TinyMCEEditor) => {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = uploadConfig.acceptTypes?.join(',') || 'image/*';
|
||||||
|
input.multiple = true;
|
||||||
|
|
||||||
|
const handleFileChange = async (event: Event) => {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const files = Array.from(target.files || []);
|
||||||
|
|
||||||
|
if (files.length === 0) return;
|
||||||
|
|
||||||
|
setUploading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const file of files) {
|
||||||
|
const isValidType = uploadConfig.acceptTypes?.includes(file.type);
|
||||||
|
if (!isValidType) {
|
||||||
|
message.error(`文件 ${file.name} 类型不支持`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isValidSize =
|
||||||
|
file.size / 1024 / 1024 < (uploadConfig.maxSize || 5);
|
||||||
|
if (!isValidSize) {
|
||||||
|
message.error(
|
||||||
|
`文件 ${file.name} 大小超过 ${uploadConfig.maxSize || 5}MB`,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = await uploadFile(file);
|
||||||
|
const imgHtml = `<img src="${url}" alt="${file.name}" style="max-width: 100%; height: auto;" />`;
|
||||||
|
editor.insertContent(imgHtml);
|
||||||
|
message.success(`${file.name} 上传成功`);
|
||||||
|
} catch (error) {
|
||||||
|
message.error(`${file.name} 上传失败: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
input.addEventListener('change', handleFileChange);
|
||||||
|
input.click();
|
||||||
|
},
|
||||||
|
[uploadConfig, uploadFile],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Editor
|
||||||
|
apiKey="xt51qhzvj8q9mxzxytigtp0nu94v4rz7dska2dbqeilkxo99"
|
||||||
|
init={{
|
||||||
|
plugins: [
|
||||||
|
// Core editing features
|
||||||
|
'anchor',
|
||||||
|
'autolink',
|
||||||
|
'charmap',
|
||||||
|
'codesample',
|
||||||
|
'emoticons',
|
||||||
|
'link',
|
||||||
|
'lists',
|
||||||
|
'media',
|
||||||
|
'searchreplace',
|
||||||
|
'table',
|
||||||
|
'visualblocks',
|
||||||
|
'wordcount',
|
||||||
|
// Your account includes a free trial of TinyMCE premium features
|
||||||
|
// Try the most popular premium features until Oct 8, 2025:
|
||||||
|
'checklist',
|
||||||
|
'mediaembed',
|
||||||
|
'casechange',
|
||||||
|
'formatpainter',
|
||||||
|
'pageembed',
|
||||||
|
'a11ychecker',
|
||||||
|
'tinymcespellchecker',
|
||||||
|
'permanentpen',
|
||||||
|
'powerpaste',
|
||||||
|
'advtable',
|
||||||
|
'advcode',
|
||||||
|
'advtemplate',
|
||||||
|
'ai',
|
||||||
|
'uploadcare',
|
||||||
|
'mentions',
|
||||||
|
'tinycomments',
|
||||||
|
'tableofcontents',
|
||||||
|
'footnotes',
|
||||||
|
'mergetags',
|
||||||
|
'autocorrect',
|
||||||
|
'typography',
|
||||||
|
'inlinecss',
|
||||||
|
'markdown',
|
||||||
|
'importword',
|
||||||
|
'exportword',
|
||||||
|
'exportpdf',
|
||||||
|
],
|
||||||
|
menubar: false,
|
||||||
|
toolbar:
|
||||||
|
'undo redo | blocks | bold italic forecolor | ' +
|
||||||
|
'alignleft aligncenter | ' +
|
||||||
|
'alignright alignjustify | bullist numlist outdent indent customupload | ' +
|
||||||
|
'removeformat ',
|
||||||
|
tinycomments_mode: 'embedded',
|
||||||
|
tinycomments_author: 'Author name',
|
||||||
|
toolbar_mode: 'sliding',
|
||||||
|
mergetags_list: [
|
||||||
|
{ value: 'First.Name', title: 'First Name' },
|
||||||
|
{ value: 'Email', title: 'Email' },
|
||||||
|
],
|
||||||
|
ai_request: (
|
||||||
|
_: any,
|
||||||
|
respondWith: { string: (arg0: () => Promise<never>) => any },
|
||||||
|
) =>
|
||||||
|
respondWith.string(() =>
|
||||||
|
Promise.reject('See docs to implement AI Assistant'),
|
||||||
|
),
|
||||||
|
language: 'zh-CN',
|
||||||
|
|
||||||
|
// 其他配置
|
||||||
|
|
||||||
|
convert_urls: false,
|
||||||
|
remove_script_host: false,
|
||||||
|
uploadcare_public_key: '0ad3671d77f59c5756dd',
|
||||||
|
|
||||||
|
setup: (editor: TinyMCEEditor) => {
|
||||||
|
// 注册自定义上传按钮
|
||||||
|
editor.ui.registry.addButton('customupload', {
|
||||||
|
text: uploading ? '上传中...' : '上传',
|
||||||
|
icon: 'upload',
|
||||||
|
tooltip: '上传图片(支持多选)',
|
||||||
|
enabled: !disabled && !uploading,
|
||||||
|
onAction: () => {
|
||||||
|
handleCustomUpload(editor);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 图片上传配置
|
||||||
|
images_upload_handler: handleImageUpload,
|
||||||
|
// 性能配置
|
||||||
|
browser_spellcheck: true,
|
||||||
|
contextmenu: 'link image table',
|
||||||
|
}}
|
||||||
|
initialValue="Welcome to TinyMCE!"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(RichEditor);
|
||||||
@@ -1 +1,5 @@
|
|||||||
export const formStatusType = { create: '创建', update: '编辑', test: '测试' };
|
export const formStatusType: { [key: string]: string } = {
|
||||||
|
create: '创建',
|
||||||
|
update: '编辑',
|
||||||
|
test: '测试',
|
||||||
|
};
|
||||||
|
|||||||
156
src/pages/prod/category/config.tsx
Normal file
156
src/pages/prod/category/config.tsx
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
import type {
|
||||||
|
ProColumns,
|
||||||
|
ProFormColumnsType,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import TagEditor from '@/components/TagEditor';
|
||||||
|
import TinyMCEEditor from '@/components/Tinymce';
|
||||||
|
export const baseTenantColumns: ProColumns<API.CategoryDO>[] = [
|
||||||
|
{
|
||||||
|
title: '类目名称',
|
||||||
|
dataIndex: 'categoryName',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目ID',
|
||||||
|
dataIndex: 'categoryId',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目层级',
|
||||||
|
dataIndex: 'grade',
|
||||||
|
hideInSearch: true, // 在搜索表单中隐藏
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '父级类目',
|
||||||
|
dataIndex: 'parentName',
|
||||||
|
|
||||||
|
hideInSearch: true, // 在搜索表单中隐藏
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '排序权重',
|
||||||
|
dataIndex: 'sort',
|
||||||
|
hideInSearch: true, // 在搜索表单中隐藏
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
valueType: 'switch',
|
||||||
|
hideInSearch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
valueType: 'dateRange',
|
||||||
|
hideInSearch: true, // 在搜索表单中隐藏
|
||||||
|
render: (_, record: API.CategoryDO) =>
|
||||||
|
dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const formColumns = (data: {
|
||||||
|
type: string;
|
||||||
|
grade: number;
|
||||||
|
}): ProFormColumnsType[] => [
|
||||||
|
{
|
||||||
|
title: '类目',
|
||||||
|
dataIndex: 'grade',
|
||||||
|
valueType: 'radio',
|
||||||
|
fieldProps: {
|
||||||
|
value: data.grade || 1,
|
||||||
|
options: [
|
||||||
|
{ label: '一级类目', value: 1 },
|
||||||
|
{ label: '二级类目', value: 2 },
|
||||||
|
{ label: '三级类目', value: 3 },
|
||||||
|
],
|
||||||
|
disabled: data.type === 'create',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目名称',
|
||||||
|
dataIndex: 'username',
|
||||||
|
formItemProps: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入用户名',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '排序权重',
|
||||||
|
dataIndex: 'sort',
|
||||||
|
valueType: 'digit',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目描述',
|
||||||
|
dataIndex: 'description',
|
||||||
|
valueType: 'textarea',
|
||||||
|
renderFormItem: () => {
|
||||||
|
return <TinyMCEEditor />;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '关联父级',
|
||||||
|
dataIndex: 'parentId',
|
||||||
|
valueType: 'select',
|
||||||
|
hideInForm: data.grade - 1 === 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目icon',
|
||||||
|
dataIndex: 'icon',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目标签',
|
||||||
|
dataIndex: 'tages',
|
||||||
|
renderFormItem: () => {
|
||||||
|
return (
|
||||||
|
<TagEditor
|
||||||
|
placeholder="输入标签名称"
|
||||||
|
maxCount={10}
|
||||||
|
tagProps={{
|
||||||
|
color: 'blue',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
hideInForm: data.type === 'create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类目ID',
|
||||||
|
dataIndex: 'categoryId',
|
||||||
|
hideInForm: data.type === 'create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
valueType: 'dateTime',
|
||||||
|
hideInForm: data.type === 'create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
dataIndex: 'creator',
|
||||||
|
hideInForm: data.type === 'create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '更新时间',
|
||||||
|
dataIndex: 'updateTime',
|
||||||
|
valueType: 'dateTime',
|
||||||
|
hideInForm: data.type === 'create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '更新人',
|
||||||
|
dataIndex: 'updator',
|
||||||
|
hideInForm: data.type === 'create',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// {
|
||||||
|
// title: "模板内容",
|
||||||
|
// dataIndex: "content",
|
||||||
|
// valueType: "textarea",
|
||||||
|
// },
|
||||||
129
src/pages/prod/category/index.tsx
Normal file
129
src/pages/prod/category/index.tsx
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
|
import type { TabsProps } from 'antd';
|
||||||
|
import { Tabs } from 'antd';
|
||||||
|
import { useCallback, useRef, useState } from 'react';
|
||||||
|
import ConfigurableDrawerForm, {
|
||||||
|
type ConfigurableDrawerFormRef,
|
||||||
|
} from '@/components/DrawerForm';
|
||||||
|
import EnhancedProTable from '@/components/EnhancedProTable';
|
||||||
|
import type { ToolbarAction } from '@/components/EnhancedProTable/types';
|
||||||
|
import { formStatusType } from '@/constants';
|
||||||
|
import { getCategoryList } from '@/services/prodApi/category';
|
||||||
|
import { baseTenantColumns, formColumns } from './config';
|
||||||
|
|
||||||
|
const ProdCategory = () => {
|
||||||
|
const tableRef = useRef<ActionType>(null);
|
||||||
|
const [type, setType] = useState<'create' | 'update' | 'test'>('create');
|
||||||
|
const [grade, setGrade] = useState<string>('');
|
||||||
|
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||||
|
const onChange = useCallback(
|
||||||
|
(key: string) => {
|
||||||
|
setGrade(key);
|
||||||
|
},
|
||||||
|
[grade],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onFetch = async (params: API.getProductCategoryCategoryListParams) => {
|
||||||
|
const data = await getCategoryList({
|
||||||
|
...params,
|
||||||
|
grade: grade ? Number(grade) : undefined,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
data: data,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
setType('create');
|
||||||
|
configurableDrawerRef.current?.open();
|
||||||
|
};
|
||||||
|
|
||||||
|
const toolbarActions: ToolbarAction[] = [
|
||||||
|
{
|
||||||
|
key: 'add',
|
||||||
|
label: '新建',
|
||||||
|
type: 'primary',
|
||||||
|
icon: <PlusOutlined />,
|
||||||
|
onClick: handleAdd,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const handleEdit = async (row: API.CategoryDO) => {
|
||||||
|
setType('update');
|
||||||
|
configurableDrawerRef.current?.open(row);
|
||||||
|
};
|
||||||
|
const handleSubmit = async (values: API.CategoryDO) => {
|
||||||
|
console.log('values', values);
|
||||||
|
// const success = await handleAdd(values as API.CategoryDO);
|
||||||
|
// if (success) {
|
||||||
|
// handleClose();
|
||||||
|
// }
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const actionColumns: ProColumns<API.CategoryDO> = {
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'option',
|
||||||
|
valueType: 'option',
|
||||||
|
fixed: 'right',
|
||||||
|
width: 120,
|
||||||
|
render: (_text: React.ReactNode, record: API.CategoryDO, _: number) => [
|
||||||
|
<a key="edit" onClick={() => handleEdit(record)}>
|
||||||
|
编辑
|
||||||
|
</a>,
|
||||||
|
<a key="detail">详情</a>,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = [...baseTenantColumns, actionColumns];
|
||||||
|
const renderChildren = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<EnhancedProTable<API.CategoryDO>
|
||||||
|
ref={tableRef}
|
||||||
|
columns={columns}
|
||||||
|
rowKey="categoryId"
|
||||||
|
request={onFetch}
|
||||||
|
toolbarActions={toolbarActions}
|
||||||
|
headerTitle="短信渠道"
|
||||||
|
showIndex={false}
|
||||||
|
showSelection={false}
|
||||||
|
/>
|
||||||
|
<ConfigurableDrawerForm
|
||||||
|
ref={configurableDrawerRef}
|
||||||
|
title={formStatusType[type]}
|
||||||
|
// width="50vw"
|
||||||
|
columns={formColumns({ grade: Number(grade), type })}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const items: TabsProps['items'] = [
|
||||||
|
{
|
||||||
|
key: '',
|
||||||
|
label: '全部分类',
|
||||||
|
children: renderChildren(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: '3',
|
||||||
|
label: '三级分类',
|
||||||
|
children: renderChildren(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: '2',
|
||||||
|
label: '二级分类',
|
||||||
|
children: renderChildren(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: '1',
|
||||||
|
label: '一级分类',
|
||||||
|
children: renderChildren(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return <Tabs defaultActiveKey={grade} items={items} onChange={onChange} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProdCategory;
|
||||||
5
src/pages/prod/list/index.tsx
Normal file
5
src/pages/prod/list/index.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const ProdList = () => {
|
||||||
|
return <div>ProdList</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProdList;
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import type {
|
import type {
|
||||||
ProColumns,
|
ProColumns,
|
||||||
ProDescriptionsItemProps,
|
|
||||||
ProFormColumnsType,
|
ProFormColumnsType,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
@@ -160,7 +159,7 @@ export const formColumns = (): ProFormColumnsType[] => [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const formTestColumns = (type: string): ProFormColumnsType[] => [
|
export const formTestColumns = (): ProFormColumnsType[] => [
|
||||||
{
|
{
|
||||||
title: '模板内容',
|
title: '模板内容',
|
||||||
dataIndex: 'content',
|
dataIndex: 'content',
|
||||||
|
|||||||
@@ -15,18 +15,17 @@ import { formStatusType } from '@/constants';
|
|||||||
import {
|
import {
|
||||||
createMailAccount,
|
createMailAccount,
|
||||||
deleteMailAccount,
|
deleteMailAccount,
|
||||||
getMailAccount,
|
|
||||||
getMailAccountPage,
|
getMailAccountPage,
|
||||||
type MailAccountVO,
|
type MailAccountVO,
|
||||||
updateMailAccount,
|
updateMailAccount,
|
||||||
} from '@/services/system/message/mail/account';
|
} from '@/services/system/message/mail/account';
|
||||||
import { baseTenantColumns, formColumns, formTestColumns } from './config';
|
import { baseTenantColumns, formColumns } from './config';
|
||||||
|
|
||||||
const SyStemMessageSmsTemplate = () => {
|
const SyStemMessageSmsTemplate = () => {
|
||||||
const tableRef = useRef<ActionType>(null);
|
const tableRef = useRef<ActionType>(null);
|
||||||
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||||
const [type, setType] = useState<'create' | 'update' | 'test'>('create');
|
const [type, setType] = useState<'create' | 'update' | 'test'>('create');
|
||||||
const testRef = useRef<ConfigurableDrawerFormRef>(null);
|
// const testRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||||
const [currentItem, setCurrentItem] = useState<MailAccountVO>();
|
const [currentItem, setCurrentItem] = useState<MailAccountVO>();
|
||||||
const onFetch = async (
|
const onFetch = async (
|
||||||
params: MailAccountVO & {
|
params: MailAccountVO & {
|
||||||
@@ -46,11 +45,11 @@ const SyStemMessageSmsTemplate = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSend = async (record: MailAccountVO) => {
|
// const handleSend = async (record: MailAccountVO) => {
|
||||||
setType('test');
|
// setType("test");
|
||||||
setCurrentItem(record);
|
// setCurrentItem(record);
|
||||||
testRef.current?.open(record);
|
// testRef.current?.open(record);
|
||||||
};
|
// };
|
||||||
|
|
||||||
const handleEdit = (record: MailAccountVO) => {
|
const handleEdit = (record: MailAccountVO) => {
|
||||||
setType('update');
|
setType('update');
|
||||||
@@ -68,10 +67,10 @@ const SyStemMessageSmsTemplate = () => {
|
|||||||
if (type === 'create') {
|
if (type === 'create') {
|
||||||
await createMailAccount(values);
|
await createMailAccount(values);
|
||||||
message.success('创建成功');
|
message.success('创建成功');
|
||||||
} else {
|
} else if (currentItem?.id) {
|
||||||
await updateMailAccount({
|
await updateMailAccount({
|
||||||
...values,
|
...values,
|
||||||
id: currentItem!.id,
|
id: currentItem.id,
|
||||||
});
|
});
|
||||||
message.success('编辑成功');
|
message.success('编辑成功');
|
||||||
}
|
}
|
||||||
@@ -97,7 +96,7 @@ const SyStemMessageSmsTemplate = () => {
|
|||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
width: 120,
|
width: 120,
|
||||||
render: (
|
render: (
|
||||||
text: React.ReactNode,
|
_text: React.ReactNode,
|
||||||
record: MailAccountVO,
|
record: MailAccountVO,
|
||||||
_: number,
|
_: number,
|
||||||
action: ProCoreActionType | undefined,
|
action: ProCoreActionType | undefined,
|
||||||
|
|||||||
@@ -3,25 +3,22 @@
|
|||||||
import { request } from "@umijs/max";
|
import { request } from "@umijs/max";
|
||||||
|
|
||||||
/** 获取菜单页面的表 GET /product/category/categoryList */
|
/** 获取菜单页面的表 GET /product/category/categoryList */
|
||||||
export async function getProductCategoryCategoryList(
|
export async function getCategoryList(
|
||||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||||
params: API.getProductCategoryCategoryListParams,
|
params: API.getProductCategoryCategoryListParams,
|
||||||
options?: { [key: string]: any }
|
options?: { [key: string]: any }
|
||||||
) {
|
) {
|
||||||
return request<API.CommonResultListCategoryDto>(
|
return request("/product/category/categoryList", {
|
||||||
"/product/category/categoryList",
|
method: "GET",
|
||||||
{
|
params: {
|
||||||
method: "GET",
|
...params,
|
||||||
params: {
|
},
|
||||||
...params,
|
...(options || {}),
|
||||||
},
|
});
|
||||||
...(options || {}),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建产品类目 创建产品类目 POST /product/category/create */
|
/** 创建产品类目 创建产品类目 POST /product/category/create */
|
||||||
export async function postProductCategoryCreate(
|
export async function postCategoryCreate(
|
||||||
body: API.CategorySaveReqVO,
|
body: API.CategorySaveReqVO,
|
||||||
options?: { [key: string]: any }
|
options?: { [key: string]: any }
|
||||||
) {
|
) {
|
||||||
@@ -36,7 +33,7 @@ export async function postProductCategoryCreate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 更新产品类目 更新产品类目 PUT /product/category/update */
|
/** 更新产品类目 更新产品类目 PUT /product/category/update */
|
||||||
export async function putProductCategoryUpdate(
|
export async function putCategoryUpdate(
|
||||||
body: API.CategorySaveReqVO,
|
body: API.CategorySaveReqVO,
|
||||||
options?: { [key: string]: any }
|
options?: { [key: string]: any }
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user