|
|
@@ -1,31 +1,37 @@
|
|
|
// 资产-产品分类-绑定
|
|
|
import type { ActionType, ProColumns } from '@jetlinks/pro-table';
|
|
|
import { DeviceBadge, service } from './index';
|
|
|
-import { message, Modal } from 'antd';
|
|
|
+import { Checkbox, message, Modal, Switch } from 'antd';
|
|
|
import Models from './model';
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
import { observer } from '@formily/react';
|
|
|
import { useIntl } from '@@/plugin-locale/localeExports';
|
|
|
import type { DeviceItem } from '@/pages/system/Department/typings';
|
|
|
-import PermissionModal from '@/pages/system/Department/Assets/permissionModal';
|
|
|
import SearchComponent from '@/components/SearchComponent';
|
|
|
import { ExtraDeviceCard } from '@/components/ProTableCard/CardItems/device';
|
|
|
import { ProTableCard } from '@/components';
|
|
|
import { AssetsModel } from '@/pages/system/Department/Assets';
|
|
|
import encodeQuery from '@/utils/encodeQuery';
|
|
|
+import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
|
+import { Store } from 'jetlinks-store';
|
|
|
+import { onlyMessage } from '@/utils/util';
|
|
|
|
|
|
interface Props {
|
|
|
reload: () => void;
|
|
|
visible: boolean;
|
|
|
onCancel: () => void;
|
|
|
parentId: string;
|
|
|
+ assetsType?: string[];
|
|
|
}
|
|
|
|
|
|
const Bind = observer((props: Props) => {
|
|
|
const intl = useIntl();
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
const [searchParam, setSearchParam] = useState({});
|
|
|
- const saveRef = useRef<{ saveData: Function }>();
|
|
|
+ const [loading, setLoading] = useState(false);
|
|
|
+ const [checkAssets, setCheckAssets] = useState<string[]>(['read']);
|
|
|
+ const [isAll, setIsAll] = useState<boolean>(false);
|
|
|
+ const bindChecks = useRef(new Map());
|
|
|
|
|
|
const columns: ProColumns<DeviceItem>[] = [
|
|
|
{
|
|
|
@@ -108,7 +114,26 @@ const Bind = observer((props: Props) => {
|
|
|
const handleBind = () => {
|
|
|
AssetsModel.params = {};
|
|
|
if (Models.bindKeys.length) {
|
|
|
- saveRef.current?.saveData();
|
|
|
+ setLoading(true);
|
|
|
+ const _data: any[] = [];
|
|
|
+ bindChecks.current.forEach((value, key) => {
|
|
|
+ _data.push({
|
|
|
+ targetType: 'org',
|
|
|
+ targetId: props.parentId,
|
|
|
+ assetType: 'device',
|
|
|
+ assetIdList: [key],
|
|
|
+ permission: value,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ service.bind('device', _data).subscribe({
|
|
|
+ next: () => onlyMessage('操作成功'),
|
|
|
+ error: () => onlyMessage('操作失败', 'error'),
|
|
|
+ complete: () => {
|
|
|
+ setLoading(false);
|
|
|
+ props.reload();
|
|
|
+ props.onCancel();
|
|
|
+ },
|
|
|
+ });
|
|
|
} else {
|
|
|
message.warn('请先勾选数据');
|
|
|
// props.onCancel();
|
|
|
@@ -161,21 +186,58 @@ const Bind = observer((props: Props) => {
|
|
|
visible={props.visible}
|
|
|
onOk={handleBind}
|
|
|
onCancel={props.onCancel}
|
|
|
+ confirmLoading={loading}
|
|
|
width={'75vw'}
|
|
|
title="绑定"
|
|
|
>
|
|
|
- <PermissionModal
|
|
|
- type="device"
|
|
|
- bindKeys={Models.bindKeys}
|
|
|
- parentId={props.parentId}
|
|
|
- ref={saveRef}
|
|
|
- onCancel={(type) => {
|
|
|
- if (type) {
|
|
|
- props.reload();
|
|
|
- props.onCancel();
|
|
|
- }
|
|
|
- }}
|
|
|
- />
|
|
|
+ {/*<PermissionModal*/}
|
|
|
+ {/* type="device"*/}
|
|
|
+ {/* bindKeys={Models.bindKeys}*/}
|
|
|
+ {/* parentId={props.parentId}*/}
|
|
|
+ {/* ref={saveRef}*/}
|
|
|
+ {/* onCancel={(type) => {*/}
|
|
|
+ {/* if (type) {*/}
|
|
|
+ {/* props.reload();*/}
|
|
|
+ {/* props.onCancel();*/}
|
|
|
+ {/* }*/}
|
|
|
+ {/* }}*/}
|
|
|
+ {/*/>*/}
|
|
|
+ <div className={'assets-bind-tip'}>
|
|
|
+ <ExclamationCircleOutlined style={{ paddingRight: 8 }} />
|
|
|
+ 只能分配有“共享”权限的资产数据
|
|
|
+ </div>
|
|
|
+ <div className={'assets-bind-switch'}>
|
|
|
+ <span>批量配置</span>
|
|
|
+ <Switch
|
|
|
+ checkedChildren="开"
|
|
|
+ unCheckedChildren="关"
|
|
|
+ onChange={(e) => {
|
|
|
+ setIsAll(e);
|
|
|
+ Store.set('assets-device', {
|
|
|
+ isAll: e,
|
|
|
+ assets: checkAssets,
|
|
|
+ bindKeys: Models.bindKeys,
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <Checkbox.Group
|
|
|
+ options={props.assetsType}
|
|
|
+ value={checkAssets}
|
|
|
+ onChange={(e: any) => {
|
|
|
+ Store.set('assets-device', {
|
|
|
+ isAll: isAll,
|
|
|
+ assets: e,
|
|
|
+ bindKeys: Models.bindKeys,
|
|
|
+ });
|
|
|
+ bindChecks.current.forEach((_, key) => {
|
|
|
+ bindChecks.current.set(key, e);
|
|
|
+ });
|
|
|
+ setCheckAssets(e);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
<SearchComponent<DeviceItem>
|
|
|
field={columns}
|
|
|
enableSave={false}
|
|
|
@@ -225,7 +287,19 @@ const Bind = observer((props: Props) => {
|
|
|
gridColumn={2}
|
|
|
columnEmptyText={''}
|
|
|
cardRender={(record) => (
|
|
|
- <ExtraDeviceCard showBindBtn={false} showTool={false} {...record} cardType={'bind'} />
|
|
|
+ <ExtraDeviceCard
|
|
|
+ showBindBtn={false}
|
|
|
+ showTool={false}
|
|
|
+ {...record}
|
|
|
+ assetsOptions={props.assetsType}
|
|
|
+ allAssets={checkAssets}
|
|
|
+ cardType={'bind'}
|
|
|
+ onAssetsChange={(e) => {
|
|
|
+ if (bindChecks.current.has(record.id)) {
|
|
|
+ bindChecks.current.set(record.id, e);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ />
|
|
|
)}
|
|
|
tableAlertRender={({ selectedRowKeys }) => <div>已选择 {selectedRowKeys.length} 项</div>}
|
|
|
tableAlertOptionRender={() => {
|
|
|
@@ -249,9 +323,16 @@ const Bind = observer((props: Props) => {
|
|
|
Models.bindKeys = [
|
|
|
...new Set([...Models.bindKeys, ...getSelectedRowsKey(selectedRows)]),
|
|
|
];
|
|
|
+ bindChecks.current.set(record.id, checkAssets);
|
|
|
} else {
|
|
|
Models.bindKeys = Models.bindKeys.filter((item) => item !== record.id);
|
|
|
+ bindChecks.current.delete(record.id);
|
|
|
}
|
|
|
+ Store.set('assets-device', {
|
|
|
+ isAll: isAll,
|
|
|
+ assets: checkAssets,
|
|
|
+ bindKeys: Models.bindKeys,
|
|
|
+ });
|
|
|
},
|
|
|
onSelectAll: (selected, selectedRows, changeRows) => {
|
|
|
if (selected) {
|
|
|
@@ -266,9 +347,43 @@ const Bind = observer((props: Props) => {
|
|
|
}
|
|
|
},
|
|
|
}}
|
|
|
- request={(params) =>
|
|
|
- service.queryDeviceList({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
|
|
|
- }
|
|
|
+ request={async (params) => {
|
|
|
+ const resp: any = await service.queryDeviceList({
|
|
|
+ ...params,
|
|
|
+ sorts: [{ name: 'createTime', order: 'desc' }],
|
|
|
+ });
|
|
|
+ let newData = [];
|
|
|
+ if (resp.status === 200) {
|
|
|
+ newData = [...resp.result.data];
|
|
|
+ const assetsResp = await service.getBindingAssets(
|
|
|
+ 'product',
|
|
|
+ resp.result.data.map((item: any) => item.id),
|
|
|
+ );
|
|
|
+ if (assetsResp.status === 200) {
|
|
|
+ newData = newData.map((item: any) => {
|
|
|
+ const assetsItem = assetsResp.result.find(
|
|
|
+ (aItem: any) => (aItem.assetId = item.id),
|
|
|
+ );
|
|
|
+ console.log(assetsItem);
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ ...assetsItem,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ code: resp.message,
|
|
|
+ result: {
|
|
|
+ data: newData as DeviceItem[],
|
|
|
+ pageIndex: 0,
|
|
|
+ pageSize: 0,
|
|
|
+ total: 0,
|
|
|
+ },
|
|
|
+ status: resp.status,
|
|
|
+ };
|
|
|
+ }}
|
|
|
params={searchParam}
|
|
|
height={'none'}
|
|
|
/>
|