|
@@ -1,18 +1,18 @@
|
|
|
-import React, { useState, useEffect, useLayoutEffect } from 'react';
|
|
|
-import { Modal, Row, Col, Space, Form, Input, Select, message, Upload, Button } from 'antd';
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
|
+import { Modal, Form, Input, Select, message, Upload } from 'antd';
|
|
|
|
|
|
-import { ScissorOutlined } from '@ant-design/icons';
|
|
|
+// import { ScissorOutlined } from '@ant-design/icons';
|
|
|
|
|
|
-import { getAgent } from '@/services/agent';
|
|
|
+// import { getAgent } from '@/services/agent';
|
|
|
|
|
|
import { postOrPutNotice } from '@/services/notice';
|
|
|
|
|
|
-import { uploadFile } from '@/services/user';
|
|
|
+// import { uploadFile } from '@/services/user';
|
|
|
|
|
|
// import ReactWEditor from 'wangeditor-for-react';
|
|
|
|
|
|
// 引入编辑器组件
|
|
|
-import BraftEditor, { ControlType, ExtendControlType, ImageControlType } from 'braft-editor';
|
|
|
+import BraftEditor, { ExtendControlType, ImageControlType } from 'braft-editor';
|
|
|
// 引入编辑器样式
|
|
|
import 'braft-editor/dist/index.css';
|
|
|
|
|
@@ -24,10 +24,10 @@ import type { noticeModalProps } from './data';
|
|
|
|
|
|
import type { Dispatch } from 'umi';
|
|
|
|
|
|
-import { useIntl } from 'react-intl';
|
|
|
-
|
|
|
import { Role } from '@/models/user';
|
|
|
|
|
|
+import PicturesWall from '@/components/upload';
|
|
|
+
|
|
|
const layout = {
|
|
|
labelCol: { span: 5 },
|
|
|
wrapperCol: { span: 16 },
|
|
@@ -230,6 +230,8 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
|
|
|
|
|
|
const [label, setLabel] = useState('');
|
|
|
|
|
|
+ const [imgUrl, setImgUrl] = useState('');
|
|
|
+
|
|
|
const [content, setContent] = useState('');
|
|
|
|
|
|
// editContent 反填
|
|
@@ -251,11 +253,11 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
|
|
|
|
|
|
// 新增或者编辑公告
|
|
|
const PostOrPutNotice = async (record: any): Promise<void> => {
|
|
|
- const { code, data } = await postOrPutNotice({ ...record });
|
|
|
- if (code === 0 && data) {
|
|
|
+ const { code } = await postOrPutNotice({ ...record });
|
|
|
+ if (code === 0) {
|
|
|
message.success(type === 1 ? '编辑成功' : '新增成功');
|
|
|
} else {
|
|
|
- message.success(type === 1 ? '编辑失败' : '新增失败');
|
|
|
+ message.error(type === 1 ? '编辑失败' : '新增失败');
|
|
|
}
|
|
|
closeModal();
|
|
|
GetNotice();
|
|
@@ -268,6 +270,7 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
|
|
|
form.setFieldsValue($par);
|
|
|
setEditForm($par);
|
|
|
setEditContent(curNoticeData.content);
|
|
|
+ setImgUrl(curNoticeData.imgUrl);
|
|
|
};
|
|
|
|
|
|
const onFinish = (values: any) => {
|
|
@@ -283,8 +286,9 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
|
|
|
$par = {
|
|
|
...editForm,
|
|
|
...values,
|
|
|
+ imgUrl,
|
|
|
userIds: ['ALL'],
|
|
|
- roles: values.roles,
|
|
|
+ roles: Array.isArray(values.roles) ? values.roles : [values.roles],
|
|
|
type: 'ANN',
|
|
|
methodType: type,
|
|
|
content,
|
|
@@ -292,19 +296,27 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
|
|
|
} else {
|
|
|
$par = {
|
|
|
...values,
|
|
|
+ imgUrl,
|
|
|
userIds: ['ALL'],
|
|
|
- roles: values.roles,
|
|
|
+ roles: Array.isArray(values.roles) ? values.roles : [values.roles],
|
|
|
type: 'ANN',
|
|
|
methodType: type,
|
|
|
content,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- console.log($par);
|
|
|
+ console.log($par, '参数');
|
|
|
|
|
|
PostOrPutNotice($par);
|
|
|
};
|
|
|
|
|
|
+ const changeImgUrl = (url: string) => {
|
|
|
+ setImgUrl(url);
|
|
|
+ form.setFieldsValue({
|
|
|
+ imgUrl: url,
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
// 提交表单
|
|
|
const onsubmit = () => form.submit();
|
|
|
|
|
@@ -323,12 +335,26 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
|
|
|
onCancel={closeModal}
|
|
|
>
|
|
|
<Form {...layout} form={form} onFinish={onFinish}>
|
|
|
+ <Form.Item
|
|
|
+ name="imgUrl"
|
|
|
+ label="封面图"
|
|
|
+ rules={[{ required: true, message: '请上传封面图' }]}
|
|
|
+ >
|
|
|
+ <PicturesWall
|
|
|
+ key={imgUrl}
|
|
|
+ imgUrl={imgUrl}
|
|
|
+ setCoverFn={changeImgUrl}
|
|
|
+ maxCount={1}
|
|
|
+ desc="上传封面图"
|
|
|
+ />
|
|
|
+ <div>建议上传尺寸:398 * 530</div>
|
|
|
+ </Form.Item>
|
|
|
<Form.Item
|
|
|
name="roles"
|
|
|
label="可看人员:"
|
|
|
rules={[{ required: true, message: '请选择可看人员' }]}
|
|
|
>
|
|
|
- <Select style={{ width: '375px' }} mode="multiple">
|
|
|
+ <Select style={{ width: '375px' }}>
|
|
|
{roleList.length &&
|
|
|
roleList.map((item: Record<string, any>) => (
|
|
|
<Select.Option key={item.id} value={item.id}>
|