From 83a18d21c0ac8ed3711dec3bf2cf0aa099233a68 Mon Sep 17 00:00:00 2001
From: JiangQiming <291854119@qq.com>
Date: Tue, 17 Jan 2023 15:52:34 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E8=AF=A6=E6=83=85?=
=?UTF-8?q?=E8=A1=A8=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/MonacoEditor/index.vue | 3 +-
src/views/notice/Template/Detail/index.vue | 569 +++++++++++++--------
src/views/notice/Template/index.vue | 16 +-
src/views/notice/Template/types.d.ts | 19 +-
src/views/notice/const.ts | 18 +-
5 files changed, 406 insertions(+), 219 deletions(-)
diff --git a/src/components/MonacoEditor/index.vue b/src/components/MonacoEditor/index.vue
index 9af9c3b1..4ec0f91d 100644
--- a/src/components/MonacoEditor/index.vue
+++ b/src/components/MonacoEditor/index.vue
@@ -32,6 +32,7 @@ self.MonacoEnvironment = {
const props = defineProps({
modelValue: [String, Number],
+ theme: { type: String, default: 'vs-dark' },
});
const emit = defineEmits(['update:modelValue']);
@@ -48,7 +49,7 @@ onMounted(() => {
tabSize: 2,
automaticLayout: true,
scrollBeyondLastLine: false,
- theme: 'vs-dark', // 主题色: vs(默认高亮), vs-dark(黑色), hc-black(高亮黑色)
+ theme: props.theme, // 主题色: vs(默认高亮), vs-dark(黑色), hc-black(高亮黑色)
});
instance.onDidChangeModelContent(() => {
diff --git a/src/views/notice/Template/Detail/index.vue b/src/views/notice/Template/Detail/index.vue
index e4a6bdc6..5a22ec3e 100644
--- a/src/views/notice/Template/Detail/index.vue
+++ b/src/views/notice/Template/Detail/index.vue
@@ -31,40 +31,46 @@
+
+
+
+ {{ item.label }}
+
+
+
-
-
-
@@ -76,155 +82,339 @@
"
>
-
+ placeholder="请选择消息类型"
+ >
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
-
-
-
-
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
- 开启SSL
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+ style="margin-bottom: 20px"
+ >
+ 默认
+ 自定义
+
+
+
+
+
@@ -263,12 +453,14 @@ import { message } from 'ant-design-vue';
import { TemplateFormData } from '../types';
import {
NOTICE_METHOD,
- CONFIG_FIELD_MAP,
+ TEMPLATE_FIELD_MAP,
MSG_TYPE,
+ ROBOT_MSG_TYPE,
+ VOICE_TYPE,
} from '@/views/notice/const';
-// import EditTable from './components/EditTable.vue';
-import configApi from '@/api/notice/config';
+import templateApi from '@/api/notice/template';
import Doc from './doc/index';
+import MonacoEditor from '@/components/MonacoEditor/index.vue';
const router = useRouter();
const route = useRoute();
@@ -290,30 +482,34 @@ const msgType = ref([
// 表单数据
const formData = ref({
- description: '',
+ template: {},
name: '',
- provider: '',
- type: NOTICE_METHOD[2].value,
- template: {
- subject: '',
- sendTo: [],
- attachments: [],
- message: '',
- text: '',
- },
+ type: 'email',
+ provider: 'embedded',
+ description: '',
+ variableDefinitions: [],
});
// 根据通知方式展示对应的字段
watch(
() => formData.value.type,
(val) => {
- formData.value.configuration = CONFIG_FIELD_MAP[val];
+ // formData.value.template = TEMPLATE_FIELD_MAP[val];
msgType.value = MSG_TYPE[val];
formData.value.provider = msgType.value[0].value;
+ console.log('formData.value.template: ', formData.value.template);
},
);
+computed(() => {
+ console.log('formData.value.type: ', formData.value.type);
+ Object.assign(
+ formData.value.template,
+ TEMPLATE_FIELD_MAP[formData.value.type][formData.value.provider],
+ );
+});
+
// 验证规则
const formRules = ref({
type: [{ required: true, message: '请选择通知方式' }],
@@ -322,58 +518,23 @@ const formRules = ref({
{ max: 64, message: '最多可输入64个字符' },
],
provider: [{ required: true, message: '请选择类型' }],
+ configId: [{ required: true, message: '请选择绑定配置' }],
// 钉钉
- 'configuration.appKey': [
- { required: true, message: '请输入AppKey' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- 'configuration.appSecret': [
- { required: true, message: '请输入AppSecret' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- // 'configuration.url': [{ required: true, message: '请输入WebHook' }],
+ 'template.agentId': [{ required: true, message: '请输入agentId' }],
+ 'template.messageType': [{ required: true, message: '请选择消息类型' }],
+ 'template.markdown.title': [{ required: true, message: '请输入标题' }],
+ // 'template.url': [{ required: true, message: '请输入WebHook' }],
// 微信
- 'configuration.corpId': [
- { required: true, message: '请输入corpId' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- 'configuration.corpSecret': [
- { required: true, message: '请输入corpSecret' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- // 阿里云语音/短信
- 'configuration.regionId': [
- { required: true, message: '请输入RegionId' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- 'configuration.accessKeyId': [
- { required: true, message: '请输入AccessKeyId' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- 'configuration.secret': [
- { required: true, message: '请输入Secret' },
- { max: 64, message: '最多可输入64个字符' },
- ],
+ // 'template.agentId': [{ required: true, message: '请输入agentId' }],
// 邮件
- 'configuration.host': [{ required: true, message: '请输入服务器地址' }],
- 'configuration.sender': [{ required: true, message: '请输入发件人' }],
- 'configuration.username': [
- { required: true, message: '请输入用户名' },
- { max: 64, message: '最多可输入64个字符' },
- ],
- 'configuration.password': [
- { required: true, message: '请输入密码' },
- { max: 64, message: '最多可输入64个字符' },
- ],
+ 'template.subject': [{ required: true, message: '请输入标题' }],
+ // 阿里云语音
+ 'template.templateType': [{ required: true, message: '请选择类型' }],
+ 'template.templateCode': [{ required: true, message: '请输入模板ID' }],
+ // 短信
+ 'template.code': [{ required: true, message: '请选择模板' }],
+ 'template.signName': [{ required: true, message: '请输入签名' }],
// webhook
- 'configuration.url': [
- { required: true, message: '请输入Webhook' },
- {
- pattern:
- /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/,
- message: 'Webhook需要是一个合法的URL',
- },
- ],
description: [{ max: 200, message: '最多可输入200个字符' }],
});
@@ -390,12 +551,12 @@ watch(
);
const getDetail = async () => {
- const res = await configApi.detail(route.params.id as string);
+ const res = await templateApi.detail(route.params.id as string);
// console.log('res: ', res);
formData.value = res.result;
// console.log('formData.value: ', formData.value);
};
-getDetail();
+// getDetail();
/**
* 表单提交
@@ -404,19 +565,19 @@ const btnLoading = ref(false);
const handleSubmit = () => {
validate()
.then(async () => {
- // console.log('formData.value: ', formData.value);
+ console.log('formData.value: ', formData.value);
btnLoading.value = true;
- let res;
- if (!formData.value.id) {
- res = await configApi.save(formData.value);
- } else {
- res = await configApi.update(formData.value);
- }
- // console.log('res: ', res);
- if (res?.success) {
- message.success('保存成功');
- router.back();
- }
+ // let res;
+ // if (!formData.value.id) {
+ // res = await templateApi.save(formData.value);
+ // } else {
+ // res = await templateApi.update(formData.value);
+ // }
+ // // console.log('res: ', res);
+ // if (res?.success) {
+ // message.success('保存成功');
+ // router.back();
+ // }
btnLoading.value = false;
})
.catch((err) => {
diff --git a/src/views/notice/Template/index.vue b/src/views/notice/Template/index.vue
index 93e4d46b..3201947b 100644
--- a/src/views/notice/Template/index.vue
+++ b/src/views/notice/Template/index.vue
@@ -3,6 +3,20 @@
通知模板
-
+
diff --git a/src/views/notice/Template/types.d.ts b/src/views/notice/Template/types.d.ts
index 664ab4c9..a505514a 100644
--- a/src/views/notice/Template/types.d.ts
+++ b/src/views/notice/Template/types.d.ts
@@ -16,14 +16,6 @@ interface IVariableDefinitions {
}
export type TemplateFormData = {
- name: string;
- type: string;
- provider: string;
- description: string;
- id?: string;
- creatorId?: string;
- createTime?: number;
- configId?: string;
template: {
// 钉钉消息
agentId?: string;
@@ -41,7 +33,7 @@ export type TemplateFormData = {
text: string;
};
// 微信
- agentId?: string;
+ // agentId?: string;
// message?: string;
toParty?: string;
toUser?: string;
@@ -69,6 +61,13 @@ export type TemplateFormData = {
contextAsBody?: boolean;
body?: string;
};
+ name: string;
+ type: string;
+ provider: string;
+ description: string;
variableDefinitions: IVariableDefinitions[];
-
+ id?: string;
+ creatorId?: string;
+ createTime?: number;
+ configId?: string;
};
\ No newline at end of file
diff --git a/src/views/notice/const.ts b/src/views/notice/const.ts
index ec814842..9bd71ca6 100644
--- a/src/views/notice/const.ts
+++ b/src/views/notice/const.ts
@@ -33,7 +33,7 @@ export const NOTICE_METHOD: INoticeMethod[] = [
},
];
-// 消息类型
+// 类型
export const MSG_TYPE = {
dingTalk: [
{
@@ -203,8 +203,20 @@ export const TEMPLATE_FIELD_MAP = {
},
webhook: {
http: {
- contextAsBody: false,
+ contextAsBody: true,
body: ''
}
},
-};
\ No newline at end of file
+};
+
+// 钉钉机器人-消息类型
+export const ROBOT_MSG_TYPE = [
+ { label: 'markdown', value: 'markdown' },
+ { label: 'text', value: 'text' },
+ { label: 'link', value: 'link' },
+]
+// 语音通知类型
+export const VOICE_TYPE = [
+ { label: '语音通知', value: 'voice' },
+ { label: '语音验证码', value: 'tts' },
+]
\ No newline at end of file