lbp-text.js
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
160
161
162
163
164
165
166
167
import { quillEditor } from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import './styles/text-overwrite-quil-snow-theme.scss'
export default {
render (h) {
const {
color,
textAlign,
fontSize,
lineHeight,
borderColor,
borderWidth
} = this
const style = {
position: 'relative',
textAlign,
fontSize,
color: `${color} !important`,
textDecoration: 'none',
backgroundColor: 'transparent',
lineHeight: lineHeight + 'em',
border: `${borderWidth}px solid ${borderColor}`
}
const pureText = <div domPropsInnerHTML={this.text} class="ql-editor ql-container"></div>
return (
<div
onDblclick={e => {
this.canEdit = true
e.stopPropagation()
}}
onMousedown={e => {
if (this.canEdit) { e.stopPropagation() }
}}
v-click-outside={(e) => {
this.canEdit = false
}}
style={style}
>
{
this.canEdit
? <quillEditor
content={this.text}
options={{
modules: {
// toolbar: '#toolbar-wrapper'
toolbar: [
['bold', 'italic', 'underline', 'strike'], // 切换按钮
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'color': [] }, { 'background': [] }], // 主题默认下拉,使用主题提供的值
[{ 'align': [] }],
['clean'], // 清除格式
[{ 'header': [1, 2, 3, 4, 5, 6, false] }]
// https://github.com/quilljs/quill/issues/1208
]
},
theme: 'snow'
}}
onChange={({ quill, html, text }) => {
this.$emit('input', {
value: html,
pluginName: 'lbp-text'
})
}}>
</quillEditor>
: pureText
}
</div>
)
},
name: 'lbp-text',
data () {
return {
canEdit: false,
innerText: this.text || '双击修改文字'
}
},
props: {
text: {
type: String,
default: '双击修改文字'
},
disabled: {
type: Boolean,
default: false
},
backgroundColor: {
type: String,
default: 'transparent'
},
lineHeight: {
type: Number,
default: 1
},
borderWidth: {
type: Number,
default: 0
},
borderRadius: {
type: Number,
default: 0
},
borderColor: {
type: String,
default: '#ced4da'
},
borderStyle: {
type: String,
default: 'solid'
}
},
editorConfig: {
propsConfig: {
borderColor: {
type: 'a-input', // lbs-color-picker
label: '边框颜色',
prop: {
type: 'color'
},
require: true,
defaultPropValue: '#333333'
},
borderWidth: {
type: 'a-input-number',
label: '边框宽度(px)',
require: true,
prop: {
step: 1,
min: 0,
max: 10
},
defaultPropValue: 0
},
borderRadius: {
type: 'a-input-number',
label: '圆角(px)',
require: true,
prop: {
step: 0.1,
min: 0,
max: 10
},
defaultPropValue: 0
},
borderStyle: {
type: 'a-input',
label: '边框形式',
require: true,
defaultPropValue: 'solid'
},
lineHeight: {
type: 'a-input-number',
label: '行高',
require: true,
prop: {
step: 0.1,
min: 0.1,
max: 10
},
defaultPropValue: 1
}
}
}
}