334 lines
11 KiB
Vue
334 lines
11 KiB
Vue
<template>
|
|
<page-container>
|
|
<div>
|
|
<Search
|
|
:columns="query.columns"
|
|
target="device-instance"
|
|
@search="handleSearch"
|
|
></Search>
|
|
<JProTable
|
|
:columns="columns"
|
|
:request="queryList"
|
|
ref="tableRef"
|
|
:defaultParams="{
|
|
sorts: [{ name: 'createTime', order: 'desc' }],
|
|
}"
|
|
:params="params"
|
|
>
|
|
<template #headerTitle>
|
|
<j-space>
|
|
<PermissionButton
|
|
type="primary"
|
|
@click="add"
|
|
hasPermission="rule-engine/Instance:add"
|
|
>
|
|
<template #icon
|
|
><AIcon type="PlusOutlined"
|
|
/></template>
|
|
新增
|
|
</PermissionButton>
|
|
</j-space>
|
|
</template>
|
|
<template #card="slotProps">
|
|
<CardBox
|
|
:value="slotProps"
|
|
:actions="getActions(slotProps, 'card')"
|
|
v-bind="slotProps"
|
|
:status="slotProps.state?.value"
|
|
:statusText="slotProps.state?.text"
|
|
@click="openRuleEditor"
|
|
:statusNames="{
|
|
started: 'success',
|
|
disable: 'error',
|
|
}"
|
|
>
|
|
<template #img>
|
|
<slot name="img">
|
|
<img :src="getImage('/device-product.png')" />
|
|
</slot>
|
|
</template>
|
|
<template #content>
|
|
<Ellipsis style="width: calc(100% - 100px)">
|
|
<span style="font-weight: 600; font-size: 16px">
|
|
{{ slotProps.name }}
|
|
</span>
|
|
</Ellipsis>
|
|
<a-row>
|
|
<a-col :span="12">
|
|
<Ellipsis>
|
|
<div>
|
|
{{ slotProps.description }}
|
|
</div>
|
|
</Ellipsis>
|
|
</a-col>
|
|
</a-row>
|
|
</template>
|
|
<template #actions="item">
|
|
<PermissionButton
|
|
:disabled="item.disabled"
|
|
:popConfirm="item.popConfirm"
|
|
:tooltip="{
|
|
...item.tooltip,
|
|
}"
|
|
:hasPermission="
|
|
'rule-engine/Instance:' + item.key
|
|
"
|
|
@click="item.onClick"
|
|
>
|
|
<AIcon
|
|
type="DeleteOutlined"
|
|
v-if="item.key === 'delete'"
|
|
/>
|
|
<template v-else>
|
|
<AIcon :type="item.icon" />
|
|
<span>{{ item?.text }}</span>
|
|
</template>
|
|
</PermissionButton>
|
|
</template>
|
|
</CardBox>
|
|
</template>
|
|
<template #state="slotProps">
|
|
<a-badge
|
|
:text="
|
|
slotProps.state?.value === 'started'
|
|
? '正常'
|
|
: '禁用'
|
|
"
|
|
:status="
|
|
slotProps.state?.value === 'started'
|
|
? 'success'
|
|
: 'error'
|
|
"
|
|
/>
|
|
</template>
|
|
<template #action="slotProps">
|
|
<a-space :size="16">
|
|
<template
|
|
v-for="i in getActions(slotProps, 'table')"
|
|
:key="i.key"
|
|
>
|
|
<PermissionButton
|
|
:disabled="i.disabled"
|
|
:popConfirm="i.popConfirm"
|
|
:tooltip="{
|
|
...i.tooltip,
|
|
}"
|
|
@click="i.onClick"
|
|
type="link"
|
|
style="padding: 0px"
|
|
>
|
|
<template #icon
|
|
><AIcon :type="i.icon"
|
|
/></template>
|
|
</PermissionButton>
|
|
</template>
|
|
</a-space>
|
|
</template>
|
|
</JProTable>
|
|
<!-- 新增、编辑 -->
|
|
<Save
|
|
ref="saveRef"
|
|
:isAdd="isAdd"
|
|
:title="title"
|
|
@success="refresh"
|
|
/>
|
|
</div>
|
|
</page-container>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import JTable from '@/components/Table';
|
|
import type { InstanceItem } from './typings';
|
|
import {
|
|
queryList,
|
|
startRule,
|
|
stopRule,
|
|
deleteRule,
|
|
} from '@/api/rule-engine/instance';
|
|
import type { ActionsType } from '@/components/Table/index.vue';
|
|
import { getImage } from '@/utils/comm';
|
|
import { message } from 'ant-design-vue';
|
|
import Save from './Save/index.vue';
|
|
import { SystemConst } from '@/utils/consts';
|
|
const params = ref<Record<string, any>>({});
|
|
let isAdd = ref<number>(0);
|
|
let title = ref<string>('');
|
|
let saveRef = ref();
|
|
let currentForm = ref();
|
|
const tableRef = ref<Record<string, any>>({});
|
|
const query = {
|
|
columns: [
|
|
{
|
|
title: '名称',
|
|
dataIndex: 'name',
|
|
key: 'name',
|
|
search: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
{
|
|
title: '状态',
|
|
dataIndex: 'state',
|
|
key: 'state',
|
|
search: {
|
|
type: 'select',
|
|
options: [
|
|
{
|
|
label: '正常',
|
|
value: 'started',
|
|
},
|
|
{
|
|
label: '禁用',
|
|
value: 'disable',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
title: '说明',
|
|
key: 'description',
|
|
dataIndex: 'description',
|
|
search: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
],
|
|
};
|
|
const columns = [
|
|
{
|
|
title: '名称',
|
|
dataIndex: 'name',
|
|
key: 'name',
|
|
},
|
|
{
|
|
title: '状态',
|
|
dataIndex: 'state',
|
|
key: 'state',
|
|
scopedSlots: true,
|
|
},
|
|
{
|
|
title: '说明',
|
|
dataIndex: 'description',
|
|
key: 'description',
|
|
},
|
|
{
|
|
title: '操作',
|
|
key: 'action',
|
|
fixed: 'right',
|
|
width: 250,
|
|
scopedSlots: true,
|
|
},
|
|
];
|
|
const getActions = (
|
|
data: Partial<Record<string, any>>,
|
|
type?: 'card' | 'table',
|
|
): ActionsType[] => {
|
|
if (!data) {
|
|
return [];
|
|
}
|
|
const actions = [
|
|
{
|
|
key: 'update',
|
|
text: '编辑',
|
|
tooltip: {
|
|
title: '编辑',
|
|
},
|
|
|
|
icon: 'EditOutlined',
|
|
onClick: () => {
|
|
title.value = '编辑';
|
|
isAdd.value = 2;
|
|
nextTick(() => {
|
|
saveRef.value.show(data);
|
|
});
|
|
},
|
|
},
|
|
{
|
|
key: 'view',
|
|
text: '查看',
|
|
tooltip: {
|
|
title: '查看',
|
|
},
|
|
icon: 'EyeOutlined',
|
|
},
|
|
{
|
|
key: 'action',
|
|
text: data.state?.value !== 'disable' ? '禁用' : '启用',
|
|
tooltip: {
|
|
title: data.state?.value !== 'disable' ? '禁用' : '启用',
|
|
},
|
|
icon:
|
|
data.state?.value !== 'disable'
|
|
? 'StopOutlined'
|
|
: 'CheckCircleOutlined',
|
|
popConfirm: {
|
|
title: `确认${data.state !== 'disable' ? '禁用' : '启用'}?`,
|
|
onConfirm: async () => {
|
|
let response = undefined;
|
|
if (data.state?.value !== 'started') {
|
|
response = await startRule(data.id);
|
|
} else {
|
|
response = await stopRule(data.id);
|
|
}
|
|
if (response && response.status === 200) {
|
|
message.success('操作成功!');
|
|
tableRef.value?.reload();
|
|
} else {
|
|
message.error('操作失败!');
|
|
}
|
|
},
|
|
},
|
|
},
|
|
{
|
|
key: 'delete',
|
|
text: '删除',
|
|
disabled: data?.state?.value !== 'disable',
|
|
tooltip: {
|
|
title:
|
|
data?.state?.value !== 'disable'
|
|
? '请先禁用再删除'
|
|
: '删除',
|
|
},
|
|
popConfirm: {
|
|
title: '确认删除?',
|
|
onConfirm: async () => {
|
|
const resp = await deleteRule(data.id);
|
|
if (resp.status === 200) {
|
|
message.success('操作成功!');
|
|
tableRef.value?.reload();
|
|
} else {
|
|
message.error('操作失败!');
|
|
}
|
|
},
|
|
},
|
|
icon: 'DeleteOutlined',
|
|
},
|
|
];
|
|
if (type === 'card')
|
|
return actions.filter((i: ActionsType) => i.key !== 'view');
|
|
return actions;
|
|
};
|
|
const add = () => {
|
|
isAdd.value = 1;
|
|
title.value = '新增';
|
|
nextTick(() => {
|
|
saveRef.value.show(currentForm.value);
|
|
});
|
|
};
|
|
/**
|
|
* 刷新数据
|
|
*/
|
|
const refresh = () => {
|
|
tableRef.value?.reload();
|
|
};
|
|
const handleSearch = (e: any) => {
|
|
params.value = e;
|
|
};
|
|
const openRuleEditor = (item: any) => {
|
|
window.open(
|
|
`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${item.id}`,
|
|
);
|
|
};
|
|
</script>
|
|
<style scoped>
|
|
</style> |