This commit is contained in:
2021-06-23 18:06:30 +08:00
10 changed files with 272 additions and 202 deletions

View File

@@ -1456,5 +1456,20 @@
上报备注 上报备注
</summary> </summary>
</member> </member>
<member name="P:Ewide.Application.AddHouseZoneInput.Pid">
<summary>
所属街道
</summary>
</member>
<member name="P:Ewide.Application.AddHouseZoneInput.Name">
<summary>
名称
</summary>
</member>
<member name="P:Ewide.Application.UpdateHouseZoneInput.Id">
<summary>
机构Id
</summary>
</member>
</members> </members>
</doc> </doc>

View File

@@ -1,4 +1,5 @@
using System; using Ewide.Core.Service;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@@ -13,4 +14,28 @@ namespace Ewide.Application
[MinLength(9, ErrorMessage = "区域编码长度必须为9位及以上")] [MinLength(9, ErrorMessage = "区域编码长度必须为9位及以上")]
public string AreaCode { get; set; } public string AreaCode { get; set; }
} }
public class AddHouseZoneInput : OrgInput
{
/// <summary>
/// 所属街道
/// </summary>
[Required(ErrorMessage = "所属街道不能为空")]
public override string Pid { get; set; }
/// <summary>
/// 名称
/// </summary>
[Required(ErrorMessage = "片区名称不能为空")]
public override string Name { get; set; }
}
public class UpdateHouseZoneInput : AddHouseZoneInput
{
/// <summary>
/// 机构Id
/// </summary>
[Required(ErrorMessage = "片区Id不能为空")]
public string Id { get; set; }
}
} }

View File

@@ -2,9 +2,11 @@
using Ewide.Core.Extension; using Ewide.Core.Extension;
using Ewide.Core.Service; using Ewide.Core.Service;
using Furion.DatabaseAccessor; using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection; using Furion.DependencyInjection;
using Furion.DynamicApiController; using Furion.DynamicApiController;
using Furion.FriendlyException; using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
@@ -104,9 +106,9 @@ namespace Ewide.Application.Service
} }
[HttpGet("/houseZone/autoIncrement")] [HttpGet("/houseZone/autoIncrement")]
public async Task<dynamic> AutoIncrement([FromQuery] string code) public async Task<dynamic> AutoIncrement([FromQuery] string roadId)
{ {
var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.AreaCode == code); var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == roadId && p.Type == 3);
if (road == null) throw Oops.Oh("组织机构错误"); if (road == null) throw Oops.Oh("组织机构错误");
return await AutoIncrement(road); return await AutoIncrement(road);
} }
@@ -119,7 +121,7 @@ namespace Ewide.Application.Service
} }
[HttpPost("/houseZone/add")] [HttpPost("/houseZone/add")]
public async Task AddZone(AddOrgInput input) public async Task AddZone(AddHouseZoneInput input)
{ {
/* /*
* 区县市限定所属区域/上级机构是否为当前区 * 区县市限定所属区域/上级机构是否为当前区
@@ -136,15 +138,14 @@ namespace Ewide.Application.Service
var roles = await _userManager.GetUserRoleList(); var roles = await _userManager.GetUserRoleList();
if (roles.Any(p => p.Code == areaManager)) if (roles.Any(p => p.Code == areaManager))
{ {
var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.AreaCode == input.AreaCode); var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.Pid);
if (!road.Pids.Contains(org.Id)) throw Oops.Oh("组织机构错误"); if (!road.Pids.Contains(org.Id)) throw Oops.Oh("当前用户组织机构错误");
input.Pid = road.Id; input.AreaCode = road.AreaCode;
input.Code = road.Code + (await AutoIncrement(road)).ToString().PadLeft(3, '0'); input.Code = road.Code + (await AutoIncrement(road)).ToString().PadLeft(3, '0');
} }
else if (roles.Any(p => p.Code == roadManager)) else if (roles.Any(p => p.Code == roadManager))
{ {
input.Pid = org.Id;
input.AreaCode = org.AreaCode; input.AreaCode = org.AreaCode;
input.Code = org.Code + (await AutoIncrement(org)).ToString().PadLeft(3, '0'); input.Code = org.Code + (await AutoIncrement(org)).ToString().PadLeft(3, '0');
@@ -152,7 +153,17 @@ namespace Ewide.Application.Service
input.Type = (int)OrgType.; input.Type = (int)OrgType.;
await _sysOrgService.AddOrg(input); AddOrgInput addOrgInput = input.Adapt<AddOrgInput>();
await _sysOrgService.AddOrg(addOrgInput);
}
[HttpPost("/houseZone/edit")]
public async Task EditZone(UpdateHouseZoneInput input)
{
var zone = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(z => z.Id == input.Id);
if(zone == null) throw Oops.Oh("修改失败:数据有误,刷新列表后再尝试修改");
zone.Remark = input.Remark;
await zone.UpdateIncludeAsync(new[] { nameof(SysOrg.Remark) }, true);
} }
} }
} }

View File

@@ -10,7 +10,7 @@ namespace Ewide.Core.Service
/// <summary> /// <summary>
/// 父Id /// 父Id
/// </summary> /// </summary>
public string Pid { get; set; } public virtual string Pid { get; set; }
/// <summary> /// <summary>
/// 父Ids /// 父Ids

View File

@@ -7,7 +7,8 @@ const urls = {
houseZoneList: '/houseZone/list', houseZoneList: '/houseZone/list',
houseZoneAutoIncrement: '/houseZone/autoIncrement', houseZoneAutoIncrement: '/houseZone/autoIncrement',
houseZoneAdd: ['/houseZone/add', 'post'] houseZoneAdd: ['/houseZone/add', 'post'],
houseZoneEdit: ['/houseZone/edit', 'post']
} }
export default urls export default urls

View File

@@ -121,6 +121,7 @@ export default class form extends Component {
async loadAreaData() { async loadAreaData() {
const { data } = await api.getAreaTree() const { data } = await api.getAreaTree()
console.log(data)
const clearChiildren = data => { const clearChiildren = data => {
data.forEach(item => { data.forEach(item => {
if (item.children && item.children.length) { if (item.children && item.children.length) {

View File

@@ -47,22 +47,26 @@ export default class index extends Component {
{ {
title: '项目名称', title: '项目名称',
dataIndex: 'name', dataIndex: 'name',
width: 150,
sorter: true, sorter: true,
}, },
{ {
title: '社区', title: '社区',
dataIndex: 'areaName', dataIndex: 'areaName',
width: 100,
sorter: true, sorter: true,
}, },
{ {
title: '备注', title: '备注',
dataIndex: 'note', dataIndex: 'note',
width: 150,
sorter: true, sorter: true,
}, },
{ {
title: '类型', title: '类型',
dataIndex: 'type', dataIndex: 'type',
sorter: true, sorter: true,
width: 80,
render: text => <>{this.bindCodeValue(text, 'house_type')}</>, render: text => <>{this.bindCodeValue(text, 'house_type')}</>,
}, },
] ]
@@ -73,7 +77,7 @@ export default class index extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
const flag = auth({ sysArea: [['edit'], ['delete']] }) const flag = auth({ houseProjectInfo: [['edit'], ['delete']] })
if (flag) { if (flag) {
this.columns.push({ this.columns.push({

View File

@@ -1,24 +1,36 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Cascader, Form, Input, InputNumber, Select, Spin, TreeSelect } from 'antd' import { Form, Input, InputNumber, Spin, TreeSelect } from 'antd'
import { AntIcon } from 'components' import { AntIcon } from 'components'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import getDictData from 'util/dic'
import { api } from 'common/api' import { api } from 'common/api'
import { numberToChinese } from 'util/format'; import { numberToChinese } from 'util/format'
import store from 'store'
const { getState, subscribe } = store
const storePath = 'user'
const initialValues = { const initialValues = {
sort: 100 sort: 100,
} }
export default class form extends Component { export default class form extends Component {
state = { state = {
// 加载状态 // 加载状态
loading: true, loading: true,
exist: false,
options: { options: {
areaData: [] orgData: [],
} },
user: getState(storePath),
} }
constructor(props) {
super(props)
this.unsubscribe = subscribe(storePath, () => {
this.setState({
user: getState(storePath),
})
})
}
// 表单实例 // 表单实例
form = React.createRef() form = React.createRef()
@@ -31,67 +43,55 @@ export default class form extends Component {
componentDidMount() { componentDidMount() {
this.props.created && this.props.created(this) this.props.created && this.props.created(this)
} }
componentWillUnmount() {
this.unsubscribe()
}
/** /**
* 填充数据 * 填充数据
* 可以在设置this.record之后对其作出数据结构调整 * 可以在设置this.record之后对其作出数据结构调整
* [异步,必要] * [异步,必要]
* @param {*} params * @param {*} params
*/ */
async fillData(params) { async fillData(params) {
const { user } = this.state
this.record = cloneDeep(params.record) this.record = cloneDeep(params.record)
//#region 从后端转换成前段所需格式 //#region 从后端转换成前段所需格式
const areaData = await this.loadAreaData() const orgData = await this.loadOrgData()
this.setState({ this.setState({
options: { areaData } exist: !!params.record,
options: { orgData },
}) })
const areaCode = []; //街道角色新增,不管左侧树选中与否,默认值均为本街道
const findCode = (data, level) => { if (user.adminType === 2) {
level = level || 0; user.roles.map(role => {
for (let i = 0; i < data.length; i++) { if (role.code == 'road_manager') {
const item = data[i]; params.orgId = user.loginEmpInfo.orgId
areaCode[level] = item.code;
if (item.code === params.record.areaCode) {
areaCode.length = level + 1;
return true;
} }
})
if (item.children && item.children.length) {
const found = findCode(item.children, level + 1);
if (found) {
return true;
}
}
}
};
if (params.record && params.record.areaCode) {
findCode(areaData);
} }
this.record = { this.record = {
pid: params.orgId, pid: params.orgId,
...this.record, ...this.record,
areaCode
} }
this.record.areaCode = areaCode
//#endregion
//#endregion
if (!params.record && !!params.orgId) {
this.onOrgIdChanged(params.orgId)
}
this.form.current.setFieldsValue(this.record) this.form.current.setFieldsValue(this.record)
this.setState({ this.setState({
loading: false loading: false,
}) })
} }
/** /**
* 获取数据 * 获取数据
* 可以对postData进行数据结构调整 * 可以对postData进行数据结构调整
* [异步,必要] * [异步,必要]
* @returns * @returns
*/ */
async getData() { async getData() {
const form = this.form.current const form = this.form.current
@@ -102,74 +102,64 @@ export default class form extends Component {
if (this.record) { if (this.record) {
postData.id = this.record.id postData.id = this.record.id
} }
//#region 从前段转换后端所需格 //#region 从前段转换后端所需格
postData.areaCode = postData.areaCode[postData.areaCode.length - 1]
//#endregion //#endregion
return postData return postData
} }
} }
async loadAreaData() { async loadOrgData() {
const { data } = await api.getAreaTree({ level: 3 }) const { data } = await api.getOrgTree({ type: 4 })
const clearChiildren = (data) => {
data.forEach((item) => {
if (item.children && item.children.length) {
clearChiildren(item.children);
} else {
delete item.children;
}
});
};
clearChiildren(data);
return data return data
} }
onAreaCodeChange(value) { onOrgIdChanged(value) {
this.loading = true; this.loading = true
// const { data } = api.houseZoneAutoIncrement({ code: selectedOptions[selectedOptions.length - 1] });
api.houseZoneAutoIncrement({ code: value[value.length - 1] }) api.houseZoneAutoIncrement({ roadId: value })
.then(({ data }) => { .then(({ data }) => {
this.form.current.setFieldsValue({ this.form.current.setFieldsValue({
name: `片区${numberToChinese(data)}` name: `片区${numberToChinese(data)}`,
sort: data,
}) })
}) })
.catch(() => { .catch(() => {
this.form.current.setFieldsValue({ this.form.current.setFieldsValue({
name: '', name: '',
areaCode: [] sort: 0,
}) })
}) })
.finally(() => { .finally(() => {
this.loading = false; this.loading = false
}); })
} }
render() { render() {
return ( return (
<Form <Form initialValues={initialValues} ref={this.form} className="yo-form">
initialValues={initialValues}
ref={this.form}
className="yo-form"
>
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}> <Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
<div className="yo-form-group"> <div className="yo-form-group">
<Form.Item label="所属区域" name="areaCode" rules={[{ required: true, message: '请选择所属区域' }]}> <Form.Item
<Cascader label="所属街道"
options={this.state.options.areaData} name="pid"
fieldNames={{ rules={[{ required: true, message: '请选择所属街道' }]}
label: 'name', >
value: 'code', <TreeSelect
children: 'children' treeData={this.state.options.orgData}
}} dropdownStyle={{ maxHeight: '300px', overflow: 'auto' }}
expandTrigger="hover" treeDefaultExpandAll
// changeOnSelect placeholder="请选择所属街道"
placeholder="请选择所属区域" onChange={(value, label, extra) => this.onOrgIdChanged(value)}
onChange={(val, selectedOptions) => this.onAreaCodeChange(val)} disabled={this.state.exist}
/> />
</Form.Item> </Form.Item>
<Form.Item label="片区名称" name="name" rules={[{ required: true, message: '片区名称', trigger: 'blur' }]}>
<Input autoComplete="off" placeholder="请输入机构名称" /> <Form.Item
label="片区名称"
name="name"
rules={[{ required: true, message: '片区名称', trigger: 'blur' }]}
>
<Input autoComplete="off" placeholder="请输入机构名称" disabled />
</Form.Item> </Form.Item>
<Form.Item label="排序" name="sort"> <Form.Item label="排序" name="sort">
<InputNumber <InputNumber
@@ -177,6 +167,7 @@ export default class form extends Component {
min={0} min={0}
placeholder="请输入排序" placeholder="请输入排序"
className="w-100-p" className="w-100-p"
disabled
/> />
</Form.Item> </Form.Item>
<Form.Item label="备注" name="remark"> <Form.Item label="备注" name="remark">
@@ -187,4 +178,4 @@ export default class form extends Component {
</Form> </Form>
) )
} }
} }

View File

@@ -1,6 +1,14 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd' import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd'
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions, QueryTreeLayout } from 'components' import {
AntIcon,
Auth,
Container,
ModalForm,
QueryTable,
QueryTableActions,
QueryTreeLayout,
} from 'components'
import { api } from 'common/api' import { api } from 'common/api'
import auth from 'components/authorized/handler' import auth from 'components/authorized/handler'
import { toCamelCase } from 'util/format' import { toCamelCase } from 'util/format'
@@ -12,14 +20,13 @@ const apiAction = {
tree: api.getOrgTree, tree: api.getOrgTree,
page: api.houseZonePage, page: api.houseZonePage,
add: api.houseZoneAdd, add: api.houseZoneAdd,
edit: api.sysOrgEdit, edit: api.houseZoneEdit,
delete: api.sysOrgDelete delete: api.sysOrgDelete,
} }
const name = '片区' const name = '片区'
export default class index extends Component { export default class index extends Component {
// 树框架实例 // 树框架实例
treeLayout = React.createRef() treeLayout = React.createRef()
@@ -58,32 +65,34 @@ export default class index extends Component {
/** /**
* 构造函数,在渲染前动态添加操作字段等 * 构造函数,在渲染前动态添加操作字段等
* @param {*} props * @param {*} props
*/ */
constructor(props) { constructor(props) {
super(props) super(props)
const flag = auth({ sysOrg: [['edit'], ['delete']] }) const flag = auth({ houseZone: [['edit'], ['delete']] })
if (flag) { if (flag) {
this.columns.push({ this.columns.push({
title: '操作', title: '操作',
width: 150, width: 150,
dataIndex: 'actions', dataIndex: 'actions',
render: (text, record) => (<QueryTableActions> render: (text, record) => (
<Auth auth="sysOrg:edit"> <QueryTableActions>
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a> <Auth auth="houseZone:edit">
</Auth> <a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
<Auth auth="sysOrg:delete"> </Auth>
<Popconfirm <Auth auth="houseZone:delete">
placement="topRight" <Popconfirm
title="是否确认删除" placement="topRight"
onConfirm={() => this.onDelete(record)} title="是否确认删除"
> onConfirm={() => this.onDelete(record)}
<a>删除</a> >
</Popconfirm> <a>删除</a>
</Auth> </Popconfirm>
</QueryTableActions>) </Auth>
</QueryTableActions>
),
}) })
} }
} }
@@ -92,9 +101,9 @@ export default class index extends Component {
* 阻止外部组件引发的渲染,提升性能 * 阻止外部组件引发的渲染,提升性能
* 可自行添加渲染条件 * 可自行添加渲染条件
* [必要] * [必要]
* @param {*} props * @param {*} props
* @param {*} state * @param {*} state
* @returns * @returns
*/ */
shouldComponentUpdate(props, state) { shouldComponentUpdate(props, state) {
return !isEqual(this.state, state) return !isEqual(this.state, state)
@@ -111,14 +120,14 @@ export default class index extends Component {
/** /**
* 调用加载数据接口,可在调用前对query进行处理 * 调用加载数据接口,可在调用前对query进行处理
* [异步,必要] * [异步,必要]
* @param {*} params * @param {*} params
* @param {*} query * @param {*} query
* @returns * @returns
*/ */
loadData = async (params, query) => { loadData = async (params, query) => {
query = { query = {
...query, ...query,
pid: this.selectId pid: this.selectId,
} }
const { data } = await apiAction.page({ const { data } = await apiAction.page({
@@ -141,7 +150,7 @@ export default class index extends Component {
/** /**
* 树节点选中事件 * 树节点选中事件
* [必要] * [必要]
* @param {*} id * @param {*} id
*/ */
onSelectTree(id) { onSelectTree(id) {
this.selectId = id this.selectId = id
@@ -150,15 +159,15 @@ export default class index extends Component {
/** /**
* 绑定字典数据 * 绑定字典数据
* @param {*} code * @param {*} code
* @param {*} name * @param {*} name
* @returns * @returns
*/ */
bindCodeValue(code, name) { bindCodeValue(code, name) {
name = toCamelCase(name) name = toCamelCase(name)
const codes = this.state.codes[name] const codes = this.state.codes[name]
if (codes) { if (codes) {
const c = codes.find((p) => p.code === code) const c = codes.find(p => p.code === code)
if (c) { if (c) {
return c.value return c.value
} }
@@ -168,21 +177,21 @@ export default class index extends Component {
/** /**
* 打开新增/编辑弹窗 * 打开新增/编辑弹窗
* @param {*} modal * @param {*} modal
* @param {*} record * @param {*} record
*/ */
onOpen(modal, record) { onOpen(modal, record) {
modal.current.open({ modal.current.open({
orgId: this.selectId, orgId: this.selectId,
record record,
}) })
} }
/** /**
* 对表格上的操作进行统一处理 * 对表格上的操作进行统一处理
* [异步] * [异步]
* @param {*} action * @param {*} action
* @param {*} successMessage * @param {*} successMessage
*/ */
async onAction(action, successMessage) { async onAction(action, successMessage) {
this.table.current.onLoading() this.table.current.onLoading()
@@ -202,13 +211,10 @@ export default class index extends Component {
/** /**
* 删除 * 删除
* @param {*} record * @param {*} record
*/ */
onDelete(record) { onDelete(record) {
this.onAction( this.onAction(apiAction.delete(record), '删除成功')
apiAction.delete(record),
'删除成功'
)
} }
//#region 自定义方法 //#region 自定义方法
@@ -220,7 +226,7 @@ export default class index extends Component {
ref={this.treeLayout} ref={this.treeLayout}
loadData={this.loadTreeData} loadData={this.loadTreeData}
defaultExpanded={true} defaultExpanded={true}
onSelect={(key) => this.onSelectTree(key)} onSelect={key => this.onSelectTree(key)}
> >
<Container mode="fluid"> <Container mode="fluid">
<Card bordered={false}> <Card bordered={false}>
@@ -239,7 +245,9 @@ export default class index extends Component {
<Button <Button
icon={<AntIcon type="plus" />} icon={<AntIcon type="plus" />}
onClick={() => this.onOpen(this.addForm)} onClick={() => this.onOpen(this.addForm)}
>新增{name}</Button> >
新增{name}
</Button>
} }
/> />
</Card> </Card>

View File

@@ -1,6 +1,14 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd' import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd'
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions, QueryTreeLayout } from 'components' import {
AntIcon,
Auth,
Container,
ModalForm,
QueryTable,
QueryTableActions,
QueryTreeLayout,
} from 'components'
import { api } from 'common/api' import { api } from 'common/api'
import auth from 'components/authorized/handler' import auth from 'components/authorized/handler'
import { toCamelCase } from 'util/format' import { toCamelCase } from 'util/format'
@@ -13,17 +21,16 @@ const apiAction = {
page: api.sysAreaPage, page: api.sysAreaPage,
add: api.sysAreaAdd, add: api.sysAreaAdd,
edit: api.sysAreaEdit, edit: api.sysAreaEdit,
delete: api.sysAreaDelete delete: api.sysAreaDelete,
} }
const name = '区域' const name = '区域'
export default class index extends Component { export default class index extends Component {
state = { state = {
codes: { codes: {
dicAreacodeType: [] areacodeType: [],
} },
} }
// 表格实例 // 表格实例
@@ -41,37 +48,43 @@ export default class index extends Component {
title: '区域类型', title: '区域类型',
dataIndex: 'levelType', dataIndex: 'levelType',
sorter: true, sorter: true,
render: text => (<>{this.bindCodeValue(text, 'dic_areacode_type')}</>) width: 50,
render: text => <>{this.bindCodeValue(text, 'areacode_type')}</>,
}, },
{ {
title: '区域名称', title: '区域名称',
dataIndex: 'name', dataIndex: 'name',
width: 100,
sorter: true, sorter: true,
}, },
{ {
title: '区域编号', title: '区域编号',
dataIndex: 'code', dataIndex: 'code',
width: 80,
sorter: true, sorter: true,
}, },
{ {
title: '行政编号', title: '行政编号',
dataIndex: 'adCode', dataIndex: 'adCode',
width: 80,
sorter: true, sorter: true,
}, },
{ {
title: '描述', title: '描述',
dataIndex: 'note', dataIndex: 'note',
width: 200,
sorter: false, sorter: false,
}, },
{ {
title: '排序', title: '排序',
dataIndex: 'sort', dataIndex: 'sort',
width: 80,
sorter: true, sorter: true,
}, },
] ]
/** /**
* 构造函数,在渲染前动态添加操作字段等 * 构造函数,在渲染前动态添加操作字段等
* @param {*} props * @param {*} props
*/ */
constructor(props) { constructor(props) {
super(props) super(props)
@@ -83,20 +96,22 @@ export default class index extends Component {
title: '操作', title: '操作',
width: 150, width: 150,
dataIndex: 'actions', dataIndex: 'actions',
render: (text, record) => (<QueryTableActions> render: (text, record) => (
<Auth auth="sysArea:edit"> <QueryTableActions>
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a> <Auth auth="sysArea:edit">
</Auth> <a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
<Auth auth="sysArea:delete"> </Auth>
<Popconfirm <Auth auth="sysArea:delete">
placement="topRight" <Popconfirm
title="是否确认删除" placement="topRight"
onConfirm={() => this.onDelete(record)} title="是否确认删除"
> onConfirm={() => this.onDelete(record)}
<a>删除</a> >
</Popconfirm> <a>删除</a>
</Auth> </Popconfirm>
</QueryTableActions>) </Auth>
</QueryTableActions>
),
}) })
} }
} }
@@ -104,9 +119,9 @@ export default class index extends Component {
* 阻止外部组件引发的渲染,提升性能 * 阻止外部组件引发的渲染,提升性能
* 可自行添加渲染条件 * 可自行添加渲染条件
* [必要] * [必要]
* @param {*} props * @param {*} props
* @param {*} state * @param {*} state
* @returns * @returns
*/ */
shouldComponentUpdate(props, state) { shouldComponentUpdate(props, state) {
return !isEqual(this.state, state) return !isEqual(this.state, state)
@@ -118,31 +133,33 @@ export default class index extends Component {
*/ */
componentDidMount() { componentDidMount() {
this.table.current.onLoading() this.table.current.onLoading()
getDictData('dic_areacode_type').then(res => { getDictData('areacode_type').then(res => {
this.setState({ this.setState(
codes: res {
}, () => { codes: res,
this.table.current.onLoadData() },
}) () => {
this.table.current.onLoadData()
}
)
}) })
} }
/** /**
* 调用加载数据接口,可在调用前对query进行处理 * 调用加载数据接口,可在调用前对query进行处理
* [异步,必要] * [异步,必要]
* @param {*} params * @param {*} params
* @param {*} query * @param {*} query
* @returns * @returns
*/ */
loadData = async (params, query) => { loadData = async (params, query) => {
query = { query = {
...query, ...query,
pcode: this.selectCode pcode: this.selectCode,
} }
//首次加载根据code列升序排序 //首次加载根据code列升序排序
if (!params.sortField) { if (!params.sortField) {
params.sortField = 'code'; params.sortField = 'code'
params.sortOrder = 'ascend'; params.sortOrder = 'ascend'
} }
const { data } = await apiAction.page({ const { data } = await apiAction.page({
...params, ...params,
@@ -164,7 +181,7 @@ export default class index extends Component {
/** /**
* 树节点选中事件 * 树节点选中事件
* [必要] * [必要]
* @param {*} id * @param {*} id
*/ */
onSelectTree(code) { onSelectTree(code) {
this.selectCode = code this.selectCode = code
@@ -173,15 +190,15 @@ export default class index extends Component {
/** /**
* 绑定字典数据 * 绑定字典数据
* @param {*} code * @param {*} code
* @param {*} name * @param {*} name
* @returns * @returns
*/ */
bindCodeValue(code, name) { bindCodeValue(code, name) {
name = toCamelCase(name) name = toCamelCase(name)
const codes = this.state.codes[name] const codes = this.state.codes[name]
if (codes) { if (codes) {
const c = codes.find((p) => +p.code === code) const c = codes.find(p => +p.code === code)
if (c) { if (c) {
return c.value return c.value
} }
@@ -191,21 +208,21 @@ export default class index extends Component {
/** /**
* 打开新增/编辑弹窗 * 打开新增/编辑弹窗
* @param {*} modal * @param {*} modal
* @param {*} record * @param {*} record
*/ */
onOpen(modal, record) { onOpen(modal, record) {
modal.current.open({ modal.current.open({
pcode: this.pcode, pcode: this.pcode,
record record,
}) })
} }
/** /**
* 对表格上的操作进行统一处理 * 对表格上的操作进行统一处理
* [异步] * [异步]
* @param {*} action * @param {*} action
* @param {*} successMessage * @param {*} successMessage
*/ */
async onAction(action, successMessage) { async onAction(action, successMessage) {
this.table.current.onLoading() this.table.current.onLoading()
@@ -220,13 +237,10 @@ export default class index extends Component {
/** /**
* 删除 * 删除
* @param {*} record * @param {*} record
*/ */
onDelete(record) { onDelete(record) {
this.onAction( this.onAction(apiAction.delete(record), '删除成功')
apiAction.delete(record),
'删除成功'
)
} }
render() { render() {
@@ -234,7 +248,7 @@ export default class index extends Component {
<QueryTreeLayout <QueryTreeLayout
loadData={this.loadTreeData} loadData={this.loadTreeData}
defaultExpanded={true} defaultExpanded={true}
onSelect={(key) => this.onSelectTree(key)} onSelect={key => this.onSelectTree(key)}
replaceFields={{ value: 'code', title: 'name', children: 'children' }} replaceFields={{ value: 'code', title: 'name', children: 'children' }}
> >
<Container mode="fluid"> <Container mode="fluid">
@@ -259,12 +273,12 @@ export default class index extends Component {
<Button <Button
icon={<AntIcon type="plus" />} icon={<AntIcon type="plus" />}
onClick={() => this.onOpen(this.addForm)} onClick={() => this.onOpen(this.addForm)}
>新增{name}</Button> >
新增{name}
</Button>
</Auth> </Auth>
} }
> ></QueryTable>
</QueryTable>
</Card> </Card>
</Container> </Container>
<ModalForm <ModalForm
@@ -287,4 +301,4 @@ export default class index extends Component {
</QueryTreeLayout> </QueryTreeLayout>
) )
} }
} }