Skip to content

Commit

Permalink
Updated something and added deployment tools
Browse files Browse the repository at this point in the history
  • Loading branch information
thondery committed May 22, 2019
1 parent 33e1a68 commit 0597da6
Show file tree
Hide file tree
Showing 23 changed files with 407 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ deploy/**/*.js
deploy/**/*.conf
deploy/**/*.pem
deploy/**/*.key
deploy/**/*.ini
deploy/**/*.md
deploy/**/*.json
deploy/**/*.bson
deploy/**/*.ico
deploy/**/*.png
deploy/**/*.jpg
deploy/**/*.gif
deploy/**/*.jpeg


# TypeScript v1 declaration files
Expand Down
2 changes: 1 addition & 1 deletion components/console/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="header-start">
<div class="header-link-box">
<nuxt-link class="header-link logo" to="/">
<img src="~/assets/images/logo.png" />
<img src="/logo.png" />
</nuxt-link>
</div>
<el-dropdown @command="selectChannel" placement="top-start" trigger="click" @visible-change="handleVisible">
Expand Down
11 changes: 10 additions & 1 deletion data/register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ lost_pass:

# 设置短信服务
sms:
alicound : kenote
alicound : kenote

# 注册登录页面设置
pages:
- key : index
main_title : [ 不至于 后台管理,, Express + Vue + Element-UI ]
secondary_title : JSON Web Token (JWT) & 服务端渲染(Server Side Render)
- key : login
main_title : [ 不至于 后台管理,, Express + Vue + Element-UI ]
secondary_title : JSON Web Token (JWT) & 服务端渲染(Server Side Render)
18 changes: 16 additions & 2 deletions layouts/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<div class="layout-account">
<header>
<a class="logo">
<img src="~/assets/images/logo.png" />
<img src="/logo.png" />
</a>
<div class="list">
<nuxt-link to="/login">登录</nuxt-link>
<nuxt-link v-if="user" to="/dashboard">控制台</nuxt-link>
<nuxt-link v-else to="/login">登录</nuxt-link>
<nuxt-link to="/">首页</nuxt-link>
</div>
</header>
Expand All @@ -21,18 +22,31 @@
<script lang="ts">
import Component from 'nuxt-class-component'
import { Vue } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import * as auth from '~/store/modules/auth'
import * as setting from '~/store/modules/setting'
import { BindingHelpers } from 'vuex-class/lib/bindings'
import { Register } from '~/server/types/config'
import { responseDocument as responseUserDocument } from '~/server/types/proxys/user'
import '~/assets/scss/account/layout.scss'
import '~/assets/scss/account/page.scss'
const Auth: BindingHelpers = namespace(auth.name)
const Setting: BindingHelpers = namespace(setting.name)
@Component({
mounted () {
document.body.className = 'account-warpper'
}
})
export default class extends Vue {
@Auth.State user: responseUserDocument
@Setting.State register: Register
head () {
return {
title: this.register.site_name,
meta: [
{
name: 'viewport',
Expand Down
11 changes: 10 additions & 1 deletion layouts/accounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<header>
<div class="container">
<a class="logo">
<img src="~/assets/images/logo.png" />
<img src="/logo.png" />
</a>
<div class="list">
<nuxt-link to="/">返回首页</nuxt-link>
Expand All @@ -17,14 +17,23 @@
<script lang="ts">
import Component from 'nuxt-class-component'
import { Vue } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import * as setting from '~/store/modules/setting'
import { BindingHelpers } from 'vuex-class/lib/bindings'
import { Register } from '~/server/types/config'
import '~/assets/scss/accounts/layout.scss'
import '~/assets/scss/accounts/page.scss'
const Setting: BindingHelpers = namespace(setting.name)
@Component
export default class extends Vue {
@Setting.State register: Register
head () {
return {
title: this.register.site_name,
meta: [
{
name: 'viewport',
Expand Down
8 changes: 8 additions & 0 deletions layouts/console.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import consoleHeader from '~/components/console/header.vue'
import consoleSidebar from '~/components/console/sidebar.vue'
import { responseDocument as responseUserDocument } from '~/server/types/proxys/user'
import channel from '~/server/types/channel'
import { Register } from '~/server/types/config'
import { Dropdown, Command } from '~/types'
import { getChannelId } from '~/utils/channel'
import { parseCommand } from '~/utils'
Expand Down Expand Up @@ -117,6 +118,7 @@ const userEntrance: Array<Dropdown.MenuItem> = [
export default class extends Vue {
@Auth.State user: responseUserDocument
@Setting.State register: Register
@Setting.State loading: setting.Loading
@Setting.State channels: Array<channel.NavMenus>
@Setting.State flags: channel.Flags
Expand All @@ -129,6 +131,12 @@ export default class extends Vue {
@Provide() permission: boolean = true
@Provide() pageSetting: channel.MenuItem = { index: '-1', name: '' }
head () {
return {
title: this.register.site_name
}
}
handleSelectChannel (value: number): void {
if (this.selectedChannel.id === value) return
let channel: channel.NavMenus = <channel.NavMenus> this.channels.find( o => o.id === value )
Expand Down
8 changes: 8 additions & 0 deletions layouts/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { BindingHelpers } from 'vuex-class/lib/bindings'
import consoleHeader from '~/components/console/header.vue'
import { responseDocument as responseUserDocument } from '~/server/types/proxys/user'
import channel from '~/server/types/channel'
import { Register } from '~/server/types/config'
import { Dropdown, Command } from '~/types'
import { parseCommand } from '~/utils'
import http, { resufulInfo } from '~/utils/http'
Expand Down Expand Up @@ -80,11 +81,18 @@ const userEntrance: Array<Dropdown.MenuItem> = [
export default class extends Vue {
@Auth.State user: responseUserDocument
@Setting.State register: Register
@Setting.State channels: Array<channel.NavMenus>
@Setting.Getter selectedChannel: channel.NavMenus
@Provide() userEntrance: Array<Dropdown.MenuItem> = userEntrance
head () {
return {
title: this.register.site_name
}
}
handleSelectChannel (value: number): void {
if (this.selectedChannel.id === value) return
let channel: channel.NavMenus = <channel.NavMenus> this.channels.find( o => o.id === value )
Expand Down
13 changes: 13 additions & 0 deletions middleware/unauthenticated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import nuxt from '~/types/nuxt'
import * as auth from '~/store/modules/auth'
import { responseDocument } from '~/server/types/proxys/user'

export default function (context: nuxt.Context): void {
// If the user is not authenticated
let { store, redirect, route } = context
let Auth: auth.State = store.state.auth
let user: responseDocument | null = Auth.user
if (user) {
return redirect(`/dashboard`)
}
}
3 changes: 3 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// buefy cause 'ReferenceError: HTMLElement is not defined'
// See https://github.com/buefy/buefy/issues/712
global.HTMLElement = typeof window === 'undefined' ? Object : window.HTMLElement
module.exports = {
head: {
title: '后台管理',
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"stop": "pm2 stop ecosystem.config.js",
"delete": "pm2 delete ecosystem.config.js",
"clear": "rimraf ./build ./.nuxt",
"deploy": "deploy-proxy"
"deploy": "deploy-proxy",
"tools": "babel-node --plugins transform-decorators-legacy --presets env ./tools.es6"
},
"dependencies": {
"@alicloud/pop-core": "^1.7.6",
Expand Down Expand Up @@ -49,11 +50,13 @@
"nuxt-class-component": "^1.2.1",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"runscript": "^1.3.0",
"tty-table": "^2.7.0",
"v-charts": "^1.19.0",
"validator": "^10.11.0",
"vue-codemirror": "^4.0.6",
"vue-property-decorator": "^7.3.0",
"xlsx": "^0.14.3",
"yaml": "^1.5.0"
},
"devDependencies": {
Expand Down Expand Up @@ -83,11 +86,14 @@
"@types/validator": "^10.9.0",
"@types/yaml": "^1.0.2",
"awesome-typescript-loader": "^5.2.1",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-preset-env": "^1.7.0",
"backpack-core": "^0.8.3",
"kenote-deploy-kit": "^1.2.1",
"node-sass": "^4.11.0",
"sass-loader": "^7.1.0",
"ts-loader": "^5.3.3",
"ts-node": "^8.1.0",
"typescript": "^3.3.1"
}
}
41 changes: 40 additions & 1 deletion pages/_channel/_page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
inactive-text="不分页"
>
</el-switch>
<template v-if="pageSetting.export">
<el-button type="success" plain @click="handleExport(pageSetting.export)" style="margin-left:15px">导出Excel</el-button>
</template>
</channel-result-table>
</page>
</template>
Expand All @@ -53,7 +56,8 @@ import channel from '~/server/types/channel'
import http, { resufulInfo } from '~/utils/http'
import { HeaderOptions } from '~/server/types/resuful'// pagination
import { getDifferenceDate } from '~/utils'
import { zipObject, concat } from 'lodash'
import { zipObject, concat, map } from 'lodash'
import { xlsxBlob } from '~/utils/xlsx'
const Setting: BindingHelpers = namespace(setting.name)
const Auth: BindingHelpers = namespace(auth.name)
Expand Down Expand Up @@ -202,5 +206,40 @@ export default class extends Vue {
}
}
handleExport (options: channel.Export): void {
let { sheetName } = options
let columns: Array<channel.ColumnItem> = this.pageSetting.columns || []
let headers: string[] = map(columns, 'name')
let data: Array<{}> = []
for (let item of this.data) {
let obj: {} = {}
let keys: string[] = Object.keys(item)
for (let k of keys) {
let c: channel.ColumnItem = <channel.ColumnItem> columns.find( o => o.key === k )
obj[c.name] = c.format ? this.formatString(item[k], c.format) : item[k]
}
data.push(obj)
}
let fileBlob: Blob = xlsxBlob(sheetName || 'mySheet', headers, data)
let link: HTMLElement | null = document.getElementById('download-blob-file')
if (!link) {
link = document.createElement('a')
}
link['href'] = window.URL.createObjectURL(fileBlob)
link['download'] = (sheetName || '导出Excel') + '.xlsx'
link.click()
}
formatString (value: string | number, fmt: channel.Format): string {
if (fmt.regexp) {
return String(value).replace(fmt.regexp, fmt.substr || '')
}
if (fmt.function) {
let _value: string | number = fmt.type === 'number' ? Number(String(value).replace(/[^0-9\.]/g, '')) : String(value)
return (fmt.prefix || '') + _value[fmt.function](...fmt.options) + (fmt.suffix || '')
}
return String(value)
}
}
</script>
36 changes: 31 additions & 5 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<template>
<div>
<h1>Hello world</h1>
<el-button>默认按钮</el-button>
</div>
<page>
<div class="landing-activity">
<p v-for="(item, key) in main_title" :key="key" class="main-title">{{ item }}</p>
<p class="secondary-title">{{ secondary_title }}</p>
</div>
</page>
</template>

<script lang="ts">
import Component from 'nuxt-class-component'
import { Provide, Vue } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import { BindingHelpers } from 'vuex-class/lib/bindings'
import * as auth from '~/store/modules/auth'
import * as setting from '~/store/modules/setting'
import { Register, Page } from '~/server/types/config'
import { responseDocument as responseUserDocument } from '~/server/types/proxys/user'
const Auth: BindingHelpers = namespace(auth.name)
const Setting: BindingHelpers = namespace(setting.name)
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
Expand All @@ -17,10 +29,24 @@ declare module 'vue/types/options' {
}
@Component({
layout: 'default'
layout: 'account',
mounted () {
let pages: Array<Page> = this.register.pages
let page: Page | undefined = pages.find( o => o.key === 'index' )
if (page) {
this.$data.main_title = page.main_title || []
this.$data.secondary_title = page.secondary_title || ''
}
}
})
export default class extends Vue {
@Auth.State user: responseUserDocument
@Setting.State register: Register
@Provide() main_title: string[] = []
@Provide() secondary_title: string = ''
}
</script>
Expand Down
Loading

0 comments on commit 0597da6

Please sign in to comment.