<template>
|
<view class="pages-my-log-email">
|
<view class="content">
|
<view class="group">
|
<view class="item">
|
<view>{{translate("email_service")}}</view>
|
<input class="right-input" :placeholder="translate('input_email_service')" v-model="form.host" />
|
</view>
|
<view class="item">
|
<view>{{translate("email_port")}}</view>
|
<input class="right-input" :placeholder="translate('input_email_port')" v-model="form.port" />
|
</view>
|
<view class="item">
|
<view>{{translate("sender_email")}}</view>
|
<input class="right-input" :placeholder="translate('input_sender_email')"
|
v-model="form.yourEmail" />
|
</view>
|
<view class="item">
|
<view>{{translate("authorization_code")}}</view>
|
<input class="right-input" password :placeholder="translate('input_authorization_code')"
|
v-model="form.yourPwd" />
|
</view>
|
|
<view class="item">
|
<view>{{translate("receiver_email")}}</view>
|
<input class="right-input" :placeholder="translate('input_receiver_email')"
|
v-model="form.toEmail" />
|
</view>
|
<view class="item">
|
<view>{{translate("email_subject")}}</view>
|
<input class="right-input" :placeholder="translate('input_email_subject')" v-model="form.subject" />
|
</view>
|
<view class="item">
|
<textarea class="oi-content" auto-height fixed name="msgBody" comfirm-type="done"
|
show-confirm-bar="{{false}}" type="text" v-model="form.msgBody"
|
:placeholder="translate('input_email_content')+'...'" :maxlength="-1" />
|
</view>
|
|
</view>
|
|
<view class="title">
|
{{translate("attachment")}}
|
</view>
|
|
|
<view class="group">
|
<view class="item" v-for="(item,index) in form.attachment" :key="item">
|
{{index+ 1}}、{{item}}
|
</view>
|
</view>
|
</view>
|
|
<view class="button-line"> <a-button type="primary" class="button" @click="sendEmail">
|
{{translate('send')}}
|
</a-button></view>
|
</view>
|
</template>
|
|
<script>
|
// 获取 module
|
const emailModule = uni.requireNativePlugin('EmailPlugin');
|
import {
|
session,
|
showToast,
|
showModal,
|
showError
|
} from "@/comm/utils.js"
|
import {
|
Button
|
} from 'antd-mobile-vue-next'
|
export default {
|
name: "PagesMyLogEmail",
|
components: {
|
'a-button': Button
|
},
|
data() {
|
return {
|
form: {
|
host: "",
|
port: "",
|
yourEmail: "",
|
yourPwd: "",
|
toEmail: "",
|
subject: '',
|
msgBody: '',
|
attachment: []
|
|
},
|
configureSMTPFlag: false
|
}
|
},
|
onLoad(option) {
|
const attachments = JSON.parse(option.attachment || "") || []
|
const info = session.getValue("log_email") || {}
|
|
this.form = {
|
host: info.host || "smtp.163.com",
|
port: info.port || "465",
|
yourEmail: info.yourEmail ||"cuiqian2004@163.com",
|
yourPwd: info.yourPwd || "QWfCFwa54a6L66Xr",
|
toEmail: info.toEmail || "nancy0606@qq.com",
|
subject: "ES-GO:" + this.translate("error_log_package"),
|
msgBody: '',
|
attachment: attachments
|
}
|
},
|
methods: {
|
configureSMTP() {
|
// 配置SMTP服务器
|
return new Promise((resolve, reject) => {
|
if (!this.form.host.trim()) {
|
|
return reject(this.translate("input_email_service"))
|
}
|
if (!this.form.port.trim()) {
|
return reject(this.translate("input_email_port"))
|
}
|
if (!this.form.yourEmail.trim()) {
|
return reject(this.translate("input_sender_email"))
|
}
|
if (!this.form.yourPwd.trim()) {
|
return reject(this.translate("input_authorization_code"))
|
}
|
emailModule.configureSMTP({
|
host: this.form.host,
|
port: this.form.port,
|
username: this.form.yourEmail,
|
password: this.form.yourPwd,
|
enableSSL: true,
|
fromAlias: 'mobox'
|
}, (result) => {
|
|
if (result.success) {
|
resolve()
|
|
} else {
|
reject(result.error)
|
}
|
});
|
})
|
},
|
async sendEmail() {
|
try {
|
// 静默发送邮件
|
const _this = this
|
uni.showLoading({
|
title: this.translate("email_sending")
|
})
|
console.log('静默发送邮件');
|
if (!this.configureSMTPFlag) {
|
await this.configureSMTP()
|
this.configureSMTPFlag = true
|
|
const info = {
|
host: this.form.host,
|
port: this.form.port,
|
yourEmail: this.form.yourEmail,
|
yourPwd: this.form.yourPwd,
|
toEmail: this.form.toEmail,
|
}
|
session.setValue("log_email", info)
|
}
|
|
const info = session.getValue("log_email") || {}
|
if (!this.form.toEmail.trim()) {
|
uni.hideLoading()
|
uni.showToast({
|
title: this.translate("input_receiver_email"),
|
icon: 'warning'
|
});
|
return
|
}
|
var subject = this.form.subject
|
if (!subject.trim()) {
|
subject = "ES-GO Error"
|
}
|
const attachs = this.form.attachment.map((ele) => ele)
|
// this.form.attachment.forEach((ele) => {
|
// attachs.push(ele)
|
// })
|
|
// [
|
// "/storage/emulated/0/Android/data/uni.EasyGo/apps/__UNI__C988375/doc/download/test.zip"
|
// ]
|
console.log(attachs)
|
emailModule.sendSilentEmail({
|
to: this.form.toEmail,
|
subject: subject,
|
body: this.form.msgBody,
|
attachments: attachs
|
}, (result) => {
|
console.log('发送结束', result);
|
_this.loading = true
|
if (result.success) {
|
session.setValue("log_email", info)
|
uni.hideLoading()
|
showModal({
|
title: "",
|
content: this.translate("email_send_success"),
|
confirmText: this.translate("ok")
|
}).then(() => {
|
uni.navigateBack({
|
delta: 1, //返回层数,2则上上页
|
})
|
})
|
|
} else {
|
showError(`${this.translate("email_send_fail")},${result.error}}`)
|
}
|
});
|
} catch (ex) {
|
showError(ex)
|
uni.hideLoading()
|
this.loading = true
|
}
|
},
|
translate(t) {
|
if (typeof this.$t == "function") return this.$t(`page.${t}`)
|
else return t;
|
},
|
}
|
}
|
</script>
|
<style lang="less">
|
.pages-my-log-email {
|
display: flex;
|
width: 750rpx;
|
height: 100vh;
|
flex-direction: column;
|
background-color: #F8F8F8;
|
|
.content {
|
width: 750rpx;
|
display: flex;
|
flex-direction: column;
|
flex: 1;
|
overflow-y: auto;
|
|
.title {
|
margin: 10rpx 30rpx;
|
}
|
|
.group {
|
width: calc(100% - 60rpx);
|
// border: 1px solid #ccc;
|
border-radius: 20rpx;
|
margin: 10rpx 20rpx;
|
padding: 0 10rpx;
|
display: flex;
|
flex-direction: column;
|
background-color: #fff;
|
font-size: 30rpx;
|
|
.item {
|
width: calc(100% - 20rpx);
|
padding: 20rpx 10rpx;
|
display: flex;
|
flex-direction: row;
|
align-items: center;
|
word-wrap: break-word;
|
word-break: break-all;
|
border-bottom: 1px solid #ddd;
|
|
.right {
|
flex: 1;
|
text-align: right;
|
color: #888;
|
padding-right: 5px;
|
|
}
|
|
.right-input {
|
text-align: right;
|
flex: 1;
|
color: #1890FF;
|
}
|
|
.text {
|
flex: 1;
|
color: #888;
|
|
}
|
|
.icon {
|
color: #888;
|
}
|
|
a {
|
margin-left: 20rpx;
|
}
|
|
.input {
|
margin-left: 20rpx;
|
margin-right: 10rpx;
|
width: 75rpx;
|
}
|
|
}
|
.item:last-child {
|
border-bottom: 0;
|
|
}
|
|
}
|
|
}
|
|
.button-line {
|
margin: 20rpx;
|
|
.button {
|
margin: auto;
|
width: 500rpx !important;
|
border-radius: 40rpx;
|
height: 80rpx;
|
line-height: 50rpx;
|
}
|
}
|
|
}
|
</style>
|