|
@@ -22,7 +22,7 @@ import urlConfig from "@/apis/url-config";
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
export default {
|
|
|
name: "comModule",
|
|
|
-
|
|
|
+
|
|
|
mixins: [resToken],
|
|
|
props: ["id", "value"],
|
|
|
data() {
|
|
@@ -44,6 +44,9 @@ export default {
|
|
|
event.stopPropagation();
|
|
|
let focusOffset = 0;
|
|
|
let anchorOffset = 0;
|
|
|
+ let einput = this.$refs.txt1.innerHTML || "";
|
|
|
+ const typeList = ["image/jpg", "image/png", "image/jpeg"];
|
|
|
+ let len = einput.length;
|
|
|
if (
|
|
|
window.getSelection().focusOffset <= window.getSelection().anchorOffset
|
|
|
) {
|
|
@@ -53,25 +56,33 @@ export default {
|
|
|
focusOffset = window.getSelection().anchorOffset;
|
|
|
anchorOffset = window.getSelection().focusOffset;
|
|
|
}
|
|
|
-
|
|
|
+ console.log(focusOffset, anchorOffset, len);
|
|
|
+ let left = "",
|
|
|
+ right = "";
|
|
|
+ if (focusOffset !== 0) {
|
|
|
+ left = einput.slice(0, focusOffset);
|
|
|
+ }
|
|
|
+ if (anchorOffset !== len) {
|
|
|
+ right = einput.slice(anchorOffset);
|
|
|
+ }
|
|
|
const items = (event.clipboardData || window.clipboardData).items;
|
|
|
let file = null;
|
|
|
-
|
|
|
+ let findex = -1;
|
|
|
if (!items || items.length === 0) {
|
|
|
this.$message.error("当前浏览器不支持本地或请打开图片再复制");
|
|
|
return;
|
|
|
}
|
|
|
- let typeList = ["image/jpg", "image/png", "image/jpeg"];
|
|
|
- // 搜索剪切板items
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
- items[i].getAsFileSystemHandle().then((re) => {
|
|
|
- console.log(re);
|
|
|
- });
|
|
|
-
|
|
|
- let index = typeList.findIndex((v) => v == items[i].type);
|
|
|
- if (index !== -1) {
|
|
|
- file = items[i].getAsFile();
|
|
|
- break;
|
|
|
+ if (items[i].type === "text/plain") {
|
|
|
+ let clipboardData = event.clipboardData || window.clipboardData;
|
|
|
+ let pastedData = clipboardData.getData("Text");
|
|
|
+ this.input = `${left}${pastedData}${right}`;
|
|
|
+ } else {
|
|
|
+ findex = typeList.findIndex((v) => v == items[i].type);
|
|
|
+ if (findex !== -1) {
|
|
|
+ file = items[i].getAsFile();
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (!file) {
|
|
@@ -88,13 +99,11 @@ export default {
|
|
|
await this.logout();
|
|
|
} else {
|
|
|
const { name, url } = res;
|
|
|
- this.input = `${this.input.slice(
|
|
|
- 0,
|
|
|
- focusOffset
|
|
|
- )}<img style='display: inline-block;max-width: 100%;height: auto;' src='${url}'/>${this.input.slice(
|
|
|
- anchorOffset
|
|
|
- )}`;
|
|
|
+ this.input = `${left}<img style='display: inline-block;max-width: 50%;' src='${url}'/>${right}`;
|
|
|
}
|
|
|
+ // console.log(left);
|
|
|
+ // console.log(right);
|
|
|
+ // console.log(this.input);
|
|
|
},
|
|
|
|
|
|
async httpupLoad(file) {
|
|
@@ -132,7 +141,13 @@ export default {
|
|
|
async submitForm() {
|
|
|
this.loading = true;
|
|
|
let str = this.$refs.txt1.innerHTML;
|
|
|
+ let length = 2000;
|
|
|
if (str) {
|
|
|
+ if (str.length > length) {
|
|
|
+ this.$message.warning("评论文字及图片总长度不能超过2000!");
|
|
|
+ this.loading = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.loading = false;
|
|
|
this.$emit("submit", {
|
|
|
id: this.id,
|