Skip to content

Commit

Permalink
🎨 项目结构调整
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosen95 committed Sep 25, 2019
1 parent f4f12b6 commit ee76894
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 181 deletions.
20 changes: 10 additions & 10 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
presets: ["@vue/app"],
plugins: [
[
"component",
{
libraryName: "element-ui",
styleLibraryName: "theme-chalk"
}
]
]
presets: ["@vue/app"]
// plugins: [
// [
// "component",
// {
// libraryName: "element-ui",
// styleLibraryName: "theme-chalk"
// }
// ]
// ]
};
3 changes: 3 additions & 0 deletions src/api/articles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getData, postData } from "@/utils/request";

export const getArticles = (data: any) => getData("/articles", data);
7 changes: 7 additions & 0 deletions src/api/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getData, postData } from "@/utils/request";

export const getUserInfo = (data: any) => postData("/users/info", data);

export const login = (data: any) => postData("/users/login", data);

export const logout = () => postData("/users/logout");
85 changes: 85 additions & 0 deletions src/components/Breadcrumb/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(item, index) in breadcrumbs" :key="item.path">
<span
v-if="item.redirect === 'noredirect' || index === breadcrumbs.length-1"
class="no-redirect"
>{{ item.meta.title }}</span>
<a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
</el-breadcrumb-item>
</transition-group>
</el-breadcrumb>
</template>

<script lang="ts">
import pathToRegexp from "path-to-regexp";
import { Component, Vue, Watch } from "vue-property-decorator";
import { RouteRecord, Route } from "vue-router";
@Component({
name: "Breadcrumb"
})
export default class extends Vue {
private breadcrumbs: RouteRecord[] = [];
@Watch("$route")
private onRouteChange(route: Route) {
// if you go to the redirect page, do not update the breadcrumbs
if (route.path.startsWith("/redirect/")) {
return;
}
this.getBreadcrumb();
}
created() {
this.getBreadcrumb();
}
private getBreadcrumb() {
let matched = this.$route.matched.filter(
item => item.meta && item.meta.title
);
const first = matched[0];
if (!this.isDashboard(first)) {
matched = [
{ path: "/dashboard", meta: { title: "Dashboard" } } as RouteRecord
].concat(matched);
}
this.breadcrumbs = matched.filter(item => {
return item.meta && item.meta.title && item.meta.breadcrumb !== false;
});
}
private isDashboard(route: RouteRecord) {
const name = route && route.meta && route.meta.title;
return name === "Dashboard";
}
private pathCompile(path: string) {
// To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
const { params } = this.$route;
const toPath = pathToRegexp.compile(path);
return toPath(params);
}
private handleLink(item: any) {
const { redirect, path } = item;
if (redirect) {
this.$router.push(redirect);
return;
}
this.$router.push(this.pathCompile(path));
}
}
</script>

<style lang="scss" scoped>
.el-breadcrumb__inner,
.el-breadcrumb__inner a {
font-weight: 400 !important;
}
.app-breadcrumb.el-breadcrumb {
display: inline-block;
font-size: 14px;
line-height: 50px;
margin-left: 8px;
.no-redirect {
color: #97a8be;
cursor: text;
}
}
</style>
27 changes: 27 additions & 0 deletions src/components/Hamburger/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div :class="[{'is-active': isActive}]" @click="toggleClick">
<svg-icon name="hamburger" width="20" height="20" />
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
@Component({
name: "Hamburger"
})
export default class extends Vue {
@Prop({ default: false }) private isActive!: boolean;
private toggleClick() {
this.$emit("toggleClick");
}
}
</script>

<style lang="scss" scoped>
.svg-icon {
vertical-align: middle;
}
.is-active {
transform: rotate(180deg);
}
</style>
130 changes: 0 additions & 130 deletions src/components/HelloWorld.vue

This file was deleted.

31 changes: 10 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,18 @@ import Vue from "vue";
import App from "./App.vue";
import Component from "vue-class-component";
import router from "./router";
import store from "./store/index";
import store from "./store";

import {
Container,
Header,
Aside,
Main,
Footer,
Menu,
MenuItem,
Row,
Col
} from "element-ui";
Vue.component(Container.name, Container);
Vue.component(Header.name, Header);
Vue.component(Aside.name, Aside);
Vue.component(Main.name, Main);
Vue.component(Footer.name, Footer);
Vue.component(Menu.name, Menu);
Vue.component(MenuItem.name, MenuItem);
Vue.component(Row.name, Row);
Vue.component(Col.name, Col);
import "normalize.css";
import ElementUI from "element-ui";
import SvgIcon from "vue-svgicon";

Vue.use(ElementUI);
Vue.use(SvgIcon, {
tagName: "svg-icon",
defaultWidth: "1em",
defaultHeight: "1em"
});
Vue.config.productionTip = false;

new Vue({
Expand Down
16 changes: 8 additions & 8 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Vue from "vue";
import Vuex from "vuex";
import user from "./modules/user";
import { IUserState } from "./modules/user";
import { IAppState } from "./modules/app";

Vue.use(Vuex);

const store = new Vuex.Store({
strict: process.env.NODE_ENV !== "production",
modules: {
user
}
});
export interface IRootState {
app: IAppState;
user: IUserState;
}

export default store;
// Declare empty store first, dynamically register all modules later.
export default new Vuex.Store<IRootState>({});
Loading

0 comments on commit ee76894

Please sign in to comment.