feat(1.3.0-beta1): 定时任务添加复制按钮, 使用[更多]对操作按钮进行折叠

This commit is contained in:
dhb52 2024-12-07 08:07:30 +08:00
parent 4a53dd8773
commit 9a3166f150
3 changed files with 97 additions and 37 deletions

View File

@ -245,6 +245,15 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,
openDrawer(); openDrawer();
} }
function handleCopy(id: T['id']) {
operateType.value = 'add';
const findItem = data.value.find(item => item.id === id) || null;
editingData.value = jsonClone(findItem);
delete editingData.value?.id;
openDrawer();
}
/** the checked row keys of table */ /** the checked row keys of table */
const checkedRowKeys = ref<string[]>([]); const checkedRowKeys = ref<string[]>([]);
@ -272,6 +281,7 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,
handleAdd, handleAdd,
editingData, editingData,
handleEdit, handleEdit,
handleCopy,
checkedRowKeys, checkedRowKeys,
onBatchDeleted, onBatchDeleted,
onDeleted onDeleted

View File

@ -1,5 +1,5 @@
<script setup lang="tsx"> <script setup lang="tsx">
import { NButton, NPopconfirm, NTag } from 'naive-ui'; import { NButton, NDropdown, NPopconfirm, NTag } from 'naive-ui';
import { useBoolean } from '@sa/hooks'; import { useBoolean } from '@sa/hooks';
import { ref } from 'vue'; import { ref } from 'vue';
import { fetchBatchDeleteJob, fetchGetJobPage, fetchTriggerJob, fetchUpdateJobStatus } from '@/service/api'; import { fetchBatchDeleteJob, fetchGetJobPage, fetchTriggerJob, fetchUpdateJobStatus } from '@/service/api';
@ -177,10 +177,61 @@ const { columnChecks, columns, data, getData, loading, mobilePagination, searchP
key: 'operate', key: 'operate',
title: $t('common.operate'), title: $t('common.operate'),
align: 'center', align: 'center',
width: 180, width: 120,
fixed: 'right', fixed: 'right',
render: row => ( render: row => {
const options = [
{
label: $t('common.copy'),
key: 'copy',
click: () => copy(row.id!)
},
{
type: 'divider',
key: 'd2'
},
{
label: $t('common.batchList'),
key: 'batchList',
click: () => goToBatch(row.id!)
},
{
type: 'divider',
key: 'd2'
},
{
type: 'render',
key: 'delete',
render: () => (
<div class="flex-center">
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}>
{{
default: () => $t('common.confirmDelete'),
trigger: () => (
<NButton quaternary size="small">
{$t('common.delete')}
</NButton>
)
}}
</NPopconfirm>
</div>
)
}
];
const onSelect = (key: string) => {
const fun = options.filter(o => o.key === key)[0].click;
if (fun) fun();
};
return (
<div class="flex-center gap-8px"> <div class="flex-center gap-8px">
<NButton text type="warning" ghost size="small" onClick={() => edit(row.id!)}>
{$t('common.edit')}
</NButton>
<n-divider vertical />
<NPopconfirm onPositiveClick={() => handleTriggerJob(row.id!)}> <NPopconfirm onPositiveClick={() => handleTriggerJob(row.id!)}>
{{ {{
default: () => $t('common.confirmExecute'), default: () => $t('common.confirmExecute'),
@ -191,27 +242,21 @@ const { columnChecks, columns, data, getData, loading, mobilePagination, searchP
) )
}} }}
</NPopconfirm> </NPopconfirm>
<n-divider vertical /> <n-divider vertical />
<NButton type="primary" ghost text size="small" onClick={() => goToBatch(row.id!)}>
{$t('common.batchList')} <NDropdown trigger="click" show-arrow={false} options={options} size="small" on-select={onSelect}>
</NButton>
<n-divider vertical />
<NButton type="warning" ghost text size="small" onClick={() => edit(row.id!)}>
{$t('common.edit')}
</NButton>
<n-divider vertical />
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}>
{{ {{
default: () => $t('common.confirmDelete'), default: () => (
trigger: () => ( <NButton text type="primary" ghost size="small">
<NButton type="error" text ghost size="small"> 更多
{$t('common.delete')}
</NButton> </NButton>
) )
}} }}
</NPopconfirm> </NDropdown>
</div> </div>
) );
}
} }
] ]
}); });
@ -222,6 +267,7 @@ const {
editingData, editingData,
handleAdd, handleAdd,
handleEdit, handleEdit,
handleCopy,
checkedRowKeys, checkedRowKeys,
onDeleted, onDeleted,
onBatchDeleted onBatchDeleted
@ -244,6 +290,10 @@ function edit(id: string) {
handleEdit(id); handleEdit(id);
} }
function copy(id: string) {
handleCopy(id);
}
async function handleTriggerJob(id: string) { async function handleTriggerJob(id: string) {
const { error } = await fetchTriggerJob(id); const { error } = await fetchTriggerJob(id);
if (error) { if (error) {

View File

@ -202,7 +202,7 @@ function createDefaultScriptParams() {
} }
function handleUpdateModelWhenEdit() { function handleUpdateModelWhenEdit() {
if (props.operateType === 'add') { if (props.operateType === 'add' && !props.rowData) {
Object.assign(model, createDefaultModel()); Object.assign(model, createDefaultModel());
executorCustomType.value = 0; executorCustomType.value = 0;
httpHeaders.value = []; httpHeaders.value = [];
@ -211,7 +211,7 @@ function handleUpdateModelWhenEdit() {
return; return;
} }
if (props.operateType === 'edit' && props.rowData) { if (props.rowData) {
Object.assign(model, props.rowData); Object.assign(model, props.rowData);
if (model.taskType === 3 && model.argsStr) { if (model.taskType === 3 && model.argsStr) {
Object.assign(dynamicForm, { Object.assign(dynamicForm, {