Notice Module Update
This commit is contained in:
@@ -4,37 +4,44 @@ const urls = {
|
||||
*/
|
||||
sysNoticePage: ['/sysNotice/page', 'post'],
|
||||
|
||||
|
||||
/**
|
||||
* 添加系统通知公告
|
||||
*/
|
||||
sysNoticeAdd: ['/sysNotice/add', 'post'],
|
||||
|
||||
|
||||
/**
|
||||
* 编辑系统通知公告
|
||||
*/
|
||||
sysNoticeEdit: ['/sysNotice/edit', 'post'],
|
||||
|
||||
|
||||
/**
|
||||
* 删除系统通知公告
|
||||
*/
|
||||
sysNoticeDelete: ['/sysNotice/delete', 'post'],
|
||||
|
||||
|
||||
/**
|
||||
* 通知公告详情
|
||||
*/
|
||||
sysNoticeDetail: ['/sysNotice/detail', 'get'],
|
||||
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
*/
|
||||
sysNoticeChangeStatus: ['/sysNotice/changeStatus', 'post'],
|
||||
|
||||
/**
|
||||
* 获取Notice总数
|
||||
*/
|
||||
sysNoticeGetCount: ['/NoticeUser/getCount', 'get'],
|
||||
|
||||
/**
|
||||
* 获取Notice详细
|
||||
*/
|
||||
sysNoticeInfo: ['/NoticeUser/GetNoticeInfo', 'get'],
|
||||
/**
|
||||
* 获取Notice详细ByID
|
||||
*/
|
||||
sysNoticeShow: ['/sysNotice/detailById', 'get'],
|
||||
}
|
||||
|
||||
export default urls
|
||||
export default urls
|
||||
|
||||
56
web-react/src/components/form/braft-editor/index.jsx
Normal file
56
web-react/src/components/form/braft-editor/index.jsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Col, Input, InputNumber, Row } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import BraftEditor from 'braft-editor'
|
||||
import 'braft-editor/dist/index.css'
|
||||
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
editorState: BraftEditor.createEditorState(this.props.value), // 设置编辑器初始内容
|
||||
outputHTML: '<p></p>',
|
||||
}
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
// 3秒后更改编辑器内容
|
||||
setTimeout(this.setEditorContentAsync, 2000)
|
||||
}
|
||||
componentWillUnmount() {
|
||||
this.isLivinig = false
|
||||
}
|
||||
handleChange = editorState => {
|
||||
const outputHTML = editorState.toHTML()
|
||||
|
||||
const { onChange } = this.props
|
||||
|
||||
this.setState({
|
||||
editorState: editorState,
|
||||
outputHTML,
|
||||
})
|
||||
|
||||
onChange && onChange(outputHTML)
|
||||
}
|
||||
|
||||
setEditorContentAsync = () => {
|
||||
const { placeholder, value, onChange } = this.props
|
||||
this.isLivinig &&
|
||||
this.setState({
|
||||
editorState: BraftEditor.createEditorState(value),
|
||||
})
|
||||
}
|
||||
render() {
|
||||
const { editorState, outputHTML } = this.state
|
||||
|
||||
//localStorage.setItem('props', JSON.stringify(this.props))
|
||||
const controls = ['bold', 'italic', 'underline', 'text-color', 'separator', 'media']
|
||||
return (
|
||||
<BraftEditor
|
||||
value={editorState}
|
||||
controls={controls}
|
||||
onChange={this.handleChange}
|
||||
placeholder={'输入内容'}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,5 @@ export { default as PhotoPreview } from './photo-preview'
|
||||
export { default as QueryList } from './query-list'
|
||||
export { default as QueryTable } from './query-table'
|
||||
export { default as QueryTableActions } from './query-table-actions'
|
||||
export { default as QueryTreeLayout } from './query-tree-layout'
|
||||
export { default as QueryTreeLayout } from './query-tree-layout'
|
||||
export { default as BraftEditor } from './form/braft-editor'
|
||||
|
||||
146
web-react/src/pages/system/notice/form.jsx
Normal file
146
web-react/src/pages/system/notice/form.jsx
Normal file
@@ -0,0 +1,146 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Spin, Input, Radio, Select } from 'antd'
|
||||
import { api } from 'common/api'
|
||||
import { AntIcon, BraftEditor } from 'components'
|
||||
import getDictData from 'util/dic'
|
||||
import { cloneDeep } from 'lodash'
|
||||
// import BraftEditor from 'braft-editor'
|
||||
// import 'braft-editor/dist/index.css'
|
||||
const initialValues = {}
|
||||
|
||||
export default class form extends Component {
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
options: {
|
||||
userList: [],
|
||||
},
|
||||
codes: {
|
||||
noticeType: [],
|
||||
noticeStatus: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
this.isLivinig = true
|
||||
// 3秒后更改编辑器内容
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
//#region 从后端转换成前段所需格式,也可以在此处调用获取详细数据接口
|
||||
if (params.id) {
|
||||
this.record = (await api.sysNoticeDetail({ id: params.id })).data
|
||||
}
|
||||
const {
|
||||
data: { items: userList },
|
||||
} = await this.onLoadUser()
|
||||
const codes = await getDictData('notice_status', 'notice_type')
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false,
|
||||
options: {
|
||||
userList,
|
||||
},
|
||||
codes,
|
||||
})
|
||||
}
|
||||
async onLoadUser() {
|
||||
const data = await api.getUserPage()
|
||||
return data
|
||||
}
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
|
||||
const valid = await form.validateFields()
|
||||
if (valid) {
|
||||
const postData = form.getFieldsValue()
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
const { options, codes } = this.state
|
||||
|
||||
return (
|
||||
<Form initialValues={initialValues} ref={this.form} className="yo-form">
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item
|
||||
label="标题"
|
||||
name="title"
|
||||
rules={[{ required: true, message: '请输入标题', trigger: 'blur' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入标题" className="w-300" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="类型"
|
||||
name="type"
|
||||
rules={[{ required: true, message: '请选择类型' }]}
|
||||
>
|
||||
<Radio.Group buttonStyle="solid">
|
||||
{codes.noticeType.map(item => (
|
||||
<Radio.Button key={item.code} value={+item.code}>
|
||||
{item.value}
|
||||
</Radio.Button>
|
||||
))}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="内容"
|
||||
name="content"
|
||||
// rules={[{ required: true, message: '请输入内容' }]}
|
||||
>
|
||||
<BraftEditor />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="通知到的人" name="noticeUserIdList">
|
||||
<Select
|
||||
mode="tags"
|
||||
placeholder="请选择通知到的人"
|
||||
tokenSeparators={[',']}
|
||||
>
|
||||
{options.userList.map(item => (
|
||||
<Select.Option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
277
web-react/src/pages/system/notice/index.jsx
Normal file
277
web-react/src/pages/system/notice/index.jsx
Normal file
@@ -0,0 +1,277 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm, Select } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import { toCamelCase } from 'util/format'
|
||||
import FormBody from './form'
|
||||
|
||||
/**
|
||||
* 注释段[\/**\/]为必须要改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 配置页面所需接口函数
|
||||
*/
|
||||
const apiAction = {
|
||||
page: api.sysNoticePage,
|
||||
add: api.sysNoticeAdd,
|
||||
edit: api.sysNoticeEdit,
|
||||
delete: api.sysNoticeDelete,
|
||||
Detail: api.sysNoticeDetail,
|
||||
Status: api.sysNoticeChangeStatus,
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于弹窗标题
|
||||
* [必要]
|
||||
*/
|
||||
const name = '啥玩意'
|
||||
|
||||
/**
|
||||
* 统一配置权限标识
|
||||
* [必要]
|
||||
*/
|
||||
const authName = '/**/'
|
||||
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
codes: {
|
||||
noticeStatus: [],
|
||||
noticeType: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
// 新增窗口实例
|
||||
addForm = React.createRef()
|
||||
// 编辑窗口实例
|
||||
editForm = React.createRef()
|
||||
|
||||
columns = [
|
||||
{
|
||||
title: '标题',
|
||||
dataIndex: 'title',
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'type',
|
||||
render: text => this.bindCodeValue(text, 'notice_type'),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: text => this.bindCodeValue(text, 'notice_status'),
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const flag = auth({ [authName]: [['edit'], ['delete']] })
|
||||
|
||||
if (flag) {
|
||||
this.columns.push({
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth={{ [authName]: 'edit' }}>
|
||||
<a onClick={() => this.onOpen(this.editForm, record.id)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth={{ [authName]: 'delete' }}>
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record.id)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字典数据,之后开始加载表格数据
|
||||
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
|
||||
*/
|
||||
componentDidMount() {
|
||||
const { onLoading, onLoadData } = this.table.current
|
||||
onLoading()
|
||||
getDictData('notice_status', 'notice_type').then(codes => {
|
||||
this.setState({ codes }, () => {
|
||||
onLoadData()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
...query,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} id
|
||||
*/
|
||||
onOpen(modal, id) {
|
||||
modal.current.open({
|
||||
id,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
const { onLoading, onLoaded, onReloadData } = this.table.current
|
||||
onLoading()
|
||||
try {
|
||||
if (action) {
|
||||
await action
|
||||
}
|
||||
if (successMessage) {
|
||||
Message.success(successMessage)
|
||||
}
|
||||
onReloadData()
|
||||
} catch {
|
||||
onLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} id
|
||||
*/
|
||||
onDelete(id) {
|
||||
this.onAction(apiAction.delete({ id }), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
const { codes } = this.state
|
||||
return (
|
||||
<Container mode="fluid">
|
||||
<br />
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
ref={this.table}
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
query={
|
||||
<Auth auth={{ [authName]: 'page' }}>
|
||||
<Form.Item label="关键字" name="searchValue">
|
||||
<Input
|
||||
autoComplete="off"
|
||||
placeholder="请输入标题、内容"
|
||||
className="w-400"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="类型" name="type">
|
||||
<Select placeholder="请选择类型" className="w-400" allowClear>
|
||||
{codes.noticeType.map(item => (
|
||||
<Select.Option key={item.code} value={item.code}>
|
||||
{item.value}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
operator={
|
||||
<Auth auth={{ [authName]: 'add' }}>
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Auth auth={{ [authName]: 'add' }}>
|
||||
<ModalForm
|
||||
title={`新增${name}`}
|
||||
action={apiAction.add}
|
||||
ref={this.addForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
</Auth>
|
||||
|
||||
<Auth auth={{ [authName]: 'edit' }}>
|
||||
<ModalForm
|
||||
title={`编辑${name}`}
|
||||
action={apiAction.edit}
|
||||
ref={this.editForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
</Auth>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,23 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Layout, Badge } from 'antd'
|
||||
import React, { Component, useState } from 'react'
|
||||
import { Layout, Badge, Popover, Menu, Modal } from 'antd'
|
||||
import { AntIcon, Container } from 'components'
|
||||
import Logo from '../logo'
|
||||
import User from './user'
|
||||
import Search from './search'
|
||||
import store from 'store'
|
||||
import { api } from 'common/api'
|
||||
|
||||
const { getState, subscribe, dispatch } = store
|
||||
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
...getState('layout'),
|
||||
notice: {
|
||||
count: 0,
|
||||
data: [],
|
||||
},
|
||||
modalVisible: false,
|
||||
currentNotice: {},
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
@@ -21,6 +28,10 @@ export default class index extends Component {
|
||||
})
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadNotice()
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.unsubscribe()
|
||||
}
|
||||
@@ -32,9 +43,27 @@ export default class index extends Component {
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
const { allowSiderCollapsed } = this.state
|
||||
async loadNotice() {
|
||||
const { data } = await api.sysNoticeGetCount()
|
||||
const items = await api.sysNoticeInfo()
|
||||
this.setState({
|
||||
notice: {
|
||||
count: data,
|
||||
data: items.data,
|
||||
},
|
||||
})
|
||||
}
|
||||
async showDetail(params, visible) {
|
||||
this.setState({ currentNotice: params })
|
||||
|
||||
if (visible) {
|
||||
this.setState({ modalVisible: visible })
|
||||
} else {
|
||||
this.setState({ modalVisible: visible })
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const { allowSiderCollapsed, notice, currentNotice } = this.state
|
||||
return (
|
||||
<Layout.Header>
|
||||
<Container mode="fluid">
|
||||
@@ -57,11 +86,51 @@ export default class index extends Component {
|
||||
>
|
||||
<AntIcon type="reload" />
|
||||
</span>
|
||||
<span className="header-action">
|
||||
<Badge count="5">
|
||||
<AntIcon type="bell" />
|
||||
</Badge>
|
||||
</span>
|
||||
<Popover
|
||||
arrowPointAtCenter={true}
|
||||
overlayClassName="yo-user-popover"
|
||||
placement="bottomRight"
|
||||
content={
|
||||
<Menu selectable={false}>
|
||||
<Menu.Divider />
|
||||
{notice.data.map(item => (
|
||||
<Menu.Item
|
||||
onClick={() => this.showDetail(item, true)}
|
||||
key={item.id}
|
||||
>
|
||||
{item.title}
|
||||
</Menu.Item>
|
||||
))}
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<span className="header-action">
|
||||
<Badge count={notice.count}>
|
||||
<AntIcon type="bell" />
|
||||
</Badge>
|
||||
</span>
|
||||
|
||||
<Modal
|
||||
title={currentNotice.title}
|
||||
width={1000}
|
||||
style={{ top: 120 }}
|
||||
visible={this.state.modalVisible}
|
||||
onOk={() => this.showDetail(false)}
|
||||
onCancel={() => this.showDetail(false)}
|
||||
style={{ zIndex: 1000 }}
|
||||
>
|
||||
<div style={{ textAlign: 'center', fontSize: '30px' }}>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: currentNotice.content }}
|
||||
></div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right', fontSize: '10px' }}>
|
||||
<span>发布人:{currentNotice.createdUserName}</span>
|
||||
{' '}
|
||||
<span>发布时间:{currentNotice.createdTime} </span>
|
||||
</div>
|
||||
</Modal>
|
||||
</Popover>
|
||||
<User />
|
||||
</div>
|
||||
</Container>
|
||||
|
||||
Reference in New Issue
Block a user