From 02cd7c049ebc8c715bb4ed4f8d56cf44744a091f Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Wed, 24 Jul 2019 19:24:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=83=E5=88=86=E4=BD=8D=E5=8F=AA=E5=8A=A0?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E7=82=B9=E5=89=8D=E9=9D=A2=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Dialog.tsx | 132 +++++++++++++++++++-------------------- src/utils/tpl-builtin.ts | 6 +- 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/src/renderers/Dialog.tsx b/src/renderers/Dialog.tsx index 52960b717..6e59aa2c1 100644 --- a/src/renderers/Dialog.tsx +++ b/src/renderers/Dialog.tsx @@ -1,17 +1,17 @@ import React from 'react'; import PropTypes from 'prop-types'; -import Scoped, {ScopedContext, IScopedContext} from '../Scoped'; -import {Renderer, RendererProps} from '../factory'; -import {ServiceStore, IServiceStore} from '../store/service'; -import {observer} from 'mobx-react'; -import {SchemaNode, Schema, Action} from '../types'; -import {filter} from '../utils/tpl'; +import Scoped, { ScopedContext, IScopedContext } from '../Scoped'; +import { Renderer, RendererProps } from '../factory'; +import { ServiceStore, IServiceStore } from '../store/service'; +import { observer } from 'mobx-react'; +import { SchemaNode, Schema, Action } from '../types'; +import { filter } from '../utils/tpl'; import Modal from '../components/Modal'; import findLast = require('lodash/findLast'); -import {guid} from '../utils/helper'; -import {reaction} from 'mobx'; -import {closeIcon} from '../components/icons'; -import {ModalStore, IModalStore} from '../store/modal'; +import { guid } from '../utils/helper'; +import { reaction } from 'mobx'; +import { closeIcon } from '../components/icons'; +import { ModalStore, IModalStore } from '../store/modal'; import { findDOMNode } from 'react-dom'; export interface DialogProps extends RendererProps { @@ -110,7 +110,7 @@ export default class Dialog extends React.Component { } buildActions(): Array { - const {actions, confirm} = this.props; + const { actions, confirm } = this.props; if (typeof actions !== 'undefined') { return actions; @@ -136,7 +136,7 @@ export default class Dialog extends React.Component { } handleSelfClose() { - const {onClose, store} = this.props; + const { onClose, store } = this.props; // clear error store.updateMessage(); @@ -144,7 +144,7 @@ export default class Dialog extends React.Component { } handleAction(e: React.UIEvent, action: Action, data: object) { - const {store, onAction} = this.props; + const { store, onAction } = this.props; if (action.type === 'reset') { store.reset(); @@ -156,7 +156,7 @@ export default class Dialog extends React.Component { } handleDialogConfirm(values: object[], action: Action, ...args: Array) { - const {store} = this.props; + const { store } = this.props; if (action.mergeData && values.length === 1 && values[0]) { store.updateData(values[0]); @@ -172,7 +172,7 @@ export default class Dialog extends React.Component { } handleDialogClose(...args: Array) { - const {store} = this.props; + const { store } = this.props; const action = store.action as Action; const dialog = action.dialog as any; @@ -185,7 +185,7 @@ export default class Dialog extends React.Component { } handleDrawerConfirm(values: object[], action: Action, ...args: Array) { - const {store} = this.props; + const { store } = this.props; if (action.mergeData && values.length === 1 && values[0]) { store.updateData(values[0]); @@ -201,7 +201,7 @@ export default class Dialog extends React.Component { } handleDrawerClose(...args: Array) { - const {store} = this.props; + const { store } = this.props; const action = store.action as Action; const drawer = action.drawer as any; @@ -227,7 +227,7 @@ export default class Dialog extends React.Component { } handleExited() { - const {store} = this.props; + const { store } = this.props; store.reset(); this.state.entered && this.setState({ @@ -236,19 +236,19 @@ export default class Dialog extends React.Component { } handleFormInit(data: any) { - const {store} = this.props; + const { store } = this.props; store.setFormData(data); } handleFormChange(data: any) { - const {store} = this.props; + const { store } = this.props; store.setFormData(data); } handleFormSaved(data: any, response: any) { - const {store} = this.props; + const { store } = this.props; store.setFormData({ ...data, @@ -261,7 +261,7 @@ export default class Dialog extends React.Component { } renderBody(body: SchemaNode, key?: any): React.ReactNode { - let {render, store} = this.props; + let { render, store } = this.props; if (Array.isArray(body)) { return body.map((body, key) => this.renderBody(body, key)); @@ -304,7 +304,7 @@ export default class Dialog extends React.Component { return null; } - const {store, render, classnames: cx} = this.props; + const { store, render, classnames: cx } = this.props; return (
@@ -312,15 +312,15 @@ export default class Dialog extends React.Component {
{store.loading ? render( - 'info', - { - type: 'spinner', - }, - { - key: 'info', - size: 'sm', - } - ) + 'info', + { + type: 'spinner', + }, + { + key: 'info', + size: 'sm', + } + ) : null} {store.error ? {store.msg} : null}
@@ -405,8 +405,8 @@ export default class Dialog extends React.Component { {header ? render('header', header, { - data: store.formData, - }) + data: store.formData, + }) : null} {!this.state.entered && lazyRender ? ( @@ -419,40 +419,40 @@ export default class Dialog extends React.Component { {body ? render( - 'drawer', - { - // 支持嵌套 - ...((store.action as Action) && ((store.action as Action).drawer as object)), - type: 'drawer', - }, - { - key: 'drawer', - data: store.drawerData, - onConfirm: this.handleDrawerConfirm, - onClose: this.handleDrawerClose, - show: store.drawerOpen, - onAction: this.handleAction, - } - ) + 'drawer', + { + // 支持嵌套 + ...((store.action as Action) && ((store.action as Action).drawer as object)), + type: 'drawer', + }, + { + key: 'drawer', + data: store.drawerData, + onConfirm: this.handleDrawerConfirm, + onClose: this.handleDrawerClose, + show: store.drawerOpen, + onAction: this.handleAction, + } + ) : null} {body ? render( - 'dialog', - { - // 支持嵌套 - ...((store.action as Action) && ((store.action as Action).dialog as object)), - type: 'dialog', - }, - { - key: 'dialog', - data: store.dialogData, - onConfirm: this.handleDialogConfirm, - onClose: this.handleDialogClose, - show: store.dialogOpen, - onAction: this.handleAction, - } - ) + 'dialog', + { + // 支持嵌套 + ...((store.action as Action) && ((store.action as Action).dialog as object)), + type: 'dialog', + }, + { + key: 'dialog', + data: store.dialogData, + onConfirm: this.handleDialogConfirm, + onClose: this.handleDialogClose, + show: store.dialogOpen, + onAction: this.handleAction, + } + ) : null} ); @@ -490,7 +490,7 @@ export class DialogRenderer extends Dialog { const components = scoped.getComponents(); const targets: Array = []; - const {onConfirm, store} = this.props; + const { onConfirm, store } = this.props; if (action.target) { targets.push( @@ -556,7 +556,7 @@ export class DialogRenderer extends Dialog { throwErrors: boolean = false, delegate?: boolean ) { - const {onAction, store, onConfirm} = this.props; + const { onAction, store, onConfirm } = this.props; if (action.from === this.$$id) { return onAction ? onAction(e, action, data, throwErrors, true) : false; diff --git a/src/utils/tpl-builtin.ts b/src/utils/tpl-builtin.ts index d4e22e2af..d6c561b81 100644 --- a/src/utils/tpl-builtin.ts +++ b/src/utils/tpl-builtin.ts @@ -138,7 +138,11 @@ export const filters: { raw: input => input, date: (input, format = "LLL", inputFormat = "X") => moment(input, inputFormat).format(format), - number: input => String(input).replace(/\B(?=(\d{3})+(?!\d))/g, ","), + number: input => { + let parts = String(input).split('.'); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); + return parts.join('.'); + }, trim: input => input.trim(), percent: (input, decimals = 0) => { input = parseFloat(input) || 0;