/* * << * Davinci * == * Copyright (C) 2016 - 2017 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> */ import React from 'react' import { Form, Row, Col, Input, Radio, Select, Tabs, Checkbox} from 'antd' import { IExludeRoles } from 'containers/Viz/components/PortalList' import { FormComponentProps } from 'antd/lib/form' const styles = require('containers/Viz/Viz.less') const TabPane = Tabs.TabPane const Option = Select.Option const FormItem = Form.Item const RadioGroup = Radio.Group const utilStyles = require('assets/less/util.less') interface IDashboardFormProps extends FormComponentProps { portalId: number type: string itemId: number dashboards: any[] onCheckUniqueName: (pathname: string, data: any, resolve: () => any, reject: (error: string) => any) => any exludeRoles?: IExludeRoles[] onChangePermission: (scope: object, e: any) => any } export class DashboardForm extends React.PureComponent { private checkNameUnique = (rule, value = '', callback) => { const { onCheckUniqueName, type, form, portalId} = this.props const { id } = form.getFieldsValue() const data = { portal: portalId, id: type === ('add' || 'copy') ? '' : id, name: value } if (!value) { callback() } type === 'move' ? callback() : onCheckUniqueName('dashboard', data, () => { callback() }, (err) => { callback(err) }) } public render () { const { getFieldDecorator } = this.props.form const { dashboards, type, itemId, exludeRoles } = this.props const commonFormItemStyle = { labelCol: { span: 6 }, wrapperCol: { span: 16 } } const authControl = exludeRoles && exludeRoles.length ? exludeRoles.map((role) => (
{role.name}
)) : [] const dashboardsArr = (dashboards as any[]).filter((d) => d.type === 0) const folderOptions = (dashboardsArr as any[]).map((s) => ) const deleteItem = (dashboards as any[]).find((d) => d.id === Number(itemId)) let deleteType = '' let deleteName = '' if (deleteItem) { deleteType = deleteItem.type === 0 ? '文件夹' : '仪表板' deleteName = deleteItem.name } return (
{type !== 'add' && type !== 'copy' && ( {getFieldDecorator('id', {})( )} )} {getFieldDecorator('folder', { rules: [{ required: true, message: '请选择所属文件夹' }], initialValue: '0' })( )} {getFieldDecorator('folder', { rules: [{ required: true, message: '请选择所属文件夹' }], // initialValue: (folderOptions as any[]).length ? `${dashboardsArr[0].name}` : '' initialValue: '0' })( )} {getFieldDecorator('config', {})( )} {getFieldDecorator('index', {})( )} {getFieldDecorator('name', { rules: [{ required: true, message: '名称 不能为空' }, { validator: this.checkNameUnique }] })( )} {getFieldDecorator('selectType', { initialValue: 1 })( 文件夹 仪表板 {/* Report */} {/* */} )} { authControl }

确定要删除 {deleteType}:{deleteName} ?

) } } export default Form.create()(DashboardForm)