| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- import { PageContainer } from '@ant-design/pro-layout';
- import Service from '@/pages/rule-engine/Instance/serivce';
- import type { InstanceItem } from '@/pages/rule-engine/Instance/typings';
- import { useRef, useState } from 'react';
- import type { ActionType, ProColumns } from '@jetlinks/pro-table';
- import {
- CheckCircleOutlined,
- DeleteOutlined,
- EditOutlined,
- EyeOutlined,
- PlusOutlined,
- StopOutlined,
- } from '@ant-design/icons';
- import { Button, message, Popconfirm, Tooltip } from 'antd';
- import { useIntl } from '@@/plugin-locale/localeExports';
- import SearchComponent from '@/components/SearchComponent';
- import { BadgeStatus, ProTableCard } from '@/components';
- import RuleInstanceCard from '@/components/ProTableCard/CardItems/ruleInstance';
- import Save from '@/pages/rule-engine/Instance/Save';
- import SystemConst from '@/utils/const';
- import { StatusColorEnum } from '@/components/BadgeStatus';
- import { getButtonPermission } from '@/utils/menu';
- export const service = new Service('rule-engine/instance');
- const Instance = () => {
- const intl = useIntl();
- const actionRef = useRef<ActionType>();
- const [visible, setVisible] = useState<boolean>(false);
- const [current, setCurrent] = useState<Partial<InstanceItem>>({});
- const [searchParams, setSearchParams] = useState<any>({});
- const tools = (record: InstanceItem) => [
- <Button
- key={'edit'}
- type={'link'}
- style={{ padding: 0 }}
- onClick={() => {
- setCurrent(record);
- setVisible(true);
- }}
- disabled={getButtonPermission('rule-engine/Instance', ['update'])}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.edit',
- defaultMessage: '编辑',
- })}
- key={'edit'}
- >
- <EditOutlined />
- 编辑
- </Tooltip>
- </Button>,
- // <Button key={'view'}
- // disabled={getButtonPermission('rule-engine/Instance', ['view'])}
- // type={'link'}
- // style={{ padding: 0 }}
- // onClick={() => {
- // window.open(`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${record.id}`);
- // }}
- // >
- // <Tooltip
- // title={intl.formatMessage({
- // id: 'pages.data.option.detail',
- // defaultMessage: '查看',
- // })}
- // key={'detail'}
- // >
- // <EyeOutlined />
- // </Tooltip>
- // </Button>,
- <Button
- key={'operate'}
- disabled={getButtonPermission('rule-engine/Instance', ['action'])}
- type={'link'}
- style={{ padding: 0 }}
- >
- <Popconfirm
- key={'state'}
- title={intl.formatMessage({
- id: `pages.data.option.${record.state.value !== 'disable' ? 'disabled' : 'enabled'}.tips`,
- defaultMessage: '确认禁用?',
- })}
- onConfirm={async () => {
- if (record.state.value !== 'disable') {
- await service.stopRule(record.id);
- } else {
- await service.startRule(record.id);
- }
- message.success(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- actionRef.current?.reload();
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: `pages.data.option.${record.state.value !== 'disable' ? 'disabled' : 'enabled'}`,
- defaultMessage: record.state.value !== 'disable' ? '禁用' : '启用',
- })}
- >
- {record.state.value !== 'disable' ? (
- <span>
- <StopOutlined />
- 禁用
- </span>
- ) : (
- <span>
- <CheckCircleOutlined />
- 启用
- </span>
- )}
- </Tooltip>
- </Popconfirm>
- </Button>,
- <Tooltip
- key={'delete'}
- title={
- record.state.value !== 'disable'
- ? '已启用不能删除'
- : intl.formatMessage({
- id: 'pages.data.option.remove',
- defaultMessage: '删除',
- })
- }
- >
- <Button
- type={'link'}
- style={{ padding: 0 }}
- disabled={
- getButtonPermission('rule-engine/Instance', ['delete']) ||
- record.state.value !== 'disable'
- }
- >
- <Popconfirm
- title={record.state.value === 'disable' ? '确认删除' : '未停止不能删除'}
- key={'delete'}
- onConfirm={async () => {
- if (record.state.value === 'disable') {
- await service.remove(record.id);
- message.success(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- actionRef.current?.reload();
- } else {
- message.error('未停止不能删除');
- }
- }}
- >
- <DeleteOutlined />
- </Popconfirm>
- </Button>
- </Tooltip>,
- ];
- const columns: ProColumns<InstanceItem>[] = [
- {
- dataIndex: 'name',
- title: intl.formatMessage({
- id: 'pages.table.name',
- defaultMessage: '名称',
- }),
- ellipsis: true,
- },
- {
- dataIndex: 'state',
- title: '状态',
- render: (text: any, record: any) => (
- <BadgeStatus
- status={record.state?.value}
- text={record.state?.text}
- statusNames={{
- started: StatusColorEnum.success,
- disable: StatusColorEnum.error,
- }}
- />
- ),
- valueType: 'select',
- valueEnum: {
- started: {
- text: '正常',
- status: 'started',
- },
- disable: {
- text: '禁用',
- status: 'disable',
- },
- },
- },
- {
- dataIndex: 'description',
- title: '说明',
- ellipsis: true,
- },
- {
- title: intl.formatMessage({
- id: 'pages.data.option',
- defaultMessage: '操作',
- }),
- valueType: 'option',
- align: 'center',
- width: 200,
- render: (text, record) => [
- <Button
- type="link"
- style={{ padding: 0 }}
- disabled={getButtonPermission('rule-engine/Instance', ['update'])}
- key={'edit'}
- onClick={() => {
- setCurrent(record);
- setVisible(true);
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.edit',
- defaultMessage: '编辑',
- })}
- >
- <EditOutlined />
- </Tooltip>
- </Button>,
- <Button
- type="link"
- style={{ padding: 0 }}
- key={'view'}
- onClick={() => {
- window.open(`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${record.id}`);
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.ruleEngine.option.detail',
- defaultMessage: '查看',
- })}
- >
- <EyeOutlined />
- </Tooltip>
- </Button>,
- <Button
- type={'link'}
- style={{ padding: 0 }}
- key={'operate'}
- disabled={getButtonPermission('rule-engine/Instance', ['action'])}
- >
- <Popconfirm
- key={'state'}
- title={intl.formatMessage({
- id: `pages.data.option.${
- record.state.value !== 'disable' ? 'disabled' : 'enabled'
- }.tips`,
- defaultMessage: '确认禁用?',
- })}
- onConfirm={async () => {
- if (record.state.value !== 'disable') {
- await service.stopRule(record.id);
- } else {
- await service.startRule(record.id);
- }
- message.success(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- actionRef.current?.reload();
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: `pages.data.option.${
- record.state.value !== 'disable' ? 'disabled' : 'enabled'
- }`,
- defaultMessage: record.state.value !== 'disable' ? '禁用' : '正常',
- })}
- >
- {record.state.value !== 'disable' ? <StopOutlined /> : <CheckCircleOutlined />}
- </Tooltip>
- </Popconfirm>
- </Button>,
- <Tooltip
- key={'delete'}
- title={
- record.state.value !== 'disable'
- ? '已启用不能删除'
- : intl.formatMessage({
- id: 'pages.data.option.remove',
- defaultMessage: '删除',
- })
- }
- >
- <Button
- disabled={
- getButtonPermission('rule-engine/Instance', ['delete']) ||
- record.state.value !== 'disable'
- }
- type={'link'}
- style={{ padding: 0 }}
- >
- <Popconfirm
- title={record.state.value === 'disable' ? '确认删除' : '未禁用不能删除'}
- key={'delete'}
- onConfirm={async () => {
- if (record.state.value === 'disable') {
- await service.remove(record.id);
- message.success(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- actionRef.current?.reload();
- } else {
- message.error('未禁用不能删除');
- }
- }}
- >
- <DeleteOutlined />
- </Popconfirm>
- </Button>
- </Tooltip>,
- ],
- },
- ];
- return (
- <PageContainer>
- <SearchComponent<InstanceItem>
- field={columns}
- target="device-instance"
- onSearch={(data) => {
- // 重置分页数据
- actionRef.current?.reset?.();
- setSearchParams(data);
- }}
- />
- <ProTableCard<InstanceItem>
- columns={columns}
- actionRef={actionRef}
- params={searchParams}
- options={{ fullScreen: true }}
- request={(params) =>
- service.query({
- ...params,
- sorts: [
- {
- name: 'createTime',
- order: 'desc',
- },
- ],
- })
- }
- rowKey="id"
- search={false}
- pagination={{ pageSize: 10 }}
- headerTitle={[
- <Button
- onClick={() => {
- setVisible(true);
- setCurrent({});
- }}
- disabled={getButtonPermission('rule-engine/Instance', ['add'])}
- style={{ marginRight: 12 }}
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- >
- {intl.formatMessage({
- id: 'pages.data.option.add',
- defaultMessage: '新增',
- })}
- </Button>,
- ]}
- cardRender={(record) => (
- <RuleInstanceCard
- {...record}
- actions={tools(record)}
- detail={
- <div
- style={{ padding: 8, fontSize: 24 }}
- onClick={() => {
- window.open(`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${record.id}`);
- }}
- >
- <EyeOutlined />
- </div>
- }
- />
- )}
- />
- {visible && (
- <Save
- data={current}
- close={() => {
- setVisible(false);
- actionRef.current?.reload();
- }}
- />
- )}
- </PageContainer>
- );
- };
- export default Instance;
|