From 8aabe0d4ed26f9f2dba8bd12c37db54f205fbc9d Mon Sep 17 00:00:00 2001 From: yehuozhili <673632758@qq.com> Date: Mon, 27 Sep 2021 21:52:16 +0800 Subject: [PATCH] update 0.9.1 --- CHANGELOG.md | 5 + packages/dooringx-doc/src/changelog/1.1.md | 5 + .../dooringx-example/src/layouts/index.tsx | 19 +- packages/dooringx-lib/README.md | 2 +- packages/dooringx-lib/package.json | 2 +- .../dooringx-lib/src/components/control.tsx | 461 ------------------ .../src/components/control/control.tsx | 276 +++++++++++ .../src/components/control/index.ts | 10 + .../src/components/control/state.ts | 38 ++ .../src/components/rightConfig.tsx | 36 +- .../src/components/timeLine/timeline.tsx | 26 +- packages/dooringx-lib/src/config/index.tsx | 3 +- .../core/resizeHandler/containerResizer.ts | 4 +- packages/dooringx-lib/src/index.tsx | 4 +- packages/dooringx-lib/src/locale/en.ts | 4 +- packages/dooringx-lib/src/locale/index.ts | 18 - packages/dooringx-lib/src/locale/index.tsx | 39 ++ packages/dooringx-lib/src/locale/zh-CN.ts | 6 +- 18 files changed, 429 insertions(+), 529 deletions(-) delete mode 100644 packages/dooringx-lib/src/components/control.tsx create mode 100644 packages/dooringx-lib/src/components/control/control.tsx create mode 100644 packages/dooringx-lib/src/components/control/index.ts create mode 100644 packages/dooringx-lib/src/components/control/state.ts delete mode 100644 packages/dooringx-lib/src/locale/index.ts create mode 100644 packages/dooringx-lib/src/locale/index.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 258ec37..65e0658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## changelog +## 0.9.1 + +增加config.i18n配置,不使用国际化则不需要导入intl的context。 +control组件第一个按钮变更为拖拽,功能合并至timeline + ## 0.9.0 增加react-intl,修改部分样式。 diff --git a/packages/dooringx-doc/src/changelog/1.1.md b/packages/dooringx-doc/src/changelog/1.1.md index 00845dd..b994f57 100644 --- a/packages/dooringx-doc/src/changelog/1.1.md +++ b/packages/dooringx-doc/src/changelog/1.1.md @@ -4,6 +4,11 @@ order: 1 --- ## changelog +## 0.9.1 + +增加config.i18n配置,不使用国际化则不需要导入intl的context。 +control组件第一个按钮变更为拖拽,功能合并至timeline + ## 0.9.0 增加react-intl,修改部分样式。 diff --git a/packages/dooringx-example/src/layouts/index.tsx b/packages/dooringx-example/src/layouts/index.tsx index 7e2113b..3e8a963 100644 --- a/packages/dooringx-example/src/layouts/index.tsx +++ b/packages/dooringx-example/src/layouts/index.tsx @@ -2,7 +2,7 @@ * @Author: yehuozhili * @Date: 2021-07-07 14:51:17 * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-27 14:45:47 + * @LastEditTime: 2021-09-27 21:44:56 * @FilePath: \dooringx\packages\dooringx-example\src\layouts\index.tsx */ import { Button } from 'antd'; @@ -19,7 +19,7 @@ import { locale } from 'dooringx-lib'; import { localeKey } from '../../../dooringx-lib/dist/locale'; export const config = new UserConfig(plugin); export const configContext = createContext(config); - +config.i18n = false; // 自定义右键 const contextMenuState = config.getContextMenuState(); const unmountContextMenu = contextMenuState.unmountContextMenu; @@ -84,11 +84,12 @@ export const LocaleContext = createContext({ export default function Layout({ children }: IRouteComponentProps) { const [l, setLocale] = useState('zh-CN'); - return ( - - - {children} - - - ); + // return ( + // + // + // {children} + // + // + // ); + return {children}; } diff --git a/packages/dooringx-lib/README.md b/packages/dooringx-lib/README.md index 84d9feb..1b24a1a 100644 --- a/packages/dooringx-lib/README.md +++ b/packages/dooringx-lib/README.md @@ -142,7 +142,7 @@ Contributions, issues and feature requests are welcome!. ### 技术交流 | Technical Communication -dooringx-lib交流群 +dooringx-lib交流群 ## License diff --git a/packages/dooringx-lib/package.json b/packages/dooringx-lib/package.json index d3897b6..acf4288 100644 --- a/packages/dooringx-lib/package.json +++ b/packages/dooringx-lib/package.json @@ -1,5 +1,5 @@ { - "version": "0.9.0", + "version": "0.9.1", "license": "MIT", "main": "dist/index.js", "module": "dist/dooringx-lib.esm.js", diff --git a/packages/dooringx-lib/src/components/control.tsx b/packages/dooringx-lib/src/components/control.tsx deleted file mode 100644 index 82187ee..0000000 --- a/packages/dooringx-lib/src/components/control.tsx +++ /dev/null @@ -1,461 +0,0 @@ -import { - CompressOutlined, - DeleteOutlined, - FullscreenExitOutlined, - FullscreenOutlined, - GatewayOutlined, - LayoutOutlined, - MenuOutlined, - SyncOutlined, - UnorderedListOutlined, - VideoCameraOutlined, -} from '@ant-design/icons'; -import { Button, Divider, Form, Input, List, message, Modal, Popconfirm, Popover } from 'antd'; -import React, { CSSProperties, PropsWithChildren, useState } from 'react'; -import { UserConfig } from '..'; -import { IBlockType, IStoreData } from '../core/store/storetype'; -import { deepCopy, arrayMove, changeItem, changeLayer, focusEle } from '../core/utils'; -import { SortEnd, SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; -import { wrapperMoveState } from './wrapperMove/event'; -import { FormattedMessage, IntlShape, useIntl } from 'react-intl'; -export interface ControlProps { - config: UserConfig; - style?: CSSProperties; -} - -const DragHandle = SortableHandle(() => ); -const SortableItem = SortableElement( - ({ value }: { value: { value: IBlockType; config: UserConfig; intl: IntlShape } }) => ( -
-
- -
- -
- {value.config.getComponentRegister().getMap()[value.value.name].display} -
- -
{value.value.id.slice(-6)}
- -
{value.value.position}
- -
- { - changeItem(value.config.getStore(), value.value.id, 'position', 'absolute'); - }} - okText={value.intl.formatMessage({ id: 'yes' })} - cancelText={value.intl.formatMessage({ id: 'no' })} - > - - - { - changeItem(value.config.getStore(), value.value.id, 'position', 'static'); - }} - okText={value.intl.formatMessage({ id: 'yes' })} - cancelText={value.intl.formatMessage({ id: 'no' })} - > - - - - { - changeLayer(value.config.getStore(), value.value.id, 'delete'); - }} - okText={value.intl.formatMessage({ id: 'yes' })} - cancelText={value.intl.formatMessage({ id: 'no' })} - > - - -
-
- ) -); -const SortableList = SortableContainer( - ({ items }: { items: { data: IBlockType[]; config: UserConfig; intl: IntlShape } }) => { - return ( -
- {items.data.map((value, index: number) => ( - - ))} -
- ); - } -); - -const moveState = { - startX: 0, - startY: 0, - isMove: false, -}; - -const mouseUp = () => { - if (moveState.isMove) { - moveState.isMove = false; - } -}; - -export function Control(props: PropsWithChildren) { - const { style } = props; - const [visible, setVisible] = useState(false); - const [configVisible, setConfigVisible] = useState(false); - const [form] = Form.useForm(); - - const data = props.config.getStore().getData().block; - - const onSortEnd = (sort: SortEnd) => { - const { oldIndex, newIndex } = sort; - const newblocks: IBlockType[] = arrayMove(data, oldIndex, newIndex); - // 这里要判断是否edit ,如果edit时,只要看第一个是不是container,不是则不移动 - const isEdit = props.config.getStoreChanger().isEdit(); - if (isEdit) { - const firstType = newblocks[0].name; - if (firstType !== 'modalMask') { - return; - } - } - const store = props.config.getStore(); - const cloneData: IStoreData = deepCopy(store.getData()); - cloneData.block = newblocks; - store.setData(cloneData); - }; - - const intl = useIntl(); - - const content = - data.length === 0 ? ( -
- -
- ) : ( -
- -
- ); - const [xy, setXy] = useState({ x: 0, y: 0 }); - return ( - <> -
{ - moveState.startX = e.clientX; - moveState.startY = e.clientY; - moveState.isMove = true; - }} - onMouseMove={(e) => { - if (moveState.isMove) { - const diffx = e.clientX - moveState.startX; - const diffy = e.clientY - moveState.startY; - setXy((pre) => ({ x: pre.x + diffx, y: pre.y + diffy })); - moveState.startX = e.clientX; - moveState.startY = e.clientY; - } - }} - onMouseUp={mouseUp} - onMouseLeave={mouseUp} - style={{ - display: 'flex', - flexDirection: 'column', - justifyContent: 'center', - alignItems: 'center', - transform: `translate(${xy.x}px,${xy.y}px)`, - ...style, - }} - > - - - - - - - -
- } - > - - - - - - - - setConfigVisible(false)} - onCancel={() => setConfigVisible(false)} - footer={null} - > - - {props.config.getStoreChanger().getState().modalEditName !== '' && ( -
- -
- )} - {props.config.getStoreChanger().getState().modalEditName === '' && - Object.keys(props.config.getStore().getData().modalMap).map((v) => { - return ( - { - const sign = props.config - .getStoreChanger() - .updateModal(props.config.getStore(), v); - if (!sign.success && sign.sign === 0) { - message.error( - intl.formatMessage({ - id: 'modal.popup.save', - defaultMessage: '请保存弹窗后编辑其他弹窗', - }) - ); - } - if (!sign.success && sign.sign === 1) { - message.error( - intl.formatMessage( - { - id: 'modal.popup.notfond', - defaultMessage: '未找到该弹窗 {name}', - }, - { - name: sign.param, - } - ) - ); - } - setConfigVisible(false); - }} - okText={intl.formatMessage({ id: 'yes' })} - cancelText={intl.formatMessage({ id: 'no' })} - > - - , - - { - const sign = props.config - .getStoreChanger() - .removeModal(props.config.getStore(), v); - if (!sign.success && sign.sign === 0) { - message.error( - intl.formatMessage({ - id: 'modal.popup.save', - defaultMessage: '请保存弹窗后编辑其他弹窗', - }) - ); - } - if (!sign.success && sign.sign === 1) { - message.error( - intl.formatMessage( - { - id: 'modal.popup.notfond', - defaultMessage: '未找到该弹窗 {name}', - }, - { - name: sign.param, - } - ) - ); - } - - setConfigVisible(false); - }} - okText={intl.formatMessage({ id: 'yes' })} - cancelText={intl.formatMessage({ id: 'no' })} - > - - , - ]} - > - {v} - - ); - })} - {props.config.getStoreChanger().getState().modalEditName === '' && - Object.keys(props.config.getStore().getData().modalMap).length === 0 && ( -
- -
- )} -
-
- { - form - .validateFields() - .then((values) => { - form.resetFields(); - const modalName = values.modalName; - const sign = props.config - .getStoreChanger() - .newModalMap(props.config.getStore(), modalName); - if (sign.succeess && sign.sign === 0) { - message.error( - intl.formatMessage({ - id: 'modal.popup.save', - defaultMessage: '请保存弹窗后编辑其他弹窗', - }) - ); - } - if (sign.succeess && sign.sign === 1) { - message.error( - intl.formatMessage( - { - id: 'modal.popup.repeat', - defaultMessage: '已有重名弹窗 {name}', - }, - { - name: sign.param, - } - ) - ); - } - setVisible(false); - }) - .catch((info) => { - console.log('Validate Failed:', info); - }); - }} - title={intl.formatMessage({ id: 'modal.new', defaultMessage: '新增弹窗' })} - onCancel={() => setVisible(false)} - visible={visible} - > -
- - - -
-
- - ); -} - -export default Control; diff --git a/packages/dooringx-lib/src/components/control/control.tsx b/packages/dooringx-lib/src/components/control/control.tsx new file mode 100644 index 0000000..0940f2d --- /dev/null +++ b/packages/dooringx-lib/src/components/control/control.tsx @@ -0,0 +1,276 @@ +import { + GatewayOutlined, + LayoutOutlined, + SyncOutlined, + UnorderedListOutlined, + VideoCameraOutlined, +} from '@ant-design/icons'; +import { Button, Form, Input, List, message, Modal, Popconfirm, Popover } from 'antd'; +import React, { CSSProperties, PropsWithChildren, useState } from 'react'; +import { UserConfig } from '../..'; +import { wrapperMoveState } from '../wrapperMove/event'; +import { replaceLocale } from '../../locale'; +import { mouseUp, moveState } from './state'; + +export interface ControlProps { + config: UserConfig; + style?: CSSProperties; +} + +export function Control(props: PropsWithChildren) { + const { style } = props; + const [visible, setVisible] = useState(false); + const [configVisible, setConfigVisible] = useState(false); + const [form] = Form.useForm(); + + const [xy, setXy] = useState({ x: 0, y: 0 }); + return ( + <> +
+ + + + + +
+ } + > + + + + + + + + setConfigVisible(false)} + onCancel={() => setConfigVisible(false)} + footer={null} + > + + {props.config.getStoreChanger().getState().modalEditName !== '' && ( +
+ {replaceLocale('modal.popup.exit', '请退出编辑弹窗后再打开该配置', props.config)} +
+ )} + {props.config.getStoreChanger().getState().modalEditName === '' && + Object.keys(props.config.getStore().getData().modalMap).map((v) => { + return ( + { + const sign = props.config + .getStoreChanger() + .updateModal(props.config.getStore(), v); + if (!sign.success && sign.sign === 0) { + message.error( + replaceLocale( + 'modal.popup.save', + '请保存弹窗后编辑其他弹窗', + props.config + ) + ); + } + if (!sign.success && sign.sign === 1) { + message.error( + replaceLocale( + 'modal.popup.notfond', + `未找到该弹窗 ${sign.param}`, + props.config, + { name: sign.param }, + '未找到该弹窗 {name}' + ) + ); + } + setConfigVisible(false); + }} + okText={replaceLocale('yes', '确定', props.config)} + cancelText={replaceLocale('no', '取消', props.config)} + > + + , + + { + const sign = props.config + .getStoreChanger() + .removeModal(props.config.getStore(), v); + if (!sign.success && sign.sign === 0) { + message.error( + replaceLocale( + 'modal.popup.save', + '请保存弹窗后编辑其他弹窗', + props.config + ) + ); + } + if (!sign.success && sign.sign === 1) { + message.error( + replaceLocale( + 'modal.popup.notfond', + `未找到该弹窗 ${sign.param}`, + props.config, + { name: sign.param }, + '未找到该弹窗 {name}' + ) + ); + } + + setConfigVisible(false); + }} + okText={replaceLocale('yes', '确定', props.config)} + cancelText={replaceLocale('no', '取消', props.config)} + > + + , + ]} + > + {v} + + ); + })} + {props.config.getStoreChanger().getState().modalEditName === '' && + Object.keys(props.config.getStore().getData().modalMap).length === 0 && ( +
+ {replaceLocale('modal.popup.nomodal', `暂时没有弹窗`, props.config)} +
+ )} +
+
+ { + form + .validateFields() + .then((values) => { + form.resetFields(); + const modalName = values.modalName; + const sign = props.config + .getStoreChanger() + .newModalMap(props.config.getStore(), modalName); + + if (!sign.succeess && sign.sign === 0) { + message.error( + replaceLocale('modal.popup.save', `请保存弹窗后编辑其他弹窗`, props.config) + ); + } + if (!sign.succeess && sign.sign === 1) { + message.error( + replaceLocale( + 'modal.popup.repeat', + `已有重名弹窗 ${sign.param}`, + props.config, + { + name: sign.param, + }, + '已有重名弹窗 {name}' + ) + ); + } + setVisible(false); + }) + .catch((info) => { + console.log('Validate Failed:', info); + }); + }} + title={replaceLocale('modal.new', '新增弹窗', props.config)} + onCancel={() => setVisible(false)} + visible={visible} + > +
+ + + +
+
+ + ); +} + +export default Control; diff --git a/packages/dooringx-lib/src/components/control/index.ts b/packages/dooringx-lib/src/components/control/index.ts new file mode 100644 index 0000000..e3d3612 --- /dev/null +++ b/packages/dooringx-lib/src/components/control/index.ts @@ -0,0 +1,10 @@ +/* + * @Author: yehuozhili + * @Date: 2021-09-27 20:57:27 + * @LastEditors: yehuozhili + * @LastEditTime: 2021-09-27 20:59:34 + * @FilePath: \dooringx\packages\dooringx-lib\src\components\control\index.ts + */ + +import Control from './control'; +export default Control; diff --git a/packages/dooringx-lib/src/components/control/state.ts b/packages/dooringx-lib/src/components/control/state.ts new file mode 100644 index 0000000..8819c15 --- /dev/null +++ b/packages/dooringx-lib/src/components/control/state.ts @@ -0,0 +1,38 @@ +/* + * @Author: yehuozhili + * @Date: 2021-09-27 20:56:21 + * @LastEditors: yehuozhili + * @LastEditTime: 2021-09-27 20:57:01 + * @FilePath: \dooringx\packages\dooringx-lib\src\components\control\state.ts + */ + +interface MoveStateType { + startX: number; + startY: number; + fn: Function; + isMove: boolean; +} + +export const moveState: MoveStateType = { + startX: 0, + startY: 0, + fn: () => {}, + isMove: false, +}; + +export const mouseUp = () => { + if (moveState.isMove) { + moveState.isMove = false; + } +}; + +export const controlMouseMove = (e: React.MouseEvent) => { + if (moveState.isMove) { + const diffx = e.clientX - moveState.startX; + const diffy = e.clientY - moveState.startY; + const setXy = moveState.fn; + if (setXy) setXy((pre: { x: number; y: number }) => ({ x: pre.x + diffx, y: pre.y + diffy })); + moveState.startX = e.clientX; + moveState.startY = e.clientY; + } +}; diff --git a/packages/dooringx-lib/src/components/rightConfig.tsx b/packages/dooringx-lib/src/components/rightConfig.tsx index 9cd1b1c..4d81beb 100644 --- a/packages/dooringx-lib/src/components/rightConfig.tsx +++ b/packages/dooringx-lib/src/components/rightConfig.tsx @@ -2,7 +2,7 @@ * @Author: yehuozhili * @Date: 2021-03-14 05:42:13 * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-27 16:20:29 + * @LastEditTime: 2021-09-27 20:33:04 * @FilePath: \dooringx\packages\dooringx-lib\src\components\rightConfig.tsx */ import { CreateOptionsRes } from '../core/components/formTypes'; @@ -14,7 +14,7 @@ import UserConfig from '../config'; import { RGBColor, SketchPicker } from 'react-color'; import { rgba2Obj } from '../core/utils'; import deepcopy from 'deepcopy'; -import { FormattedMessage } from 'react-intl'; +import { replaceLocale } from '../locale'; const colStyle: CSSProperties = { display: 'flex', @@ -84,14 +84,7 @@ function RightConfig(props: PropsWithChildren) { ); }); } else { - return ( -
- -
- ); + return
{replaceLocale('right.noprops', '还没有配置属性', props.config)}
; } } return null; @@ -164,11 +157,11 @@ function RightConfig(props: PropsWithChildren) { {!current && !isEdit && !customGlobal && (
- + {replaceLocale('right.global', '全局设置', props.config)} - + {replaceLocale('title', '标题', props.config)} ) { - + {replaceLocale('right.containerheight', '容器高度', props.config)} ) { - + {replaceLocale('right.containerColor', '容器底色', props.config)} { @@ -300,7 +287,7 @@ function RightConfig(props: PropsWithChildren) { - + {replaceLocale('right.bodyColor', 'body底色', props.config)} { @@ -378,14 +365,11 @@ function RightConfig(props: PropsWithChildren) { {!current && isEdit && (
- + {replaceLocale('modal.control', '弹窗配置', props.config)} - + {replaceLocale('modal.control.remove', '取消点击删除弹窗', props.config)}
{value.config.getComponentRegister().getMap()[value.value.name].display}
{value.value.id.slice(-6)}
+
+ { + const store = value.config.getStore(); + const clone = deepcopy(store.getData()); + clone.block = clone.block.filter((v) => { + return !(v.id === value.value.id && !specialCoList.includes(value.value.name)); + }); + store.setData(clone); + }} + okText={replaceLocale('yes', '确定', value.config)} + cancelText={replaceLocale('no', '取消', value.config)} + > + + +
) @@ -182,7 +200,7 @@ export function TimeLine(props: TimeLineProps) { height: itemHeight, }} > - + {replaceLocale('timeline.name', '组件名称', props.config)} ) { const mergeConfig = userConfigMerge(defaultConfig, initConfig); this.initConfig = mergeConfig; diff --git a/packages/dooringx-lib/src/core/resizeHandler/containerResizer.ts b/packages/dooringx-lib/src/core/resizeHandler/containerResizer.ts index 4dde3d0..4a426a6 100644 --- a/packages/dooringx-lib/src/core/resizeHandler/containerResizer.ts +++ b/packages/dooringx-lib/src/core/resizeHandler/containerResizer.ts @@ -2,10 +2,11 @@ * @Author: yehuozhili * @Date: 2021-03-09 15:19:36 * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-09 14:37:55 + * @LastEditTime: 2021-09-27 20:58:13 * @FilePath: \dooringx\packages\dooringx-lib\src\core\resizeHandler\containerResizer.ts */ +import { controlMouseMove } from '../../components/control/state'; import UserConfig from '../../config'; import { IStoreData } from '../store/storetype'; import { deepCopy } from '../utils'; @@ -39,6 +40,7 @@ export const containerResizer = { store.setData(clonedata); containerState.startY = e.clientY; } + controlMouseMove(e); }, onMouseUp: (config: UserConfig) => { if (containerState.isDrag) { diff --git a/packages/dooringx-lib/src/index.tsx b/packages/dooringx-lib/src/index.tsx index acb8258..50f34bf 100644 --- a/packages/dooringx-lib/src/index.tsx +++ b/packages/dooringx-lib/src/index.tsx @@ -2,7 +2,7 @@ * @Author: yehuozhili * @Date: 2021-03-14 04:22:18 * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-27 14:21:09 + * @LastEditTime: 2021-09-27 21:08:40 * @FilePath: \dooringx\packages\dooringx-lib\src\index.tsx */ @@ -21,7 +21,7 @@ export { default as RightConfig } from './components/rightConfig'; // 画布外层 export { default as ContainerWrapper } from './components/wrapperMove'; // 控制全局 弹窗等 -export { default as Control } from './components/control'; +export { default as Control } from './components/control/control'; // 这个放到外层容器属性里 ...innerContainerDragUp() export { innerContainerDragUp } from './core/innerDrag'; diff --git a/packages/dooringx-lib/src/locale/en.ts b/packages/dooringx-lib/src/locale/en.ts index 001364b..c86bab3 100644 --- a/packages/dooringx-lib/src/locale/en.ts +++ b/packages/dooringx-lib/src/locale/en.ts @@ -2,7 +2,7 @@ * @Author: yehuozhili * @Date: 2021-08-27 10:20:23 * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-27 16:06:49 + * @LastEditTime: 2021-09-27 21:11:51 * @FilePath: \dooringx\packages\dooringx-lib\src\locale\en.ts */ @@ -37,5 +37,5 @@ export const en: typeof zhCN = { 'right.containerheight': 'Container height', 'right.containerColor': 'Container background color', 'right.bodyColor': 'Body background color', - title: 'title', + title: 'Title', }; diff --git a/packages/dooringx-lib/src/locale/index.ts b/packages/dooringx-lib/src/locale/index.ts deleted file mode 100644 index da03aed..0000000 --- a/packages/dooringx-lib/src/locale/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * @Author: yehuozhili - * @Date: 2021-08-27 10:20:38 - * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-27 14:30:05 - * @FilePath: \dooringx\packages\dooringx-lib\src\locale\index.ts - */ -import { en } from './en'; -import { zhCN } from './zh-CN'; - -export const localeMap = { - 'zh-CN': zhCN, - en, -}; -export type localeKey = keyof typeof localeMap; - -export { en } from './en'; -export { zhCN } from './zh-CN'; diff --git a/packages/dooringx-lib/src/locale/index.tsx b/packages/dooringx-lib/src/locale/index.tsx new file mode 100644 index 0000000..604a7e8 --- /dev/null +++ b/packages/dooringx-lib/src/locale/index.tsx @@ -0,0 +1,39 @@ +/* + * @Author: yehuozhili + * @Date: 2021-08-27 10:20:38 + * @LastEditors: yehuozhili + * @LastEditTime: 2021-09-27 18:08:49 + * @FilePath: \dooringx\packages\dooringx-lib\src\locale\index.tsx + */ +import React from 'react'; +import { FormattedMessage } from 'react-intl'; +import { UserConfig } from '..'; +import { en } from './en'; +import { zhCN } from './zh-CN'; + +export const localeMap = { + 'zh-CN': zhCN, + en, +}; +export type localeKey = keyof typeof localeMap; + +export { en } from './en'; +export { zhCN } from './zh-CN'; + +export const replaceLocale = ( + id: string, + msg: string, + config: UserConfig, + param?: any, + paramString?: string +) => { + if (config.i18n) { + if (paramString) { + return ( + + ); + } + return ; + } + return msg; +}; diff --git a/packages/dooringx-lib/src/locale/zh-CN.ts b/packages/dooringx-lib/src/locale/zh-CN.ts index 45c58fd..d1d5110 100644 --- a/packages/dooringx-lib/src/locale/zh-CN.ts +++ b/packages/dooringx-lib/src/locale/zh-CN.ts @@ -2,7 +2,7 @@ * @Author: yehuozhili * @Date: 2021-08-27 10:20:15 * @LastEditors: yehuozhili - * @LastEditTime: 2021-08-27 16:06:45 + * @LastEditTime: 2021-09-27 21:11:43 * @FilePath: \dooringx\packages\dooringx-lib\src\locale\zh-CN.ts */ export const zhCN = { @@ -27,8 +27,8 @@ export const zhCN = { 'modal.popup.name': '请输入弹窗名称', 'modal.name': '弹窗名称', 'modal.control.remove': '取消点击删除弹窗', - yes: '是', - no: '否', + yes: '确定', + no: '取消', 'right.noprops': '还没有配置属性', 'right.global': '全局设置', 'right.containerheight': '容器高度',