mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-24 11:54:33 +08:00
refactor(workflow): 替换 Switch 为 ApiSwitch 并优化状态常量
将流程定义列表中的 Switch 组件替换为 ApiSwitch 以统一异步操作处理,并添加 `as const` 修饰常量以提高类型安全性。同时修复激活状态逻辑,确保与系统其他定义一致。
This commit is contained in:
@@ -13,7 +13,7 @@ import { useRouter } from 'vue-router';
|
|||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
import { Popconfirm, RadioGroup, Space, Switch } from 'antdv-next';
|
import { Popconfirm, RadioGroup, Space } from 'antdv-next';
|
||||||
|
|
||||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
@@ -25,6 +25,7 @@ import {
|
|||||||
workflowDefinitionList,
|
workflowDefinitionList,
|
||||||
workflowDefinitionPublish,
|
workflowDefinitionPublish,
|
||||||
} from '#/api/workflow/definition';
|
} from '#/api/workflow/definition';
|
||||||
|
import { ApiSwitch } from '#/components/global';
|
||||||
import { downloadByData } from '#/utils/file/download';
|
import { downloadByData } from '#/utils/file/download';
|
||||||
|
|
||||||
import CategoryTree from './category-tree.vue';
|
import CategoryTree from './category-tree.vue';
|
||||||
@@ -151,14 +152,19 @@ function handleDesign(row: any, _disabled: boolean) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ...跟系统其他定义的变量竟然是反的
|
||||||
|
const activeStatus = {
|
||||||
|
Enable: 1,
|
||||||
|
Disable: 0,
|
||||||
|
} as const;
|
||||||
/**
|
/**
|
||||||
* 激活/挂起流程
|
* 激活/挂起流程
|
||||||
* @param row row
|
* @param row row
|
||||||
*/
|
*/
|
||||||
async function handleActive(row: any, status: boolean | number | string) {
|
async function handleActive(row: any, checked: boolean) {
|
||||||
const lastStatus = status === 1 ? 0 : 1;
|
const lastStatus = checked ? activeStatus.Enable : activeStatus.Disable;
|
||||||
try {
|
try {
|
||||||
await workflowDefinitionActive(row.id, !!status);
|
await workflowDefinitionActive(row.id, !!checked);
|
||||||
await tableApi.query();
|
await tableApi.query();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
row.activityStatus = lastStatus;
|
row.activityStatus = lastStatus;
|
||||||
@@ -305,13 +311,20 @@ async function handleReload(type: 'add' | 'update') {
|
|||||||
</Space>
|
</Space>
|
||||||
</template>
|
</template>
|
||||||
<template #activityStatus="{ row }">
|
<template #activityStatus="{ row }">
|
||||||
<Switch
|
<!-- <Switch
|
||||||
v-model:checked="row.activityStatus"
|
v-model:checked="row.activityStatus"
|
||||||
:checked-value="1"
|
:checked-value="1"
|
||||||
:unchecked-value="0"
|
:unchecked-value="0"
|
||||||
checked-children="激活"
|
checked-children="激活"
|
||||||
un-checked-children="挂起"
|
un-checked-children="挂起"
|
||||||
@change="(status) => handleActive(row, status)"
|
@change="(status) => handleActive(row, status)"
|
||||||
|
/> -->
|
||||||
|
<ApiSwitch
|
||||||
|
:value="row.activityStatus === activeStatus.Enable"
|
||||||
|
checked-children="激活"
|
||||||
|
un-checked-children="挂起"
|
||||||
|
:api="(checked) => handleActive(row, checked)"
|
||||||
|
@reload="() => tableApi.query()"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #action="{ row }">
|
<template #action="{ row }">
|
||||||
@@ -346,6 +359,8 @@ async function handleReload(type: 'add' | 'update') {
|
|||||||
<a-button v-if="!row.isPublish" size="small" type="link">
|
<a-button v-if="!row.isPublish" size="small" type="link">
|
||||||
发布流程
|
发布流程
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<span v-else></span>
|
||||||
|
<!-- 必须要保证在Popconfirm存在元素 所以用v-else来接收 -->
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ export const DEFAULT_CLIENT_ID = 1;
|
|||||||
export const EnableStatus = {
|
export const EnableStatus = {
|
||||||
Enable: '0',
|
Enable: '0',
|
||||||
Disable: '1',
|
Disable: '1',
|
||||||
};
|
} as const;
|
||||||
|
|
||||||
export const YesNo = {
|
export const YesNo = {
|
||||||
Yes: 'Y',
|
Yes: 'Y',
|
||||||
No: 'N',
|
No: 'N',
|
||||||
};
|
} as const;
|
||||||
|
|||||||
Reference in New Issue
Block a user