TenantMailServerManager.vue
8.51 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<template>
<div class="fullheight" style="overflow-y: auto;">
<el-form
v-form
data-vv-scope="tenantMailServerForm"
label-position="left"
class="tenant-mail-server-form"
>
<ht-form-item label="邮箱地址" label-width="150px">
<ht-input
v-model="tenantMailServer.userName"
validate="required"
:maxlength="100"
:showWordLimit="true"
@input="userNameChange"
/>
</ht-form-item>
<ht-form-item label="邮件类型" label-width="150px">
<ht-select
v-model="tenantMailServer.mailType"
:options="[
{key: 'pop3', value: 'pop3类型'},
{key: 'imap', value: 'imap类型'}
]"
:validate="{required: true}"
@change="mailTypeChange"
/>
</ht-form-item>
<ht-form-item label="协议服务器" label-width="150px">
<ht-input
v-model="tenantMailServer.mailHost"
autocomplete="off"
validate="required"
:maxlength="100"
:showWordLimit="true"
/>
</ht-form-item>
<ht-form-item label="密码" label-width="150px" class="is-required">
<ht-input
v-model="tenantMailServer.mailPass"
show-password
autocomplete="off"
validate="required"
:maxlength="100"
:showWordLimit="true"
/>
<p class="password-tips">
该密码为邮箱授权码,非登录密码
</p>
</ht-form-item>
<ht-form-item label="昵称" label-width="150px">
<ht-input
v-model="tenantMailServer.nickName"
validate="required"
:maxlength="100"
:showWordLimit="true"
/>
</ht-form-item>
<ht-form-item label="端口号" label-width="150px">
<ht-input
v-model="tenantMailServer.mailPort"
validate="required|numeric"
:maxlength="5"
:showWordLimit="true"
/>
</ht-form-item>
<ht-form-item label="是否使用SSL认证" label-width="150px">
<ht-radio
:options="[
{key: 1, value: '是'},
{key: 0, value: '否'}
]"
v-model="tenantMailServer.useSsl"
validate="required"
@change="useSslChange"
/>
</ht-form-item>
<ht-form-item label="smtphost" label-width="150px">
<ht-input
v-model="tenantMailServer.smtpHost"
validate="required"
:maxlength="100"
:showWordLimit="true"
/>
</ht-form-item>
<ht-form-item label="sendport" label-width="150px">
<ht-input
v-model="tenantMailServer.sendPort"
validate="required|numeric"
:maxlength="5"
:showWordLimit="true"
/>
</ht-form-item>
<ht-form-item label="说明" label-width="150px">
<ht-input
type="textarea"
v-model="tenantMailServer.desc"
placeholder="请输入邮件服务器说明"
:maxlength="200"
:showWordLimit="true"
/>
</ht-form-item>
<el-form-item label-width="150px">
<el-button @click="testConnect()" type="primary" plain
>测试连接</el-button
>
<ht-submit-button
url="${uc}/uc/tenantMailServer/v1/save"
ref="tenantMailSaveBtn"
:model="tenantMailServer"
scope-name="tenantMailServerForm"
>{{ $t('eip.common.save') }}</ht-submit-button
>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
name: 'tenantMailSereverManager',
props: {
tenantId: String
},
data() {
return {
dialogVisible: false,
data: [],
pageResult: {
page: 1,
pageSize: 50,
total: 0
},
tenantMailServer: {
smtpHost: 'smtp.'
}
}
},
mounted() {
this.$validator = this.$root.$validator
let url = '${uc}/uc/tenantMailServer/v1/getByCurrent'
if (this.tenantId) {
url += '?tenantId=' + this.tenantId
}
this.$http.get(url).then(
resp => {
this.tenantMailServer = {...this.tenantMailServer, ...resp.data}
},
error => {
reject(error)
}
)
},
methods: {
testConnect() {
const this_ = this
this_.$validator.validateAll('tenantMailServerForm').then(result => {
if (result) {
let mailType = this.tenantMailServer.mailType
let mailSetting = {
mailType: this.tenantMailServer.mailType,
mailAddress: this.tenantMailServer.userName,
password: this.tenantMailServer.mailPass,
nickName: this.tenantMailServer.nickName,
smtpHost: this.tenantMailServer.smtpHost,
sendPort: this.tenantMailServer.sendPort,
validate: true,
isDeleteRemote: false,
isHandleAttach: true
}
if (this.tenantMailServer.useSsl == '0') {
mailSetting.ssl = false
} else {
mailSetting.ssl = true
}
if (mailType == 'pop3') {
mailSetting.popHost = this.tenantMailServer.mailHost
mailSetting.popPort = this.tenantMailServer.mailPort
} else if (mailType == 'imap') {
mailSetting.imapHost = this.tenantMailServer.mailHost
mailSetting.imapPort = this.tenantMailServer.mailPort
}
let address = this.tenantMailServer.userName
let s = address
.substring(address.indexOf('@') + 1, address.length + 1)
.trim()
mailSetting.smtpPort = mailSetting.ssl ? 465 : 25
let url = '${portal}/mail/mail/mailSetting/v1/test?isOriginPwd=false'
this.$http.post(url, mailSetting).then(resp => {
if (resp.data.state) {
this.$message.success('测试连接成功!')
}
})
} else {
let arr = this_.$validator.errors.items.filter(
item => item.scope == 'tenantMailServerForm'
)
let errorLength = arr.length
this_.$message({
showClose: true,
message: `有${errorLength}个字段未通过校验,请正确填写表单内容。`,
type: 'warning'
})
}
})
},
mailTypeChange(change) {
if (this.tenantMailServer.userName) {
let address = this.tenantMailServer.userName
let s = address
.substring(address.indexOf('@') + 1, address.length + 1)
.trim()
if (change == 'pop3') {
this.tenantMailServer.mailHost = 'pop.' + s
}
if (change == 'pop3') {
if (
!(
s == 'gmail.com' ||
s == 'msn.com' ||
s == 'live.cn' ||
s == 'live.com' ||
s == 'hotmail.com'
)
) {
this.tenantMailServer.mailPort =
this.tenantMailServer.useSsl == '0' ? '110' : '995'
}
} else if (change == 'imap') {
if (
!(
s == 'gmail.com' ||
s == 'msn.com' ||
s == 'live.cn' ||
s == 'live.com' ||
s == 'hotmail.com'
)
) {
this.tenantMailServer.mailPort =
this.tenantMailServer.useSsl == '0' ? '143' : '993'
}
this.tenantMailServer.mailHost = 'imap' + '.' + s
}
}
},
useSslChange(val) {
if (this.tenantMailServer.mailType == 'pop3') {
this.tenantMailServer.mailPort = val === 1 ? '995' : '110'
} else if (this.tenantMailServer.mailType == 'imap') {
this.tenantMailServer.mailPort = val === 1 ? '993' : '143'
}
this.tenantMailServer.sendPort = val === 1 ? '465' : '25'
},
userNameChange(val) {
if (val.indexOf('@') >= 0) {
let s = val.substring(val.indexOf('@') + 1, val.length + 1).trim()
this.tenantMailServer.smtpHost = 'smtp.' + s
} else {
this.tenantMailServer.smtpHost = 'smtp.'
}
}
}
}
</script>
<style lang="scss" scoped>
.sp-manager__dialog /deep/ > .el-dialog > .el-dialog__body {
height: calc(100% - 170px);
}
.inputs.ht-form-inputs__inline {
width: 480px !important;
}
.tenant-mail-server-form {
margin-top: 40px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
/deep/ .el-form-item--small.el-form-item {
margin-bottom: 30px;
}
}
.password-tips {
font-size: 12px;
font-weight: 400;
color: #ffae44;
margin-top: 5px;
}
</style>