Skip to content

Commit

Permalink
feat(多租户): 多租户资产解绑
Browse files Browse the repository at this point in the history
多租户设备/协议/产品资产解绑
  • Loading branch information
Lind-pro committed Jun 19, 2020
1 parent 4a4a81d commit 5392b50
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Add = (props: Props) => {
const [loading, setLoading] = useState<boolean>(true);
const [userList, setUserList] = useState();
const { data } = props;
const [checkedUserList, setCheckedUserList] = useState<string[]>([props.user]);
const [checkedUserList, setCheckedUserList] = useState<string[]>(props.user ? [props.user] : []);
const [selectedAssetsId, setSelectedAssetsId] = useState<string[]>([]);

useEffect(() => {
Expand Down
27 changes: 24 additions & 3 deletions src/pages/system/tenant/components/assets/device/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Drawer, Button, Table, } from "antd";
import { Drawer, Button, Table, message, } from "antd";
import React, { useEffect, useState, Fragment } from "react";
import Service from "@/pages/system/tenant/service";
import encodeQueryParam from "@/utils/encodeParam";
Expand All @@ -20,6 +20,7 @@ const Edit = (props: Props) => {
const { data } = props;
const [cat, setCat] = useState<boolean>(false);
const [asset, setAsset] = useState();
const [selected, setSelected] = useState<any[]>([]);
const handleSearch = () => {
service.assets.device(encodeQueryParam({
terms: {
Expand All @@ -39,7 +40,8 @@ const Edit = (props: Props) => {
}, []);
const rowSelection = {
onChange: (selectedRowKeys: any[], selectedRows: any[]) => {
console.log(selectedRows);
// console.log(selectedRows);
setSelected(selectedRows);
},
getCheckboxProps: (record: any) => ({
name: record.name,
Expand All @@ -62,7 +64,16 @@ const Edit = (props: Props) => {
}}>查看</a>
</Fragment>
)
}]
}];
const unbind = () => {
service.assets.unbind(data.id, [{
assetIdList: selected.map(item => item.id),
assetType: 'device'
}]).subscribe(() => {
message.error('解绑成功');
handleSearch();
})
}
return (
<Drawer
title="编辑设备资产"
Expand Down Expand Up @@ -92,6 +103,16 @@ const Edit = (props: Props) => {
type="primary"
style={{ marginBottom: 10 }}
onClick={() => setAdd(true)}>添加</Button>
{
selected.length > 0 && (
<Button
type="danger"
style={{ marginBottom: 10, marginLeft: 10 }}
onClick={() => { unbind() }}>
{`解绑${selected.length}项`}
</Button>
)
}
<Table
rowKey="id"
rowSelection={rowSelection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Add = (props: Props) => {
const [loading, setLoading] = useState<boolean>(true);
const [userList, setUserList] = useState();
const { data } = props;
const [checkedUserList, setCheckedUserList] = useState<string[]>([props.user]);
const [checkedUserList, setCheckedUserList] = useState<string[]>(props.user ? [props.user] : []);
const [selectedAssetsId, setSelectedAssetsId] = useState<string[]>([]);

useEffect(() => {
Expand All @@ -35,7 +35,6 @@ const Add = (props: Props) => {

service.member.query(data.id, {}).subscribe(resp => {
setUserList(resp.data);
console.log(resp, 'res');
});
}, []);

Expand All @@ -49,7 +48,6 @@ const Add = (props: Props) => {
assetIdList: selectedAssetsId,
allPermission: true,
}));
console.log(checkedUserList.length, bindData, 'jjj');
if (checkedUserList.length === 0) {
message.error('请选择成员');
setLoading(false);
Expand Down
24 changes: 22 additions & 2 deletions src/pages/system/tenant/components/assets/product/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Drawer, Button, Table, Select } from "antd";
import { Drawer, Button, Table, message } from "antd";
import React, { useState, useEffect, Fragment } from "react";
import Service from "@/pages/system/tenant/service";
import { ListData } from "@/services/response";
Expand All @@ -20,6 +20,7 @@ const Edit = (props: Props) => {
const [cat, setCat] = useState<boolean>(false);
const [asset, setAsset] = useState();
const { data } = props;
const [selected, setSelected] = useState<any[]>([]);

const handleSearch = () => {
service.assets.product(encodeQueryParam({
Expand All @@ -40,7 +41,7 @@ const Edit = (props: Props) => {
}, []);
const rowSelection = {
onChange: (selectedRowKeys: any[], selectedRows: any[]) => {
console.log(selectedRows);
setSelected(selectedRows)
},
getCheckboxProps: (record: any) => ({
name: record.name,
Expand All @@ -65,6 +66,15 @@ const Edit = (props: Props) => {
)
}]

const unbind = () => {
service.assets.unbind(data.id, [{
assetIdList: selected.map(item => item.id),
assetType: 'product'
}]).subscribe(() => {
message.error('解绑成功');
handleSearch();
})
}
return (
<Drawer
title="编辑产品资产"
Expand Down Expand Up @@ -94,6 +104,16 @@ const Edit = (props: Props) => {
type="primary"
style={{ marginBottom: 10 }}
onClick={() => setAdd(true)}>添加</Button>
{
selected.length > 0 && (
<Button
type="danger"
style={{ marginBottom: 10, marginLeft: 10 }}
onClick={() => { unbind() }}>
{`解绑${selected.length}项`}
</Button>
)
}
<Table
rowKey="id"
rowSelection={rowSelection}
Expand Down
27 changes: 24 additions & 3 deletions src/pages/system/tenant/components/assets/protocol/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Drawer, Button, Table, Select } from "antd";
import { Drawer, Button, Table, Select, message } from "antd";
import React, { useState, useEffect, Fragment } from "react";
import Service from "@/pages/system/tenant/service";
import { ListData } from "@/services/response";
Expand All @@ -19,6 +19,8 @@ const Edit = (props: Props) => {
const [add, setAdd] = useState<boolean>(false);
const [cat, setCat] = useState<boolean>(false);
const [asset, setAsset] = useState();
const [selected, setSelected] = useState<any[]>([]);

const { data } = props;

const handleSearch = () => {
Expand All @@ -40,7 +42,7 @@ const Edit = (props: Props) => {
}, []);
const rowSelection = {
onChange: (selectedRowKeys: any[], selectedRows: any[]) => {
console.log(selectedRows);
setSelected(selectedRows);
},
getCheckboxProps: (record: any) => ({
name: record.name,
Expand All @@ -63,7 +65,16 @@ const Edit = (props: Props) => {
}}>查看</a>
</Fragment>
)
}]
}];
const unbind = () => {
service.assets.unbind(data.id, [{
assetIdList: selected.map(item => item.id),
assetType: 'protocol'
}]).subscribe(() => {
message.error('解绑成功');
handleSearch();
})
}

return (
<Drawer
Expand Down Expand Up @@ -94,6 +105,16 @@ const Edit = (props: Props) => {
type="primary"
style={{ marginBottom: 10 }}
onClick={() => setAdd(true)}>添加</Button>
{
selected.length > 0 && (
<Button
type="danger"
style={{ marginBottom: 10, marginLeft: 10 }}
onClick={() => { unbind() }}>
{`解绑${selected.length}项`}
</Button>
)
}
<Table
rowKey="id"
rowSelection={rowSelection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Protocol = (props: Props) => {
terms: {
id$assets: JSON.stringify({
tenantId: data?.id,
assetType: 'device',
assetType: 'protocol',
memberId: props.user,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/system/tenant/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Service extends BaseService<TenantItem>{
map(resp => resp)
)),
unbind: (id: string, data: {
userId: string,
userId?: string,
assetType: string,
assetIdList: string[]
}[]) => defer(() => from(
Expand Down

0 comments on commit 5392b50

Please sign in to comment.