Ч¹ûͼ
Ö±½Ó°ÑÍêÕû×é¼þÄóöÀ´,ʹÓÃʱºò×Ô¼º¿´ºÃ½Ó¿Ú¸ÉÂïµÄ,¶ÔÓ¦ÉÏ
<template>
<div class="box">
<el-button
type="primary"
icon="el-icon-view"
style="cursor: pointer; margin-bottom: 20px"
@click="see()"
>Ô¤ÀÀ</el-button
>
<el-button
v-if="!isignore"
type="primary"
@click="sensitive()"
icon="el-icon-view"
style="cursor: pointer; margin-bottom: 20px"
>Ò»¼üºöÂÔÃô¸Ð´Ê»ã</el-button
>
<el-button
v-else
type="success"
icon="el-icon-check"
style="cursor: pointer; margin-bottom: 20px"
>ÒѺöÂÔÃô¸Ð´Ê»ã</el-button
>
<!-- <el-button
type="primary"
@click="discern()"
icon="el-icon-view"
style="cursor: pointer; margin-bottom: 20px"
>ʶ±ð</el-button
> -->
<el-button
v-if="isignore"
type="warning"
@click="again()"
icon="el-icon-close"
style="cursor: pointer; margin-bottom: 20px"
>½â³ýºöÂÔ</el-button
>
<div id="editor"></div>
<!-- <el-row>
<el-col :span="12"> <div id="editor"></div></el-col>
<el-col :span="12">
Ô¤ÀÀ
<hr />
<div class="html" v-html="contentEditor"></div
></el-col>
</el-row> -->
<div id="editorBox" v-if="lookSEE">
<el-dialog :visible.sync="lookSEE">
<el-dialog
width="1100px"
title="ÕýÎÄÄÚÈÝ > Ч¹ûÔ¤ÀÀ"
:visible.sync="lookSEE"
append-to-body
@close="concal()"
>
<hr />
<div class="html" v-html="contentEditor"></div>
<div slot="footer" class="dialog-footer">
<el-button @click="concal()">È¡Ïû</el-button>
</div>
</el-dialog>
</el-dialog>
</div>
</div>
</template>
<script>
import E from "wangeditor";
import { getToken } from "@/utils/auth";
import { uploadPath } from "@/api/upload";
import { alllist } from "@/api/business/sensitiveWord";
export default {
data() {
return {
contentEditor: "",
lookSEE: false,
isignore: true,
ignore: '<i style="display: none;">ÒѺöÂÔÃô¸Ð´Ê</i>',
editor: undefined,
show: true,
ignoreChars:
" \t\r\n~!@#$%^&*()_+-=¡¾¡¿¡¢{}|;':\",¡£¡¢¡¶¡·?¦Á¦Â¦Ã¦Ä¦Å¦Æ¦Ç¦È¦É¦Ê¦Ë¦Ì¦Í¦Î¦Ï¦Ð¦Ñ¦Ò¦Ó¦Ô¦Õ¦Ö¦×¦Ø¦¡¦¢¦£¦¤¦¥¦¦¦§¦¨¦©¦ª¦«¦¬¦¦®¦¯¦°¦±¦²¦³¦´¦µ¦¶¦·¦¸¡£,¡¢;:?!¡¡ª¡¤¡¥¡§¡®¡¯¡°¡±¡©~¡¬¡Ã"'`|¡¨¡²¡³¡´¡µ¡¶¡·¡¸¡¹¡º¡».¡¼¡½¡¾¡¿()[]{}¢ñ¢ò¢ó¢ô¢õ¢ö¢÷¢ø¢ù¢ú¢û¢ü¢±¢²¢³¢´¢µ¢¶¢·¢¸¢¹¢º¢»¢¼¢½¢¾¢¿¢À¢Á¢Â¢Ã¢Ä¢å¢æ¢ç¢è¢é¢ê¢ë¢ì¢í¢î¢Ù¢Ú¢Û¢Ü¢Ý¢Þ¢ß¢à¢á¢â¢Å¢Æ¢Ç¢È¢É¢Ê¢Ë¢Ì¢Í¢Î¢Ï¢Ð¢Ñ¢Ò¢Ó¢Ô¢Õ¢Ö¢×¢Ø¡Ö¡Ô¡Ù=¡Ü¡Ý<>¡Ú¡Û¡Ë¡À+-¡Á¡Â/¡Ò¡Ó¡Ø¡Þ¡Ä¡Å¡Æ¡Ç¡È¡É¡Ê¡ß¡à¡Í¡Î¡Ï¡Ð¡Ñ¡Õ¡×¡Ì¡ì¡í¡î¡ï¡ð¡ñ¡ò¡ó¡ô¡õ¡æ¡ë€¡ö¡÷¡ø¡ù¡ú¡û¡ü¡ý¡þ¡è¡ã#&@\¦ä_ ̄¨D©°©±©²©´©µ©¶©·©¤©¨©¬©À©Á©Â©Ã©Ä©Å©Æ©Ç©¦©ª©®©Ð©Ñ©Ò©Ó©Ô©Õ©Ö©×©à©á©â©ã©ä©å©æ©ç©¸©¹©º©»©¼©½©¾©¿©¥©©©©È©É©Ê©Ë©Ì©Í©Î©Ï©§©«©¯©Ø©Ù©Ú©Û©Ü©Ý©Þ©ß©ï©î©í©ì©ë©ê©é©è",
ignoreObj: {},
keywords: ["Ãô¸Ð´ÊÇë¸ü¸Ä", "·¨ÂÖ¹¦"],
sensitiveWords: undefined,
map: undefined,
iskeyword: false,
queryParams: {},
};
},
props: {
contentHtml: {
type: String,
default() {
return "";
},
},
},
created() {
for (let i = 0, j = this.ignoreChars.length; i < j; i++) {
this.ignoreObj[this.ignoreChars.charCodeAt(i)] = true;
}
alllist(this.queryParams, this.$i18n.locale).then((response) => {
this.keywords = response.data;
this.map = this.buildMap(this.keywords);
});
if (this.contentHtml) {
this.contentEditor = this.contentHtml;
}
let reg = new RegExp(/<i style="display: none;">ÒѺöÂÔÃô¸Ð´Ê<\/i>/, "g");
this.isignore = reg.test(this.contentEditor);
},
mounted() {
this.editor = new E("#editor");
this.editor.config.height = 300;
this.editor.config.zIndex = 20;
this.editor.config.placeholder = "ÇëÊäÈëÕýÎÄ";
this.editor.config.focus = false;
this.editor.config.menus = [
"head",
"bold",
"fontSize",
"fontName",
"italic",
"underline",
"strikeThrough",
"indent",
"lineHeight",
"foreColor",
"backColor",
"link",
"list",
"justify",
"quote",
"emoticon",
"image",
"video",
"table",
"splitLine",
"undo",
"redo",
];
this.editor.config.colors = [
"#333333",
"#1c487f",
"#eeece0",
"#4d80bf",
"#ffffff",
"#FF0000",
"#00FF00",
" #0000FF",
"#FF00FF",
"#FFFF00",
"#70DB93",
"#5C3317",
];
this.editor.config.fontNames = [
"΢ÈíÑźÚ",
"Microsoft YaHei",
];
this.editor.config.fontSizes = {
"x-small": { name: "14px", value: "1" },
small: { name: "16px", value: "2" },
normal: { name: "18px", value: "3" },
large: { name: "20px", value: "4" },
"x-large": { name: "22px", value: "5" },
"xx-large": { name: "24px", value: "6" },
"xxx-large": { name: "26px", value: "7" },
};
this.editor.config.lineHeights = [
"1",
"1.25",
"1.5",
"1.75",
"2",
"2.5",
"3",
];
this.editor.config.linkImgCallback = function (src, alt, href) {
};
this.editor.config.pasteFilterStyle = false;
this.editor.config.pasteIgnoreImg = false;
this.editor.config.pasteTextHandle = (pasteStr) => {
let arr = this.checkSensitive(pasteStr);
if (arr) this.iskeyword = true;
arr.forEach((item, index) => {
var reg = new RegExp(item, "g");
pasteStr = pasteStr.replace(
reg,
` <span id="checkSensitive" style="background-color: rgb(250, 228, 34);">${item}<i style="color: rgb(250, 0, 0);font-style: italic;">[Ãô¸Ð´Ê,Çë¸ü¸Ä]</i></span> `
);
});
return pasteStr;
};
this.editor.config.showLinkImg = true;
this.editor.config.uploadImgMaxSize = 8 * 1024 * 1024;
this.editor.config.uploadImgAccept = [];
this.editor.config.uploadImgMaxLength = 3;
this.editor.config.uploadImgServer = uploadPath;
this.editor.config.uploadFileName = "file";
this.editor.config.uploadImgHeaders = {
Authorization: getToken(),
};
this.editor.config.uploadImgHooks = {
fail: function (xhr, editor, result) {
},
success: function (xhr, editor, result) {
},
before: function (xhr, editor, files) {
},
error: function (xhr, editor) {
},
customInsert: function (insertImgFn, result) {
insertImgFn(result.data.full);
},
};
this.editor.config.uploadVideoServer = uploadPath;
this.editor.config.uploadVideoParams = {
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundarycZm1pHksXeHS6t5r'
}
this.editor.config.uploadVideoHeaders = {
Authorization: getToken(),
};
let this_ = this
this.editor.config.uploadVideoName = "file";
this.editor.config.uploadVideoHooks = {
fail: (xhr, editor, result) => {
},
success: (xhr, editor, result) => {
},
timeout: (xhr, editor) => {
},
error: (xhr, editor) => {
console.log("err--->", xhr);
},
customInsert: function (insertVideo, result) {
console.log("result--->", result);
const link = result.data.full;
insertVideo(link)
},
};
this.editor.config.onchange = (html) => {
this.contentEditor = html;
this.sentContent();
};
this.editor.config.onfocus = (html) => {
if (this.isignore) {
this.sendIskeyword();
this.contentEditor = html;
} else {
this.changIsignore(html);
}
this.sentContent();
};
this.editor.create();
this.$nextTick(() => {
if (this.contentEditor) {
this.editor.txt.html(this.contentEditor);
}
});
},
methods: {
sensitive() {
this.isignore = true;
this.show = false;
this.contentEditor = this.ignore + this.contentEditor;
let reg = new RegExp(
/<i style="color: rgb\(250, 0, 0\);font-style: italic;">\[Ãô¸Ð´Ê,Çë¸ü¸Ä\]<\/i>/,
"g"
);
let reg1 = new RegExp(
/style="background-color: rgb\(250, 228, 34\);"/,
"g"
);
this.contentEditor = this.contentEditor.replace(reg1, "");
this.contentEditor = this.contentEditor.replace(reg, "");
this.editor.txt.html(this.contentEditor);
this.sentContent();
this.sendIskeyword();
},
sentContent() {
this.$emit("sentContent", this.contentEditor);
},
sendIskeyword() {
let reg = new RegExp(/\[Ãô¸Ð´Ê,Çë¸ü¸Ä\]/);
let val = reg.test(this.contentEditor);
this.$emit("sendIskeyword", val);
},
again() {
let reg = new RegExp(/<i style="display: none;">ÒѺöÂÔÃô¸Ð´Ê<\/i>/, "g");
this.contentEditor = this.contentEditor.replace(reg, "");
this.isignore = false;
this.changIsignore(this.contentEditor);
this.sendIskeyword();
},
see() {
this.lookSEE = true;
if (this.isignore) {
this.sendIskeyword();
this.contentEditor = this.contentEditor;
} else {
this.changIsignore(this.contentEditor);
}
},
concal() {
this.lookSEE = false;
},
changIsignore(html) {
let arr = this.checkSensitive(html);
arr.forEach((item, index) => {
var reg = new RegExp(item, "g");
html = html.replace(
reg,
` <span id="checkSensitive" style="background-color: rgb(250, 228, 34);">${item}<i style="color: rgb(250, 0, 0);font-style: italic;">[Ãô¸Ð´Ê,Çë¸ü¸Ä]</i></span> `
);
});
this.contentEditor = html;
this.editor.txt.html(this.contentEditor);
if (arr.length > 0) {
this.sendIskeyword();
} else {
this.sendIskeyword();
}
},
check(map, content) {
const result = [];
let stack = [];
let point = map;
for (let i = 0, len = content.length; i < len; ++i) {
const code = content.charCodeAt(i);
if (this.ignoreObj[code]) {
continue;
}
const ch = content.charAt(i);
const item = point[ch.toLowerCase()];
if (!item) {
i = i - stack.length;
stack = [];
point = map;
} else if (item.empty) {
stack.push(ch);
result.push(stack.join(""));
stack = [];
point = map;
} else {
stack.push(ch);
point = item;
}
}
return result;
},
buildMap(wordList) {
const result = {};
for (let i = 0, len = wordList.length; i < len; ++i) {
let map = result;
const word = wordList[i];
for (let j = 0; j < word.length; ++j) {
const ch = word.charAt(j).toLowerCase();
if (map[ch]) {
map = map[ch];
if (map.empty) {
break;
}
} else {
if (map.empty) {
delete map.empty;
}
map[ch] = {
empty: true,
};
map = map[ch];
}
}
}
return result;
},
checkSensitive(content) {
const words = this.check(this.map, content);
return words;
},
},
};
</script>
<style scoped>
#contentEditor {
width: 900px;
}
.html {
margin-top: 20px;
height: 100%;
min-height: 70vh;
}
.wrap {
width: 670px;
height: 300px;
line-height: 300px;
background-color: rgb(75, 73, 73);
color: #fff;
text-align: center;
}
.box {
position: relative;
}
font[size="1"] {
font-size: 14px;
}
font[size="2"] {
font-size: 16px;
}
font[size="3"] {
font-size: 18px;
}
font[size="4"] {
font-size: 20px;
}
font[size="5"] {
font-size: 22px;
}
font[size="6"] {
font-size: 24px;
}
font[size="7"] {
font-size: 26px;
}
.html >>> table {
border-top: 1px solid #ccc;
border-left: 1px solid #ccc;
margin: 10px 0;
line-height: 1.5;
}
.html >>> table td,
.html >>> table th {
border-bottom: 1px solid #ccc;
border-right: 1px solid #ccc;
padding: 3px 5px;
min-height: 30px;
height: 30px;
}
.html >>> table th {
border-bottom: 2px solid #ccc;
text-align: center;
background-color: #f1f1f1;
}
</style>
|