oak-general-business/app/pages/userRelation/listTwo/index.pc.tsx

194 lines
7.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react';
import {
Table,
Input,
Select,
Button,
Avatar,
Space,
Tag
} from 'tdesign-react';
export default function render() {
const { t } = this;
const { users = [], oakLoading, editableRowKeys = [] } = this.state;
const { relations, entity, entityId } = this.props;
const relationArr =
typeof relations === 'object'
? relations
: relations && JSON.parse(relations);
return (
<div>
<Space>
<Button
shape="rectangle"
size="medium"
type="button"
variant="base"
onClick={() => this.goUpsert()}
>
</Button>
<Button
shape="rectangle"
size="medium"
type="button"
variant="base"
onClick={() => this.goUserEntityGrantWithGrant()}
>
</Button>
</Space>
<Table
loading={oakLoading}
resizable
bordered={false}
ref={this.tableRef}
rowKey="id"
editableRowKeys={editableRowKeys}
onRowEdit={(params) => this.onRowEdit(params)}
onRowValidate={(params) => this.onRowValidate(params)}
columns={[
{
colKey: 'avatar',
title: '头像',
cell: ({ row, rowIndex, col, colIndex }) => {
const { avatar } = row;
return avatar ? (
<Avatar
hideOnLoadFailed={false}
image={avatar}
shape="circle"
/>
) : (
<span></span>
);
},
},
{
colKey: 'name',
title: '姓名',
edit: {
component: Input,
props: {
clearable: true,
autofocus: true,
autoWidth: true,
},
rules: [{ required: true, message: '不能为空' }],
showEditIcon: false,
},
},
{
colKey: 'nickname',
title: '昵称',
edit: {
component: Input,
props: {
clearable: true,
autofocus: true,
autoWidth: true,
},
rules: [{ required: true, message: '不能为空' }],
showEditIcon: false,
},
},
{
colKey: 'mobile',
title: '手机号',
},
{
colKey: 'relations',
title: '权限',
cell: ({ row, rowIndex, col, colIndex }) => {
return (
<Space>
{row.relations?.map((ele, index) => (
<Tag key={index}>
{t(entity + ':r.' + ele)}
</Tag>
))}
</Space>
);
},
edit: {
component: Select,
// props, 透传全部属性到 Select 组件
// props 为函数时参数有col, row, rowIndex, colIndex, editedRow。一般用于实现编辑组件之间的联动
props: ({ editedRow }) => {
return {
multiple: true,
minCollapsedNum: 1,
autoWidth: true,
options:
relationArr &&
relationArr.map((ele, index) => ({
value: ele,
label: t(entity + ':r.' + ele),
})),
};
},
showEditIcon: false,
rules: [
{ required: true, message: '请至少选择一个权限' },
],
},
},
{
title: '操作',
colKey: 'operate',
cell: ({ row }) => {
const editable = editableRowKeys.includes(row.id);
return (
<Space>
<Button
theme="primary"
variant="text"
onClick={(e) => this.goDetail(row.id)}
>
</Button>
{!editable && (
<Button
theme="primary"
variant="text"
data-id={row.id}
onClick={(e) => this.onEdit(e)}
>
</Button>
)}
{editable && (
<Button
theme="primary"
variant="text"
data-id={row.id}
onClick={(e) => this.onSave(e)}
>
</Button>
)}
{editable && (
<Button
theme="primary"
variant="text"
data-id={row.id}
onClick={(e) => this.onCancel(e)}
>
</Button>
)}
</Space>
);
},
},
]}
data={users}
/>
</div>
);
}