fix(测试跟踪): 富文本框图片上传报错

--bug=1017611 --user=陈建星 测试计划评论时添加图片报错 https://www.tapd.cn/55049933/s/1258676
This commit is contained in:
chenjianxing 2022-10-11 17:56:59 +08:00 committed by jianxing
parent 5e5f54f087
commit 8156ffef1f
12 changed files with 16 additions and 714 deletions

View File

@ -114,7 +114,7 @@
<script>
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
import MsInputTag from "@/business/automation/scenario/MsInputTag";
import MsMarkDownText from "./MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
import {getProjectMemberOption} from "@/api/project";
export default {

View File

@ -5,7 +5,7 @@
</template>
<script>
import MsMarkDownText from "./MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
export default {
name: "FormRichTextItem",
components: {MsMarkDownText},

View File

@ -1,229 +0,0 @@
<template>
<mavon-editor :id="id" :editable="!disabled" @imgAdd="imgAdd" :default-open="defaultOpenValue"
:xss-options="xssOptions" :style="{'min-height': customMinHeight + 'px', 'min-width': '100px'}"
@change="$emit('change')"
:subfield="false" :toolbars="toolbars" :language="language" :toolbarsFlag="!disabled"
@imgDel="imgDel" v-model="data[prop]" ref="md"/>
</template>
<script>
import {getUUID} from "metersphere-frontend/src/utils";
import {getCurrentUser} from "metersphere-frontend/src/utils/token";
import {deleteMarkDownImg, uploadMarkDownImg} from "@/api/image";
import {DEFAULT_XSS_ATTR} from "metersphere-frontend/src/utils/constants";
export default {
name: "MsMarkDownText",
components: {},
props: {
data: Object,
prop: String,
disabled: Boolean,
defaultOpen: {
type: String,
default() {
return 'preview';
}
},
autoReview: {
type: Boolean,
default() {
return true;
}
},
customMinHeight: {
type: [Number, String],
default() {
return 20;
}
},
toolbars: {
type: Object,
default() {
return {
bold: true, //
italic: true, //
header: true, //
underline: true, // 线
strikethrough: true, // 线
mark: true, //
superscript: true, //
subscript: true, //
quote: true, //
ol: true, //
ul: true, //
link: true, //
imagelink: true, //
code: true, // code
table: true, //
fullscreen: true, //
readmodel: true, //
htmlcode: true, // html
help: true, //
/* 1.3.5 */
undo: true, //
redo: true, //
trash: true, //
save: false, // eventssave
/* 1.4.2 */
navigation: true, //
/* 2.1.8 */
alignleft: true, //
aligncenter: true, //
alignright: true, //
/* 2.2.1 */
subfield: true, //
preview: true, //
}
}
}
},
data() {
return {
result: {loading: false},
id: getUUID(),
xssOptions: {
whiteList: {
div: DEFAULT_XSS_ATTR,
p: DEFAULT_XSS_ATTR,
br: [],
h1: DEFAULT_XSS_ATTR,
h2: DEFAULT_XSS_ATTR,
h3: DEFAULT_XSS_ATTR,
h4: DEFAULT_XSS_ATTR,
h5: DEFAULT_XSS_ATTR,
h6: DEFAULT_XSS_ATTR,
hr: DEFAULT_XSS_ATTR,
span: DEFAULT_XSS_ATTR,
strong: DEFAULT_XSS_ATTR,
b: DEFAULT_XSS_ATTR,
i: DEFAULT_XSS_ATTR,
pre: DEFAULT_XSS_ATTR,
code: DEFAULT_XSS_ATTR,
tr: DEFAULT_XSS_ATTR,
table: [...DEFAULT_XSS_ATTR, 'width', 'border'],
td: [...DEFAULT_XSS_ATTR, 'width', 'colspan'],
th: [...DEFAULT_XSS_ATTR, 'width', 'colspan'],
a: [...DEFAULT_XSS_ATTR, 'target', 'href', 'title', 'rel'],
img: [...DEFAULT_XSS_ATTR, "src", "alt", "width", "height"],
tbody: DEFAULT_XSS_ATTR,
ul: DEFAULT_XSS_ATTR,
li: DEFAULT_XSS_ATTR,
ol: DEFAULT_XSS_ATTR,
dl: DEFAULT_XSS_ATTR,
dt: DEFAULT_XSS_ATTR,
em: DEFAULT_XSS_ATTR,
blockquote: DEFAULT_XSS_ATTR,
},
stripIgnoreTagBody: true
},
defaultOpenValue: 'preview'
}
},
computed: {
language() {
const user = getCurrentUser();
//
if (!user) {
return 'zh_CN';
}
const language = user.language;
switch (language) {
case 'zh_CN':
return 'zh-CN';
case 'zh_TW':
return 'zh-TW';
case 'en_US':
return 'en';
default:
return 'zh-CN';
}
}
},
watch: {
defaultOpen() {
if (this.defaultOpen) {
this.defaultOpenValue = this.defaultOpen;
}
}
},
mounted() {
if (!this.disabled) {
//
let el = document.getElementById(this.id);
if (!this.autoReview) {
this.defaultOpenValue = null;
}
if (this.defaultOpen) {
this.defaultOpenValue = this.defaultOpen;
}
if (el) {
el.addEventListener('click', () => {
let imagePreview = el.getElementsByClassName('v-note-img-wrapper');
if (imagePreview.length > 0) { //
if (this.autoReview) {
this.defaultOpenValue = 'preview';
}
} else {
if (this.autoReview) {
this.defaultOpenValue = null;
}
}
});
let input = el.getElementsByClassName('auto-textarea-input');
input[0].addEventListener('blur', () => {
if (this.autoReview) {
this.defaultOpenValue = 'preview';
}
});
}
}
},
methods: {
imgAdd(pos, file) {
this.result = true;
uploadMarkDownImg(file, (data) => {
this.$success(this.$t('commons.save_success'));
let url = '/resource/md/get?fileName=' + data;
this.$refs.md.$img2Url(pos, url);
this.result = false;
});
this.$emit('imgAdd', file);
},
imgDel(file) {
deleteMarkDownImg(file);
},
getContent() {
return this.$refs.md.d_render;
},
getTextareaDom() {
return this.$refs.md.getTextareaDom();
},
toolbar_left_click(param) {
this.$refs.md.toolbar_left_click(param);
}
}
}
</script>
<style scoped>
:deep(.v-note-wrapper) {
display: block !important;
position: static !important;
}
:deep(.dropdown-item.dropdown-images) {
display: none;
}
:deep(.v-note-op .v-left-item.transition .op-icon.fa.fa-mavon-picture-o.dropdown.dropdown-wrapper .op-image.popup-dropdown.transition) {
margin-left: 45px;
}
:deep(.v-note-op .v-left-item.transition .add-image-link-wrapper .add-image-link .op-btn.sure) {
background: #783887;
}
</style>

View File

@ -1,5 +1,5 @@
import {getUUID} from "../utils";
import {get, request} from "../plugins/request"
import {fileUpload, get} from "../plugins/request"
export function uploadMarkDownImg(file) {
@ -8,15 +8,7 @@ export function uploadMarkDownImg(file) {
};
file.prefix = param.id;
param.fileName = file.name.substring(file.name.lastIndexOf('.'));
let config = {
method: 'POST',
url: '/plugin/add',
data: param,
headers: {
'Content-Type': undefined
}
};
return request(config);
return fileUpload('/resource/md/upload', file, param);
}
export function deleteMarkDownImg(file) {

View File

@ -5,7 +5,7 @@
</template>
<script>
import MsMarkDownText from "./MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
export default {
name: "FormRichTextItem",
components: {MsMarkDownText},

View File

@ -184,12 +184,13 @@ export default {
methods: {
imgAdd(pos, file) {
this.result.loading = true;
uploadMarkDownImg(file, (data) => {
this.$success(this.$t('commons.save_success'));
let url = '/resource/md/get?fileName=' + data;
this.$refs.md.$img2Url(pos, url);
this.result.loading = false;
});
uploadMarkDownImg(file)
.then((r) => {
this.$success(this.$t('commons.save_success'));
let url = '/resource/md/get?fileName=' + r.data;
this.$refs.md.$img2Url(pos, url);
this.result.loading = false;
});
this.$emit('imgAdd', file);
},
imgDel(file) {

View File

@ -116,7 +116,7 @@
import MsTableColumn from "../table/MsTableColumn";
import MsInputTag from "../MsInputTag";
import {getProjectMemberOption} from "../../api/user";
import MsMarkDownText from "../MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
export default {
name: "CustomFiledComponent",

View File

@ -1,231 +0,0 @@
<template>
<mavon-editor :id="id" :editable="!disabled" @imgAdd="imgAdd" :default-open="defaultOpenValue"
:xss-options="xssOptions" :style="{'min-height': customMinHeight + 'px', 'min-width': '100px'}"
@change="$emit('change')"
:subfield="false" :toolbars="toolbars" :language="language" :toolbarsFlag="!disabled"
@imgDel="imgDel" v-model="data[prop]" ref="md"/>
</template>
<script>
import {getCurrentUser} from "metersphere-frontend/src/utils/token";
import {getUUID} from "metersphere-frontend/src/utils";
import {deleteMarkDownImg, uploadMarkDownImg} from "../../../api/img";
import {DEFAULT_XSS_ATTR} from "metersphere-frontend/src/utils/constants";
export default {
name: "MsMarkDownText",
components: {},
props: {
data: Object,
prop: String,
disabled: Boolean,
defaultOpen: {
type: String,
default() {
return 'preview';
}
},
autoReview: {
type: Boolean,
default() {
return true;
}
},
customMinHeight: {
type: [Number, String],
default() {
return 20;
}
},
toolbars: {
type: Object,
default() {
return {
bold: true, //
italic: true, //
header: true, //
underline: true, // 线
strikethrough: true, // 线
mark: true, //
superscript: true, //
subscript: true, //
quote: true, //
ol: true, //
ul: true, //
link: true, //
imagelink: true, //
code: true, // code
table: true, //
fullscreen: true, //
readmodel: true, //
htmlcode: true, // html
help: true, //
/* 1.3.5 */
undo: true, //
redo: true, //
trash: true, //
save: false, // eventssave
/* 1.4.2 */
navigation: true, //
/* 2.1.8 */
alignleft: true, //
aligncenter: true, //
alignright: true, //
/* 2.2.1 */
subfield: true, //
preview: true, //
}
}
}
},
data() {
return {
result: {loading: false},
id: getUUID(),
xssOptions: {
whiteList: {
div: DEFAULT_XSS_ATTR,
p: DEFAULT_XSS_ATTR,
br: [],
h1: DEFAULT_XSS_ATTR,
h2: DEFAULT_XSS_ATTR,
h3: DEFAULT_XSS_ATTR,
h4: DEFAULT_XSS_ATTR,
h5: DEFAULT_XSS_ATTR,
h6: DEFAULT_XSS_ATTR,
hr: DEFAULT_XSS_ATTR,
span: DEFAULT_XSS_ATTR,
strong: DEFAULT_XSS_ATTR,
b: DEFAULT_XSS_ATTR,
i: DEFAULT_XSS_ATTR,
pre: DEFAULT_XSS_ATTR,
code: DEFAULT_XSS_ATTR,
tr: DEFAULT_XSS_ATTR,
table: [...DEFAULT_XSS_ATTR, 'width', 'border'],
td: [...DEFAULT_XSS_ATTR, 'width', 'colspan'],
th: [...DEFAULT_XSS_ATTR, 'width', 'colspan'],
a: [...DEFAULT_XSS_ATTR, 'target', 'href', 'title', 'rel'],
img: [...DEFAULT_XSS_ATTR, "src", "alt", "width", "height"],
tbody: DEFAULT_XSS_ATTR,
ul: DEFAULT_XSS_ATTR,
li: DEFAULT_XSS_ATTR,
ol: DEFAULT_XSS_ATTR,
dl: DEFAULT_XSS_ATTR,
dt: DEFAULT_XSS_ATTR,
em: DEFAULT_XSS_ATTR,
blockquote: DEFAULT_XSS_ATTR,
},
stripIgnoreTagBody: true
},
defaultOpenValue: 'preview'
}
},
computed: {
language() {
const user = getCurrentUser();
//
if (!user) {
return 'zh_CN';
}
const language = user.language;
switch (language) {
case 'zh_CN':
return 'zh-CN';
case 'zh_TW':
return 'zh-TW';
case 'en_US':
return 'en';
default:
return 'zh-CN';
}
}
},
watch: {
defaultOpen() {
if (this.defaultOpen) {
this.defaultOpenValue = this.defaultOpen;
}
}
},
mounted() {
if (!this.disabled) {
//
let el = document.getElementById(this.id);
if (!this.autoReview) {
this.defaultOpenValue = null;
}
if (this.defaultOpen) {
this.defaultOpenValue = this.defaultOpen;
}
if (el) {
el.addEventListener('click', () => {
let imagePreview = el.getElementsByClassName('v-note-img-wrapper');
if (imagePreview.length > 0) { //
if (this.autoReview) {
this.defaultOpenValue = 'preview';
}
} else {
if (this.autoReview) {
this.defaultOpenValue = null;
}
}
});
let input = el.getElementsByClassName('auto-textarea-input');
input[0].addEventListener('blur', () => {
if (this.autoReview) {
this.defaultOpenValue = 'preview';
}
});
}
}
},
methods: {
imgAdd(pos, file) {
this.result.loading = true;
uploadMarkDownImg(file).then(data => {
this.$success(this.$t('commons.save_success'));
let url = '/resource/md/get?fileName=' + data;
this.$refs.md.$img2Url(pos, url);
this.result.loading = false;
})
this.$emit('imgAdd', file);
},
imgDel(file) {
deleteMarkDownImg(file);
},
getContent() {
return this.$refs.md.d_render;
},
getTextareaDom() {
return this.$refs.md.getTextareaDom();
},
toolbar_left_click(param) {
this.$refs.md.toolbar_left_click(param);
}
}
}
</script>
<style scoped>
:deep(.v-note-wrapper) {
display: block !important;
position: static !important;
}
:deep(.dropdown-item.dropdown-images) {
display: none;
}
:deep(.v-note-op .v-left-item.transition .op-icon.fa.fa-mavon-picture-o.dropdown.dropdown-wrapper .op-image.popup-dropdown.transition) {
margin-left: 45px;
}
:deep(.v-note-op .v-left-item.transition .add-image-link-wrapper .add-image-link .op-btn.sure) {
background: #783887;
}
</style>

View File

@ -121,7 +121,7 @@
<script>
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
import MsInputTag from "metersphere-frontend/src/components/MsInputTag";
import MsMarkDownText from "../common/MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
import {getProjectMemberOption} from "metersphere-frontend/src/api/user"
export default {

View File

@ -5,7 +5,7 @@
</template>
<script>
import MsMarkDownText from "../../common/MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
export default {
name: "FormRichTextItem",

View File

@ -1,231 +0,0 @@
<template>
<mavon-editor :id="id" :editable="!disabled" @imgAdd="imgAdd" :default-open="defaultOpenValue"
:xss-options="xssOptions" :style="{'min-height': customMinHeight + 'px', 'min-width': '100px'}"
@change="$emit('change')"
:subfield="false" :toolbars="toolbars" :language="language" :toolbarsFlag="!disabled"
@imgDel="imgDel" v-model="data[prop]" ref="md"/>
</template>
<script>
import {getCurrentUser} from "metersphere-frontend/src/utils/token";
import {getUUID} from "metersphere-frontend/src/utils";
import {deleteMarkDownImg, uploadMarkDownImg} from "@/api/img";
import {DEFAULT_XSS_ATTR} from "metersphere-frontend/src/utils/constants";
export default {
name: "MsMarkDownText",
components: {},
props: {
data: Object,
prop: String,
disabled: Boolean,
defaultOpen: {
type: String,
default() {
return 'preview';
}
},
autoReview: {
type: Boolean,
default() {
return true;
}
},
customMinHeight: {
type: [Number, String],
default() {
return 20;
}
},
toolbars: {
type: Object,
default() {
return {
bold: true, //
italic: true, //
header: true, //
underline: true, // 线
strikethrough: true, // 线
mark: true, //
superscript: true, //
subscript: true, //
quote: true, //
ol: true, //
ul: true, //
link: true, //
imagelink: true, //
code: true, // code
table: true, //
fullscreen: true, //
readmodel: true, //
htmlcode: true, // html
help: true, //
/* 1.3.5 */
undo: true, //
redo: true, //
trash: true, //
save: false, // eventssave
/* 1.4.2 */
navigation: true, //
/* 2.1.8 */
alignleft: true, //
aligncenter: true, //
alignright: true, //
/* 2.2.1 */
subfield: true, //
preview: true, //
}
}
}
},
data() {
return {
result: {loading: false},
id: getUUID(),
xssOptions: {
whiteList: {
div: DEFAULT_XSS_ATTR,
p: DEFAULT_XSS_ATTR,
br: [],
h1: DEFAULT_XSS_ATTR,
h2: DEFAULT_XSS_ATTR,
h3: DEFAULT_XSS_ATTR,
h4: DEFAULT_XSS_ATTR,
h5: DEFAULT_XSS_ATTR,
h6: DEFAULT_XSS_ATTR,
hr: DEFAULT_XSS_ATTR,
span: DEFAULT_XSS_ATTR,
strong: DEFAULT_XSS_ATTR,
b: DEFAULT_XSS_ATTR,
i: DEFAULT_XSS_ATTR,
pre: DEFAULT_XSS_ATTR,
code: DEFAULT_XSS_ATTR,
tr: DEFAULT_XSS_ATTR,
table: [...DEFAULT_XSS_ATTR, 'width', 'border'],
td: [...DEFAULT_XSS_ATTR, 'width', 'colspan'],
th: [...DEFAULT_XSS_ATTR, 'width', 'colspan'],
a: [...DEFAULT_XSS_ATTR, 'target', 'href', 'title', 'rel'],
img: [...DEFAULT_XSS_ATTR, "src", "alt", "width", "height"],
tbody: DEFAULT_XSS_ATTR,
ul: DEFAULT_XSS_ATTR,
li: DEFAULT_XSS_ATTR,
ol: DEFAULT_XSS_ATTR,
dl: DEFAULT_XSS_ATTR,
dt: DEFAULT_XSS_ATTR,
em: DEFAULT_XSS_ATTR,
blockquote: DEFAULT_XSS_ATTR,
},
stripIgnoreTagBody: true
},
defaultOpenValue: 'preview'
}
},
computed: {
language() {
const user = getCurrentUser();
//
if (!user) {
return 'zh_CN';
}
const language = user.language;
switch (language) {
case 'zh_CN':
return 'zh-CN';
case 'zh_TW':
return 'zh-TW';
case 'en_US':
return 'en';
default:
return 'zh-CN';
}
}
},
watch: {
defaultOpen() {
if (this.defaultOpen) {
this.defaultOpenValue = this.defaultOpen;
}
}
},
mounted() {
if (!this.disabled) {
//
let el = document.getElementById(this.id);
if (!this.autoReview) {
this.defaultOpenValue = null;
}
if (this.defaultOpen) {
this.defaultOpenValue = this.defaultOpen;
}
if (el) {
el.addEventListener('click', () => {
let imagePreview = el.getElementsByClassName('v-note-img-wrapper');
if (imagePreview.length > 0) { //
if (this.autoReview) {
this.defaultOpenValue = 'preview';
}
} else {
if (this.autoReview) {
this.defaultOpenValue = null;
}
}
});
let input = el.getElementsByClassName('auto-textarea-input');
input[0].addEventListener('blur', () => {
if (this.autoReview) {
this.defaultOpenValue = 'preview';
}
});
}
}
},
methods: {
imgAdd(pos, file) {
this.result.loading = true;
uploadMarkDownImg(file).then(response => {
this.$success(this.$t('commons.save_success'));
let url = '/resource/md/get?fileName=' + response.data;
this.$refs.md.$img2Url(pos, url);
this.result.loading = false;
})
this.$emit('imgAdd', file);
},
imgDel(file) {
deleteMarkDownImg(file);
},
getContent() {
return this.$refs.md.d_render;
},
getTextareaDom() {
return this.$refs.md.getTextareaDom();
},
toolbar_left_click(param) {
this.$refs.md.toolbar_left_click(param);
}
}
}
</script>
<style scoped>
:deep(.v-note-wrapper) {
display: block !important;
position: static !important;
}
:deep(.dropdown-item.dropdown-images) {
display: none;
}
:deep(.v-note-op .v-left-item.transition .op-icon.fa.fa-mavon-picture-o.dropdown.dropdown-wrapper .op-image.popup-dropdown.transition) {
margin-left: 45px;
}
:deep(.v-note-op .v-left-item.transition .add-image-link-wrapper .add-image-link .op-btn.sure) {
background: #783887;
}
</style>

View File

@ -17,7 +17,7 @@
<script>
import MsMarkDownText from "@/business/compnent/form/MsMarkDownText";
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
export default {
name: "ReportAttachInfo",