gtsoft-snail-job-admin/src/views/notify/recipient/modules/notify-recipient-operate-drawer.vue

126 lines
3.8 KiB
Vue
Raw Normal View History

2024-04-17 23:20:57 +08:00
<script setup lang="ts">
2024-04-18 23:33:34 +08:00
import { computed, ref, watch } from 'vue';
import { useNaiveForm } from '@/hooks/common/form';
2024-04-17 23:20:57 +08:00
import OperateDrawer from '@/components/common/operate-drawer.vue';
import { $t } from '@/locales';
2024-04-18 23:33:34 +08:00
import { fetchAddNotifyRecipient, fetchEditNotifyRecipient } from '@/service/api';
import DingDingForm from './dingding-form.vue';
import LarkForm from './lark-form.vue';
import EmailForm from './email-form.vue';
import WeComForm from './wecom-form.vue';
2024-04-17 23:20:57 +08:00
defineOptions({
name: 'NotifyRecipientOperateDrawer'
});
const CommonRef = ref();
2024-04-17 23:20:57 +08:00
interface Props {
/** the type of operation */
operateType: NaiveUI.TableOperateType;
/** the edit row data */
rowData?: Api.NotifyRecipient.NotifyRecipient | null;
}
const props = defineProps<Props>();
interface Emits {
(e: 'submitted'): void;
}
const emit = defineEmits<Emits>();
const visible = defineModel<boolean>('visible', {
default: false
});
2024-04-18 23:33:34 +08:00
const defaultTabPane = defineModel<string>('defaultTabPane', {
default: '1'
});
const { restoreValidation } = useNaiveForm();
2024-04-17 23:20:57 +08:00
const title = computed(() => {
const titles: Record<NaiveUI.TableOperateType, string> = {
add: $t('page.notifyRecipient.addNotifyRecipient'),
edit: $t('page.notifyRecipient.editNotifyRecipient')
};
return titles[props.operateType];
});
function handleUpdateModelWhenEdit() {
if (props.operateType === 'add') {
2024-04-18 23:33:34 +08:00
CommonRef.value?.createDefaultModel();
2024-04-17 23:20:57 +08:00
return;
}
if (props.operateType === 'edit' && props.rowData) {
2024-04-18 23:33:34 +08:00
defaultTabPane.value = props.rowData.notifyType.toString();
CommonRef.value?.showData(props.rowData);
2024-04-17 23:20:57 +08:00
}
}
async function handleSubmit() {
// request
if (props.operateType === 'add') {
CommonRef.value?.save();
2024-04-17 23:20:57 +08:00
}
if (props.operateType === 'edit') {
2024-04-18 23:33:34 +08:00
CommonRef.value?.update();
2024-04-17 23:20:57 +08:00
}
2024-04-18 23:33:34 +08:00
2024-04-17 23:20:57 +08:00
emit('submitted');
}
const commonFetchAdd = (dingDingModel: Api.NotifyRecipient.NotifyRecipient) => {
const { recipientName, notifyAttribute, notifyType, description } = dingDingModel;
fetchAddNotifyRecipient({ recipientName, notifyAttribute, notifyType, description });
2024-04-18 23:33:34 +08:00
window.$message?.success($t('common.addSuccess'));
};
const commonFetchUpdate = (dingDingModel: Api.NotifyRecipient.NotifyRecipient) => {
const { id, recipientName, notifyAttribute, notifyType, description } = dingDingModel;
fetchEditNotifyRecipient({ id, recipientName, notifyAttribute, notifyType, description });
window.$message?.success($t('common.updateSuccess'));
};
function closeDrawer() {
visible.value = false;
}
2024-04-17 23:20:57 +08:00
watch(visible, () => {
if (visible.value) {
handleUpdateModelWhenEdit();
restoreValidation();
}
});
</script>
<template>
<OperateDrawer v-model="visible" :title="title" @handle-submit="handleSubmit">
2024-04-18 23:33:34 +08:00
<NTabs v-model:value="defaultTabPane" type="segment" animated>
<NTabPane name="1" :tab="$t('page.notifyRecipient.dingDing')">
2024-04-18 23:33:34 +08:00
<DingDingForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
</NTabPane>
<NTabPane name="2" :tab="$t('page.notifyRecipient.email')">
2024-04-18 23:33:34 +08:00
<EmailForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
</NTabPane>
<NTabPane name="3" :tab="$t('page.notifyRecipient.weCom')">
<WeComForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
</NTabPane>
<NTabPane name="4" :tab="$t('page.notifyRecipient.lark')">
2024-04-18 23:33:34 +08:00
<LarkForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
</NTabPane>
</NTabs>
2024-04-18 14:49:49 +08:00
<template #footer>
<NSpace :size="16">
<NButton @click="closeDrawer">{{ $t('common.cancel') }}</NButton>
<NButton type="primary" @click="handleSubmit">{{ $t('common.save') }}</NButton>
</NSpace>
</template>
2024-04-17 23:20:57 +08:00
</OperateDrawer>
</template>
<style scoped></style>