2024-12-12 16:07:42 +08:00
|
|
|
<script setup lang="ts">
|
2024-12-16 16:48:18 +08:00
|
|
|
import { computed, onMounted } from 'vue';
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
|
|
|
import { Card } from 'ant-design-vue';
|
|
|
|
import dayjs from 'dayjs';
|
2024-12-16 16:48:18 +08:00
|
|
|
import { cloneDeep } from 'lodash-es';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
|
|
|
import { useVbenForm } from '#/adapter/form';
|
|
|
|
|
2024-12-16 16:48:18 +08:00
|
|
|
import { leaveAdd, leaveInfo } from './api';
|
2024-12-12 16:07:42 +08:00
|
|
|
import { modalSchema } from './data';
|
|
|
|
|
|
|
|
const route = useRoute();
|
2024-12-16 16:48:18 +08:00
|
|
|
const readonly = route.query?.readonly === 'true';
|
2024-12-12 16:07:42 +08:00
|
|
|
const id = route.query?.id as string;
|
|
|
|
|
2024-12-16 16:48:18 +08:00
|
|
|
/**
|
|
|
|
* id存在&readonly时候
|
|
|
|
*/
|
|
|
|
const showActionBtn = computed(() => {
|
|
|
|
return id && !readonly;
|
|
|
|
});
|
|
|
|
|
2024-12-12 16:07:42 +08:00
|
|
|
const [BasicForm, formApi] = useVbenForm({
|
|
|
|
commonConfig: {
|
|
|
|
// 默认占满两列
|
|
|
|
formItemClass: 'col-span-2',
|
|
|
|
// 默认label宽度 px
|
|
|
|
labelWidth: 80,
|
|
|
|
// 通用配置项 会影响到所有表单项
|
|
|
|
componentProps: {
|
|
|
|
class: 'w-full',
|
2024-12-16 16:48:18 +08:00
|
|
|
disabled: readonly,
|
2024-12-12 16:07:42 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
schema: modalSchema(),
|
|
|
|
showDefaultActions: false,
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
// 只读 获取信息赋值
|
2024-12-16 16:48:18 +08:00
|
|
|
if (id) {
|
2024-12-12 16:07:42 +08:00
|
|
|
const resp = await leaveInfo(id);
|
|
|
|
await formApi.setValues(resp);
|
|
|
|
const dateRange = [dayjs(resp.startDate), dayjs(resp.endDate)];
|
|
|
|
await formApi.setFieldValue('dateRange', dateRange);
|
|
|
|
}
|
|
|
|
});
|
2024-12-16 16:48:18 +08:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
async function handleTempSave() {
|
|
|
|
try {
|
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const data = cloneDeep(await formApi.getValues()) as any;
|
|
|
|
// 处理日期
|
|
|
|
data.startDate = dayjs(data.dateRange[0]).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
data.endDate = dayjs(data.dateRange[1]).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
await leaveAdd(data);
|
|
|
|
router.push('/demo/leave');
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
2024-12-12 16:07:42 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<Card>
|
2024-12-16 13:53:58 +08:00
|
|
|
<div id="leave-form">
|
|
|
|
<BasicForm />
|
2024-12-16 16:48:18 +08:00
|
|
|
<div v-if="showActionBtn" class="flex justify-end gap-2">
|
|
|
|
<a-button @click="handleTempSave">暂存</a-button>
|
|
|
|
<a-button type="primary">提交</a-button>
|
|
|
|
</div>
|
2024-12-16 13:53:58 +08:00
|
|
|
</div>
|
2024-12-12 16:07:42 +08:00
|
|
|
</Card>
|
|
|
|
</template>
|
2024-12-16 13:53:58 +08:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
/**
|
|
|
|
去除 '菜单加载中' 主要是iframe内嵌使用
|
|
|
|
*/
|
|
|
|
html:has(#leave-form) {
|
|
|
|
.ant-message-notice-content:has(.ant-message-loading) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|