2024-03-11 14:19:36 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="page-bg-wrap">
|
|
|
|
|
<div class="top-toolbar">
|
|
|
|
|
<a-space :size="10" wrap>
|
|
|
|
|
<a-button style="margin-right: 10px" @click="close">
|
|
|
|
|
<slot name="icon">
|
|
|
|
|
<close-outlined />
|
|
|
|
|
</slot>
|
|
|
|
|
关闭
|
|
|
|
|
</a-button>
|
2024-04-28 10:26:39 +08:00
|
|
|
<a-button v-if="mode != 'view'" type="primary" @click="handleSubmit">
|
2024-04-24 10:47:28 +08:00
|
|
|
<slot name="icon">
|
|
|
|
|
<check-circle-outlined />
|
|
|
|
|
</slot>
|
2024-04-28 10:26:39 +08:00
|
|
|
确认
|
2024-04-24 18:19:12 +08:00
|
|
|
</a-button>
|
2024-03-11 14:19:36 +08:00
|
|
|
</a-space>
|
|
|
|
|
</div>
|
|
|
|
|
<component :is="dynamicComponent" ref="formRef" :fromPage="FromPageType.MENU" @form-mounted="onFormMounted" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-04-02 14:18:15 +08:00
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
import { FromPageType } from '/@/enums/workflowEnum';
|
2024-04-28 10:26:39 +08:00
|
|
|
import { ref, computed, onMounted, onBeforeMount, nextTick, defineAsyncComponent } from 'vue';
|
2024-04-02 14:18:15 +08:00
|
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
2024-04-28 10:26:39 +08:00
|
|
|
import { CheckCircleOutlined, StopOutlined, CloseOutlined } from '@ant-design/icons-vue';
|
2024-04-02 14:18:15 +08:00
|
|
|
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
|
|
|
|
|
import useEventBus from '/@/hooks/event/useEventBus';
|
2024-04-28 10:26:39 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
const dynamicComponent = ref(null);
|
|
|
|
|
const formType = ref('2'); // 0 新建 1 修改 2 查看
|
|
|
|
|
const formRef = ref();
|
|
|
|
|
const props = defineProps({});
|
|
|
|
|
const { bus, FORM_LIST_MODIFIED } = useEventBus();
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
const router = useRouter();
|
|
|
|
|
const { currentRoute } = router;
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-28 10:26:39 +08:00
|
|
|
const { formPath } = currentRoute.value.query;
|
2024-04-02 14:18:15 +08:00
|
|
|
const pathArr = formPath.split('/');
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
const tabStore = useMultipleTabStore();
|
|
|
|
|
const formProps = ref(null);
|
|
|
|
|
const formId = ref(currentRoute.value?.params?.id);
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
const { notification } = useMessage();
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
const hash = location.hash;
|
|
|
|
|
const mode = ref('read');
|
|
|
|
|
if (hash.indexOf('createForm') > 0) {
|
|
|
|
|
mode.value = 'create';
|
|
|
|
|
} else if (hash.indexOf('updateForm') > 0) {
|
|
|
|
|
mode.value = 'update';
|
|
|
|
|
} else if (hash.indexOf('viewForm') > 0) {
|
|
|
|
|
mode.value = 'view';
|
|
|
|
|
}
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
dynamicComponent.value = defineAsyncComponent({
|
|
|
|
|
loader: () => import(`./../../views/${pathArr[0]}/${pathArr[1]}/components/Form.vue`)
|
|
|
|
|
});
|
2024-04-24 10:47:28 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
function onFormMounted(_formProps) {
|
|
|
|
|
formProps.value = _formProps;
|
|
|
|
|
setFormType();
|
|
|
|
|
}
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
async function setFormType() {
|
|
|
|
|
const _mode = mode.value;
|
|
|
|
|
if (_mode === 'create') {
|
|
|
|
|
return;
|
2024-03-11 14:19:36 +08:00
|
|
|
}
|
2024-04-02 14:18:15 +08:00
|
|
|
await nextTick();
|
|
|
|
|
if (_mode === 'view') {
|
2024-04-24 18:33:21 +08:00
|
|
|
await formRef.value.setDisabledForm();
|
2024-03-11 14:19:36 +08:00
|
|
|
}
|
2024-04-02 14:18:15 +08:00
|
|
|
await formRef.value.setFormDataFromId(formId.value);
|
|
|
|
|
}
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
function close() {
|
2024-04-25 10:43:33 +08:00
|
|
|
tabStore.closeTab(currentRoute.value, router);
|
2024-04-02 14:18:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
|
try {
|
|
|
|
|
const saveSuccess = await saveModal();
|
|
|
|
|
if (saveSuccess) {
|
|
|
|
|
notification.success({
|
|
|
|
|
message: 'Tip',
|
|
|
|
|
description: formType.value === '0' ? t('新增成功!') : t('修改成功!')
|
|
|
|
|
}); //提示消息
|
|
|
|
|
formRef.value.resetFields();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
bus.emit(FORM_LIST_MODIFIED, { path: formPath, mode });
|
|
|
|
|
close();
|
|
|
|
|
}, 1000);
|
2024-03-11 14:19:36 +08:00
|
|
|
}
|
2024-04-02 14:18:15 +08:00
|
|
|
} finally {
|
2024-03-11 14:19:36 +08:00
|
|
|
}
|
2024-04-02 14:18:15 +08:00
|
|
|
}
|
2024-03-11 14:19:36 +08:00
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
async function saveModal() {
|
|
|
|
|
let saveSuccess = false;
|
|
|
|
|
const _mode = mode.value;
|
|
|
|
|
try {
|
|
|
|
|
const values = await formRef.value?.validate();
|
|
|
|
|
//添加隐藏组件
|
|
|
|
|
if (formProps.hiddenComponent?.length) {
|
|
|
|
|
formProps.hiddenComponent.forEach((component) => {
|
|
|
|
|
values[component.bindField] = component.value;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (values !== false) {
|
|
|
|
|
try {
|
|
|
|
|
if (_mode === 'create') {
|
|
|
|
|
saveSuccess = await formRef.value.add(values);
|
|
|
|
|
} else {
|
|
|
|
|
saveSuccess = await formRef.value.update({ values, rowId: formId.value });
|
|
|
|
|
}
|
|
|
|
|
return saveSuccess;
|
|
|
|
|
} catch (error) { }
|
2024-03-11 14:19:36 +08:00
|
|
|
}
|
2024-04-02 14:18:15 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('saveModal Error: ', error);
|
2024-03-11 14:19:36 +08:00
|
|
|
}
|
2024-04-02 14:18:15 +08:00
|
|
|
}
|
2024-03-11 14:19:36 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
2024-04-28 10:26:39 +08:00
|
|
|
.page-bg-wrap {
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 14:18:15 +08:00
|
|
|
.top-toolbar {
|
2024-04-22 09:05:36 +08:00
|
|
|
min-height: 44px;
|
|
|
|
|
margin-bottom: 12px;
|
2024-04-02 14:18:15 +08:00
|
|
|
border-bottom: 1px solid #eee;
|
|
|
|
|
}
|
2024-03-11 14:19:36 +08:00
|
|
|
</style>
|