feat(sj_1.0.0): 完成通知更新
This commit is contained in:
parent
b508d87416
commit
6a2c763663
@ -9,6 +9,7 @@ defineOptions({
|
|||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
|
(e: 'fetchUpdate', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
@ -33,12 +34,11 @@ function createDefaultModel(): Model {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'webhookUrl' | 'ats' | 'description'>;
|
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'webhookUrl' | 'ats'>;
|
||||||
|
|
||||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||||
recipientName: defaultRequiredRule,
|
recipientName: defaultRequiredRule,
|
||||||
notifyType: defaultRequiredRule,
|
notifyType: defaultRequiredRule,
|
||||||
description: defaultRequiredRule,
|
|
||||||
webhookUrl: defaultRequiredRule,
|
webhookUrl: defaultRequiredRule,
|
||||||
ats: defaultRequiredRule
|
ats: defaultRequiredRule
|
||||||
};
|
};
|
||||||
@ -49,13 +49,31 @@ const buildNotifyAttribute = (webhookUrl: string, ats: string[]) => {
|
|||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
await validate();
|
await validate();
|
||||||
const { id, recipientName, notifyType, webhookUrl, ats, description } = model;
|
const { recipientName, notifyType, webhookUrl, ats, description } = model;
|
||||||
const notifyAttribute = buildNotifyAttribute(webhookUrl, ats);
|
const notifyAttribute = buildNotifyAttribute(webhookUrl, ats);
|
||||||
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
emit('fetchAdd', { recipientName, notifyType, notifyAttribute, description });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function update() {
|
||||||
|
await validate();
|
||||||
|
const { id, recipientName, notifyType, webhookUrl, ats, description } = model;
|
||||||
|
const notifyAttribute = buildNotifyAttribute(webhookUrl, ats);
|
||||||
|
emit('fetchUpdate', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
|
}
|
||||||
|
|
||||||
|
const showData = (rowData: Api.NotifyRecipient.NotifyRecipient) => {
|
||||||
|
if (rowData.notifyAttribute) {
|
||||||
|
const notifyAttribute = JSON.parse(rowData.notifyAttribute);
|
||||||
|
Object.assign(model, rowData);
|
||||||
|
Object.assign(model, notifyAttribute);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
save
|
save,
|
||||||
|
createDefaultModel,
|
||||||
|
showData,
|
||||||
|
update
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -89,8 +107,8 @@ defineExpose({
|
|||||||
v-model:value="model.description"
|
v-model:value="model.description"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:placeholder="$t('page.notifyRecipient.form.description')"
|
:placeholder="$t('page.notifyRecipient.form.description')"
|
||||||
round
|
|
||||||
clearable
|
clearable
|
||||||
|
round
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</NForm>
|
</NForm>
|
||||||
|
@ -9,6 +9,7 @@ defineOptions({
|
|||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
|
(e: 'fetchUpdate', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
@ -29,12 +30,11 @@ function createDefaultModel(): Model {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'tos' | 'description'>;
|
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'tos'>;
|
||||||
|
|
||||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||||
recipientName: defaultRequiredRule,
|
recipientName: defaultRequiredRule,
|
||||||
notifyType: defaultRequiredRule,
|
notifyType: defaultRequiredRule,
|
||||||
description: defaultRequiredRule,
|
|
||||||
tos: defaultRequiredRule
|
tos: defaultRequiredRule
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,8 +49,26 @@ async function save() {
|
|||||||
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showData = (rowData: Api.NotifyRecipient.NotifyRecipient) => {
|
||||||
|
if (rowData.notifyAttribute) {
|
||||||
|
const notifyAttribute = JSON.parse(rowData.notifyAttribute);
|
||||||
|
Object.assign(model, rowData);
|
||||||
|
Object.assign(model, notifyAttribute);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function update() {
|
||||||
|
await validate();
|
||||||
|
const { id, recipientName, notifyType, tos, description } = model;
|
||||||
|
const notifyAttribute = buildNotifyAttribute(tos);
|
||||||
|
emit('fetchUpdate', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
|
}
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
save
|
save,
|
||||||
|
showData,
|
||||||
|
createDefaultModel,
|
||||||
|
update
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ defineOptions({
|
|||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
|
(e: 'fetchUpdate', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
@ -33,12 +34,11 @@ function createDefaultModel(): Model {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'webhookUrl' | 'ats' | 'description'>;
|
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'webhookUrl' | 'ats'>;
|
||||||
|
|
||||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||||
recipientName: defaultRequiredRule,
|
recipientName: defaultRequiredRule,
|
||||||
notifyType: defaultRequiredRule,
|
notifyType: defaultRequiredRule,
|
||||||
description: defaultRequiredRule,
|
|
||||||
webhookUrl: defaultRequiredRule,
|
webhookUrl: defaultRequiredRule,
|
||||||
ats: defaultRequiredRule
|
ats: defaultRequiredRule
|
||||||
};
|
};
|
||||||
@ -54,8 +54,26 @@ async function save() {
|
|||||||
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function update() {
|
||||||
|
await validate();
|
||||||
|
const { id, recipientName, notifyType, webhookUrl, ats, description } = model;
|
||||||
|
const notifyAttribute = buildNotifyAttribute(webhookUrl, ats);
|
||||||
|
emit('fetchUpdate', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
|
}
|
||||||
|
|
||||||
|
const showData = (rowData: Api.NotifyRecipient.NotifyRecipient) => {
|
||||||
|
if (rowData.notifyAttribute) {
|
||||||
|
const notifyAttribute = JSON.parse(rowData.notifyAttribute);
|
||||||
|
Object.assign(model, rowData);
|
||||||
|
Object.assign(model, notifyAttribute);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
save
|
save,
|
||||||
|
showData,
|
||||||
|
createDefaultModel,
|
||||||
|
update
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, reactive, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useNaiveForm } from '@/hooks/common/form';
|
import { useNaiveForm } from '@/hooks/common/form';
|
||||||
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { fetchAddNotifyRecipient } from '@/service/api';
|
import { fetchAddNotifyRecipient, fetchEditNotifyRecipient } from '@/service/api';
|
||||||
import DingDingForm from './dingding-form.vue';
|
import DingDingForm from './dingding-form.vue';
|
||||||
import LarkForm from './lark-form.vue';
|
import LarkForm from './lark-form.vue';
|
||||||
import EmailForm from './email-form.vue';
|
import EmailForm from './email-form.vue';
|
||||||
@ -34,6 +34,10 @@ const visible = defineModel<boolean>('visible', {
|
|||||||
default: false
|
default: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultTabPane = defineModel<string>('defaultTabPane', {
|
||||||
|
default: '1'
|
||||||
|
});
|
||||||
|
|
||||||
const { restoreValidation } = useNaiveForm();
|
const { restoreValidation } = useNaiveForm();
|
||||||
|
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
@ -44,30 +48,15 @@ const title = computed(() => {
|
|||||||
return titles[props.operateType];
|
return titles[props.operateType];
|
||||||
});
|
});
|
||||||
|
|
||||||
type Model = Pick<
|
|
||||||
Api.NotifyRecipient.NotifyRecipient,
|
|
||||||
'id' | 'recipientName' | 'notifyType' | 'notifyAttribute' | 'description'
|
|
||||||
>;
|
|
||||||
|
|
||||||
const model: Model = reactive(createDefaultModel());
|
|
||||||
|
|
||||||
function createDefaultModel(): Model {
|
|
||||||
return {
|
|
||||||
recipientName: '',
|
|
||||||
notifyType: 1,
|
|
||||||
notifyAttribute: '',
|
|
||||||
description: ''
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleUpdateModelWhenEdit() {
|
function handleUpdateModelWhenEdit() {
|
||||||
if (props.operateType === 'add') {
|
if (props.operateType === 'add') {
|
||||||
Object.assign(model, createDefaultModel());
|
CommonRef.value?.createDefaultModel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
Object.assign(model, props.rowData);
|
defaultTabPane.value = props.rowData.notifyType.toString();
|
||||||
|
CommonRef.value?.showData(props.rowData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,15 +67,22 @@ async function handleSubmit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (props.operateType === 'edit') {
|
if (props.operateType === 'edit') {
|
||||||
console.log('更新');
|
CommonRef.value?.update();
|
||||||
}
|
}
|
||||||
window.$message?.success($t('common.updateSuccess'));
|
|
||||||
emit('submitted');
|
emit('submitted');
|
||||||
}
|
}
|
||||||
|
|
||||||
const commonFetchAdd = (dingDingModel: Api.NotifyRecipient.NotifyRecipient) => {
|
const commonFetchAdd = (dingDingModel: Api.NotifyRecipient.NotifyRecipient) => {
|
||||||
const { recipientName, notifyAttribute, notifyType, description } = dingDingModel;
|
const { recipientName, notifyAttribute, notifyType, description } = dingDingModel;
|
||||||
fetchAddNotifyRecipient({ recipientName, notifyAttribute, notifyType, description });
|
fetchAddNotifyRecipient({ recipientName, notifyAttribute, notifyType, description });
|
||||||
|
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() {
|
function closeDrawer() {
|
||||||
@ -103,18 +99,18 @@ watch(visible, () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<OperateDrawer v-model="visible" :title="title" @handle-submit="handleSubmit">
|
<OperateDrawer v-model="visible" :title="title" @handle-submit="handleSubmit">
|
||||||
<NTabs type="segment" animated>
|
<NTabs v-model:value="defaultTabPane" type="segment" animated>
|
||||||
<NTabPane name="dingding" tab="钉钉">
|
<NTabPane name="1" tab="钉钉">
|
||||||
<DingDingForm ref="CommonRef" @fetch-add="commonFetchAdd" />
|
<DingDingForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
<NTabPane name="feishu" tab="飞书">
|
<NTabPane name="2" tab="邮箱">
|
||||||
<LarkForm ref="CommonRef" @fetch-add="commonFetchAdd" />
|
<EmailForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
<NTabPane name="qiYeWeche" tab="企业微信">
|
<NTabPane name="3" tab="企业微信">
|
||||||
<QiyeWechtForm ref="CommonRef" @fetch-add="commonFetchAdd" />
|
<QiyeWechtForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
<NTabPane name="email" tab="邮箱">
|
<NTabPane name="4" tab="飞书">
|
||||||
<EmailForm ref="CommonRef" @fetch-add="commonFetchAdd" />
|
<LarkForm ref="CommonRef" @fetch-add="commonFetchAdd" @fetch-update="commonFetchUpdate" />
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
</NTabs>
|
</NTabs>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
@ -9,6 +9,7 @@ defineOptions({
|
|||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
(e: 'fetchAdd', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
|
(e: 'fetchUpdate', model: Api.NotifyRecipient.NotifyRecipient): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
@ -33,12 +34,11 @@ function createDefaultModel(): Model {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'webhookUrl' | 'ats' | 'description'>;
|
type RuleKey = Extract<keyof Model, 'recipientName' | 'notifyType' | 'webhookUrl' | 'ats'>;
|
||||||
|
|
||||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||||
recipientName: defaultRequiredRule,
|
recipientName: defaultRequiredRule,
|
||||||
notifyType: defaultRequiredRule,
|
notifyType: defaultRequiredRule,
|
||||||
description: defaultRequiredRule,
|
|
||||||
webhookUrl: defaultRequiredRule,
|
webhookUrl: defaultRequiredRule,
|
||||||
ats: defaultRequiredRule
|
ats: defaultRequiredRule
|
||||||
};
|
};
|
||||||
@ -54,8 +54,26 @@ async function save() {
|
|||||||
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
emit('fetchAdd', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function update() {
|
||||||
|
await validate();
|
||||||
|
const { id, recipientName, notifyType, webhookUrl, ats, description } = model;
|
||||||
|
const notifyAttribute = buildNotifyAttribute(webhookUrl, ats);
|
||||||
|
emit('fetchUpdate', { id, recipientName, notifyType, notifyAttribute, description });
|
||||||
|
}
|
||||||
|
|
||||||
|
const showData = (rowData: Api.NotifyRecipient.NotifyRecipient) => {
|
||||||
|
if (rowData.notifyAttribute) {
|
||||||
|
const notifyAttribute = JSON.parse(rowData.notifyAttribute);
|
||||||
|
Object.assign(model, rowData);
|
||||||
|
Object.assign(model, notifyAttribute);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
save
|
save,
|
||||||
|
showData,
|
||||||
|
createDefaultModel,
|
||||||
|
update
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user