소스 검색

项目类型

魏熙美 5 년 전
부모
커밋
ccb4fc5e7a
3개의 변경된 파일56개의 추가작업 그리고 9개의 파일을 삭제
  1. 49
    6
      src/pages/building/type/edi.jsx
  2. 3
    3
      src/pages/building/type/index.jsx
  3. 4
    0
      src/services/apis.js

+ 49
- 6
src/pages/building/type/edi.jsx 파일 보기

1
-import React from 'react';
1
+import React, { useState, useEffect } from 'react';
2
 import { Input, Button, Row, Col, Form, Alert } from 'antd';
2
 import { Input, Button, Row, Col, Form, Alert } from 'antd';
3
 import router from 'umi/router';
3
 import router from 'umi/router';
4
 import Styles from './style.less';
4
 import Styles from './style.less';
8
 function body(props) {
8
 function body(props) {
9
   const { getFieldDecorator } = props.form;
9
   const { getFieldDecorator } = props.form;
10
 
10
 
11
-  console.log('id: ', props.location.query.id)
11
+  // eslint-disable-next-line react-hooks/rules-of-hooks
12
+  let data = {}
13
+  const { id } = props.location.query;
14
+
15
+  if (id !== '') {
16
+    // eslint-disable-next-line react-hooks/rules-of-hooks
17
+    useEffect(() => {
18
+      getById(id)
19
+    }, [])
20
+  }
12
 
21
 
13
   function handleSubmit(e) {
22
   function handleSubmit(e) {
14
     e.preventDefault();
23
     e.preventDefault();
15
     props.form.validateFields((err, values) => {
24
     props.form.validateFields((err, values) => {
16
       if (!err) {
25
       if (!err) {
17
         // 提交数据
26
         // 提交数据
18
-        values.status = 1
19
-        values.createDate = new Date()
20
         submitData(values)
27
         submitData(values)
21
       }
28
       }
22
     });
29
     });
23
   }
30
   }
24
 
31
 
25
-  function submitData(data) {
26
-    request({ ...apis.buildingType.add, data: { ...data } }).then(() => {
32
+  // 获取详情信息
33
+  function getById(currentId) {
34
+    const { url, method } = apis.buildingType.getById
35
+    const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(currentId)
36
+
37
+    request({ url: tempUrl, method }).then(res => {
38
+      data = res
39
+      props.form.setFieldsValue(res)
40
+    })
41
+  }
42
+
43
+  function submitData(dataSources) {
44
+    if (id !== '') {
45
+      // 修改
46
+      updateType(dataSources)
47
+      return
48
+    }
49
+
50
+    dataSources.status = 1
51
+    dataSources.createDate = new Date()
52
+    request({ ...apis.buildingType.add, data: { ...dataSources } }).then(() => {
27
       // eslint-disable-next-line no-unused-expressions
53
       // eslint-disable-next-line no-unused-expressions
28
       <Alert
54
       <Alert
29
         style={{
55
         style={{
47
     })
73
     })
48
   }
74
   }
49
 
75
 
76
+    // 修改
77
+    function updateType(row) {
78
+      const { url, method } = apis.buildingType.update
79
+      const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(row.buildingTypeId)
80
+
81
+      request({ url: tempUrl, method, data: { ...row } }).then(() => {
82
+        router.go(-1)
83
+      })
84
+    }
85
+
50
   return (
86
   return (
51
     <>
87
     <>
52
         <Form onSubmit={handleSubmit} style={{ width: '500px', margin: 'auto' }}>
88
         <Form onSubmit={handleSubmit} style={{ width: '500px', margin: 'auto' }}>
89
+          <Form.Item style={{ display: 'none' }}>
90
+            {getFieldDecorator('buildingTypeId')(
91
+              <Input
92
+                placeholder="buildingTtypeId"
93
+              />,
94
+            )}
95
+          </Form.Item>
53
           <Form.Item>
96
           <Form.Item>
54
             {getFieldDecorator('buildingTypeName', {
97
             {getFieldDecorator('buildingTypeName', {
55
               rules: [{ required: true, message: '请输入名称' }],
98
               rules: [{ required: true, message: '请输入名称' }],

+ 3
- 3
src/pages/building/type/index.jsx 파일 보기

85
   }
85
   }
86
 
86
 
87
   // 跳转修改页
87
   // 跳转修改页
88
-  function toEdi(id) {
88
+  function toEdi(currentId) {
89
     router.push({
89
     router.push({
90
       pathname: '/building/type/edi',
90
       pathname: '/building/type/edi',
91
       query: {
91
       query: {
92
-        id,
92
+        id: currentId || '',
93
       },
93
       },
94
     });
94
     });
95
   }
95
   }
96
 
96
 
97
   return (
97
   return (
98
     <>
98
     <>
99
-      <Button type="primary" className={Styles.addButton} onClick={toEdi}>新增类型</Button>
99
+      <Button type="primary" className={Styles.addButton} onClick={() => toEdi()}>新增类型</Button>
100
       <Table dataSource={data.records} columns={columns} pagination={false}/>
100
       <Table dataSource={data.records} columns={columns} pagination={false}/>
101
       {/* 分页 */}
101
       {/* 分页 */}
102
       <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
102
       <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>

+ 4
- 0
src/services/apis.js 파일 보기

34
       method: 'POST',
34
       method: 'POST',
35
       url: `${prefix}/tdBuildingType`,
35
       url: `${prefix}/tdBuildingType`,
36
     },
36
     },
37
+    getById: {
38
+      method: 'GET',
39
+      url: `${prefix}/tdBuildingType/id`,
40
+    },
37
   },
41
   },
38
 }
42
 }