chore: add alert plugin for docs; :star2:
New file |
| | |
| | | <template> |
| | | <div class="alert" :style="`top: ${top}px`"> |
| | | <slot></slot> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | name: 'Alert', |
| | | props: ['show'], |
| | | data() { |
| | | return { |
| | | top: 100 |
| | | } |
| | | }, |
| | | mounted() { |
| | | console.log(this) |
| | | // this.$page.alert = this.$page.alert ? this.$page.alert : {top: 100} |
| | | // this.$page.alert.top += 20 |
| | | // this.top = this.$page.alert.top |
| | | setTimeout(() => { |
| | | this.$el.remove() |
| | | }, 1000) |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .alert{ |
| | | position: absolute; |
| | | padding: 6px 8px; |
| | | background-color: #f0f2f5; |
| | | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); |
| | | border-radius: 4px; |
| | | margin: 0 auto; |
| | | z-index: 999; |
| | | top: 100px; |
| | | width: fit-content; |
| | | left: 0; |
| | | right: 0; |
| | | } |
| | | </style> |
New file |
| | |
| | | <template> |
| | | <div :data-clipboard-text="color" class="color" @click="onClick" :style="`background-color:${color}`" /> |
| | | </template> |
| | | |
| | | <script> |
| | | import Clipboard from 'clipboard' |
| | | export default { |
| | | name: 'Color', |
| | | props: ['color'], |
| | | data() { |
| | | return { |
| | | alert: false |
| | | } |
| | | }, |
| | | methods: { |
| | | onClick() { |
| | | let clipboard = new Clipboard('.color') |
| | | clipboard.on('success', () => { |
| | | this.$alert(`颜色代码已复制:${this.color}`) |
| | | clipboard.destroy() |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .color{ |
| | | border: 1px dashed #a0d911; |
| | | display: inline-block; |
| | | width: 20px; |
| | | height: 20px; |
| | | cursor: pointer; |
| | | } |
| | | </style> |
New file |
| | |
| | | <template> |
| | | <div> |
| | | <color class="color" :key="index" v-for="(color, index) in colors" :color="color" ></color> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | name: 'ColorList', |
| | | props: ['colors'] |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .color{ |
| | | margin: 0 2px; |
| | | } |
| | | </style> |
| | |
| | | nextLinks: true, |
| | | prevLinks: true, |
| | | }, |
| | | plugins: ['@vuepress/back-to-top'], |
| | | plugins: ['@vuepress/back-to-top', require('./plugins/alert')], |
| | | markdown: { |
| | | lineNumbers: true |
| | | } |
New file |
| | |
| | | <template> |
| | | <div class="alert" :style="`top: ${top}px`"> |
| | | <slot></slot> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | name: 'Alert', |
| | | props: ['alert'], |
| | | data() { |
| | | return { |
| | | top: 0 |
| | | } |
| | | }, |
| | | beforeMount() { |
| | | this.top = this.alert.top |
| | | }, |
| | | mounted() { |
| | | window.addEventListener('alert_remove', (e) => { |
| | | this.top -= e.detail.height |
| | | }) |
| | | }, |
| | | watch: { |
| | | 'page.alert.top': function (value) { |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .alert{ |
| | | position: fixed; |
| | | padding: 6px 8px; |
| | | background-color: #fff; |
| | | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25); |
| | | border-radius: 4px; |
| | | margin: 0 auto; |
| | | z-index: 999; |
| | | top: 100px; |
| | | width: fit-content; |
| | | left: 0; |
| | | right: 0; |
| | | transition: top 0.3s; |
| | | } |
| | | </style> |
New file |
| | |
| | | import Alert from './Alert' |
| | | |
| | | const AlertMixin = { |
| | | install(Vue) { |
| | | Vue.mixin({ |
| | | methods: { |
| | | $alert(message, duration = 2000) { |
| | | let Constructor= Vue.extend(Alert) |
| | | let alert = new Constructor() |
| | | alert.$slots.default = message |
| | | alert.$props.alert = this.$page.alert |
| | | alert.$mount() |
| | | document.body.appendChild(alert.$el) |
| | | |
| | | const appendHeight = alert.$el.offsetHeight + 16 |
| | | this.$page.alert.top += appendHeight |
| | | |
| | | setTimeout(() => { |
| | | this.$page.alert.top -= appendHeight |
| | | this.triggerRemoveAlert(appendHeight) |
| | | setTimeout(() => { |
| | | alert.$destroy() |
| | | alert.$el.remove() |
| | | }, 100) |
| | | }, duration) |
| | | }, |
| | | triggerRemoveAlert(height) { |
| | | const event = new CustomEvent('alert_remove', { |
| | | detail: {height} |
| | | }) |
| | | window.dispatchEvent(event) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | export default AlertMixin |
New file |
| | |
| | | export default { |
| | | updated() { |
| | | this.$page.alert.top = 100 |
| | | } |
| | | } |
New file |
| | |
| | | import AlertMixin from './alertMixin' |
| | | |
| | | export default ({Vue}) => { |
| | | Vue.use(AlertMixin) |
| | | } |
New file |
| | |
| | | const path = require('path') |
| | | |
| | | module.exports = (options, ctx) => { |
| | | return { |
| | | clientRootMixin: path.resolve(__dirname, 'clientRootMixin.js'), |
| | | extendPageData($page) { |
| | | $page.alert = { |
| | | top: 100 |
| | | } |
| | | }, |
| | | enhanceAppFiles: path.resolve(__dirname, 'enhanceApp.js') |
| | | } |
| | | } |