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';
|
2024-04-18 16:36:11 +08:00
|
|
|
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';
|
2024-04-18 16:36:11 +08:00
|
|
|
import DingDingForm from './dingding-form.vue';
|
2024-04-18 18:18:02 +08:00
|
|
|
import LarkForm from './lark-form.vue';
|
|
|
|
import EmailForm from './email-form.vue';
|
2024-04-19 12:33:18 +08:00
|
|
|
import WeComForm from './wecom-form.vue';
|
2024-04-17 23:20:57 +08:00
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
name: 'NotifyRecipientOperateDrawer'
|
|
|
|
});
|
|
|
|
|
2024-04-18 18:18:02 +08:00
|
|
|
const CommonRef = ref();
|
2024-04-18 16:36:11 +08:00
|
|
|
|
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'
|
|
|
|
});
|
|
|
|
|
2024-04-18 16:36:11 +08:00
|
|
|
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') {
|
2024-04-18 18:18:02 +08:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:18:02 +08:00
|
|
|
const commonFetchAdd = (dingDingModel: Api.NotifyRecipient.NotifyRecipient) => {
|
2024-04-18 16:36:11 +08:00
|
|
|
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'));
|
2024-04-18 16:36:11 +08:00
|
|
|
};
|
|
|
|
|
2024-04-18 16:41:32 +08:00
|
|
|
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>
|
2024-04-19 12:33:18 +08:00
|
|
|
<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" />
|
2024-04-18 18:18:02 +08:00
|
|
|
</NTabPane>
|
2024-04-19 12:33:18 +08:00
|
|
|
<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" />
|
2024-04-18 16:36:11 +08:00
|
|
|
</NTabPane>
|
2024-04-19 12:33:18 +08:00
|
|
|
<NTabPane name="3" :tab="$t('page.notifyRecipient.weCom')">
|
|
|
|
<WeComForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
|
2024-04-18 16:36:11 +08:00
|
|
|
</NTabPane>
|
2024-04-19 12:33:18 +08:00
|
|
|
<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" />
|
2024-04-18 16:36:11 +08:00
|
|
|
</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>
|