This commit is contained in:
2021-06-29 16:19:19 +08:00
15 changed files with 567 additions and 32 deletions

View File

@@ -35,6 +35,7 @@
@import './lib/tree-layout.less';
@import './lib/authority-view.less';
@import './lib/icon-selector.less';
@import './lib/color-selector.less';
@import './lib/anchor.less';
@import './lib/disabled.less';
@import './theme/primary.less';

View File

@@ -9,7 +9,12 @@
width: 150px;
}
.ant-descriptions {
clear: both;
margin-bottom: @padding-sm;
.ant-descriptions-view {
overflow: visible;
}
&:last-child {
margin-bottom: 0;
}
@@ -26,4 +31,23 @@
}
}
}
.ant-card-grid {
width: 25%;
margin-bottom: @padding-sm;
padding: @padding-xs;
cursor: pointer;
}
.ant-card {
margin-bottom: 0;
background-color: transparent;
&-body {
margin: -1px 0 0 -1px;
padding: 0;
}
.ant-card-grid {
margin-bottom: 0;
}
}
}

View File

@@ -0,0 +1,18 @@
@import (reference) '../extend.less';
.ant-select-dropdown {
.chrome-picker {
width: auto !important;
margin: -@padding-xxs 0;
border-radius: 0 !important;
background: transparent !important;
box-shadow: none !important;
}
}
.color-selector--palette {
width: 32px;
height: 32px;
border-radius: @border-radius-base;
box-shadow: inset 0 0 0 @border-width-base @border-color-base, inset 0 0 0 3px @white;
}

View File

@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { Checkbox, Descriptions, Empty, Spin, Tooltip } from 'antd'
import { Card, Checkbox, Descriptions, Empty, Popover, Spin, Tooltip } from 'antd'
import { AntIcon } from 'components'
import { EMPTY_ID } from 'util/global'
@@ -58,7 +58,7 @@ function renderDescriptions(data) {
function renderItem(data) {
return (
<Descriptions bordered column={1}>
<Descriptions bordered column={1} contentStyle={{ padding: 0 }}>
<Descriptions.Item
label={
<Checkbox
@@ -71,7 +71,7 @@ function renderItem(data) {
</Checkbox>
}
>
{renderDescriptions.call(this, data.children)}
<Card bordered={false}>{renderDescriptions.call(this, data.children)}</Card>
</Descriptions.Item>
</Descriptions>
)
@@ -79,16 +79,26 @@ function renderItem(data) {
function renderCheckbox(data) {
return (
<div className="yo-authority-view--checkbox">
<Checkbox value={data.id} checked={data.checked} onChange={e => this.onChange(e, data)}>
{data.title}
</Checkbox>
{data.visibleParent && data.type == 2 && (
<Tooltip placement="top" title="选中此项才会显示菜单">
<AntIcon type="eye" style={{ color: '#1890ff' }} className="mr-xxs" />
</Tooltip>
)}
</div>
<label className="ant-card-grid ant-card-grid-hoverable">
<Popover
placement="topLeft"
content={data.remark || <span className="text-normal">没有说明</span>}
>
<Checkbox
value={data.id}
checked={data.checked}
onChange={e => this.onChange(e, data)}
>
{data.title}
</Checkbox>
{data.visibleParent && data.type == 2 && (
<Tooltip placement="bottom" title="选中此项才会显示菜单">
<AntIcon type="eye" style={{ color: '#1890ff' }} className="mr-xxs" />
</Tooltip>
)}
<div className="text-gray">{data.permission}</div>
</Popover>
</label>
)
}

View File

@@ -0,0 +1,55 @@
import React, { Component } from 'react'
import { Col, Row, Select } from 'antd'
import { ChromePicker } from 'react-color'
export default class index extends Component {
select = React.createRef()
state = {
color: null,
}
onChange(color) {
this.setState({ color: color.hex })
}
onChangeComplete(color) {
this.props.onChange && this.props.onChange(color.hex)
}
render() {
const { color } = this.state
const { value } = this.props
return (
<Row gutter={8}>
<Col flex="1">
<Select
ref={this.select}
dropdownRender={() => (
<ChromePicker
color={color || value || '#000'}
disableAlpha
onChange={color => this.onChange(color)}
onChangeComplete={color => this.onChangeComplete(color)}
/>
)}
showArrow={false}
{...this.props}
value={value}
/>
</Col>
<Col flex="32px">
<div
className="color-selector--palette"
style={{ backgroundColor: color || value || '#000' }}
onClick={() => {
this.select.current.focus()
}}
></div>
</Col>
</Row>
)
}
}

View File

@@ -1,6 +1,7 @@
export { default as AntIcon } from 'components/ant-icon'
export { default as AuthorityView } from './authority-view'
export { default as Auth } from './authorized'
export { default as ColorSelector } from './color-selector'
export { default as ComponentDynamic } from './component-dynamic'
export { default as Container } from './container'
export { default as IconSelector } from './icon-selector'

View File

@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { Form, Button, Table, Tooltip } from 'antd'
import { Form, Button, Table, Tooltip, Drawer } from 'antd'
import { AntIcon } from 'components'
import { isEqual } from 'lodash'
@@ -34,15 +34,15 @@ const rowNoColumn = {
* @returns
*/
function renderQueryBar() {
const { query, moreQuery, onQueryChange } = this.props
const { query, moreQuery, onQueryChange, queryInitialValues } = this.props
return (
<div className="yo-query-bar">
<Form
layout="inline"
ref={this.form}
ref={this.queryForm}
onFinish={value => this.onQuery(value)}
initialValues={this.props.queryInitialValues}
initialValues={queryInitialValues}
onValuesChange={(changedValues, allValues) =>
onQueryChange && onQueryChange(changedValues, allValues)
}
@@ -55,18 +55,62 @@ function renderQueryBar() {
</Button>
<Tooltip placement="bottom" title="重置查询">
<Button
onClick={() => this.onResetQuery()}
onClick={() => this.onResetQuery(this.queryForm)}
icon={<AntIcon type="undo" />}
/>
</Tooltip>
</Button.Group>
{moreQuery && <Button>更多查询条件</Button>}
{moreQuery && (
<Button type="text" onClick={() => this.onOpenMoreQuery()}>
更多查询条件
</Button>
)}
</Form.Item>
</Form>
</div>
)
}
function renderMoreQueryBody() {
const { moreQueryVisible } = this.state
const { moreQuery } = this.props
return (
<Drawer
width="33%"
title="查询"
className="yo-drawer-form"
visible={moreQueryVisible}
onClose={() => this.setState({ moreQueryVisible: false })}
>
<Form ref={this.moreQueryForm}>
<div className="yo-drawer-form--body">{moreQuery}</div>
<div className="ant-drawer-footer">
<Button.Group>
<Button
htmlType="submit"
type="primary"
icon={<AntIcon type="search" />}
onClick={() =>
this.onQuery(this.moreQueryForm.current.getFieldsValue())
}
>
查询
</Button>
<Tooltip placement="top" title="重置查询">
<Button
onClick={() => this.onResetQuery(this.moreQueryForm)}
icon={<AntIcon type="undo" />}
/>
</Tooltip>
</Button.Group>
</div>
</Form>
</Drawer>
)
}
function renderTable(props, on) {
return <Table className="yo-table" {...props} {...on} />
}
@@ -79,10 +123,14 @@ export default class QueryTable extends Component {
type: 'tree',
// 数据
dataSource: [],
moreQueryVisible: false,
}
// 查询表单实例
form = React.createRef()
queryForm = React.createRef()
// 更多查询表单实例
moreQueryForm = React.createRef()
// 查询值
query = {}
@@ -213,7 +261,13 @@ export default class QueryTable extends Component {
* @param {*} values
*/
onQuery = values => {
this.query = values
const { queryInitialValues } = this.props
this.query = {
...queryInitialValues,
...this.query,
...values,
}
this.onReloadData(true)
}
@@ -221,15 +275,23 @@ export default class QueryTable extends Component {
* 重置查询
* 初始化表单字段值,加载数据,并返回到第一页
*/
onResetQuery = () => {
const { queryInitialValues, onQueryChange } = this.props
onResetQuery = from => {
const { queryInitialValues, onQueryChange, query, moreQuery } = this.props
let queryValues = {}
if (from === this.queryForm) {
from.current.resetFields()
queryValues = moreQuery ? this.moreQueryForm.current.getFieldsValue() : {}
} else if (from === this.moreQueryForm) {
from.current.resetFields()
queryValues = query ? this.queryForm.current.getFieldsValue() : {}
}
this.form.current.resetFields()
this.query = {
...queryInitialValues,
...queryValues,
}
const values = this.form.current.getFieldsValue()
onQueryChange && onQueryChange(values, values)
onQueryChange && onQueryChange(this.query)
this.onReloadData(true)
}
@@ -277,12 +339,16 @@ export default class QueryTable extends Component {
return false
}
onOpenMoreQuery = () => {
this.setState({ moreQueryVisible: true })
}
render() {
const { rowNumber } = this
const { loading, dataSource, type } = this.state
const { query, operator, columns, expandable, expandedRowRender } = this.props
const { query, moreQuery, operator, columns, expandable, expandedRowRender } = this.props
const attrs = {}
Object.keys(this.props).forEach(key => {
@@ -337,6 +403,7 @@ export default class QueryTable extends Component {
) : (
renderTable.call(this, props, on)
)}
{moreQuery && renderMoreQueryBody.call(this)}
</section>
)
}

View File

@@ -0,0 +1,267 @@
import React, { Component } from 'react'
import { Button, Card, Form, Input, message as Message, Popconfirm, Radio, Select, Tag } from 'antd'
import { AntIcon, Auth, Container, QueryTable } 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'
/**
* 注释段[\/**\/]为必须要改
*/
/**
* 配置页面所需接口函数
*/
const apiAction = {
page: api.houseTaskPage,
}
/**
* 用于弹窗标题
* [必要]
*/
const name = '/**/'
/**
* 统一配置权限标识
* [必要]
*/
const authName = 'houseTask'
export default class index extends Component {
state = {
codes: {
houseType: [],
houseIndustry: [],
},
type: '',
}
// 表格实例
table = React.createRef()
// 新增窗口实例
addForm = React.createRef()
// 编辑窗口实例
editForm = React.createRef()
columns = [
{
title: '房屋编码',
dataIndex: 'houseCode',
sorter: true,
width: 300,
render: (text, record) => (
<>
{`${record.areaName}-${record.roadName}-${record.commName}-${
record.note
}-${record.no.toString().padStart(3, '0')}`}
<br />
<Tag color="purple">{text}</Tag>
</>
),
},
{
title: '房屋性质及行业',
dataIndex: 'type',
sorter: true,
width: 150,
render: text => this.bindCodeValue(text, 'house_type'),
},
{
title: '地址',
dataIndex: 'address',
sorter: true,
},
{
title: '任务截止时间',
dataIndex: 'endTime',
sorter: true,
width: 150,
},
]
/**
* 构造函数,在渲染前动态添加操作字段等
* @param {*} props
*/
constructor(props) {
super(props)
const flag = auth({ [authName]: [['edit'], ['delete']] })
}
/**
* 阻止外部组件引发的渲染,提升性能
* 可自行添加渲染条件
* [必要]
* @param {*} props
* @param {*} state
* @returns
*/
shouldComponentUpdate(props, state) {
return !isEqual(this.state, state)
}
/**
* 加载字典数据,之后开始加载表格数据
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
*/
componentDidMount() {
const { onLoading, onLoadData } = this.table.current
onLoading()
getDictData('house_type', 'house_industry').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, type } = 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="type">
<Radio.Group buttonStyle="solid">
<Radio.Button value="">全部</Radio.Button>
{codes.houseType.map(item => (
<Radio.Button key={item.code} value={item.code}>
{item.value}
</Radio.Button>
))}
</Radio.Group>
</Form.Item>
{type == 2 && (
<Form.Item label="行业" name="industry">
<Select
allowClear
className="w-150"
placeholder="请选择行业"
>
{codes.houseIndustry.map(item => (
<Select.Option key={item.code} value={item.code}>
{item.value}
</Select.Option>
))}
</Select>
</Form.Item>
)}
<Form.Item label="地址" name="address">
<Input autoComplete="off" placeholder="请输入地址" />
</Form.Item>
<Form.Item label="房屋唯一编码" name="houseCode">
<Input autoComplete="off" placeholder="请输入房屋唯一编码" />
</Form.Item>
</Auth>
}
moreQuery={
<Auth auth={{ [authName]: 'page' }}>
<Form.Item label="地址" name="addresstest">
<Input autoComplete="off" placeholder="请输入地址" />
</Form.Item>
</Auth>
}
operator={
<Auth auth={{ [authName]: 'add' }}>
<Button
icon={<AntIcon type="plus" />}
onClick={() => this.onOpen(this.addForm)}
>
新增{name}
</Button>
</Auth>
}
/>
</Card>
</Container>
)
}
}

View File

@@ -1,7 +1,6 @@
import React, { Component } from 'react'
import { Form, Input, InputNumber, Spin } from 'antd'
import { AntIcon, IconSelector } from 'components'
import { cloneDeep } from 'lodash'
import { AntIcon, ColorSelector, IconSelector } from 'components'
import { api } from 'common/api'
const initialValues = {
@@ -107,6 +106,9 @@ export default class form extends Component {
}
/>
</Form.Item>
<Form.Item label="颜色" name="color">
<ColorSelector placeholder="请选择颜色" />
</Form.Item>
<Form.Item label="排序" name="sort">
<InputNumber
max={1000}

View File

@@ -38,6 +38,33 @@ export default class index extends Component {
// 表格字段
columns = [
{
title: '图标',
dataIndex: 'icon',
width: 32,
render: (text, record) => (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '32px',
height: '32px',
borderRadius: '100%',
backgroundColor: record.color,
margin: '0 auto',
}}
>
<AntIcon
type={text}
style={{
fontSize: '20px',
color: '#fff',
}}
/>
</div>
),
},
{
title: '应用名称',
dataIndex: 'name',