Skip to content

Commit

Permalink
源码按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
FairyEver committed Nov 16, 2018
1 parent b0a9d79 commit 66f5713
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
46 changes: 44 additions & 2 deletions src/components/d2-container/components/d2-source.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
<template>
<div class="d2-source">
<div
class="d2-source"
:class="{ 'd2-source--active': isActive }"
@click="handleClick">
<d2-icon name="code"/> SourceCode
</div>
</template>

<script>
export default {
props: {
// 文件路径
filename: {
type: String,
default: ''
}
},
data () {
return {
isActive: false
}
},
mounted () {
// 一秒后显示按钮
setTimeout(() => {
this.isActive = true
}, 1000)
},
methods: {
// 点击按钮的时候跳转到源代码
handleClick () {
const file = this.filename.split('?')[0]
const url = file
? `https://github.com/d2-projects/d2-admin/blob/master/${file}`
: 'https://github.com/d2-projects/d2-admin'
this.$open(url)
}
}
}
</script>

<style lang="scss" scoped>
@import '~@/assets/style/public.scss';
.d2-source {
$borderRadius: 4px;
$paddingLR: 15px;
$paddingTB: 7px;
$fontSize: 12px;
$rightOuter: $paddingLR / 2;
opacity: 0;
position: absolute;
right: - $borderRadius;
right: - $borderRadius - $rightOuter;
bottom: 20px;
font-size: $fontSize;
line-height: $fontSize;
Expand All @@ -25,7 +63,11 @@
color: #FFF;
transition: all .3s;
@extend %unable-select;
&.d2-source--active {
opacity: 1;
}
&:hover {
right: - $borderRadius;
background-color: rgba(#000, .9);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/d2-container/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default {
scroll: e => this.$emit('scroll', e)
}
}, slots),
h(d2Source)
h(d2Source, {
props: this.$attrs
})
])
}
}
9 changes: 8 additions & 1 deletion src/pages/index/page.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template>
<d2-container class="page">
<d2-container
class="page"
:filename="filename">
<d2-page-cover
:title="`D2 Admin ${version}`"
sub-title="优雅的中后台集成方案">
Expand Down Expand Up @@ -43,6 +45,11 @@ export default {
D2HelpBtn,
D2Badge
},
data () {
return {
filename: __filename
}
},
computed: {
...mapState('d2admin/releases', [
'version'
Expand Down

0 comments on commit 66f5713

Please sign in to comment.