diff --git a/src/views/notice/Config/Detail/index.vue b/src/views/notice/Config/Detail/index.vue index 7a5a85b8..88a92a1e 100644 --- a/src/views/notice/Config/Detail/index.vue +++ b/src/views/notice/Config/Detail/index.vue @@ -336,23 +336,9 @@ watch( route.params.id !== ':id' ? formData.value.provider : msgType.value[0].value; - - // formData.value.configuration = - // CONFIG_FIELD_MAP[val][formData.value.provider]; - - // clearValid(); }, ); -// watch( -// () => formData.value.provider, -// (val) => { -// // formData.value.configuration = -// // CONFIG_FIELD_MAP[formData.value.type][val]; -// // clearValid(); -// }, -// ); - // 验证规则 const formRules = ref({ type: [{ required: true, message: '请选择通知方式' }], @@ -421,12 +407,6 @@ const { resetFields, validate, validateInfos, clearValidate } = useForm( formRules.value, ); -const clearValid = () => { - setTimeout(() => { - clearValidate(); - }, 200); -}; - const getDetail = async () => { if (route.params.id === ':id') return; const res = await configApi.detail(route.params.id as string); @@ -444,7 +424,7 @@ const handleTypeChange = () => { setTimeout(() => { formData.value.configuration = CONFIG_FIELD_MAP[formData.value.type][formData.value.provider]; - // resetPublicFiles(); + resetPublicFiles(); }, 0); }; @@ -454,7 +434,48 @@ const handleTypeChange = () => { const handleProviderChange = () => { formData.value.configuration = CONFIG_FIELD_MAP[formData.value.type][formData.value.provider]; - // resetPublicFiles(); + resetPublicFiles(); +}; + +/** + * 重置字段值 + */ +const resetPublicFiles = () => { + switch (formData.value.provider) { + case 'dingTalkMessage': + formData.value.configuration.appKey = ''; + formData.value.configuration.appSecret = ''; + break; + case 'dingTalkRobotWebHook': + formData.value.configuration.url = ''; + break; + case 'corpMessage': + formData.value.configuration.corpId = ''; + formData.value.configuration.corpSecret = ''; + break; + case 'embedded': + formData.value.configuration.host = ''; + formData.value.configuration.port = 25; + formData.value.configuration.ssl = false; + formData.value.configuration.sender = ''; + formData.value.configuration.username = ''; + formData.value.configuration.password = ''; + break; + case 'aliyun': + formData.value.configuration.regionId = ''; + formData.value.configuration.accessKeyId = ''; + formData.value.configuration.secret = ''; + break; + case 'aliyunSms': + formData.value.configuration.regionId = ''; + formData.value.configuration.accessKeyId = ''; + formData.value.configuration.secret = ''; + break; + case 'http': + formData.value.configuration.url = undefined; + formData.value.configuration.headers = []; + break; + } }; /** diff --git a/src/views/notice/Template/Detail/index.vue b/src/views/notice/Template/Detail/index.vue index eb5ae295..d16395f3 100644 --- a/src/views/notice/Template/Detail/index.vue +++ b/src/views/notice/Template/Detail/index.vue @@ -106,7 +106,8 @@ ({ }); /** - * 重置公用字段值 + * 重置字段值 */ const resetPublicFiles = () => { - if ( - formData.value.provider === 'dingTalkMessage' || - formData.value.type === 'weixin' - ) { - formData.value.template.toTag = undefined; - formData.value.template.toUser = undefined; - formData.value.template.agentId = undefined; + switch (formData.value.provider) { + case 'dingTalkMessage': + formData.value.template.agentId = ''; + formData.value.template.message = ''; + formData.value.template.departmentIdList = ''; + formData.value.template.userIdList = ''; + break; + case 'dingTalkRobotWebHook': + formData.value.template.message = ''; + formData.value.template.messageType = 'markdown'; + formData.value.template.markdown = { text: '', title: '' }; + break; + case 'corpMessage': + formData.value.template.agentId = ''; + formData.value.template.message = ''; + formData.value.template.toParty = ''; + formData.value.template.toUser = ''; + formData.value.template.toTag = ''; + break; + case 'embedded': + formData.value.template.subject = ''; + formData.value.template.message = ''; + formData.value.template.text = ''; + formData.value.template.sendTo = []; + formData.value.template.attachments = []; + break; + case 'aliyun': + formData.value.template.templateType = 'tts'; + formData.value.template.templateCode = ''; + formData.value.template.ttsCode = ''; + formData.value.template.message = ''; + formData.value.template.playTimes = 1; + formData.value.template.calledShowNumbers = ''; + formData.value.template.calledNumber = ''; + break; + case 'aliyunSms': + formData.value.template.code = ''; + formData.value.template.message = ''; + formData.value.template.phoneNumber = ''; + formData.value.template.signName = ''; + break; + case 'http': + formData.value.template.contextAsBody = true; + formData.value.template.body = ''; + break; } - if (formData.value.type === 'weixin') - formData.value.template.toParty = undefined; - if (formData.value.type === 'email') - formData.value.template.toParty = undefined; - // formData.value.description = ''; - formData.value.template.messageType = 'markdown'; - formData.value.template.message = ''; formData.value.configId = undefined; formData.value.variableDefinitions = []; handleMessageTypeChange(); @@ -833,15 +865,8 @@ watch( route.params.id !== ':id' ? formData.value.provider : msgType.value[0].value; - // formData.value.provider = formData.value.provider || msgType.value[0].value; - // console.log('formData.value.template: ', formData.value.template); - - // formData.value.template = - // TEMPLATE_FIELD_MAP[val][formData.value.provider]; if (val !== 'email') getConfigList(); - // clearValid(); - // console.log('formData.value: ', formData.value); if (val === 'sms') { getTemplateList(); @@ -850,15 +875,6 @@ watch( }, ); -// watch( -// () => formData.value.provider, -// (val) => { -// formData.value.template = TEMPLATE_FIELD_MAP[formData.value.type][val]; - -// clearValid(); -// }, -// ); - // 验证规则 const formRules = ref({ type: [{ required: true, message: '请选择通知方式' }], @@ -1069,6 +1085,7 @@ const handleTypeChange = () => { setTimeout(() => { formData.value.template = TEMPLATE_FIELD_MAP[formData.value.type][formData.value.provider]; + // console.log('formData.value.template: ', formData.value.template); resetPublicFiles(); }, 0); }; @@ -1146,8 +1163,9 @@ const handleSubmit = () => { setTimeout(() => { validate() .then(async () => { - formData.value.template.ttsCode = - formData.value.template.templateCode; + if (formData.value.provider === 'ttsCode') + formData.value.template.ttsCode = + formData.value.template.templateCode; btnLoading.value = true; let res; if (!formData.value.id) { diff --git a/src/views/notice/Template/types.d.ts b/src/views/notice/Template/types.d.ts index bae9e021..23e9ca57 100644 --- a/src/views/notice/Template/types.d.ts +++ b/src/views/notice/Template/types.d.ts @@ -36,6 +36,8 @@ export type TemplateFormData = { // 钉钉消息 agentId?: string; message?: string; + departmentIdList?: string; + userIdList?: string; // 钉钉机器人 messageType?: string; markdown?: IMarkDown; diff --git a/src/views/notice/const.ts b/src/views/notice/const.ts index 32116d21..39c36df7 100644 --- a/src/views/notice/const.ts +++ b/src/views/notice/const.ts @@ -147,10 +147,12 @@ export const TEMPLATE_FIELD_MAP = { dingTalkMessage: { agentId: '', message: '', + departmentIdList: '', + userIdList: '' }, dingTalkRobotWebHook: { message: '', - messageType: '', + messageType: 'markdown', markdown: { text: '', title: '',