Commit fc7ce3a7 by Sweet Zhang

直接发邮件时改签名

parent 575d46a2
......@@ -8,19 +8,12 @@
import { ref, defineProps, defineEmits, watch, onMounted, onUnmounted } from 'vue'
import WangEditor from 'wangeditor'
import axios from 'axios'
import { env } from '@/utils/env' // 之前创建的环境配置文件
// Props 定义(保持和原组件一致,无缝替换)
// Props/Emits 保持不变
const props = defineProps<{
modelValue: string
config?: {
height?: number
uploadUrl?: string
placeholder?: string
}
config?: { height?: number; uploadUrl?: string; placeholder?: string }
}>()
// Emits 定义
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void
(e: 'change', value: string): void
......@@ -32,7 +25,6 @@ const defaultConfig = {
uploadUrl: `${import.meta.env.VITE_REMOTE_API_BASE_URL}/oss/api/oss/upload`,
placeholder: '请输入内容...',
}
const config = { ...defaultConfig, ...props.config }
// 编辑器实例
......@@ -40,48 +32,49 @@ const editorRef = ref<HTMLDivElement | null>(null)
let editor: WangEditor | null = null
const content = ref(props.modelValue)
// 初始化编辑器
// 封装上传方法(复用)
const uploadImage = async (file: File) => {
const formData = new FormData()
formData.append('file', file) // 固定key为file
const res = await axios.post(config.uploadUrl, formData, {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: localStorage.getItem('authToken') || '',
},
})
if (res.data.code !== 200) throw new Error(res.data.msg || '上传失败')
return res.data.data.url
}
onMounted(() => {
if (!editorRef.value) return
// 创建编辑器
editor = new WangEditor(editorRef.value)
// 配置
// 基础配置(保留wangEditor原生风格)
editor.config.height = config.height
editor.config.placeholder = config.placeholder
editor.config.showLinkImg = false // 隐藏网络图片功能
editor.config.uploadImgServer = config.uploadUrl // 图片上传接口
editor.config.uploadImgHeaders = {
Authorization: `${localStorage.getItem('authToken')}`,
}
editor.config.uploadImgMaxSize = 2 * 1024 * 1024 // 2MB
editor.config.uploadImgMaxLength = 1 // 单次上传1张(LOGO)
editor.config.showLinkImg = false
editor.config.onchange = (html: string) => {
content.value = html
emit('update:modelValue', html)
emit('change', html)
}
// 图片上传成功处理
editor.config.uploadImgHooks = {
success: (xhr: any, editor: any, result: any) => {
if (result.code === 200) {
return result.data.url
}
},
fail: (xhr: any, editor: any, result: any) => {
console.error('图片上传失败:', result)
},
// 核心:仅重写上传逻辑(最简版)
editor.config.customUploadImg = async (files, insertImg) => {
try {
// 仅上传第一张(符合原限制)
const url = await uploadImage(files[0])
insertImg(url) // 插入到编辑器
} catch (err) {
console.error('图片上传失败:', err)
// 可添加Element Plus提示:ElMessage.error('图片上传失败')
}
}
// 创建编辑器
editor.create()
// 设置初始内容
if (props.modelValue) {
editor.txt.html(props.modelValue)
}
// 初始化内容
if (props.modelValue) editor.txt.html(props.modelValue)
})
// 监听外部内容变化
......@@ -97,12 +90,7 @@ watch(
)
// 销毁编辑器
onUnmounted(() => {
if (editor) {
editor.destroy()
editor = null
}
})
onUnmounted(() => editor?.destroy())
</script>
<style scoped>
......@@ -111,18 +99,14 @@ onUnmounted(() => {
border-radius: 4px;
width: 100%;
}
.editor-container {
min-height: 300px;
padding: 10px;
}
/* 适配 wangEditor 样式 */
:deep(.w-e-toolbar) {
border-bottom: 1px solid #e5e7eb;
flex-wrap: wrap;
}
:deep(.w-e-text-container) {
min-height: 250px;
}
......
......@@ -239,7 +239,7 @@
@close="showVariableSelector = false"
/>
<!-- 发送邮件弹窗 -->
<el-dialog v-model="dialogVisible" title="提示" width="500">
<el-dialog v-model="dialogVisible" title="提示" width="500" :z-index="99999">
<span>邮件发送任务已提交,请前往邮件记录中查看发送状态</span>
<template #footer>
<div class="dialog-footer">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment