李志伟 2 anos atrás
pai
commit
27b1be946f

+ 0
- 113
src/components/ExtendContent/List.jsx Ver arquivo

@@ -1,113 +0,0 @@
1
-import { useEffect, useState, forwardRef, useImperativeHandle, useRef } from 'react';
2
-import { Table, Space, Button, Popconfirm } from 'antd';
3
-import { getList, remove } from '@/services/extendContent';
4
-
5
-export default forwardRef((props, ref) => {
6
-  const { targetType, targetId, onEdit } = props;
7
-
8
-  const [loading, setLoading] = useState(false);
9
-  const [list, setList] = useState([]);
10
-  const refs = useRef();
11
-
12
-  const tableList = () => {
13
-    setLoading(true);
14
-    getList({
15
-      pageSize: 9999,
16
-      targetId,
17
-      targetType,
18
-    })
19
-      .then((res) => {
20
-        setList(res.records || []);
21
-        setLoading(false);
22
-      })
23
-      .catch((err) => {
24
-        console.log(err.message)
25
-        setLoading(false)
26
-      });
27
-  };
28
-
29
-  refs.current = tableList;
30
-
31
-  // 父组件调用 updateList 来修改 list
32
-  useImperativeHandle(ref, () => ({
33
-    reload: refs.current,
34
-    setLoading,
35
-  }));
36
-
37
-  const handleEdit = (record) => {
38
-    onEdit(record);
39
-  };
40
-  //删除
41
-  const handleDelete = (record) => {
42
-    setLoading(true);
43
-    remove(record.extId)
44
-      .then(() => {
45
-        setList(list.filter((x) => x.extId !== record.extId));
46
-        setLoading(false);
47
-        // refs.current.reload();
48
-      })
49
-      .catch((err) => {
50
-        console.log(err.message)
51
-        setLoading(false)
52
-      });
53
-  };
54
-
55
-  const columns = [
56
-    {
57
-      title: '序号',
58
-      key: 'index',
59
-      dataIndex: 'index',
60
-      render: (t, record, index) => `${index + 1}`,
61
-    },
62
-    {
63
-      title: '权重',
64
-      key: 'sort',
65
-      dataIndex: 'sort',
66
-      render: (t, record) => `${record.sort}`,
67
-    },
68
-    {
69
-      title: '内容',
70
-      key: 'content',
71
-      dataIndex: 'content',
72
-      ellipsis: true,
73
-      render: (t, record) => {
74
-        if (record.contentType === 'text') return t;
75
-        if (record.contentType === 'image') {
76
-          return <img style={{ width: '110px' }} src={t} alt="" />;
77
-        }
78
-      },
79
-    },
80
-    {
81
-      title: '操作',
82
-      key: 'option',
83
-      render: (_, record) => {
84
-        return (
85
-          <Space>
86
-            <Button type="link" onClick={() => handleEdit(record)}>
87
-              编辑
88
-            </Button>
89
-            {/* <Button type="link" onClick={() => handleEdit(record)}>插入</Button> */}
90
-            <Popconfirm title="确定进行当前操作 ?" onConfirm={() => handleDelete(record)}>
91
-              <Button type="link">删除</Button>
92
-            </Popconfirm>
93
-          </Space>
94
-        );
95
-      },
96
-    },
97
-  ];
98
-
99
-  useEffect(() => {
100
-    if (targetType) {
101
-      refs.current();
102
-    }
103
-  }, [targetType]);
104
-  return (
105
-    <Table
106
-      loading={loading}
107
-      rowKey="extId"
108
-      columns={columns}
109
-      dataSource={list}
110
-      pagination={false}
111
-    />
112
-  );
113
-});

+ 0
- 68
src/components/ExtendContent/ModalButton.jsx Ver arquivo

@@ -1,68 +0,0 @@
1
-import { useEffect, useImperativeHandle, useState, forwardRef } from 'react';
2
-import { Button } from 'antd';
3
-import ModalText from './ModalText';
4
-import ModalImage from './Modalimage';
5
-
6
-export default forwardRef((props, ref) => {
7
-  const { contentType, record, onChange, onClose, ...btnProps } = props;
8
-
9
-  const [visible, setVisible] = useState(false);
10
-  const [content, setContent] = useState();
11
-  const [sortVale, setSortVale] = useState();
12
-
13
-  const handleClose = () => {
14
-    setContent();
15
-    setSortVale();
16
-    setVisible(false);
17
-    onClose();
18
-  };
19
-
20
-  const handleChange = (val, e) => {
21
-    onChange(
22
-      {
23
-        ...(record || {}),
24
-        content: val,
25
-        sort: e - 0,
26
-        contentType,
27
-      },
28
-      handleClose,
29
-    );
30
-  };
31
-
32
-  useImperativeHandle(ref, () => ({
33
-    toggle: () => {
34
-      setVisible(!visible);
35
-    },
36
-  }));
37
-
38
-  useEffect(() => {
39
-    setContent(record?.content);
40
-    setSortVale(record?.sort);
41
-  }, [record, visible]);
42
-
43
-  return (
44
-    <>
45
-      <Button onClick={() => setVisible(true)} {...btnProps}>
46
-        {props.children}
47
-      </Button>
48
-      {contentType === 'text' && (
49
-        <ModalText
50
-          sortVale={sortVale}
51
-          visible={visible}
52
-          value={content}
53
-          onChange={handleChange}
54
-          onCancel={handleClose}
55
-        />
56
-      )}
57
-      {contentType === 'image' && (
58
-        <ModalImage
59
-          sortVale={sortVale}
60
-          visible={visible}
61
-          value={content}
62
-          onChange={handleChange}
63
-          onCancel={handleClose}
64
-        />
65
-      )}
66
-    </>
67
-  );
68
-});

+ 0
- 42
src/components/ExtendContent/ModalText.jsx Ver arquivo

@@ -1,42 +0,0 @@
1
-import { Input, Modal, Form, Button } from 'antd'
2
-import { useEffect, useState } from 'react'
3
-
4
-
5
-const FormItem = Form.Item
6
-export default (props) => {
7
-  const { value, visible, onChange, onCancel, sortVale } = props
8
-
9
-  const [text, setText] = useState()
10
-  const [sort, setSort] = useState()
11
-
12
-  const Submit = (e) => {
13
-    setSort(e.target.value)
14
-  }
15
-
16
-  const handleChange = (e) => {
17
-    setText(e.target.value || 0)
18
-  }
19
-
20
-  const handleOk = () => {
21
-    onChange(text, sort)
22
-  }
23
-
24
-  useEffect(() => {
25
-    setText(value)
26
-    setSort(sortVale)
27
-
28
-  }, [value, visible, sortVale])
29
-
30
-  return (
31
-    <Modal title="请输入文字" visible={visible} onOk={handleOk} onCancel={onCancel} destroyOnClose={true}>
32
-      <Form >
33
-        <FormItem label="内容" rules={[{ required: true, message: '请输入内容' }]} >
34
-          <Input.TextArea value={text} onChange={handleChange} />
35
-        </FormItem>
36
-        <FormItem label="权重" rules={[{ required: true, message: '请设置权重' }]}>
37
-          <Input min={0} placeholder="请输入权重" type='number' value={sort} onChange={Submit} style={{ width: '350px' }} />
38
-        </FormItem>
39
-      </Form>
40
-    </Modal>
41
-  )
42
-}

+ 0
- 38
src/components/ExtendContent/Modalimage.jsx Ver arquivo

@@ -1,38 +0,0 @@
1
-import { useEffect, useState } from 'react'
2
-import { UploadImage } from '@/components/Upload'
3
-import { Input, Modal, Form, Button } from 'antd'
4
-
5
-
6
-const FormItem = Form.Item
7
-export default (props) => {
8
-  const { value, visible, onChange, onCancel, sortVale } = props
9
-
10
-  const [image, setImage] = useState()
11
-  const [sort, setSort] = useState()
12
-
13
-  const Submit = (e) => {
14
-    setSort(e.target.value || 0)
15
-  }
16
-  const handleOk = () => {
17
-    onChange(image, sort)
18
-  }
19
-
20
-  useEffect(() => {
21
-    setImage(value)
22
-    setSort(sortVale)
23
-  }, [value, visible, sortVale])
24
-
25
-
26
-  return (
27
-    <Modal title="请上传图片" visible={visible} onOk={handleOk} onCancel={onCancel} destroyOnClose={true}>
28
-      <Form >
29
-        <FormItem label="内容" rules={[{ required: true, message: '请输入内容' }]} >
30
-          <UploadImage value={image} onChange={setImage} />
31
-        </FormItem>
32
-        <FormItem label="权重" rules={[{ required: true, message: '请设置权重' }]}>
33
-          <Input min={0} placeholder="请输入权重" type='number' value={sort} onChange={Submit} style={{ width: '350px' }} />
34
-        </FormItem>
35
-      </Form>
36
-    </Modal>
37
-  )
38
-}

+ 0
- 104
src/components/ExtendContent/index.jsx Ver arquivo

@@ -1,104 +0,0 @@
1
-import { Button, message, Space } from 'antd';
2
-import { PlusOutlined } from '@ant-design/icons';
3
-import { useRef, useState } from 'react';
4
-import ModalButton from './ModalButton';
5
-import List from './List';
6
-import { save, update } from '@/services/extendContent';
7
-
8
-export default (props) => {
9
-  const { onCancel, targetId, targetType } = props;
10
-
11
-  const [record, setRecord] = useState();
12
-  const listRef = useRef();
13
-  const textBtnRef = useRef();
14
-  const imageBtnRef = useRef();
15
-  const videoBtnRef = useRef();
16
-
17
-  const handleChange = (row, next) => {
18
-    const data = {
19
-      ...(row || {}),
20
-      targetId,
21
-      targetType,
22
-    };
23
-
24
-    if (data.extId) {
25
-      // 编辑提交
26
-
27
-      update(data.extId, data).then(() => {
28
-        listRef.current.reload();
29
-        next();
30
-
31
-        message.success('更新数据成功');
32
-      }).catch((err) => {
33
-        console.log(err.message)
34
-      });
35
-    } else if (data.content) {
36
-      // 新增提交
37
-      listRef.current.setLoading(true);
38
-      save(data).then((res) => {
39
-        listRef.current.reload();
40
-        next();
41
-
42
-        message.success('保存数据成功');
43
-      }).catch((err) => {
44
-        console.log(err.message)
45
-      });
46
-    } else {
47
-      next();
48
-    }
49
-  };
50
-
51
-  const handleEdit = (row) => {
52
-    setRecord(row);
53
-    switch (row.contentType) {
54
-      case 'text':
55
-        textBtnRef.current.toggle();
56
-        break;
57
-      case 'image':
58
-        imageBtnRef.current.toggle();
59
-        break;
60
-      case 'video':
61
-        videoBtnRef.current.toggle();
62
-        break;
63
-      default:
64
-        break;
65
-    }
66
-  };
67
-
68
-  const handleClose = () => {
69
-    setRecord();
70
-  };
71
-
72
-  return (
73
-    <div>
74
-      <Space size="large" style={{ marginBottom: '18px' }}>
75
-        <ModalButton
76
-          ref={textBtnRef}
77
-          type="dashed"
78
-          icon={<PlusOutlined />}
79
-          record={record}
80
-          contentType="text"
81
-          onChange={handleChange}
82
-          onClose={handleClose}
83
-        >
84
-          文字
85
-        </ModalButton>
86
-        <ModalButton
87
-          ref={imageBtnRef}
88
-          type="dashed"
89
-          icon={<PlusOutlined />}
90
-          record={record}
91
-          contentType="image"
92
-          onChange={handleChange}
93
-          onClose={handleClose}
94
-        >
95
-          图片
96
-        </ModalButton>
97
-      </Space>
98
-      <List ref={listRef} targetType={targetType} onEdit={handleEdit} targetId={targetId} />
99
-      {/* <Button onClick={onCancel} style={{ marginTop: '2em', float: 'right' }}>
100
-        返回
101
-      </Button> */}
102
-    </div>
103
-  );
104
-};

+ 21
- 17
src/components/rich-editor/index.jsx Ver arquivo

@@ -1,8 +1,7 @@
1
-import React, { useRef, useEffect, useMemo } from 'react'
1
+import React, { forwardRef, useRef, useEffect, useMemo, useImperativeHandle } from 'react'
2 2
 
3
-export default (props) => {
3
+export default forwardRef((props, ref) => {
4 4
   const editorRef = useRef()
5
-  const initedRef = useRef(false)
6 5
   const id = useMemo(() => `mce-${Math.random().toString(36).substring(2, 10)}`, [])
7 6
 
8 7
   useEffect(() => {
@@ -10,30 +9,35 @@ export default (props) => {
10 9
       selector: `#${id}`,
11 10
       menubar: false,
12 11
       setup: (editor) => {
13
-        editorRef.current = editor;
14
-        if (props.value) {
15
-          initedRef.current = true
16
-          editor.setContent(props.value)
17
-        }
18
-
19
-        editor.on('input', () => {
12
+        editor.on('change', () => {
20 13
           props.onChange(editor.getContent());
14
+          console.log(editor.getContent())
21 15
         })
16
+      },
17
+      init_instance_callback: (editor) => {
18
+        editorRef.current = editor;
22 19
       }
23 20
     });
24 21
   // eslint-disable-next-line react-hooks/exhaustive-deps
25 22
   }, [id])
26 23
 
27
-  useEffect(() => {
28
-    if (editorRef.current && !initedRef.current) {
29
-      if (props.inited) {
30
-        initedRef.current = true
31
-        editorRef.current.setContent(props.value)
24
+  useImperativeHandle(ref, () => ({
25
+    setContent: (val) => {
26
+      if (editorRef.current) {
27
+        editorRef.current.setContent(val)
28
+      } else {
29
+        const t = setInterval(() => {
30
+          if (editorRef.current) {
31
+            editorRef.current.setContent(val)
32
+            clearInterval(t)
33
+            console.log('-clearInterval-')
34
+          }
35
+        }, 200)
32 36
       }
33 37
     }
34
-  }, [props.value, props.inited])
38
+  }))
35 39
 
36 40
   return (
37 41
     <textarea id={id} />
38 42
   )
39
-}
43
+})

+ 3
- 3
src/pages/applicationList/index.jsx Ver arquivo

@@ -4,7 +4,7 @@ import moment from 'moment';
4 4
 import { DatePicker, Button } from 'antd';
5 5
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
6 6
 import PageTable from '@/components/PageTable'
7
-import { getList } from '@/services/work'
7
+import { getApplicationList } from '@/services/application'
8 8
 
9 9
 const { RangePicker } = DatePicker;
10 10
 
@@ -79,7 +79,7 @@ export default (props) => {
79 79
       <PageTable
80 80
         actionRef={actionRef}
81 81
         columns={columns}
82
-        request={getList}
82
+        request={getApplicationList}
83 83
         options={false}
84 84
         search={{
85 85
           defaultCollapsed: false
@@ -88,7 +88,7 @@ export default (props) => {
88 88
         manualRequest={true}
89 89
         revalidateOnFocus={false}
90 90
         beforeSearchSubmit={handleBeforSearch}
91
-        rowKey="formId"
91
+        rowKey="applicationId"
92 92
       />
93 93
     </PageHeaderWrapper>
94 94
   )

+ 1
- 1
src/pages/dashboard/index.jsx Ver arquivo

@@ -9,6 +9,6 @@ export default (props) => {
9 9
   const [value, setValue] = useState()
10 10
 
11 11
   return (
12
-    <RichEditor value={value} onChange={setValue}/>
12
+    <RichEditor value={value} onChange={setValue} />
13 13
   )
14 14
 }

+ 26
- 17
src/pages/notice/edit.jsx Ver arquivo

@@ -1,9 +1,10 @@
1 1
 import { Input, Card, Select, Button, Form, InputNumber, message } from 'antd';
2
-import { useEffect, useState } from 'react';
2
+import { useEffect, useState, useRef } from 'react';
3 3
 import { history } from 'umi';
4 4
 import ProCard from '@ant-design/pro-card';
5
-import ExtendContent from '@/components/ExtendContent';
6
-import { addNews, updateNews, getNewsDetail } from '@/services/news';
5
+import { addNotice, updateNotice, getNoticeDetail } from '@/services/notice'
6
+import RichEditor from "@/components/rich-editor";
7
+
7 8
 
8 9
 const { Option } = Select;
9 10
 const goBack = () => {
@@ -15,6 +16,9 @@ export default (props) => {
15 16
   const { id } = location.query;
16 17
   const [form] = Form.useForm();
17 18
   const [loading, setLoading] = useState(false);
19
+  const [data, setData] = useState();
20
+
21
+  const editorRef = useRef()
18 22
 
19 23
   const formItemLayout = {
20 24
     //布局
@@ -22,10 +26,11 @@ export default (props) => {
22 26
     wrapperCol: { span: 14 },
23 27
   };
24 28
 
25
-  const Submit = (data) => {
29
+  const Submit = (value) => {
30
+    var myData = { ...data, ...value };
26 31
     setLoading(true);
27 32
     if (id) {
28
-      updateNews(id, data)
33
+      updateNotice(id, myData)
29 34
         .then(() => {
30 35
           setLoading(false);
31 36
           message.success('数据更新成功');
@@ -36,11 +41,11 @@ export default (props) => {
36 41
           message.error(err.message || err);
37 42
         });
38 43
     } else {
39
-      addNews(data)
44
+      addNotice(myData)
40 45
         .then((res) => {
41 46
           setLoading(false);
42 47
           message.success('数据保存成功');
43
-          history.replace(`./edit.jsx?id=${res.newsId}`);
48
+          history.replace(`./edit.jsx?id=${res.noticeId}`);
44 49
         })
45 50
         .catch((err) => {
46 51
           setLoading(false);
@@ -49,14 +54,17 @@ export default (props) => {
49 54
     }
50 55
   };
51 56
   useEffect(() => {
52
-    if (id) {
53
-      getNewsDetail(id).then((res) => {
57
+    if (id && form) {
58
+      getNoticeDetail(id).then((res) => {
54 59
         form.setFieldsValue(res);
60
+        setData(res);
61
+        editorRef.current.setContent(res.content);
55 62
       }).catch((err) => {
56 63
         console.log(err.message)
57 64
       });
58 65
     }
59
-  }, [id]);
66
+  }, [id, form]);
67
+
60 68
   return (
61 69
     <Card>
62 70
       <ProCard tabs={{ type: 'card' }} style={{ marginTop: '16px' }}>
@@ -64,7 +72,10 @@ export default (props) => {
64 72
           <Form {...formItemLayout} onFinish={Submit} form={form}>
65 73
             <FormItem label="标题" name="title" rules={[{ required: true, message: '请输入' }]}>
66 74
               <Input placeholder="请输入" style={{ width: '350px' }} />
67
-            </FormItem>           
75
+            </FormItem>
76
+            <FormItem label="正文" name='content' rules={[{ required: true, message: '请输入' }]}>
77
+              <RichEditor ref={editorRef} />
78
+            </FormItem>
68 79
             <FormItem label="权重" name="weight" rules={[{ required: true, message: '请输入' }]}>
69 80
               <InputNumber min={0} placeholder="请输入权重" style={{ width: '350px' }} />
70 81
             </FormItem>
@@ -74,13 +85,11 @@ export default (props) => {
74 85
                 <Option value={0}>未发布</Option>
75 86
               </Select>
76 87
             </FormItem>
77
-            {id && (
78
-              <FormItem label="详情" colon={false}>
79
-                <ExtendContent targetType="news" targetId={id} onCancel={() => history.goBack()} />
80
-              </FormItem>
81
-            )}
82 88
             <FormItem label=" " colon={false}>
83
-              <Button type="default" onClick={() => goBack()}>
89
+              <Button
90
+                type="default"
91
+                onClick={() => goBack()}
92
+              >
84 93
                 返回
85 94
               </Button>
86 95
               <Button

+ 3
- 3
src/pages/notice/index.jsx Ver arquivo

@@ -91,13 +91,13 @@ export default (props) => {
91 91
         <Button style={{ padding: 0 }} type="link" key={1} onClick={() => handleOK(record)}>
92 92
           {record.status === 0 ? '发布' : '取消发布'}
93 93
         </Button>,
94
-        <Button style={{ padding: 0 }} type="link" key={2} onClick={() => gotoEdit(record.newsId)}>
94
+        <Button style={{ padding: 0 }} type="link" key={2} onClick={() => gotoEdit(record.noticeId)}>
95 95
           编辑
96 96
         </Button>,
97 97
         <Popconfirm
98 98
           key={3}
99 99
           title="您是否确认删除 ?"
100
-          onConfirm={() => handleDelete(record.newsId)}
100
+          onConfirm={() => handleDelete(record.noticeId)}
101 101
           okText="确定"
102 102
           cancelText="取消"
103 103
         >
@@ -116,7 +116,7 @@ export default (props) => {
116 116
         toolBarRender={actions}
117 117
         actionRef={actionRef}
118 118
         columns={columns}
119
-        rowKey="newsId"
119
+        rowKey="noticeId"
120 120
         options={false}
121 121
         scroll={{ x: 1000 }}
122 122
       />

+ 29
- 0
src/services/application.js Ver arquivo

@@ -0,0 +1,29 @@
1
+import request from '@/utils/request';
2
+
3
+/**
4
+ * 审批
5
+ * @param {*} data
6
+ * @returns
7
+ */
8
+export const updateAudit = (id, data) => request(`/application/${id}/audit`, { method: 'put', data });
9
+
10
+/**
11
+ * 发证
12
+ * @param {*} data
13
+ * @returns
14
+ */
15
+export const updateMake = (id, data) => request(`/application/${id}/make`, { method: 'put', data });
16
+
17
+/**
18
+ * 查询申请列表
19
+ * @param {*} params
20
+ * @returns
21
+ */
22
+export const getApplicationList = (params) => request('/application', { params });
23
+
24
+/**
25
+ * 查询申请详情
26
+ * @param {*} params
27
+ * @returns
28
+ */
29
+export const getApplicationDetail = (id) => request(`/application/${id}`);

+ 0
- 36
src/services/extendContent.js Ver arquivo

@@ -1,36 +0,0 @@
1
-import request from '@/utils/request';
2
-
3
-/**
4
- * 保存扩展内容
5
- * @param {*} data
6
- * @returns
7
- */
8
-export const save = (data) => request('/extend-content', { method: 'post', data });
9
-
10
-/**
11
- * 修改扩展内容
12
- * @param {*} data
13
- * @returns
14
- */
15
-export const update = (id, data) => request(`/extend-content/${id}`, { method: 'put', data });
16
-
17
-/**
18
- * 查询扩展内容列表
19
- * @param {*} params
20
- * @returns
21
- */
22
-export const getList = (params) => request('/extend-content', { params });
23
-
24
-/**
25
- * 删除扩展内容
26
- * @param {*} data
27
- * @returns
28
- */
29
-export const remove = (id) => request(`/extend-content/${id}`, { method: 'delete' });
30
-
31
-/**
32
- * 查询扩展内容详情
33
- * @param {*} params
34
- * @returns
35
- */
36
-export const getDetail = (id) => request(`/extend-content/${id}`);

+ 0
- 36
src/services/news.js Ver arquivo

@@ -1,36 +0,0 @@
1
-import request from '@/utils/request';
2
-
3
-/**
4
- * 保存资讯
5
- * @param {*} data
6
- * @returns
7
- */
8
-export const addNews = (data) => request('/news', { method: 'post', data });
9
-
10
-/**
11
- * 修改资讯
12
- * @param {*} data
13
- * @returns
14
- */
15
-export const updateNews = (id, data) => request(`/news/${id}`, { method: 'put', data });
16
-
17
-/**
18
- * 查询资讯列表
19
- * @param {*} params
20
- * @returns
21
- */
22
-export const getNewsList = (params) => request('/news', { params });
23
-
24
-/**
25
- * 删除资讯
26
- * @param {*} data
27
- * @returns
28
- */
29
-export const deleteNews = (id) => request(`/news/${id}`, { method: 'delete' });
30
-
31
-/**
32
- * 查询资讯详情
33
- * @param {*} params
34
- * @returns
35
- */
36
-export const getNewsDetail = (id) => request(`/news/${id}`);