add 文件管理

This commit is contained in:
2021-06-23 17:56:29 +08:00
parent 3734dda2db
commit 32856f4757
9 changed files with 636 additions and 157 deletions

View File

@@ -15,18 +15,17 @@ const apiAction = {
edit: api.sysAppEdit,
delete: api.sysAppDelete,
setDefault: api.sysAppSetAsDefault
setDefault: api.sysAppSetAsDefault,
}
// 用于弹窗标题
const name = '应用'
export default class index extends Component {
state = {
codes: {
commonStatus: []
}
commonStatus: [],
},
}
// 表格实例
@@ -42,51 +41,58 @@ export default class index extends Component {
{
title: '应用名称',
dataIndex: 'name',
width: 300,
sorter: true,
},
{
title: '唯一编码',
dataIndex: 'code',
width: 300,
sorter: true,
},
{
title: '是否默认',
dataIndex: 'active',
width: 200,
sorter: true,
render: (text, record) => (<>
{text ? '是' : '否'}
{
!record.active && <Auth auth="sysApp:setAsDefault">
<QueryTableActions>
<span></span>
<Popconfirm
placement="topRight"
title="是否确认设置为默认应用"
onConfirm={() => this.onSetDefault(record)}
>
<a>设为默认</a>
</Popconfirm>
</QueryTableActions>
</Auth>
}
</>)
render: (text, record) => (
<>
{text ? '是' : '否'}
{!record.active && (
<Auth auth="sysApp:setAsDefault">
<QueryTableActions>
<span></span>
<Popconfirm
placement="topRight"
title="是否确认设置为默认应用"
onConfirm={() => this.onSetDefault(record)}
>
<a>设为默认</a>
</Popconfirm>
</QueryTableActions>
</Auth>
)}
</>
),
},
{
title: '状态',
dataIndex: 'status',
width: 100,
sorter: true,
render: text => (<>{this.bindCodeValue(text, 'common_status')}</>)
render: text => <>{this.bindCodeValue(text, 'common_status')}</>,
},
{
title: '排序',
dataIndex: 'sort',
width: 100,
sorter: true,
},
]
/**
* 构造函数,在渲染前动态添加操作字段等
* @param {*} props
* @param {*} props
*/
constructor(props) {
super(props)
@@ -98,20 +104,22 @@ export default class index extends Component {
title: '操作',
width: 150,
dataIndex: 'actions',
render: (text, record) => (<QueryTableActions>
<Auth auth="sysApp:edit">
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
</Auth>
<Auth auth="sysApp:delete">
<Popconfirm
placement="topRight"
title="是否确认删除"
onConfirm={() => this.onDelete(record)}
>
<a>删除</a>
</Popconfirm>
</Auth>
</QueryTableActions>)
render: (text, record) => (
<QueryTableActions>
<Auth auth="sysApp:edit">
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
</Auth>
<Auth auth="sysApp:delete">
<Popconfirm
placement="topRight"
title="是否确认删除"
onConfirm={() => this.onDelete(record)}
>
<a>删除</a>
</Popconfirm>
</Auth>
</QueryTableActions>
),
})
}
}
@@ -120,9 +128,9 @@ export default class index extends Component {
* 阻止外部组件引发的渲染,提升性能
* 可自行添加渲染条件
* [必要]
* @param {*} props
* @param {*} state
* @returns
* @param {*} props
* @param {*} state
* @returns
*/
shouldComponentUpdate(props, state) {
return !isEqual(this.state, state)
@@ -136,20 +144,23 @@ export default class index extends Component {
const { onLoading, onLoadData } = this.table.current
onLoading()
getDictData('common_status').then(res => {
this.setState({
codes: res
}, () => {
onLoadData()
})
this.setState(
{
codes: res,
},
() => {
onLoadData()
}
)
})
}
/**
* 调用加载数据接口,可在调用前对query进行处理
* [异步,必要]
* @param {*} params
* @param {*} query
* @returns
* @param {*} params
* @param {*} query
* @returns
*/
loadData = async (params, query) => {
const { data } = await apiAction.page({
@@ -161,15 +172,15 @@ export default class index extends Component {
/**
* 绑定字典数据
* @param {*} code
* @param {*} name
* @returns
* @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)
const c = codes.find(p => p.code == code)
if (c) {
return c.value
}
@@ -179,20 +190,20 @@ export default class index extends Component {
/**
* 打开新增/编辑弹窗
* @param {*} modal
* @param {*} record
* @param {*} modal
* @param {*} record
*/
onOpen(modal, record) {
modal.current.open({
record
record,
})
}
/**
* 对表格上的操作进行统一处理
* [异步]
* @param {*} action
* @param {*} successMessage
* @param {*} action
* @param {*} successMessage
*/
async onAction(action, successMessage) {
const { onLoading, onLoaded, onReloadData } = this.table.current
@@ -212,21 +223,15 @@ export default class index extends Component {
/**
* 删除
* @param {*} record
* @param {*} record
*/
onDelete(record) {
this.onAction(
apiAction.delete(record),
'删除成功'
)
this.onAction(apiAction.delete(record), '删除成功')
}
//#region 自定义方法
async onSetDefault(record) {
this.onAction(
apiAction.setDefault(record),
'设置成功'
)
this.onAction(apiAction.setDefault(record), '设置成功')
}
//#endregion
@@ -255,7 +260,9 @@ export default class index extends Component {
<Button
icon={<AntIcon type="plus" />}
onClick={() => this.onOpen(this.addForm)}
>新增{name}</Button>
>
新增{name}
</Button>
</Auth>
}
/>