Skip to content

Commit ca9a675

Browse files
author
gongjs
authored
Tinymce (#214)
* Update README.md * Update axios.js * feat:富文本 Tinymce * fix:去掉tinymce标识 * update:新增富文本部分内置插件 * fix:富文本上传图片加入token验证 * fix:自动化导入富文本插件
1 parent 8afc951 commit ca9a675

File tree

7 files changed

+81
-53
lines changed

7 files changed

+81
-53
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ QQ群搜索:林间有风 或 643205479
8989

9090
## 版本日志
9191

92+
<<<<<<< HEAD
9293
最新版本 `0.2.0`
9394

9495
### 0.2.0
9596

9697
1. `A` 新增图像上传、图像预览、富文本等自定义组件
9798
2. `A` 新增 lin-cms-ui 多个基础组件
99+
=======
100+
最新版本 `0.1.0-beta.3`
101+
>>>>>>> 0b890cda57f1aaa11af9315d031ae15fae4def51
98102
99103
### 0.1.0-beta.3
100104

package-lock.json

Lines changed: 45 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"moment": "^2.24.0",
2626
"photoswipe": "^4.1.2",
2727
"screenfull": "^4.2.0",
28-
"tinymce": "^5.0.9",
28+
"tinymce": "^5.0.12",
2929
"vue": "^2.6.8",
3030
"vue-awesome-swiper": "^3.1.3",
3131
"vue-croppa": "^1.3.8",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// eslint-disable-next-line
2+
const importAll = (requireContext) => requireContext.keys().forEach(requireContext)
3+
try {
4+
// 导入所有插件
5+
importAll(require.context('../../../../node_modules/tinymce/plugins', true))
6+
} catch (err) {
7+
console.log(err)
8+
}

src/components/base/tinymce/index.vue

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
<editor id="tinymceEditor" :init="tinymceInit" v-model="content" :key="tinymceFlag"></editor>
44
</div>
55
</template>
6-
76
<script>
87
// eslint-disable-next-line
98
import tinymce from 'tinymce/tinymce'
109
import Editor from '@tinymce/tinymce-vue'
1110
import 'tinymce/themes/silver/theme'
12-
import 'tinymce/plugins/textcolor'
13-
import 'tinymce/plugins/advlist'
14-
import 'tinymce/plugins/table'
15-
import 'tinymce/plugins/lists'
16-
import 'tinymce/plugins/paste'
17-
import 'tinymce/plugins/preview'
18-
import 'tinymce/plugins/fullscreen'
19-
import 'tinymce/plugins/image'
20-
import 'tinymce/plugins/code'
21-
import 'tinymce/plugins/link'
11+
import './importAll'
2212
2313
export default {
2414
name: 'TinymceEditor',
@@ -39,6 +29,11 @@ export default {
3929
type: Boolean,
4030
default: true,
4131
},
32+
toolbar: {
33+
type: String,
34+
// eslint-disable-next-line
35+
default: ' undo redo |formatselect | bold italic strikethrough forecolor backcolor formatpainter | link image | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | preview fullscreen code',
36+
},
4237
},
4338
components: {
4439
Editor,
@@ -64,32 +59,25 @@ export default {
6459
statusbar: false, // 隐藏编辑器底部的状态栏
6560
paste_data_images: true, // 允许粘贴图像
6661
menubar: this.showMenubar, // 隐藏最上方menu
67-
plugins: 'advlist table lists paste preview fullscreen image code link',
6862
// eslint-disable-next-line
69-
toolbar:' undo redo |fontselect fontsizeselect forecolor backcolor bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | link image | h1 h2 h3 blockquote table numlist bullist | preview fullscreen code',
63+
plugins: 'print fullpage searchreplace autolink directionality visualblocks visualchars template codesample charmap hr pagebreak nonbreaking anchor toc insertdatetime wordcount textpattern help advlist table lists paste preview fullscreen image imagetools code link',
64+
toolbar: this.toolbar,
7065
// eslint-disable-next-line
7166
images_upload_handler: async function(blobInfo, success, failure) {
72-
// eslint-disable-next-line
73-
let json
74-
const xhr = new XMLHttpRequest()
75-
xhr.withCredentials = false
76-
xhr.open('POST', `${_this.upload_url}`)
77-
// eslint-disable-next-line
78-
xhr.onload = function() {
79-
if (xhr.status !== 200) {
80-
failure(`HTTP Error: ${xhr.status}`)
81-
return
82-
}
83-
json = JSON.parse(xhr.responseText)
84-
if (json[0] && json[0].url) {
85-
success(json[0].url)
86-
} else {
87-
failure(`Invalid JSON: ${xhr.responseText}`)
67+
const file = new File([blobInfo.blob()], blobInfo.filename(), {
68+
type: 'image/*',
69+
})
70+
_this.$axios({
71+
method: 'post',
72+
url: '/cms/file/',
73+
data: {
74+
file,
75+
},
76+
}).then((res) => {
77+
if (res[0] && res[0].url) {
78+
success(res[0].url)
8879
}
89-
}
90-
const formData = new FormData()
91-
formData.append('file', blobInfo.blob(), blobInfo.filename())
92-
xhr.send(formData)
80+
}).catch(err => failure(err))
9381
},
9482
}
9583
},

src/config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Config = {
2-
baseUrl: process.env.VUE_APP_BASE_URL,
2+
baseUrl: 'http://dev.lin.colorful3.com/',
33
stagnateTime: 1 * 60 * 60 * 1000, // 无操作停滞时间 默认1小时
44
openAutoJumpOut: true, // 是否开启无操作跳出
55
notLoginRoute: ['login'], // 无需登录即可访问的路由 name,

src/plugins/custom/views/Tinymce.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</template>
99

1010
<script>
11+
1112
import Tinymce from '@/components/base/tinymce'
1213
1314
export default {

0 commit comments

Comments
 (0)