feat-wip(components): 抽取leaveEdit组件,适配流程编辑和预览功能
This commit is contained in:
parent
1cbeb59c0b
commit
85115ce327
@ -2,23 +2,30 @@
|
|||||||
import { computed, reactive, ref, watch } from 'vue';
|
import { computed, reactive, ref, watch } from 'vue';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useBoolean } from '@sa/hooks';
|
import { useBoolean } from '@sa/hooks';
|
||||||
import { flowCodeTypeOptions, leaveTypeOptions } from '@/constants/workflow';
|
import { flowCodeTypeOptions, flowCodeTypeRecord, leaveTypeOptions, leaveTypeRecord } from '@/constants/workflow';
|
||||||
import { fetchCreateLeave, fetchStartWorkflow, fetchUpdateLeave } from '@/service/api/workflow';
|
import { fetchCreateLeave, fetchGetLeaveDetail, fetchStartWorkflow, fetchUpdateLeave } from '@/service/api/workflow';
|
||||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||||
|
import { useDict } from '@/hooks/business/dict';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'LeaveOperateDrawer'
|
name: 'LeaveEdit'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useDict('wf_task_status');
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
/** the type of operation */
|
operateType: CommonType.WorkflowTableOperateType;
|
||||||
operateType: NaiveUI.TableOperateType;
|
/** 业务ID */
|
||||||
|
businessId?: CommonType.IdType;
|
||||||
/** the edit row data */
|
/** the edit row data */
|
||||||
rowData?: Api.Workflow.Leave | null;
|
rowData?: Api.Workflow.Leave | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
rowData: null,
|
||||||
|
businessId: undefined
|
||||||
|
});
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'submitted'): void;
|
(e: 'submitted'): void;
|
||||||
@ -34,12 +41,17 @@ const { formRef, validate, restoreValidation } = useNaiveForm();
|
|||||||
const { createRequiredRule } = useFormRules();
|
const { createRequiredRule } = useFormRules();
|
||||||
|
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
const titles: Record<NaiveUI.TableOperateType, string> = {
|
const titles: Record<CommonType.WorkflowTableOperateType, string> = {
|
||||||
add: '新增请假申请',
|
add: '新增请假申请',
|
||||||
edit: '编辑请假申请'
|
edit: '编辑请假申请',
|
||||||
|
detail: '查看请假申请',
|
||||||
|
approval: '审批请假申请'
|
||||||
};
|
};
|
||||||
return titles[props.operateType];
|
return titles[props.operateType];
|
||||||
});
|
});
|
||||||
|
const readonly = computed(() => {
|
||||||
|
return props.operateType === 'detail' || props.operateType === 'approval';
|
||||||
|
});
|
||||||
|
|
||||||
const respLeave = ref<Api.Workflow.Leave>();
|
const respLeave = ref<Api.Workflow.Leave>();
|
||||||
const startWorkflowResult = ref<Api.Workflow.StartWorkflowResult>();
|
const startWorkflowResult = ref<Api.Workflow.StartWorkflowResult>();
|
||||||
@ -47,12 +59,9 @@ const startWorkflowResult = ref<Api.Workflow.StartWorkflowResult>();
|
|||||||
type Model = Api.Workflow.LeaveOperateParams & {
|
type Model = Api.Workflow.LeaveOperateParams & {
|
||||||
flowCode: Api.Workflow.FlowCodeType;
|
flowCode: Api.Workflow.FlowCodeType;
|
||||||
};
|
};
|
||||||
type StartWorkflowModel = Api.Workflow.StartWorkflowOperateParams;
|
|
||||||
|
|
||||||
const model: Model = reactive(createDefaultModel());
|
const model: Model = reactive(createDefaultModel());
|
||||||
|
|
||||||
const startWorkflowModel: StartWorkflowModel = reactive(createDefaultStartWorkflowModel());
|
|
||||||
|
|
||||||
function createDefaultModel(): Model {
|
function createDefaultModel(): Model {
|
||||||
return {
|
return {
|
||||||
flowCode: 'leave1',
|
flowCode: 'leave1',
|
||||||
@ -64,6 +73,29 @@ function createDefaultModel(): Model {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModelDetail = Api.Workflow.LeaveDetail & {
|
||||||
|
flowCode: Api.Workflow.FlowCodeType;
|
||||||
|
};
|
||||||
|
|
||||||
|
const modelDetail: ModelDetail = reactive(createDefaultModelDetail());
|
||||||
|
|
||||||
|
function createDefaultModelDetail(): ModelDetail {
|
||||||
|
return {
|
||||||
|
flowCode: 'leave1',
|
||||||
|
status: null,
|
||||||
|
id: null,
|
||||||
|
leaveType: null,
|
||||||
|
startDate: null,
|
||||||
|
endDate: null,
|
||||||
|
leaveDays: null,
|
||||||
|
remark: ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type StartWorkflowModel = Api.Workflow.StartWorkflowOperateParams;
|
||||||
|
|
||||||
|
const startWorkflowModel: StartWorkflowModel = reactive(createDefaultStartWorkflowModel());
|
||||||
|
|
||||||
function createDefaultStartWorkflowModel(): StartWorkflowModel {
|
function createDefaultStartWorkflowModel(): StartWorkflowModel {
|
||||||
return {
|
return {
|
||||||
flowCode: null,
|
flowCode: null,
|
||||||
@ -81,7 +113,7 @@ const dateRange = computed<[string, string] | null>({
|
|||||||
if (value) {
|
if (value) {
|
||||||
model.startDate = value[0];
|
model.startDate = value[0];
|
||||||
model.endDate = value[1];
|
model.endDate = value[1];
|
||||||
// Calculate leave days when date range changes
|
// 计算请假天数
|
||||||
const start = dayjs(value[0]);
|
const start = dayjs(value[0]);
|
||||||
const end = dayjs(value[1]);
|
const end = dayjs(value[1]);
|
||||||
model.leaveDays = end.diff(start, 'day') + 1;
|
model.leaveDays = end.diff(start, 'day') + 1;
|
||||||
@ -104,14 +136,21 @@ const rules: Record<RuleKey, App.Global.FormRule> = {
|
|||||||
leaveDays: createRequiredRule('请假天数不能为空')
|
leaveDays: createRequiredRule('请假天数不能为空')
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleUpdateModelWhenEdit() {
|
async function handleUpdateModelWhenEdit() {
|
||||||
if (props.operateType === 'add') {
|
if (props.operateType === 'add') {
|
||||||
Object.assign(model, createDefaultModel());
|
Object.assign(model, createDefaultModel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' || props.operateType === 'detail') {
|
||||||
Object.assign(model, props.rowData);
|
Object.assign(model, props.rowData);
|
||||||
|
} else {
|
||||||
|
const { error, data } = await fetchGetLeaveDetail(props.businessId!);
|
||||||
|
if (error) {
|
||||||
|
window.$message?.error(error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object.assign(modelDetail, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,6 +217,7 @@ watch(visible, () => {
|
|||||||
<template>
|
<template>
|
||||||
<NDrawer v-model:show="visible" :title="title" display-directive="show" :width="800" class="max-w-90%">
|
<NDrawer v-model:show="visible" :title="title" display-directive="show" :width="800" class="max-w-90%">
|
||||||
<NDrawerContent :title="title" :native-scrollbar="false" closable>
|
<NDrawerContent :title="title" :native-scrollbar="false" closable>
|
||||||
|
<div v-if="!readonly">
|
||||||
<NForm ref="formRef" :model="model" :rules="rules">
|
<NForm ref="formRef" :model="model" :rules="rules">
|
||||||
<NFormItem label="流程类型" path="flowCode">
|
<NFormItem label="流程类型" path="flowCode">
|
||||||
<NSelect v-model:value="model.flowCode" placeholder="请输入流程类型" :options="flowCodeTypeOptions" />
|
<NSelect v-model:value="model.flowCode" placeholder="请输入流程类型" :options="flowCodeTypeOptions" />
|
||||||
@ -201,17 +241,48 @@ watch(visible, () => {
|
|||||||
<NInput v-model:value="model.remark" placeholder="请输入请假原因" />
|
<NInput v-model:value="model.remark" placeholder="请输入请假原因" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</NForm>
|
</NForm>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<NDescriptions bordered :column="1" label-placement="left">
|
||||||
|
<NDescriptionsItem label="流程类型">
|
||||||
|
{{ flowCodeTypeRecord[model.flowCode] || '-' }}
|
||||||
|
</NDescriptionsItem>
|
||||||
|
<NDescriptionsItem label="请假类型">
|
||||||
|
<NTag type="info">{{ leaveTypeRecord[model.leaveType!] || '-' }}</NTag>
|
||||||
|
</NDescriptionsItem>
|
||||||
|
<NDescriptionsItem label="请假时间">
|
||||||
|
{{ model.startDate ? `${model.startDate} 至 ${model.endDate}` : '-' }}
|
||||||
|
</NDescriptionsItem>
|
||||||
|
<NDescriptionsItem label="请假天数">{{ model.leaveDays || '-' }} 天</NDescriptionsItem>
|
||||||
|
<NDescriptionsItem label="请假原因">
|
||||||
|
{{ model.remark || '-' }}
|
||||||
|
</NDescriptionsItem>
|
||||||
|
</NDescriptions>
|
||||||
|
<div v-if="modelDetail.status !== 'draft'" class="mt-4">
|
||||||
|
<NTimeline horizontal>
|
||||||
|
<NTimelineItem content="啊" />
|
||||||
|
<NTimelineItem type="success" title="成功" content="哪里成功" time="2018-04-03 20:46" />
|
||||||
|
<NTimelineItem type="error" content="哪里错误" time="2018-04-03 20:46" />
|
||||||
|
<NTimelineItem type="warning" title="警告" content="哪里警告" time="2018-04-03 20:46" />
|
||||||
|
<NTimelineItem type="info" title="信息" content="是的" time="2018-04-03 20:46" line-type="dashed" />
|
||||||
|
<NTimelineItem content="啊" />
|
||||||
|
</NTimeline>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
<div v-if="!readonly">
|
||||||
<NSpace :size="16">
|
<NSpace :size="16">
|
||||||
<NButton @click="closeDrawer">{{ $t('common.cancel') }}</NButton>
|
<NButton @click="closeDrawer">{{ $t('common.cancel') }}</NButton>
|
||||||
<NButton type="warning" @click="handleSaveDraft">暂存</NButton>
|
<NButton type="warning" @click="handleSaveDraft">暂存</NButton>
|
||||||
<NButton type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</NButton>
|
<NButton type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</NButton>
|
||||||
</NSpace>
|
</NSpace>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</NDrawerContent>
|
</NDrawerContent>
|
||||||
<WorkflowTaskApplyModal
|
<WorkflowTaskApplyModal
|
||||||
v-model:visible="taskApplyVisible"
|
v-model:visible="taskApplyVisible"
|
||||||
:task-id="startWorkflowResult?.taskId || ''"
|
:task-id="startWorkflowResult?.taskId!"
|
||||||
:task-variables="taskVariables"
|
:task-variables="taskVariables"
|
||||||
@finished="handleTaskFinished"
|
@finished="handleTaskFinished"
|
||||||
/>
|
/>
|
@ -1,5 +1,17 @@
|
|||||||
import { transformRecordToOption } from '@/utils/common';
|
import { transformRecordToOption } from '@/utils/common';
|
||||||
|
|
||||||
|
export const businessStatusRecord: Record<Api.Workflow.BusinessStatus, string> = {
|
||||||
|
cancel: '已撤销',
|
||||||
|
draft: '草稿',
|
||||||
|
waiting: '待审批',
|
||||||
|
finish: '已完成',
|
||||||
|
invalid: '已作废',
|
||||||
|
back: '已退回',
|
||||||
|
termination: '已终止'
|
||||||
|
};
|
||||||
|
|
||||||
|
export const businessStatusOptions = transformRecordToOption(businessStatusRecord);
|
||||||
|
|
||||||
export const messageTypeRecord: Record<Api.Workflow.MessageType, string> = {
|
export const messageTypeRecord: Record<Api.Workflow.MessageType, string> = {
|
||||||
'1': '站内信',
|
'1': '站内信',
|
||||||
'2': '邮件',
|
'2': '邮件',
|
||||||
|
@ -10,7 +10,7 @@ export function fetchGetLeaveList(params?: Api.Workflow.LeaveSearchParams) {
|
|||||||
}
|
}
|
||||||
/** 获取请假申请详情 */
|
/** 获取请假申请详情 */
|
||||||
export function fetchGetLeaveDetail(id: CommonType.IdType) {
|
export function fetchGetLeaveDetail(id: CommonType.IdType) {
|
||||||
return request<Api.Workflow.LeaveOperateParams>({
|
return request<Api.Workflow.LeaveDetail>({
|
||||||
url: `/workflow/leave/${id}`,
|
url: `/workflow/leave/${id}`,
|
||||||
method: 'get'
|
method: 'get'
|
||||||
});
|
});
|
||||||
@ -41,3 +41,11 @@ export function fetchBatchDeleteLeave(ids: CommonType.IdType[]) {
|
|||||||
method: 'delete'
|
method: 'delete'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 撤销请假申请 */
|
||||||
|
export function fetchCancelLeave(id: CommonType.IdType) {
|
||||||
|
return request<boolean>({
|
||||||
|
url: `/workflow/leave/cancel/${id}`,
|
||||||
|
method: 'put'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
11
src/typings/api/workflow.api.d.ts
vendored
11
src/typings/api/workflow.api.d.ts
vendored
@ -10,10 +10,14 @@ declare namespace Api {
|
|||||||
* backend api module: "Workflow"
|
* backend api module: "Workflow"
|
||||||
*/
|
*/
|
||||||
namespace Workflow {
|
namespace Workflow {
|
||||||
|
/** 业务流程状态 */
|
||||||
|
type BusinessStatus = 'cancel' | 'draft' | 'waiting' | 'finish' | 'invalid' | 'back' | 'termination';
|
||||||
|
|
||||||
/** 流程类型 */
|
/** 流程类型 */
|
||||||
type FlowCodeType = 'leave1' | 'leave2' | 'leave3' | 'leave4' | 'leave5' | 'leave6';
|
type FlowCodeType = 'leave1' | 'leave2' | 'leave3' | 'leave4' | 'leave5' | 'leave6';
|
||||||
/** 请假状态 */
|
/** 请假状态 */
|
||||||
type LeaveType = '1' | '2' | '3' | '4';
|
type LeaveType = '1' | '2' | '3' | '4';
|
||||||
|
|
||||||
/** leave */
|
/** leave */
|
||||||
type Leave = Common.CommonRecord<{
|
type Leave = Common.CommonRecord<{
|
||||||
/** id */
|
/** id */
|
||||||
@ -31,7 +35,7 @@ declare namespace Api {
|
|||||||
/** 请假原因 */
|
/** 请假原因 */
|
||||||
remark: string;
|
remark: string;
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
status: string;
|
status: BusinessStatus;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
/** leave search params */
|
/** leave search params */
|
||||||
@ -44,6 +48,11 @@ declare namespace Api {
|
|||||||
Pick<Api.Workflow.Leave, 'id' | 'leaveType' | 'startDate' | 'endDate' | 'leaveDays' | 'remark'>
|
Pick<Api.Workflow.Leave, 'id' | 'leaveType' | 'startDate' | 'endDate' | 'leaveDays' | 'remark'>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
/** leave detail */
|
||||||
|
type LeaveDetail = CommonType.RecordNullable<
|
||||||
|
Pick<Api.Workflow.Leave, 'id' | 'leaveType' | 'startDate' | 'endDate' | 'leaveDays' | 'remark' | 'status'>
|
||||||
|
>;
|
||||||
|
|
||||||
/** leave list */
|
/** leave list */
|
||||||
type LeaveList = Api.Common.PaginatingQueryRecord<Leave>;
|
type LeaveList = Api.Common.PaginatingQueryRecord<Leave>;
|
||||||
/** 工作流分类 */
|
/** 工作流分类 */
|
||||||
|
2
src/typings/common.d.ts
vendored
2
src/typings/common.d.ts
vendored
@ -43,4 +43,6 @@ declare namespace CommonType {
|
|||||||
/** filter function */
|
/** filter function */
|
||||||
filterFn?: (node: any) => boolean;
|
filterFn?: (node: any) => boolean;
|
||||||
};
|
};
|
||||||
|
/** the type of workflow table operate */
|
||||||
|
type WorkflowTableOperateType = 'add' | 'edit' | 'detail' | 'approval';
|
||||||
}
|
}
|
||||||
|
9
src/typings/components.d.ts
vendored
9
src/typings/components.d.ts
vendored
@ -56,7 +56,7 @@ declare module 'vue' {
|
|||||||
IconUilSearch: typeof import('~icons/uil/search')['default']
|
IconUilSearch: typeof import('~icons/uil/search')['default']
|
||||||
JsonPreview: typeof import('./../components/custom/json-preview.vue')['default']
|
JsonPreview: typeof import('./../components/custom/json-preview.vue')['default']
|
||||||
LangSwitch: typeof import('./../components/common/lang-switch.vue')['default']
|
LangSwitch: typeof import('./../components/common/lang-switch.vue')['default']
|
||||||
LeaveEdit: typeof import('./../components/custom/leave-edit/index.vue')['default']
|
LeaveEdit: typeof import('./../components/custom/work-flow/leave-edit/index.vue')['default']
|
||||||
LeaveForm: typeof import('../components/custom/workflow-leave-form.vue')['default']
|
LeaveForm: typeof import('../components/custom/workflow-leave-form.vue')['default']
|
||||||
LookForward: typeof import('./../components/custom/look-forward.vue')['default']
|
LookForward: typeof import('./../components/custom/look-forward.vue')['default']
|
||||||
MenuToggler: typeof import('./../components/common/menu-toggler.vue')['default']
|
MenuToggler: typeof import('./../components/common/menu-toggler.vue')['default']
|
||||||
@ -79,6 +79,7 @@ declare module 'vue' {
|
|||||||
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
||||||
NDataTable: typeof import('naive-ui')['NDataTable']
|
NDataTable: typeof import('naive-ui')['NDataTable']
|
||||||
NDatePicker: typeof import('naive-ui')['NDatePicker']
|
NDatePicker: typeof import('naive-ui')['NDatePicker']
|
||||||
|
NDescription: typeof import('naive-ui')['NDescription']
|
||||||
NDescriptions: typeof import('naive-ui')['NDescriptions']
|
NDescriptions: typeof import('naive-ui')['NDescriptions']
|
||||||
NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem']
|
NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem']
|
||||||
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
|
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
|
||||||
@ -128,6 +129,8 @@ declare module 'vue' {
|
|||||||
NTag: typeof import('naive-ui')['NTag']
|
NTag: typeof import('naive-ui')['NTag']
|
||||||
NText: typeof import('naive-ui')['NText']
|
NText: typeof import('naive-ui')['NText']
|
||||||
NThing: typeof import('naive-ui')['NThing']
|
NThing: typeof import('naive-ui')['NThing']
|
||||||
|
NTimeline: typeof import('naive-ui')['NTimeline']
|
||||||
|
NTimelineItem: typeof import('naive-ui')['NTimelineItem']
|
||||||
NTooltip: typeof import('naive-ui')['NTooltip']
|
NTooltip: typeof import('naive-ui')['NTooltip']
|
||||||
NTree: typeof import('naive-ui')['NTree']
|
NTree: typeof import('naive-ui')['NTree']
|
||||||
NTreeSelect: typeof import('naive-ui')['NTreeSelect']
|
NTreeSelect: typeof import('naive-ui')['NTreeSelect']
|
||||||
@ -154,7 +157,7 @@ declare module 'vue' {
|
|||||||
TinymceEditor: typeof import('./../components/custom/tinymce-editor.vue')['default']
|
TinymceEditor: typeof import('./../components/custom/tinymce-editor.vue')['default']
|
||||||
UserSelect: typeof import('./../components/custom/user-select.vue')['default']
|
UserSelect: typeof import('./../components/custom/user-select.vue')['default']
|
||||||
WaveBg: typeof import('./../components/custom/wave-bg.vue')['default']
|
WaveBg: typeof import('./../components/custom/wave-bg.vue')['default']
|
||||||
WorkflowCategorySelect: typeof import('./../components/custom/workflow-category-select.vue')['default']
|
WorkflowCategorySelect: typeof import('./../components/custom/work-flow/workflow-category-select.vue')['default']
|
||||||
WorkflowTaskApplyModal: typeof import('./../components/custom/workflow-task-apply-modal.vue')['default']
|
WorkflowTaskApplyModal: typeof import('./../components/custom/work-flow/workflow-task-apply-modal.vue')['default']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<script setup lang="tsx">
|
<script setup lang="tsx">
|
||||||
|
import { ref } from 'vue';
|
||||||
import { NDivider, NTag } from 'naive-ui';
|
import { NDivider, NTag } from 'naive-ui';
|
||||||
|
import { jsonClone } from '@sa/utils';
|
||||||
import { leaveTypeRecord } from '@/constants/workflow';
|
import { leaveTypeRecord } from '@/constants/workflow';
|
||||||
import { fetchBatchDeleteLeave, fetchGetLeaveList } from '@/service/api/workflow';
|
import { fetchBatchDeleteLeave, fetchGetLeaveList } from '@/service/api/workflow';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
@ -10,7 +12,7 @@ import { useDict } from '@/hooks/business/dict';
|
|||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import DictTag from '@/components/custom/dict-tag.vue';
|
import DictTag from '@/components/custom/dict-tag.vue';
|
||||||
import ButtonIcon from '@/components/custom/button-icon.vue';
|
import ButtonIcon from '@/components/custom/button-icon.vue';
|
||||||
import LeaveOperateDrawer from './modules/leave-operate-drawer.vue';
|
import LeaveEdit from '@/components/custom/work-flow/leave-edit/index.vue';
|
||||||
import LeaveSearch from './modules/leave-search.vue';
|
import LeaveSearch from './modules/leave-search.vue';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -23,6 +25,7 @@ const { hasAuth } = useAuth();
|
|||||||
|
|
||||||
useDict('wf_business_status');
|
useDict('wf_business_status');
|
||||||
|
|
||||||
|
const workflowTableOperateType = ref<CommonType.WorkflowTableOperateType>('add');
|
||||||
const {
|
const {
|
||||||
columns,
|
columns,
|
||||||
columnChecks,
|
columnChecks,
|
||||||
@ -78,7 +81,10 @@ const {
|
|||||||
key: 'leaveDays',
|
key: 'leaveDays',
|
||||||
title: '请假天数',
|
title: '请假天数',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
minWidth: 100
|
minWidth: 100,
|
||||||
|
render: row => {
|
||||||
|
return `${row.leaveDays} 天`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'remark',
|
key: 'remark',
|
||||||
@ -101,18 +107,31 @@ const {
|
|||||||
align: 'center',
|
align: 'center',
|
||||||
width: 130,
|
width: 130,
|
||||||
render: row => {
|
render: row => {
|
||||||
const divider = () => {
|
const buttons = [];
|
||||||
if (!hasAuth('workflow:leave:edit') || !hasAuth('workflow:leave:remove')) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return <NDivider vertical />;
|
|
||||||
};
|
|
||||||
|
|
||||||
const editBtn = () => {
|
const showEdit =
|
||||||
if (!hasAuth('workflow:leave:edit')) {
|
hasAuth('workflow:leave:edit') &&
|
||||||
return null;
|
(row.status === 'draft' || row.status === 'cancel' || row.status === 'back');
|
||||||
|
|
||||||
|
const showDelete =
|
||||||
|
hasAuth('workflow:leave:remove') &&
|
||||||
|
(row.status === 'draft' || row.status === 'cancel' || row.status === 'back');
|
||||||
|
|
||||||
|
const showCancel = row.status === 'waiting';
|
||||||
|
if (hasAuth('workflow:leave:query')) {
|
||||||
|
buttons.push(
|
||||||
|
<ButtonIcon
|
||||||
|
text
|
||||||
|
type="info"
|
||||||
|
icon="material-symbols:visibility-outline"
|
||||||
|
tooltipContent="查看"
|
||||||
|
onClick={() => view(row.id!)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return (
|
|
||||||
|
if (showEdit) {
|
||||||
|
buttons.push(
|
||||||
<ButtonIcon
|
<ButtonIcon
|
||||||
text
|
text
|
||||||
type="primary"
|
type="primary"
|
||||||
@ -121,13 +140,23 @@ const {
|
|||||||
onClick={() => edit(row.id!)}
|
onClick={() => edit(row.id!)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
const deleteBtn = () => {
|
|
||||||
if (!hasAuth('workflow:leave:remove')) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return (
|
|
||||||
|
if (showCancel) {
|
||||||
|
buttons.push(
|
||||||
|
<ButtonIcon
|
||||||
|
text
|
||||||
|
type="warning"
|
||||||
|
icon="material-symbols:cancel-outline"
|
||||||
|
tooltipContent="撤销"
|
||||||
|
popconfirmContent="确定要撤销该申请吗?"
|
||||||
|
onPositiveClick={() => {}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDelete) {
|
||||||
|
buttons.push(
|
||||||
<ButtonIcon
|
<ButtonIcon
|
||||||
text
|
text
|
||||||
type="error"
|
type="error"
|
||||||
@ -137,22 +166,24 @@ const {
|
|||||||
onPositiveClick={() => handleDelete(row.id!)}
|
onPositiveClick={() => handleDelete(row.id!)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
// 插入分隔符(仅在前后两个按钮之间插入 Divider)
|
||||||
<div class="flex-center gap-8px">
|
const buttonWithDividers = buttons.flatMap((btn, index) => {
|
||||||
{editBtn()}
|
if (index === 0) return [btn];
|
||||||
{divider()}
|
return [<NDivider vertical />, btn];
|
||||||
{deleteBtn()}
|
});
|
||||||
</div>
|
|
||||||
);
|
return <div class="flex-center gap-4px">{buttonWithDividers}</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
const { drawerVisible, operateType, editingData, handleAdd, handleEdit, checkedRowKeys, onBatchDeleted, onDeleted } =
|
const { drawerVisible, openDrawer, editingData, checkedRowKeys, onBatchDeleted, onDeleted } = useTableOperate(
|
||||||
useTableOperate(data, getData);
|
data,
|
||||||
|
getData
|
||||||
|
);
|
||||||
|
|
||||||
async function handleBatchDelete() {
|
async function handleBatchDelete() {
|
||||||
// request
|
// request
|
||||||
@ -168,8 +199,25 @@ async function handleDelete(id: CommonType.IdType) {
|
|||||||
onDeleted();
|
onDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleAdd() {
|
||||||
|
workflowTableOperateType.value = 'add';
|
||||||
|
openDrawer();
|
||||||
|
}
|
||||||
|
|
||||||
|
function cloneAndOpenDrawer(id: CommonType.IdType) {
|
||||||
|
const findItem = data.value.find(item => item.id === id) || null;
|
||||||
|
editingData.value = jsonClone(findItem);
|
||||||
|
openDrawer();
|
||||||
|
}
|
||||||
|
|
||||||
function edit(id: CommonType.IdType) {
|
function edit(id: CommonType.IdType) {
|
||||||
handleEdit('id', id);
|
workflowTableOperateType.value = 'edit';
|
||||||
|
cloneAndOpenDrawer(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function view(id: CommonType.IdType) {
|
||||||
|
workflowTableOperateType.value = 'detail';
|
||||||
|
cloneAndOpenDrawer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExport() {
|
function handleExport() {
|
||||||
@ -208,9 +256,9 @@ function handleExport() {
|
|||||||
:pagination="mobilePagination"
|
:pagination="mobilePagination"
|
||||||
class="sm:h-full"
|
class="sm:h-full"
|
||||||
/>
|
/>
|
||||||
<LeaveOperateDrawer
|
<LeaveEdit
|
||||||
v-model:visible="drawerVisible"
|
v-model:visible="drawerVisible"
|
||||||
:operate-type="operateType"
|
:operate-type="workflowTableOperateType"
|
||||||
:row-data="editingData"
|
:row-data="editingData"
|
||||||
@submitted="getDataByPage"
|
@submitted="getDataByPage"
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user