Skip to content

Commit b164c27

Browse files
committed
feat: auto router and menu
1 parent 4bc20aa commit b164c27

File tree

22 files changed

+351
-141
lines changed

22 files changed

+351
-141
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VUE_APP_XXX=XXX

.github/workflows/deploy.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Deploy
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
9+
gh-pages:
10+
name: Github Pages
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- uses: bahmutov/npm-install@v1
15+
- name: Set vue cli env
16+
shell: bash
17+
run: |
18+
echo -e "\
19+
VUE_APP_PUBLIC_PATH=/${GITHUB_REPOSITORY//*\//}/\
20+
" > .env.production.local
21+
cat .env.production.local | while read line
22+
do
23+
echo $line
24+
done
25+
- name: Build
26+
run: yarn build --report
27+
- name: Deploy
28+
uses: peaceiris/actions-gh-pages@v2
29+
env:
30+
PERSONAL_TOKEN: ${{ secrets.ACCESS_TOKEN }}
31+
PUBLISH_BRANCH: gh-pages
32+
PUBLISH_DIR: ./dist
33+
with:
34+
forceOrphan: true

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
publish:
10+
if: "! contains(github.event.head_commit.message, '[skip ci]')"
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- name: Semantic Release
15+
uses: cycjimmy/semantic-release-action@v2
16+
with:
17+
extra_plugins: |
18+
@semantic-release/changelog@3.0.6
19+
@semantic-release/git@7.0.18
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
22+
23+
# !TRICKY
24+
# https://github.community/t5/GitHub-Actions/Workflow-is-failing-if-no-job-can-be-ran-due-to-condition/td-p/38085
25+
always_job:
26+
name: Always run job
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Always run
30+
run: echo "TRICKY run"

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"serve": "vue-cli-service serve",
6+
"dev": "vue-cli-service serve",
77
"build": "vue-cli-service build",
8-
"lint": "vue-cli-service lint --fix",
9-
"git-add-all": "git add .",
10-
"git-cz": "git cz",
11-
"git-push-master": "git push origin master"
8+
"lint": "vue-cli-service lint --fix"
129
},
1310
"dependencies": {
1411
"core-js": "^3.6.4",
12+
"element-ui": "^2.13.1",
13+
"flex.css": "^1.1.7",
1514
"vue": "^2.6.11",
1615
"vue-router": "^3.1.6",
1716
"vuex": "^3.1.3"

src/App.vue

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
11
<template>
2-
<div id="app">
3-
<div id="nav">
4-
<router-link to="/">Home</router-link> |
5-
<router-link to="/about">About</router-link>
6-
</div>
7-
<router-view/>
8-
</div>
2+
<router-view/>
93
</template>
104

115
<style lang="scss">
12-
#app {
13-
font-family: Avenir, Helvetica, Arial, sans-serif;
14-
-webkit-font-smoothing: antialiased;
15-
-moz-osx-font-smoothing: grayscale;
16-
text-align: center;
17-
color: #2c3e50;
18-
}
19-
20-
#nav {
21-
padding: 30px;
22-
23-
a {
24-
font-weight: bold;
25-
color: #2c3e50;
26-
27-
&.router-link-exact-active {
28-
color: #42b983;
29-
}
30-
}
6+
html, body {
7+
height: 100%;
8+
margin: 0;
9+
padding: 0;
3110
}
3211
</style>

src/assets/logo.png

-6.69 KB
Binary file not shown.

src/assets/style/public.scss

Whitespace-only changes.

src/components/HelloWorld.vue

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/components/demo/com.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<style lang="scss">
2+
.demo {}
3+
</style>
4+
5+
<template>
6+
<div class="demo">
7+
demo
8+
</div>
9+
</template>
10+
11+
<script>
12+
export default {
13+
name: 'demo'
14+
}
15+
</script>

src/components/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Vue from 'vue'
2+
3+
const vueFiles = require.context('./', true, /com\.vue$/)
4+
vueFiles.keys().forEach(key => {
5+
const component = vueFiles(key).default
6+
Vue.component(component.name, component)
7+
})
8+
9+
const jsFiles = require.context('./', true, /com\.js$/)
10+
jsFiles.keys().forEach(key => {
11+
const component = jsFiles(key).default
12+
Vue.component(component.name, component)
13+
})

src/layout/main/index.vue

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<style lang="scss">
2+
.layout-main {
3+
height: 100%;
4+
.layout-main--side {
5+
width: 200px;
6+
background-color: #051428;
7+
.el-menu {
8+
border-right: none;
9+
.el-menu-item {
10+
&.is-active {
11+
background-color: #458DF8 !important;
12+
}
13+
}
14+
}
15+
}
16+
}
17+
</style>
18+
19+
<template>
20+
<div class="layout-main" flex="dir:left">
21+
<div class="layout-main--side" flex-box="0">
22+
<el-menu
23+
:default-active="$route.path"
24+
background-color="#051428"
25+
text-color="#969CA5"
26+
active-text-color="#FFF"
27+
router>
28+
<el-menu-item
29+
v-for="menu of menus"
30+
:key="menu.path"
31+
:index="menu.path">
32+
{{ menu.title }}
33+
</el-menu-item>
34+
</el-menu>
35+
</div>
36+
<div flex-box="1">
37+
<router-view/>
38+
</div>
39+
</div>
40+
</template>
41+
42+
<script>
43+
import { menus } from '@/router'
44+
45+
export default {
46+
name: 'layout-main',
47+
data () {
48+
return {
49+
menus
50+
}
51+
}
52+
}
53+
</script>

src/main.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import Vue from 'vue'
2-
import App from './App.vue'
3-
import router from './router'
4-
import store from './store'
2+
import App from '@/App.vue'
3+
import { router } from '@/router'
4+
import store from '@/store'
5+
6+
import ElementUI from 'element-ui'
7+
import 'element-ui/lib/theme-chalk/index.css'
8+
9+
import 'flex.css'
10+
11+
import '@/components'
512

613
Vue.config.productionTip = false
714

15+
Vue.use(ElementUI)
16+
817
new Vue({
918
router,
1019
store,

src/router/index.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
1+
import path from 'path'
2+
13
import Vue from 'vue'
24
import VueRouter from 'vue-router'
3-
import Home from '../views/Home.vue'
5+
6+
import layoutMain from '@/layout/main'
7+
8+
const views = []
9+
10+
const vueFiles = require.context('@/views', true, /page\.vue$/)
11+
vueFiles.keys().forEach(key => {
12+
const component = vueFiles(key).default
13+
const routePath = path.dirname(component.__file).replace(/^src\/views\//, '')
14+
const routeName = routePath.replace(path.sep, '-')
15+
views.push({
16+
name: routeName,
17+
path: routePath,
18+
component
19+
})
20+
})
421

522
Vue.use(VueRouter)
623

724
const routes = [
825
{
926
path: '/',
10-
name: 'Home',
11-
component: Home
12-
},
13-
{
14-
path: '/about',
15-
name: 'About',
16-
// route level code-splitting
17-
// this generates a separate chunk (about.[hash].js) for this route
18-
// which is lazy-loaded when the route is visited.
19-
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
27+
component: layoutMain,
28+
children: [
29+
{
30+
path: '',
31+
component: () => import('@/views')
32+
},
33+
...views
34+
]
2035
}
2136
]
2237

23-
const router = new VueRouter({
38+
export const menus = views.map(view => ({
39+
path: '/' + view.path,
40+
title: view.component.title
41+
}))
42+
43+
export const router = new VueRouter({
2444
routes
2545
})
26-
27-
export default router

src/store/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33

4+
const files = require.context('./modules', false, /\.js$/)
5+
const modules = {}
6+
7+
files.keys().forEach(key => {
8+
modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default({})
9+
})
10+
411
Vue.use(Vuex)
512

613
export default new Vuex.Store({
7-
state: {
8-
},
9-
mutations: {
10-
},
11-
actions: {
12-
},
13-
modules: {
14-
}
14+
modules
1515
})

0 commit comments

Comments
 (0)