Compare commits
2 Commits
1074e9c82f
...
d66225dc5d
| Author | SHA1 | Date | |
|---|---|---|---|
| d66225dc5d | |||
| 34677e1e83 |
@@ -1,7 +1,8 @@
|
||||
<template>
|
||||
<div class="tinymce-container">
|
||||
|
||||
|
||||
<i class="el-icon-copy-document" @click="handleCopy" v-if="displayValue&&readonly" style="margin-top: -30px;float: right;margin-bottom: 10px;cursor: pointer;"></i>
|
||||
<div style="clear: both;"></div>
|
||||
<div v-if="readonly" v-html="displayValue" class="readonly-content">
|
||||
|
||||
</div>
|
||||
@@ -96,6 +97,41 @@ beforeDestroy() {
|
||||
|
||||
|
||||
methods: {
|
||||
handleCopy() {
|
||||
|
||||
|
||||
if (this.displayValue) {
|
||||
// 1. 使用正则匹配 <wmath ... data-latex="内容" ...>...</wmath>
|
||||
// 这里的正则会精准提取 data-latex 属性中的值
|
||||
const cleanValue = this.displayValue.replace(/<wmath[^>]*data-latex="([^"]*)"[^>]*>[\s\S]*?<\/wmath>/g, '$1');
|
||||
|
||||
// 2. 如果你还想顺便把 <br> 转换成换行符,可以加上这一行:
|
||||
const finalValue = cleanValue.replace(/<br\s*\/?>/gi, '\n');
|
||||
|
||||
|
||||
|
||||
// 3. 执行复制到剪贴板的操作
|
||||
this.copyToClipboard(finalValue);
|
||||
}
|
||||
},
|
||||
|
||||
copyToClipboard(text) {
|
||||
// 兼容性较好的复制方法
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
this.$message({
|
||||
message: 'Successfully copied to clipboard!',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('无法复制', err);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
},
|
||||
destroyTinymce() {
|
||||
this.displayValue=null
|
||||
// 通过 window.tinymce 获取全局对象,根据 id 找到并销毁
|
||||
|
||||
Reference in New Issue
Block a user