Skip to content

Commit

Permalink
增加环境信息
Browse files Browse the repository at this point in the history
  • Loading branch information
FairyEver committed Dec 14, 2018
1 parent 76bf4a9 commit 11a8f87
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 50 deletions.
35 changes: 15 additions & 20 deletions src/components/d2-page-cover/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<div class="d2-page-cover__logo">
<slot/>
</div>
<p class="d2-page-cover__title">{{title}}</p>
<p class="d2-page-cover__sub-title d2-mt-0">{{subTitle}}</p>
<p class="d2-page-cover__title">D2 Admin {{$version}}</p>
<p class="d2-page-cover__sub-title">优雅的中后台集成方案</p>
<p class="d2-page-cover__build-time">FINAL BUILD TIME {{$buildTime}}</p>
<slot name="footer"/>
<a target="blank" href="https://github.com/d2-projects/d2-admin">
<img
Expand All @@ -15,23 +16,6 @@
</div>
</template>

<script>
export default {
props: {
title: {
type: String,
required: false,
default: 'Title'
},
subTitle: {
type: String,
required: false,
default: 'subTitle'
}
}
}
</script>

<style lang="scss" scoped>
.d2-page-cover {
@extend %full;
Expand All @@ -46,10 +30,21 @@ export default {
}
}
.d2-page-cover__title {
margin: 0px;
margin-bottom: 20px;
font-weight: bold;
color: $color-text-main;
}
.d2-page-cover__sub-title {
color: $color-text-sub;
margin: 0px;
margin-bottom: 5px;
color: $color-text-normal;
}
.d2-page-cover__build-time {
margin: 0px;
margin-bottom: 10px;
font-size: 12px;
color: $color-text-placehoder;
}
}
</style>
3 changes: 1 addition & 2 deletions src/libs/db.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'
import setting from '@/setting.js'

const adapter = new LocalStorage(`d2admin-${setting.releases.version}`)
const adapter = new LocalStorage(`d2admin-${process.env.VUE_APP_VERSION}`)
const db = low(adapter)

db
Expand Down
7 changes: 3 additions & 4 deletions src/libs/util.cookies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Cookies from 'js-cookie'
import setting from '@/setting.js'

const cookies = {}

Expand All @@ -14,15 +13,15 @@ cookies.set = function (name = 'default', value = '', cookieSetting = {}) {
expires: 1
}
Object.assign(currentCookieSetting, cookieSetting)
Cookies.set(`d2admin-${setting.releases.version}-${name}`, value, currentCookieSetting)
Cookies.set(`d2admin-${process.env.VUE_APP_VERSION}-${name}`, value, currentCookieSetting)
}

/**
* @description 拿到 cookie 值
* @param {String} name cookie name
*/
cookies.get = function (name = 'default') {
return Cookies.get(`d2admin-${setting.releases.version}-${name}`)
return Cookies.get(`d2admin-${process.env.VUE_APP_VERSION}-${name}`)
}

/**
Expand All @@ -37,7 +36,7 @@ cookies.getAll = function () {
* @param {String} name cookie name
*/
cookies.remove = function (name = 'default') {
return Cookies.remove(`d2admin-${setting.releases.version}-${name}`)
return Cookies.remove(`d2admin-${process.env.VUE_APP_VERSION}-${name}`)
}

export default cookies
12 changes: 2 additions & 10 deletions src/pages/index/page.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<template>
<d2-container :filename="filename" class="page">
<d2-page-cover
:title="`D2 Admin ${version}`"
sub-title="优雅的中后台集成方案">
<d2-page-cover>
<d2-icon-svg
class="page__logo"
name="d2-admin"/>
Expand Down Expand Up @@ -35,7 +33,6 @@
</template>

<script>
import { mapState } from 'vuex'
import D2HelpBtn from './components/d2-help-btn'
import D2Badge from './components/d2-badge'
export default {
Expand All @@ -47,11 +44,6 @@ export default {
return {
filename: __filename
}
},
computed: {
...mapState('d2admin/releases', [
'version'
])
}
}
</script>
Expand All @@ -64,7 +56,7 @@ export default {
.page__btn-group {
color: $color-text-placehoder;
font-size: 12px;
margin-top: -10px;
margin-top: 0px;
margin-bottom: 20px;
span {
color: $color-text-sub;
Expand Down
7 changes: 6 additions & 1 deletion src/plugin/d2admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ import pluginOpen from '@/plugin/open'

export default {
async install (Vue, options) {
// 设置为 false 以阻止 vue 在启动时生成生产提示。https://cn.vuejs.org/v2/api/#productionTip
// 设置为 false 以阻止 vue 在启动时生成生产提示
// https://cn.vuejs.org/v2/api/#productionTip
Vue.config.productionTip = false
// 当前环境
Vue.prototype.$env = process.env.NODE_ENV
// 当前的 baseUrl
Vue.prototype.$baseUrl = process.env.BASE_URL
// 当前版本
Vue.prototype.$version = process.env.VUE_APP_VERSION
// 构建时间
Vue.prototype.$buildTime = process.env.VUE_APP_BUILD_TIME
// Element
Vue.use(ElementUI)
// 插件
Expand Down
6 changes: 0 additions & 6 deletions src/setting.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { version } from '../package'

export default {
// 快捷键
// 支持快捷键 例如 ctrl+shift+s
Expand All @@ -26,10 +24,6 @@ export default {
}
]
},
// 版本
releases: {
version
},
// 菜单搜索
search: {
enable: true
Expand Down
9 changes: 2 additions & 7 deletions src/store/modules/d2admin/modules/releases.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import util from '@/libs/util.js'
import setting from '@/setting.js'

export default {
namespaced: true,
state: {
// D2Admin 版本
version: setting.releases.version
},
mutations: {
/**
* @description 显示版本信息
* @param {Object} state vuex state
*/
versionShow (state) {
util.log.capsule('D2Admin', `v${state.version}`)
versionShow () {
util.log.capsule('D2Admin', `v${process.env.VUE_APP_VERSION}`)
console.log('Github https://github.com/d2-projects/d2-admin')
console.log('Doc https://doc.d2admin.fairyever.com/zh/')
console.log('请不要吝啬您的 star,谢谢 ~')
Expand Down
4 changes: 4 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
// 拼接路径
const resolve = dir => require('path').join(__dirname, dir)

// 增加环境变量
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_BUILD_TIME = require('dayjs')().format('YYYY-M-D HH:mm:ss')

// 基础路径 注意发布之前要先修改这里
let baseUrl = '/'

Expand Down

0 comments on commit 11a8f87

Please sign in to comment.