-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
9,413 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# vuepress-plugin-toolbar | ||
|
||
适用于 [vuepress](https://vuepress.vuejs.org/zh/plugin/using-a-plugin.html) 插件的插件 | ||
|
||
提供的功能:可以在页面右侧区域出现自定义展示功能,如下图 | ||
|
||
![image-1](https://github.com/zq99299/vuepress-plugin/blob/master/vuepress-plugin-toolbar/docs/assets/1.png?raw=true) | ||
|
||
## Install | ||
|
||
```bash | ||
yarn add vuepress-plugin-toolbar | ||
# OR | ||
npm install vuepress-plugin-toolbar | ||
``` | ||
|
||
> open npm : https://www.npmjs.com/package/vuepress-plugin-toolbar | ||
## Usage | ||
|
||
```javascript | ||
module.exports = { | ||
"plugins": [ | ||
["vuepress-plugin-toolbar",{ | ||
"opts": [ | ||
{ | ||
"icon": "", | ||
"name": "文本展示", | ||
"popover": { | ||
"type": "text", | ||
"title": "纯文本说明", | ||
"text": "这是一个纯文本的内容展示,就是一段话" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} | ||
``` | ||
|
||
更多自定义配置,[请参考这里](https://zq99299.github.io/vuepress-plugin/vuepress-plugin-toolbar) |
29 changes: 29 additions & 0 deletions
29
.vuepress/plugins/vuepress-plugin-toolbar/ToolbarAsidebar.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<aside class="me-toolbar-sidebar"> | ||
<!-- 用户导航利用此节点插入到最前面--> | ||
<div class="logic_first-node"></div> | ||
<custom-opt v-for="item in customOptConfigs" | ||
:config="item" | ||
></custom-opt> | ||
</aside> | ||
</template> | ||
|
||
<script> | ||
import CustomOpt from './components/custom-opt/CustomOpt' | ||
export default { | ||
components: { CustomOpt }, | ||
data () { | ||
return { | ||
customOptConfigs: null | ||
} | ||
}, | ||
created () { | ||
this.customOptConfigs = MRCODE_TOOLBAR.opts | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="stylus" scoped> | ||
</style> |
81 changes: 81 additions & 0 deletions
81
.vuepress/plugins/vuepress-plugin-toolbar/clientRootMixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Vue from 'vue' | ||
import ToolbarAsidebar from './ToolbarAsidebar' | ||
import PageNav from './components/page-nav/PageNav' | ||
import CustomOpt from './components/custom-opt/CustomOpt' | ||
|
||
export default { | ||
created () { | ||
this._mrcodeToolbar = { | ||
pageAsidebar: null, | ||
pageNav: null | ||
} | ||
}, | ||
mounted () { | ||
}, | ||
watch: { | ||
'$page.path' (val) { | ||
}, | ||
'$page.key' (val) { | ||
this.pageNavUpdate(val, this.$page) | ||
} | ||
}, | ||
updated () { | ||
this.init(); | ||
}, | ||
beforeDestroy(){ | ||
}, | ||
methods: { | ||
init () { | ||
this.pageAsidebarInsert() | ||
if (MRCODE_TOOLBAR.pageNav) { | ||
this.pageNavInsert(MRCODE_TOOLBAR.pageNav) | ||
} | ||
}, | ||
pageAsidebarInsert () { | ||
if (this._mrcodeToolbar.pageAsidebar) { | ||
return | ||
} | ||
const containers = document.querySelectorAll('.theme-container') | ||
let container = null | ||
if (containers && containers.length > 0) { | ||
container = containers[0] | ||
} | ||
if (!container) { | ||
return | ||
} | ||
const PageAsidebarObj = Vue.extend(ToolbarAsidebar) | ||
const pageAsidebarObjIns = new PageAsidebarObj() | ||
pageAsidebarObjIns._parent = container | ||
pageAsidebarObjIns.$mount() | ||
container.appendChild(pageAsidebarObjIns.$el) | ||
this._mrcodeToolbar.pageAsidebar = pageAsidebarObjIns | ||
}, | ||
pageNavInsert (config) { | ||
// 如果没有初始化 | ||
if (!this._mrcodeToolbar.pageNav) { | ||
let pageAsidebar = this._mrcodeToolbar.pageAsidebar | ||
const PageNavObj = Vue.extend(PageNav) | ||
const pageNavObjIns = new PageNavObj({ | ||
propsData: { | ||
config: config | ||
} | ||
}) | ||
if(!pageAsidebar){ | ||
this.init() | ||
return; | ||
} | ||
pageNavObjIns._parent = pageAsidebar.$el | ||
pageNavObjIns.$mount() | ||
pageNavObjIns.pageObject = this.$page | ||
pageAsidebar.$el.insertBefore(pageNavObjIns.$el, pageAsidebar.$el.firstChild) | ||
this._mrcodeToolbar.pageNav = pageNavObjIns | ||
} | ||
}, | ||
pageNavUpdate (pageKey, pageObject) { | ||
if (this._mrcodeToolbar.pageNav) { | ||
this._mrcodeToolbar.pageNav.pageKey = pageKey | ||
this._mrcodeToolbar.pageNav.pageObject = pageObject | ||
} | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
.vuepress/plugins/vuepress-plugin-toolbar/components/base-opt/BaseOpt.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<template> | ||
<div class="option-box" v-if="!link"> | ||
<i v-if="icon" :class="icon"></i> | ||
<span v-if="name">{{name}}</span> | ||
<div class="popover" v-if="popover"> | ||
<template v-if="popover.title"> | ||
<div class="title">{{popover.title}}</div> | ||
<hr> | ||
</template> | ||
<slot></slot> | ||
<a class="more-btn" | ||
v-if="popover.more" | ||
:target="popover.newWindow ? '':'_blank'" | ||
:href="popover.more.link"> | ||
{{popover.more.name}} | ||
</a> | ||
</div> | ||
</div> | ||
<div class="option-box" v-else> | ||
<a :href="link" :target="newWindow ? '':'_blank'"> | ||
<i v-if="icon" :class="icon"></i> | ||
<span v-if="name">{{name}}</span> | ||
<div class="popover" v-if="popover"> | ||
<template v-if="popover.title"> | ||
<a :href="link" :target="newWindow ? '':'_blank'"> | ||
<div class="title">{{popover.title}}</div> | ||
</a> | ||
<hr> | ||
</template> | ||
<slot></slot> | ||
<a class="more-btn" | ||
v-if="popover.more" | ||
:target="popover.newWindow ? '_blank':''" | ||
:href="popover.more.link"> | ||
{{popover.more.name}} | ||
</a> | ||
</div> | ||
</a> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
//=================================== | ||
/* | ||
* 基础插件职责: | ||
* 1. 侧边栏一个 item 渲染 | ||
* 2. 弹框标题和 more 渲染 | ||
* 3. 提供插槽给外部进行扩展 | ||
*/ | ||
//=================================== | ||
const DEFAULG_CONFIG = { | ||
icon: '', | ||
name: '自定义', | ||
link: null, | ||
popover: null | ||
} | ||
// 弹框定义 | ||
const DEFAULT_CONFIG_POPOVER = { // 为空,则不显示弹框 | ||
title: null, | ||
more: null // 是否显示更多按钮,可以跳出页面 | ||
} | ||
const DEFAULT_CONFIG_POPOVER_MORE = { // 是否显示更多按钮,可以跳出页面 | ||
name: 'more', | ||
link: null | ||
} | ||
export default { | ||
props: { | ||
config: {} | ||
}, | ||
data () { | ||
return { | ||
icon: undefined, | ||
name: undefined, | ||
popover: undefined | ||
} | ||
}, | ||
created () { | ||
let config = DEFAULG_CONFIG | ||
if (this.config) { | ||
config = Object.assign({}, DEFAULG_CONFIG, this.config) | ||
} | ||
this.icon = config.icon | ||
this.name = config.name | ||
this.link = config.link | ||
if (config.popover) { | ||
this.popover = Object.assign({}, DEFAULT_CONFIG_POPOVER, this.config.popover) | ||
if (config.popover.more) { | ||
this.popover.more = Object.assign({}, DEFAULT_CONFIG_POPOVER_MORE, this.config.popover.more) | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="stylus" scoped> | ||
</style> |
49 changes: 49 additions & 0 deletions
49
.vuepress/plugins/vuepress-plugin-toolbar/components/custom-opt/CustomOpt.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<template> | ||
<base-opt :config="config"> | ||
<div class="content" v-if="popover"> | ||
<template v-if="popover.type == 'image'"> | ||
<img width="100%" :src="popover.imageUrl"> | ||
</template> | ||
<template v-if="popover.type == 'text'"> | ||
{{popover.text}} | ||
</template> | ||
<template v-if="popover.type == 'html'"> | ||
<div v-html="popover.html"></div> | ||
</template> | ||
</div> | ||
</base-opt> | ||
</template> | ||
|
||
<script> | ||
import BaseOpt from '../base-opt/BaseOpt' | ||
// 弹框定义 | ||
const DEFAULT_CONFIG_POPOVER = { // 为空,则不显示弹框 | ||
type: 'text', // 弹出类型: image、text、html | ||
imageUrl: null, // image: 地址 | ||
text: '', // text: 文字描述 | ||
html: '', // 显示一段 html | ||
} | ||
export default { | ||
components: { | ||
BaseOpt | ||
}, | ||
props: { | ||
config: {} | ||
}, | ||
data () { | ||
return { | ||
popover: undefined | ||
} | ||
}, | ||
created () { | ||
let popover = this.config.popover | ||
if (popover) { | ||
this.popover = Object.assign({}, DEFAULT_CONFIG_POPOVER, popover) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="stylus" scoped> | ||
</style> |
Oops, something went wrong.