fix: bug#10161

This commit is contained in:
JiangQiming 2023-02-23 18:45:13 +08:00
parent d2767b0a0a
commit e0837f2745
1 changed files with 86 additions and 26 deletions

View File

@ -157,6 +157,7 @@
formData.template.messageType
"
placeholder="请选择消息类型"
@change="handleMessageTypeChange"
>
<a-select-option
v-for="(
@ -819,6 +820,7 @@ const resetPublicFiles = () => {
if (formData.value.type === 'email')
formData.value.template.toParty = undefined;
// formData.value.description = '';
formData.value.variableDefinitions = [];
};
//
@ -911,39 +913,97 @@ const { resetFields, validate, validateInfos, clearValidate } = useForm(
formRules.value,
);
// markdown
watch(
() => formData.value.template.message,
() => formData.value.template.markdown?.title,
(val) => {
if (!val) return;
//
const oldKey = formData.value.variableDefinitions?.map((m) => m.id);
// ${}
const pattern = /(?<=\$\{).*?(?=\})/g;
const titleList = val.match(pattern)?.filter((f) => f);
const newKey = [...new Set(titleList)];
const result = newKey?.map((m) =>
oldKey.includes(m)
? formData.value.variableDefinitions.find(
(item) => item.id === m,
)
: {
id: m,
name: '',
type: 'string',
format: '%s',
},
);
formData.value.variableDefinitions = result as IVariableDefinitions[];
variableReg(val);
},
{ deep: true },
);
// link
watch(
() => formData.value.template.link?.title,
(val) => {
if (!val) return;
variableReg(val);
},
{ deep: true },
);
//
watch(
() => formData.value.template.subject,
(val) => {
if (!val) return;
variableReg(val);
},
{ deep: true },
);
// const clearValid = () => {
// setTimeout(() => {
// formData.value.variableDefinitions = [];
// clearValidate();
// }, 200);
// };
//
watch(
() => formData.value.template.message,
(val) => {
if (!val) return;
variableReg(val);
},
{ deep: true },
);
// webhook
watch(
() => formData.value.template.body,
(val) => {
if (!val) return;
variableReg(val);
},
{ deep: true },
);
/**
* 根据字段输入内容, 提取变量
* @param value
*/
const variableReg = (value: string) => {
//
const oldKey = formData.value.variableDefinitions?.map((m) => m.id);
// ${}
const pattern = /(?<=\$\{).*?(?=\})/g;
const titleList = value.match(pattern)?.filter((f) => f);
const newKey = [...new Set(titleList)];
const result = newKey?.map((m) =>
oldKey.includes(m)
? formData.value.variableDefinitions.find((item) => item.id === m)
: {
id: m,
name: '',
type: 'string',
format: '%s',
},
);
formData.value.variableDefinitions = [
...new Set([
...formData.value.variableDefinitions,
...(result as IVariableDefinitions[]),
]),
];
};
/**
* 钉钉机器人 消息类型选择改变
*/
const handleMessageTypeChange = () => {
formData.value.variableDefinitions = [];
formData.value.template.message = '';
if (formData.value.template.link) {
formData.value.template.link.title = '';
formData.value.template.link.picUrl = '';
formData.value.template.link.messageUrl = '';
}
if (formData.value.template.markdown) {
formData.value.template.markdown.title = '';
}
};
/**
* 获取详情