SendEmail.vue
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<template>
<BasicModal
v-bind="$attrs"
@register="register"
title="邮件发送参数"
@ok="handleOK"
width="700px"
>
<div class="pt-6px pr-6px">
<BasicForm @register="registerForm" />
</div>
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, h } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
import { useMessage } from '/@/hooks/web/useMessage';
import { Tinymce } from '/@/components/Tinymce';
import { sendEmail } from '/@/api/message/template';
const schemas: FormSchema[] = [
{
field: 'id',
component: 'Input',
label: 'id',
show: false,
},
{
field: 'templatePurpose',
label: '用途',
component: 'Input',
show: false,
},
{
field: 'messageType',
component: 'Input',
label: 'messageType',
show: false,
},
{
field: 'subject',
component: 'Input',
label: '邮件主题',
required: true,
colProps: {
span: 12,
},
},
{
field: 'to',
component: 'Input',
label: '主送',
required: true,
colProps: {
span: 12,
},
},
{
field: 'cc',
component: 'Input',
label: '抄送',
colProps: {
span: 12,
},
},
{
field: 'bcc',
component: 'Input',
label: '密送',
colProps: {
span: 12,
},
},
{
field: 'body',
component: 'Input',
label: '邮件内容',
rules: [{ required: true }],
render: ({ model, field }) => {
return h(Tinymce, {
value: model[field],
onChange: (value: string) => {
model[field] = value;
},
});
},
},
];
export default defineComponent({
components: { BasicModal, BasicForm },
setup() {
const { createMessage } = useMessage();
const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({
labelWidth: 70,
schemas,
showActionButtonGroup: false,
actionColOptions: {
span: 24,
},
});
const [register, { closeModal }] = useModalInner(async (data) => {
await resetFields();
await setFieldsValue({
...data.record,
});
});
async function handleOK() {
const values = await validate();
const to = Reflect.get(values, 'to').split(',');
const cc = Reflect.get(values, 'cc');
const bcc = Reflect.get(values, 'bcc');
if (typeof cc != 'undefined') {
cc.split(',');
Reflect.set(values, 'cc', cc);
}
if (typeof bcc != 'undefined') {
bcc.split(',');
Reflect.set(values, 'bcc', bcc);
}
Reflect.set(values, 'to', to);
Reflect.set(values, 'emailFormatEnum', 'HTML');
await sendEmail(values);
console.log(values, 'values');
closeModal();
createMessage.success('发送成功');
}
return { register, schemas, registerForm, handleOK };
},
});
</script>