Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: 编辑器默认样式美化 #22

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions src/v-editor.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<template>
<div class="v-editor">
<div class="loading-mask"
v-if="showLoading">
<div class="loading-mask" v-if="showLoading">
<div class="loading-content">
<!-- @slot 自定义上传文本 -->
<slot name="loading">
<p>文件上传中...</p>
</slot>
</div>
</div>
<div ref="editor"
style="text-align:left"
@paste="paste">
</div>
<upload-to-ali multiple
v-show="false"
ref="uploadToAli"
v-bind="uploadOptions"
@loading="handleLoading"
@loaded="handleUploadFileSuccess"></upload-to-ali>

<div ref="editor" style="text-align:left" @paste="paste"></div>
<upload-to-ali
multiple
v-show="false"
ref="uploadToAli"
v-bind="uploadOptions"
@loading="handleLoading"
@loaded="handleUploadFileSuccess"
/>
</div>
</template>

Expand Down Expand Up @@ -154,15 +151,36 @@ export default {
//设置默认值
editor.txt.html(editorValue(this.value))
//是否禁用编辑器
this.$refs.editor.querySelector('.w-e-toolbar').style[
'pointer-events'
] = this.disabled ? 'none' : ''
editor.$textElem.attr('contenteditable', !this.disabled)

const toolbar = this.$refs.editor.querySelector('.w-e-toolbar')
toolbar.style['pointer-events'] = this.disabled ? 'none' : ''
// 设置toolbar的颜色
const borderColor = '#CAD1E8'
const borderRadius = '4px'
toolbar.style.backgroundColor = '#F4F6FA'
toolbar.style.borderColor = borderColor
toolbar.style.borderTopLeftRadius = borderRadius
toolbar.style.borderTopRightRadius = borderRadius
const opacityIdle = 0.6
const opacityFocus = 1
toolbar.querySelectorAll('.w-e-menu').forEach(item => {
const i = item.querySelector('i')
i.style.color = '#2D303B'
i.style.opacity = opacityIdle
item.addEventListener(
'mouseenter',
() => (i.style.opacity = opacityFocus)
)
item.addEventListener('mouseleave', () => (i.style.opacity = opacityIdle))
})

//设置编辑器的高度
this.$refs.editor.querySelector('.w-e-text-container').style.height = `${
this.height
}px`
const textContainer = this.$refs.editor.querySelector('.w-e-text-container')
textContainer.style.borderColor = borderColor
textContainer.style.height = `${this.height}px`
textContainer.style.borderBottomLeftRadius = borderRadius
textContainer.style.borderBottomRightRadius = borderRadius

//监听上传图标的点击事件
document
Expand Down