Skip to content

Commit

Permalink
fix(link): link button
Browse files Browse the repository at this point in the history
  • Loading branch information
mekery committed Apr 24, 2020
1 parent f8b7919 commit 7dc61c0
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 deletions.
61 changes: 61 additions & 0 deletions src/components/buttons/OLinkBtn.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<o-menubar-btn icon="link" :tooltip="$o.lang.editor.hyperlink" class="o-link-btn">
<q-menu ref="linkPopover"
anchor="bottom middle"
self="top middle"
class="shadow-5" @show="onShow">
<o-meta-input :val="href" :title="$o.lang.editor.hyperlink" icon="link"
@primaryAction="insertLink(commands.link, $event)">
</o-meta-input>
</q-menu>
</o-menubar-btn>
</template>

<script>
import OMenubarBtn from 'src/components/buttons/OMenubarBtn'
import OMetaInput from 'src/components/common/OMetaInput'
export default {
name: 'o-link-btn',
data () {
return {
href: ''
}
},
props: {
commands: {
type: Object
},
isActive: {
type: Object
},
getMarkAttrs: {
type: Function
}
},
components: {
OMenubarBtn,
OMetaInput
},
methods: {
onShow () {
this.href = ''
let link = this.getMarkAttrs('link')
console.log('show', link)
if (link) {
this.href = link.href
}
},
insertLink (command, href) {
command({ href })
}
},
computed: {
}
}
</script>

<style lang="stylus">
.o-photo-btn {
}
</style>
14 changes: 13 additions & 1 deletion src/components/common/OMetaInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<section class="o-meta-input">
<div class="title">{{title}}</div>
<div class="fields">
<q-input v-model="value" ref="input" standout="bg-blue" flat
<q-input v-model="value" ref="input" standout="bg-blue" clearable flat
:autofocus="true"
@keyup.enter.native="onConfirm" :placeholder="$o.lang.label.linkAddress">
<template v-slot:prepend>
Expand Down Expand Up @@ -30,6 +30,10 @@ export default {
}
},
props: {
val: {
type: String,
default: ''
},
title: {
type: String,
default: '超链接'
Expand All @@ -56,6 +60,14 @@ export default {
this.$emit('primaryAction', this.value)
this.value = ''
}
},
watch: {
val (to, from) {
this.value = to
}
},
mounted () {
this.value = this.val
}
}
</script>
Expand Down
2 changes: 2 additions & 0 deletions src/components/menubars/OEditorMenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import OHeadingList from 'src/components/buttons/OHeadingList'
import OAddMoreBtn from 'src/components/buttons/OAddMoreBtn'
import OPhotoBtn from 'src/components/buttons/OPhotoBtn'
import OLinkBtn from 'src/components/buttons/OLinkBtn'
import OTableBtn from 'src/components/buttons/OTableBtn'
import OTableGroup from 'src/components/buttons/OTableGroup'
Expand Down Expand Up @@ -110,6 +111,7 @@ export default {
OHeadingList,
OAddMoreBtn,
OPhotoBtn,
OLinkBtn,
OTableBtn,
OTableGroup
},
Expand Down
1 change: 1 addition & 0 deletions src/data/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const DefaultToolbar = [
'separator',
'blockquote',
'code_block',
'link',
'photo',
'table',
'separator',
Expand Down
1 change: 1 addition & 0 deletions src/pages/examples/basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default {
'separator',
'blockquote',
'code_block',
'link',
'photo',
'table',
'separator',
Expand Down
7 changes: 5 additions & 2 deletions src/utils/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const CommandComponents = {
'align-group': 'o-align-group',
'line-height': 'o-line-height-dropdown',
heading: 'o-heading-dropdown',
link: 'o-link-btn',
photo: 'o-photo-btn',
table: 'o-table-btn',
}
Expand All @@ -23,14 +24,16 @@ export const CommandComponents = {
* Table toolbar
*/
export const TableToolbar = [
'add-more',
'separator',
'bold',
'italic',
'strike',
'underline',
'code',
'separator',
'font-family',
'fore-color',
'back-color',
'format_clear',
'separator',
'bullet_list',
'ordered_list',
Expand Down

0 comments on commit 7dc61c0

Please sign in to comment.