/* eslint-disable */ import React, { PureComponent, Fragment } from 'react'; import { connect } from 'dva'; import moment from 'moment'; import { Card, Form, Input, Select, Button, Modal, message, Table, TreeSelect, Radio, Divider, Icon, InputNumber, } from 'antd'; import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import styles from './ResourceList.less'; const RadioGroup = Radio.Group; const FormItem = Form.Item; const { Option } = Select; const TextArea = Input.TextArea; const types = ['未知', '菜单', '按钮']; // 添加 form 表单 const CreateForm = Form.create()(props => { const { modalVisible, form, handleAdd, handleModalVisible, modalType, initValues, selectTree, } = props; const okHandle = () => { form.validateFields((err, fieldsValue) => { if (err) return; let pid = fieldsValue.pid; if (fieldsValue.pid) { pid = pid.split('-')[1]; fieldsValue.pid = pid; } form.resetFields(); handleAdd({ fields: fieldsValue, modalType, initValues, }); }); }; const selectStyle = { width: 200, }; function onTypeChange(event) { initValues.type = parseInt(event.target.value); } // 给 type 赋予初始值 initValues.type = initValues.type || 1; const title = modalType === 'add' ? '添加一个权限' : '编辑一个权限'; const okText = modalType === 'add' ? '添加' : '编辑'; return ( handleModalVisible()} > {form.getFieldDecorator('type', { initialValue: initValues.type, })( 菜单 按钮 )} {form.getFieldDecorator('name', { rules: [{ required: true, message: '请输入名称!', min: 2 }], initialValue: initValues.name, })()} {form.getFieldDecorator('pid', { rules: [{ required: true, message: '请选择父级编号!' }], initialValue: initValues.pid === 0 ? `根节点` : initValues.pid ? `${initValues.name}` : undefined, })( )} {form.getFieldDecorator('sort', { rules: [{ required: true, message: '请输入排序!' }], initialValue: initValues.sort, })()} { initValues.type === 1 ? ( {form.getFieldDecorator('icon', { rules: [{ required: true, message: '请输入图标!' }], initialValue: initValues.icon, })()} ) : '' } { initValues.type === 1 ? ( {form.getFieldDecorator('route', { initialValue: initValues.route, })()} ) : '' } {form.getFieldDecorator('permission', { initialValue: initValues.permission, })()} ); }); @connect(({ resourceList, loading }) => ({ resourceList, list: resourceList.list, loading: loading.models.resourceList, })) @Form.create() class ResourceList extends PureComponent { state = { modalVisible: false, modalType: 'add', //add update initValues: {}, }; componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'resourceList/tree', payload: {}, }); } handleModalVisible = (flag, modalType, initValues) => { this.setState({ modalVisible: !!flag, initValues: initValues || {}, modalType: modalType || 'add', }); }; handleAdd = ({ fields, modalType, initValues }) => { const { dispatch } = this.props; if (modalType === 'add') { dispatch({ type: 'resourceList/add', payload: { body: { ...fields, }, callback: () => { message.success('添加成功'); this.handleModalVisible(); }, }, }); } else { dispatch({ type: 'resourceList/update', payload: { body: { ...initValues, ...fields, }, callback: () => { message.success('编辑成功'); this.handleModalVisible(); }, }, }); } }; handleDelete(row) { const { dispatch } = this.props; Modal.confirm({ title: `确认删除?`, content: `${row.name}`, onOk() { dispatch({ type: 'resourceList/delete', payload: { id: row.id, }, }); }, onCancel() {}, }); } render() { const { list, resourceList } = this.props; const { selectTree } = resourceList; const { modalVisible, modalType, initValues } = this.state; const parentMethods = { handleAdd: this.handleAdd, handleModalVisible: this.handleModalVisible, modalType, initValues, }; const columns = [ { title: '名称', dataIndex: 'name', }, { title: '图标', dataIndex: 'icon', render: text => text ? : '', }, { title: '类型', dataIndex: 'type', render(val) { return {types[val]}; }, }, { title: '排序', dataIndex: 'sort', }, { title: '路由', dataIndex: 'route', width: 200, render: val => {val}, }, { title: '权限标识', dataIndex: 'permission', width: 300, render: val => {val}, }, { title: '创建时间', dataIndex: 'createTime', sorter: true, render: val => {moment(val).format('YYYY-MM-DD')}, }, { title: '操作', render: (text, record) => ( this.handleModalVisible(true, 'update', record)}>编辑 this.handleDelete(record)}> 删除 ), }, ]; return (
); } } export default ResourceList;