forked from huge/frontEnd/hugeOA

Mr Ke
2020-05-27 77a2a090ff1b9d1b03795d696954a28ba0e0871f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React from 'react';
import { Card, Row, Col, Form, Input, Button, message, Spin } from 'antd';
import { createHashHistory } from 'history';
import fetch from '../../api/request';
 
const history = createHashHistory();
const FormItem = Form.Item;
const { TextArea } = Input;
 
class AppServiceDeatil extends React.Component {
  constructor(props) {
    super(props)
    this.id = props.match.params.id == 'new' ? '' : props.match.params.id;
    this.flag = props.match.params.flag == 'Modify' ? '修改' : '新增';
 
    this.state = {
      spinning: false,//页面loading
      dataSet: {}
    }
  }
 
  componentWillMount() { }
 
  //获取应用服务详情
  componentDidMount() {
    if (this.id !== '') {
      this.setState({ spinning: true });
      fetch({
        url: `api/app/getById`,
        params: { id: this.id }
      }).then(res => {
        this.setState({ loading: false });
        if (res) {
          this.setState({ dataSet: res, spinning: false });
        }
      })
    }
  }
 
  // 提交表单数据(保存)
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (err) return;
      this.setState({ spinning: true });
      fetch({
        url: `api/app/save`,
        method: 'POST',
        data: { ...values, id: this.id }
      }).then(res => {
        this.setState({ spinning: false });
        if (res) {
          message.success('保存成功');
          history.goBack();//返回至列表页面
        }
      })
    })
  }
 
  //返回上一个页面
  onBack = () => {
    history.goBack();
  }
 
  render() {
    const { getFieldDecorator } = this.props.form;
    const { dataSet } = this.state;
    const formItemLayout = {
      labelCol: { xs: { span: 24 }, sm: { span: 5 }, },
      wrapperCol: { xs: { span: 24 }, sm: { span: 19 }, },
    };
 
    return (
      <div className="appservicedetail-main h-100 margin padding bg-white">
        <Spin spinning={this.state.spinning}>
          <div>
            <Form onSubmit={this.handleSubmit}>
              <Card title={this.id ? '应用服务信息编辑' : '应用服务信息新增'} bordered={false}
                extra={<Row type="flex" gutter={20}>
                  <Col>
                    <Button onClick={this.onBack}>返回</Button>
                  </Col>
                  <Col>
                    <Button type="primary" htmlType="submit">确定</Button>
                  </Col>
                </Row>}
              >
                <Row type="flex">
                  <Col span={14}>
                    <FormItem label={"名称"} {...formItemLayout}>
                      {getFieldDecorator('name', {
                        rules: [{ required: true, message: '请输入名称' }],
                        initialValue: dataSet.name || ''
                      })(
                        <Input placeholder="请输入描述" rows={5} />
                      )}
                    </FormItem>
                  </Col>
                </Row>
                <Row type="flex">
                  <Col span={14}>
                    <FormItem label={"根路径"} {...formItemLayout}>
                      {getFieldDecorator('rootUrl', {
                        rules: [{ required: true, message: '请输入根路径' }],
                        initialValue: dataSet.rootUrl || '',
                      })(
                        <Input placeholder="请输入根路径" />
                      )}</FormItem>
                  </Col>
                </Row>
                <Row type="flex">
                  <Col span={14}>
                    <FormItem label={"标识符"} {...formItemLayout}>
                      {getFieldDecorator('symbol', {
                        rules: [{ required: true, message: '请输入标识符' }],
                        initialValue: dataSet.symbol || '',
                      })(
                        <Input placeholder="请输入标识符" />
                      )}</FormItem>
                  </Col>
                </Row>
                <Row type="flex">
                  <Col span={14}>
                    <FormItem label={"描述"} {...formItemLayout}>
                      {getFieldDecorator('description', {
                        rules: [{ max: 200, message: '描述的内容不能超过200字' }],
                        initialValue: dataSet.description || ''
                      })(
                        <TextArea placeholder="请输入描述" rows={5} />
                      )}</FormItem>
                  </Col>
                </Row>
              </Card>
            </Form>
          </div>
        </Spin>
      </div>
    )
  }
}
 
const AppServiceDeatilForm = Form.create()(AppServiceDeatil);
export default AppServiceDeatilForm;