diff --git a/src/renderers/Form/Table.tsx b/src/renderers/Form/Table.tsx index 86ed54af..e132a162 100644 --- a/src/renderers/Form/Table.tsx +++ b/src/renderers/Form/Table.tsx @@ -1,14 +1,14 @@ -import React from 'react'; -import {FormItem, FormControlProps} from './Item'; -import cx from 'classnames'; -import Button from '../../components/Button'; -import {createObject, isObjectShallowModified} from '../../utils/helper'; -import {RendererData, Action, Api, Payload} from '../../types'; -import {isEffectiveApi} from '../../utils/api'; -import {filter} from '../../utils/tpl'; -import omit = require('lodash/omit'); -import {dataMapping} from '../../utils/tpl-builtin'; -import findIndex = require('lodash/findIndex'); +import React from "react"; +import { FormItem, FormControlProps } from "./Item"; +import cx from "classnames"; +import Button from "../../components/Button"; +import { createObject, isObjectShallowModified } from "../../utils/helper"; +import { RendererData, Action, Api, Payload } from "../../types"; +import { isEffectiveApi } from "../../utils/api"; +import { filter } from "../../utils/tpl"; +import omit = require("lodash/omit"); +import { dataMapping } from "../../utils/tpl-builtin"; +import findIndex = require("lodash/findIndex"); export interface TableProps extends FormControlProps { placeholder?: string; @@ -44,29 +44,29 @@ export interface TableState { export default class FormTable extends React.Component { static defaultProps = { - placeholder: '空', + placeholder: "空", scaffold: {}, - addBtnIcon: 'fa fa-plus', - updateBtnIcon: 'fa fa-pencil', - deleteBtnIcon: 'fa fa-minus', - confirmBtnIcon: 'fa fa-check', - cancelBtnIcon: 'fa fa-times', - valueField: '' + addBtnIcon: "fa fa-plus", + updateBtnIcon: "fa fa-pencil", + deleteBtnIcon: "fa fa-minus", + confirmBtnIcon: "fa fa-check", + cancelBtnIcon: "fa fa-times", + valueField: "" }; static propsList: Array = [ - 'onChange', - 'name', - 'columns', - 'label', - 'scaffold', - 'showAddBtn', - 'addable', - 'removable', - 'editable', - 'addApi', - 'updateApi', - 'deleteApi' + "onChange", + "name", + "columns", + "label", + "scaffold", + "showAddBtn", + "addable", + "removable", + "editable", + "addApi", + "updateApi", + "deleteApi" ]; entries: Map; @@ -100,7 +100,7 @@ export default class FormTable extends React.Component { } validate(): any { - const {value, minLength, maxLength} = this.props; + const { value, minLength, maxLength } = this.props; if (minLength && (!Array.isArray(value) || value.length < minLength)) { return `组合表单成员数量不够,低于最小的设定${minLength}个,请添加更多的成员。`; @@ -115,7 +115,7 @@ export default class FormTable extends React.Component { return Promise.all(subForms.map(item => item.validate())).then( values => { if (~values.indexOf(false)) { - return '内部表单验证失败'; + return "内部表单验证失败"; } return; @@ -126,9 +126,9 @@ export default class FormTable extends React.Component { } doAction(action: Action, ctx: RendererData, ...rest: Array) { - const {onAction, value, valueField, env, onChange, editable} = this.props; + const { onAction, value, valueField, env, onChange, editable } = this.props; - if (action.actionType === 'add') { + if (action.actionType === "add") { const rows = Array.isArray(value) ? value.concat() : []; if (action.payload) { @@ -159,13 +159,13 @@ export default class FormTable extends React.Component { return this.addItem(rows.length - 1); } } else if ( - action.actionType === 'remove' || - action.actionType === 'delete' + action.actionType === "remove" || + action.actionType === "delete" ) { if (!valueField) { - return env.alert('请配置 valueField'); + return env.alert("请配置 valueField"); } else if (!action.payload) { - return env.alert('action 上请配置 payload, 否则不清楚要删除哪个'); + return env.alert("action 上请配置 payload, 否则不清楚要删除哪个"); } const rows = Array.isArray(value) ? value.concat() : []; @@ -191,7 +191,7 @@ export default class FormTable extends React.Component { } addItem(index: number, payload: any = this.props.scaffold) { - const {value, onChange} = this.props; + const { value, onChange } = this.props; let newValue = Array.isArray(value) ? value.concat() : []; newValue.splice(index + 1, 0, { ...payload @@ -249,7 +249,7 @@ export default class FormTable extends React.Component { } if (remote && !remote.ok) { - env.notify('error', remote.msg || '保存失败'); + env.notify("error", remote.msg || "保存失败"); return; } else if (remote && remote.ok) { item = { @@ -268,7 +268,7 @@ export default class FormTable extends React.Component { } cancelEdit() { - const {value, onChange} = this.props; + const { value, onChange } = this.props; if (this.state.isCreateMode) { let newValue = Array.isArray(value) ? value.concat() : []; @@ -300,7 +300,7 @@ export default class FormTable extends React.Component { const ctx = createObject(data, item); if (isEffectiveApi(deleteApi, ctx)) { const confirmed = await env.confirm( - deleteConfirmText ? filter(deleteConfirmText, ctx) : '确认要删除?' + deleteConfirmText ? filter(deleteConfirmText, ctx) : "确认要删除?" ); if (!confirmed) { // 如果不确认,则跳过! @@ -310,7 +310,7 @@ export default class FormTable extends React.Component { const result = await env.fetcher(deleteApi, ctx); if (!result.ok) { - env.notify('error', '删除失败'); + env.notify("error", "删除失败"); return; } } @@ -340,7 +340,7 @@ export default class FormTable extends React.Component { let btns = []; if (props.addable && props.showAddBtn !== false) { btns.push({ - children: ({key, rowIndex}: {key: any; rowIndex: number}) => + children: ({ key, rowIndex }: { key: any; rowIndex: number }) => ~this.state.editIndex ? null : (