e5b57447
杨鑫
'分包问卷'
|
1
2
3
4
5
6
|
<template>
<div style="border: 1px solid #ccc">
<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editor"
:class="showToolbar == true?'':'tooll'"
|
d64cd58f
wesley88
上传验收小程序
|
7
|
:default-config="toolbarConfig"
|
e5b57447
杨鑫
'分包问卷'
|
8
9
10
|
:mode="mode"
/>
<Editor
|
e5b57447
杨鑫
'分包问卷'
|
11
|
v-model="html"
|
d64cd58f
wesley88
上传验收小程序
|
12
13
|
:style="`height:${height}px;overflow-y: hidden;`"
:default-config="editorConfig"
|
e5b57447
杨鑫
'分包问卷'
|
14
15
16
17
18
19
20
21
|
:mode="mode"
@onCreated="onCreated"
@onChange="onChange"
/>
</div>
</template>
<script>
|
d64cd58f
wesley88
上传验收小程序
|
22
23
24
25
|
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import {
imgUp
} from '../../api/imgFlieUp'
|
bc51a62b
杨鑫
'最新'
|
26
|
|
e5b57447
杨鑫
'分包问卷'
|
27
28
29
|
export default {
components: { Editor, Toolbar },
props: {
|
d64cd58f
wesley88
上传验收小程序
|
30
|
value: {
|
e5b57447
杨鑫
'分包问卷'
|
31
32
33
|
type: String,
default: ''
},
|
d64cd58f
wesley88
上传验收小程序
|
34
35
36
|
read: {
type: Boolean,
default: false
|
e5b57447
杨鑫
'分包问卷'
|
37
|
},
|
d64cd58f
wesley88
上传验收小程序
|
38
39
40
41
42
43
|
height: {
type: Number,
default: 300
}
},
data () {
|
e5b57447
杨鑫
'分包问卷'
|
44
45
46
47
|
return {
// read:false,
editor: null,
showToolbar: true, // 默认显示编辑栏
|
d64cd58f
wesley88
上传验收小程序
|
48
|
html: '',
|
e5b57447
杨鑫
'分包问卷'
|
49
50
|
toolbarConfig: {
// 不要的功能按钮
|
d64cd58f
wesley88
上传验收小程序
|
51
|
excludeKeys: ['insertVideo', 'uploadVideo', 'insertImage'],
|
e5b57447
杨鑫
'分包问卷'
|
52
53
54
|
},
editorConfig: {
|
d64cd58f
wesley88
上传验收小程序
|
55
56
|
readOnly: false,
placeholder: '请输入内容...',
|
e5b57447
杨鑫
'分包问卷'
|
57
|
MENU_CONF: {
|
d64cd58f
wesley88
上传验收小程序
|
58
59
60
|
uploadImage: {
customUpload: this.uploadImg, // 自定义上传方法
},
|
e5b57447
杨鑫
'分包问卷'
|
61
62
|
},
},
|
d64cd58f
wesley88
上传验收小程序
|
63
|
mode: 'default', // or 'simple'
|
e5b57447
杨鑫
'分包问卷'
|
64
65
66
67
|
};
},
watch: {
|
d64cd58f
wesley88
上传验收小程序
|
68
69
70
71
72
|
read: {
handler (newVal, oldVal) {
// this.showToolbar = !newVal;
// this.editorConfig.readOnly = newVal;
this.$nextTick(() => {
|
e5b57447
杨鑫
'分包问卷'
|
73
74
|
this.showToolbar = !newVal;
this.editorConfig.readOnly = newVal;
|
d64cd58f
wesley88
上传验收小程序
|
75
76
77
78
79
80
81
82
83
84
|
});
},
immediate: true, // 添加此选项以立即执行回调
deep: true
},
value (newVule, old) {
if (newVule != '<p><br></p>') {
this.html = this.value;
console.log(newVule, old);
}
|
e5b57447
杨鑫
'分包问卷'
|
85
|
},
|
e5b57447
杨鑫
'分包问卷'
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
},
// computed: {
// computedEditorConfig() {
// return {
// readOnly: this.read,
// placeholder: "请输入内容...",
// MENU_CONF: {
// uploadImage: {
// customUpload: this.uploadImg, // 自定义上传方法
// },
// },
// };
// }
// },
|
d64cd58f
wesley88
上传验收小程序
|
100
|
mounted () {
|
e5b57447
杨鑫
'分包问卷'
|
101
102
103
104
105
|
// 异步渲染编辑器
this.$nextTick(() => {
this.html = this.value;
});
},
|
d64cd58f
wesley88
上传验收小程序
|
106
107
108
109
110
|
beforeDestroy () {
const editor = this.editor;
if (editor == null) return;
editor.destroy(); // 组件销毁时,及时销毁编辑器
},
|
e5b57447
杨鑫
'分包问卷'
|
111
112
|
methods: {
// 上传图片
|
d64cd58f
wesley88
上传验收小程序
|
113
|
uploadImg (file, insertFn) {
|
e5b57447
杨鑫
'分包问卷'
|
114
|
const { type } = file;
|
d64cd58f
wesley88
上传验收小程序
|
115
116
|
if (type.indexOf('image') < 0) {
this.$message.warning('请选择上传图片');
|
e5b57447
杨鑫
'分包问卷'
|
117
118
119
|
return false;
}
const formData = new FormData();
|
d64cd58f
wesley88
上传验收小程序
|
120
|
formData.append('file', file);
|
e5b57447
杨鑫
'分包问卷'
|
121
122
123
124
|
imgUp(formData)
.then((res) => {
console.log(res)
|
d64cd58f
wesley88
上传验收小程序
|
125
|
if (res.code == '') {
|
e5b57447
杨鑫
'分包问卷'
|
126
|
// 从 res 中找到 url alt href ,然后插入图片
|
d64cd58f
wesley88
上传验收小程序
|
127
|
insertFn(this.hostUrl + res.data.url);
|
e5b57447
杨鑫
'分包问卷'
|
128
|
} else {
|
d64cd58f
wesley88
上传验收小程序
|
129
|
this.$message.error(res.statusText || '上传失败');
|
e5b57447
杨鑫
'分包问卷'
|
130
131
132
|
}
})
.catch(() => {
|
d64cd58f
wesley88
上传验收小程序
|
133
|
this.$message.error('上传失败');
|
e5b57447
杨鑫
'分包问卷'
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
});
},
// 上传视频
// uploadVideo(file, insertFn) {
// const { type } = file;
// if (type.indexOf("video") < 0) {
// this.$message.warning("请选择上传视频");
// return false;
// }
// const formData = new FormData();
// formData.append("file", file);
// this.$api
// .uploadFile(formData)
// .then((res) => {
// if (res.status === 200) {
// // 从 res 中找到 url poster(封面图) ,然后插入视频
// insertFn(res.data.url);
// } else {
// this.$message.error(res.statusText || "上传失败");
// }
// })
// .catch(() => {
// this.$message.error("上传失败");
// });
// },
|
d64cd58f
wesley88
上传验收小程序
|
160
|
onCreated (editor) {
|
e5b57447
杨鑫
'分包问卷'
|
161
162
|
this.editor = Object.seal(editor); // 一定要用 Object.seal() ,否则会报错
},
|
d64cd58f
wesley88
上传验收小程序
|
163
164
|
onChange () {
this.$emit('input', this.html);
|
e5b57447
杨鑫
'分包问卷'
|
165
166
|
},
},
|
e5b57447
杨鑫
'分包问卷'
|
167
168
169
170
171
172
173
174
175
176
|
};
</script>
<style scoped lang="scss">
@import url("./index.css");
::v-deep .tooll{
.w-e-toolbar{
display: none;
}
}
|
8550d958
杨鑫
'最新'
|
177
|
|
e5b57447
杨鑫
'分包问卷'
|
178
|
</style>
|