集成后台重构版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.8 KiB

  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" :rules="rules" style="margin-top: 6px;" size="small" label-width="100px">
  4. <el-form-item label="邮件标题" prop="subject">
  5. <el-input v-model="form.subject" style="width: 646px" />
  6. </el-form-item>
  7. <el-form-item
  8. v-for="(domain, index) in tos"
  9. :key="domain.key"
  10. :label="'收件邮箱' + (index === 0 ? '': index)"
  11. >
  12. <el-input v-model="domain.value" style="width: 550px" />
  13. <el-button icon="el-icon-plus" @click="addDomain" />
  14. <el-button style="margin-left:0;" icon="el-icon-minus" @click.prevent="removeDomain(domain)" />
  15. </el-form-item>
  16. <div ref="editor" class="editor" />
  17. <el-button :loading="loading" style="margin-left:1.6%;" size="medium" type="primary" @click="doSubmit">发送邮件</el-button>
  18. </el-form>
  19. </div>
  20. </template>
  21. <script>
  22. import { send } from '@/api/tools/email'
  23. import { upload } from '@/utils/upload'
  24. import { validEmail } from '@/utils/validate'
  25. import { mapGetters } from 'vuex'
  26. import E from 'wangeditor'
  27. export default {
  28. name: 'Index',
  29. data() {
  30. return {
  31. loading: false, form: { subject: '', tos: [], content: '' },
  32. tos: [{
  33. value: ''
  34. }],
  35. rules: {
  36. subject: [
  37. { required: true, message: '标题不能为空', trigger: 'blur' }
  38. ]
  39. }
  40. }
  41. },
  42. computed: {
  43. ...mapGetters([
  44. 'imagesUploadApi'
  45. ])
  46. },
  47. mounted() {
  48. const _this = this
  49. var editor = new E(this.$refs.editor)
  50. // 自定义菜单配置
  51. editor.customConfig.zIndex = 10
  52. // 文件上传
  53. editor.customConfig.customUploadImg = function(files, insert) {
  54. // files 是 input 中选中的文件列表
  55. // insert 是获取图片 url 后,插入到编辑器的方法
  56. files.forEach(image => {
  57. files.forEach(image => {
  58. upload(_this.imagesUploadApi, image).then(data => {
  59. insert(data.data.url)
  60. })
  61. })
  62. })
  63. }
  64. editor.customConfig.onchange = (html) => {
  65. this.form.content = html
  66. }
  67. editor.create()
  68. },
  69. methods: {
  70. removeDomain(item) {
  71. var index = this.tos.indexOf(item)
  72. if (index !== -1 && this.tos.length !== 1) {
  73. this.tos.splice(index, 1)
  74. } else {
  75. this.$message({
  76. message: '请至少保留一位联系人',
  77. type: 'warning'
  78. })
  79. }
  80. },
  81. addDomain() {
  82. this.tos.push({
  83. value: '',
  84. key: Date.now()
  85. })
  86. },
  87. doSubmit() {
  88. const _this = this
  89. this.$refs['form'].validate((valid) => {
  90. this.form.tos = []
  91. if (valid) {
  92. let sub = false
  93. this.tos.forEach(function(data, index) {
  94. if (data.value === '') {
  95. _this.$message({
  96. message: '收件邮箱不能为空',
  97. type: 'warning'
  98. })
  99. sub = true
  100. } else if (validEmail(data.value)) {
  101. _this.form.tos.push(data.value)
  102. } else {
  103. _this.$message({
  104. message: '收件邮箱格式错误',
  105. type: 'warning'
  106. })
  107. sub = true
  108. }
  109. })
  110. if (sub) { return false }
  111. this.loading = true
  112. send(this.form).then(res => {
  113. this.$notify({
  114. title: '发送成功',
  115. type: 'success',
  116. duration: 2500
  117. })
  118. this.loading = false
  119. }).catch(err => {
  120. this.loading = false
  121. console.log(err.response.data.message)
  122. })
  123. } else {
  124. return false
  125. }
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style scoped>
  132. .editor{
  133. text-align:left;
  134. margin: 20px;
  135. width: 730px;
  136. }
  137. ::v-deep .w-e-text-container {
  138. height: 360px !important;
  139. }
  140. </style>