From 7e7dac82d82f3273cb709e404aa179787d561011 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 20 二月 2024 13:02:48 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/pages/system/role/index.jsx | 281 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 193 insertions(+), 88 deletions(-)
diff --git a/zy-asrs-flow/src/pages/system/role/index.jsx b/zy-asrs-flow/src/pages/system/role/index.jsx
index b9d4a8a..6352839 100644
--- a/zy-asrs-flow/src/pages/system/role/index.jsx
+++ b/zy-asrs-flow/src/pages/system/role/index.jsx
@@ -1,18 +1,21 @@
import React, { useState, useRef, useEffect } from 'react';
-import { useIntl, FormattedMessage } from '@umijs/max';
import { Button, message, Modal } from 'antd';
-import { ActionType, FooterToolbar, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
-import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined, ExportOutlined } from '@ant-design/icons';
-import { getLogininforList, removeLogininfor, exportLogininfor } from '@/services/monitor/logininfor';
+import {
+ FooterToolbar,
+ PageContainer,
+ ProTable,
+ LightFilter,
+} from '@ant-design/pro-components';
+import { PlusOutlined, ExportOutlined } from '@ant-design/icons';
import Http from '@/utils/http';
import Edit from './components/edit'
+import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch'
const handleSave = async (val) => {
const hide = message.loading('姝e湪娣诲姞');
try {
const resp = await Http.doPost('api/role/save', val);
- hide();
if (resp.code === 200) {
message.success('娣诲姞鎴愬姛');
return true;
@@ -21,72 +24,76 @@
return false;
}
} catch (error) {
- hide();
message.error('娣诲姞澶辫触璇烽噸璇曪紒');
return false;
+ } finally {
+ hide();
}
};
const handleUpdate = async (val) => {
const hide = message.loading('姝e湪鏇存柊');
try {
- const resp = await updateRole(val);
- hide();
+ const resp = await Http.doPost('api/role/update', val);
if (resp.code === 200) {
message.success('鏇存柊鎴愬姛');
+ return true;
} else {
message.error(resp.msg);
+ return false;
}
- return true;
} catch (error) {
- hide();
message.error('閰嶇疆澶辫触璇烽噸璇曪紒');
return false;
+ } finally {
+ hide();
}
};
-const handleRemove = async (selectedRows) => {
- if (!selectedRows) return true;
+const handleRemove = async (rows) => {
+ if (!rows) return true;
const hide = message.loading('姝e湪鍒犻櫎');
try {
- const resp = await removeLogininfor(selectedRows.map((row) => row.infoId).join(','));
- hide();
+ const resp = await Http.doPost('api/role/remove/' + rows.map((row) => row.id).join(','));
if (resp.code === 200) {
- message.success('鍒犻櫎鎴愬姛锛屽嵆灏嗗埛鏂�');
+ message.success('鍒犻櫎鎴愬姛');
+ return true;
} else {
message.error(resp.msg);
+ return false;
}
- return true;
} catch (error) {
- hide();
message.error('鍒犻櫎澶辫触锛岃閲嶈瘯');
return false;
+ } finally {
+ hide();
}
};
const handleExport = async () => {
const hide = message.loading('姝e湪瀵煎嚭');
try {
- await exportLogininfor();
- hide();
+ const resp = await Http.doPostBlob('api/role/export');
+ const blob = new Blob([resp], { type: 'application/vnd.ms-excel' });
+ window.location.href = window.URL.createObjectURL(blob);
message.success('瀵煎嚭鎴愬姛');
return true;
} catch (error) {
- hide();
message.error('瀵煎嚭澶辫触锛岃閲嶈瘯');
return false;
+ } finally {
+ hide();
}
};
-const LogininforTableList = () => {
+const Main = () => {
const formTableRef = useRef();
const actionRef = useRef();
const [selectedRows, setSelectedRows] = useState([]);
const [modalVisible, setModalVisible] = useState(false);
const [currentRow, setCurrentRow] = useState();
-
- const intl = useIntl();
+ const [searchParam, setSearchParam] = useState({});
useEffect(() => {
@@ -94,14 +101,110 @@
const columns = [
{
+ title: 'No',
+ dataIndex: 'index',
+ valueType: 'indexBorder',
+ width: 48,
+ },
+ {
title: '濮撳悕',
dataIndex: 'name',
valueType: 'text',
+ copyable: true,
+ filterDropdown: (props) => <TextFilter
+ name='name'
+ {...props}
+ actionRef={actionRef}
+ setSearchParam={setSearchParam}
+ />,
},
{
title: '鏍囪瘑',
dataIndex: 'code',
valueType: 'text',
+ filterDropdown: (props) => <TextFilter
+ name='code'
+ {...props}
+ actionRef={actionRef}
+ setSearchParam={setSearchParam}
+ />,
+ },
+ {
+ title: '鏈烘瀯',
+ dataIndex: 'hostId$',
+ valueType: 'text',
+ filterDropdown: (props) => <LinkFilter
+ name='hostId'
+ major='host'
+ {...props}
+ actionRef={actionRef}
+ setSearchParam={setSearchParam}
+ />,
+ },
+ {
+ title: '鐘舵��',
+ dataIndex: 'status$',
+ valueType: 'text',
+ filterDropdown: (props) => <SelectFilter
+ name='status'
+ {...props}
+ actionRef={actionRef}
+ setSearchParam={setSearchParam}
+ data={[
+ { label: '姝e父', value: 1 },
+ { label: '绂佺敤', value: 0 },
+ ]}
+ />,
+ },
+ {
+ title: '淇敼鏃堕棿',
+ dataIndex: 'updateTime$',
+ valueType: 'text',
+ filterDropdown: (props) => <DatetimeRangeFilter
+ name='updateTime'
+ {...props}
+ actionRef={actionRef}
+ setSearchParam={setSearchParam}
+ />,
+ },
+ {
+ title: '鎿嶄綔',
+ dataIndex: 'option',
+ width: 140,
+ valueType: 'option',
+ render: (_, record) => [
+ <Button
+ type="link"
+ key="edit"
+ onClick={() => {
+ setModalVisible(true);
+ setCurrentRow(record);
+ }}
+ >
+ 缂栬緫
+ </Button>,
+ <Button
+ type="link"
+ danger
+ key="batchRemove"
+ onClick={async () => {
+ Modal.confirm({
+ title: '鍒犻櫎',
+ content: '纭畾鍒犻櫎璇ラ」鍚楋紵',
+ onOk: async () => {
+ const success = await handleRemove([record]);
+ if (success) {
+ if (actionRef.current) {
+ actionRef.current.reload();
+ }
+ }
+ },
+ });
+ }}
+ >
+ 鍒犻櫎
+ </Button>,
+ ],
},
];
@@ -109,63 +212,57 @@
<PageContainer>
<div style={{ width: '100%', float: 'right' }}>
<ProTable
- headerTitle={intl.formatMessage({
- id: 'pages.searchTable.title',
- defaultMessage: '淇℃伅',
- })}
+ key="role"
+ rowKey="id"
actionRef={actionRef}
formRef={formTableRef}
- rowKey="infoId"
- key="logininforList"
- search={{
- labelWidth: 120,
+ columns={columns}
+ cardBordered
+ dateFormatter="string"
+ pagination={{ pageSize: 20 }}
+ search={false}
+ toolbar={{
+ multipleLine: true,
+ search: {
+ onSearch: (value) => {
+ setSearchParam(prevState => ({
+ ...prevState,
+ condition: value
+ }));
+ actionRef.current?.reload();
+ },
+ },
+ filter: (
+ <LightFilter
+ onValuesChange={(val) => {
+ }}
+ >
+ </LightFilter>
+ ),
+ actions: [
+ <Button
+ type="primary"
+ key="save"
+ onClick={async () => {
+ setModalVisible(true)
+ }}
+ >
+ <PlusOutlined />
+ 娣诲姞
+ </Button>,
+ <Button
+ key="export"
+ onClick={async () => {
+ handleExport();
+ }}
+ >
+ <ExportOutlined />
+ 瀵煎嚭
+ </Button>,
+ ],
}}
- toolBarRender={() => [
- <Button
- key="remove"
- danger
- hidden={selectedRows?.length === 0}
- onClick={async () => {
- Modal.confirm({
- title: '鏄惁纭鍒犻櫎鎵�閫夋暟鎹」?',
- icon: <ExclamationCircleOutlined />,
- content: '璇疯皑鎱庢搷浣�',
- async onOk() {
- const success = await handleRemove(selectedRows);
- if (success) {
- setSelectedRows([]);
- actionRef.current?.reloadAndRest?.();
- }
- },
- onCancel() { },
- });
- }}
- >
- <DeleteOutlined />
- <FormattedMessage id="pages.searchTable.delete" defaultMessage="鍒犻櫎" />
- </Button>,
- <Button
- type="primary"
- key="save"
- onClick={async () => {
- setModalVisible(true)
- }}
- >
- <PlusOutlined />
- 娣诲姞
- </Button>,
- <Button
- key="export"
- onClick={async () => {
- handleExport();
- }}
- >
- <ExportOutlined />
- 瀵煎嚭
- </Button>,
- ]}
- request={(params) =>
- Http.doPostPromise('/api/role/page', params, (res) => {
+ request={(params, sorter, filter) =>
+ Http.doPostPromise('/api/role/page', { ...params, ...searchParam }, (res) => {
return {
data: res.data.records,
total: res.data.total,
@@ -173,32 +270,40 @@
}
})
}
- columns={columns}
rowSelection={{
- onChange: (_, selectedRows) => {
- setSelectedRows(selectedRows);
+ onChange: (ids, rows) => {
+ setSelectedRows(rows);
+ }
+ }}
+ columnsState={{
+ persistenceKey: 'pro-table-role',
+ persistenceType: 'localStorage',
+ defaultValue: {
+ option: { fixed: 'right', disable: true },
+ },
+ onChange(value) {
},
}}
/>
</div>
+
{selectedRows?.length > 0 && (
<FooterToolbar
extra={
<div>
- <FormattedMessage id="pages.searchTable.chosen" defaultMessage="宸查�夋嫨" />
+ 宸查�夋嫨
<a style={{ fontWeight: 600 }}>{selectedRows.length}</a>
- <FormattedMessage id="pages.searchTable.item" defaultMessage="椤�" />
+ 椤�
</div>
}
>
<Button
key="remove"
+ danger
onClick={async () => {
Modal.confirm({
title: '鍒犻櫎',
content: '纭畾鍒犻櫎璇ラ」鍚楋紵',
- okText: '纭',
- cancelText: '鍙栨秷',
onOk: async () => {
const success = await handleRemove(selectedRows);
if (success) {
@@ -209,7 +314,7 @@
});
}}
>
- <FormattedMessage id="pages.searchTable.batchDeletion" defaultMessage="鎵归噺鍒犻櫎" />
+ 鎵归噺鍒犻櫎
</Button>
</FooterToolbar>
)}
@@ -226,9 +331,9 @@
onSubmit={async (values) => {
let ok = false;
if (values.id) {
- ok = await handleUpdate({...values})
+ ok = await handleUpdate({ ...values })
} else {
- ok = await handleSave({...values})
+ ok = await handleSave({ ...values })
}
if (ok) {
setModalVisible(false);
@@ -244,4 +349,4 @@
);
};
-export default LogininforTableList;
+export default Main;
--
Gitblit v1.9.1