Skip to content

Commit

Permalink
init commi
Browse files Browse the repository at this point in the history
  • Loading branch information
se7en authored and se7en committed Nov 21, 2017
0 parents commit a3cd269
Show file tree
Hide file tree
Showing 16 changed files with 5,005 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["env", { "modules": false }],
"stage-3"
]
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
node_modules/
dist/
npm-debug.log
yarn-error.log

# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
8 changes: 8 additions & 0 deletions .postcssrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://github.com/michael-ciniawsky/postcss-load-config

module.exports = {
"plugins": {
// to edit target browsers: use "browserlist" field in package.json
"autoprefixer": {}
}
}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# vue-org-tree

> A simple organization tree chart based on Vue2.x
## Build Setup

``` bash
# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build
```

For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>vue-org-tree</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/normalize/7.0.0/normalize.min.css">
</head>
<body>
<div id="app"></div>
<script src="/dist/build.js"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "vue-org-tree",
"description": "A simple organization tree chart based on Vue2.x",
"version": "1.0.0",
"author": "steven <[email protected]>",
"license": "MIT",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"vue": "^2.4.4"
},
"devDependencies": {
"autoprefixer": "^7.1.6",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"less": "^2.7.3",
"less-loader": "^4.0.5",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
},
"browserslist": [
"> 5%",
"last 2 versions",
"not ie <= 8"
]
}
61 changes: 61 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<div id="app" style="padding:100px;text-align:center;">
<org-tree :data="orgData" :vertical="true" @on-node-click="onNodeClick">
<!-- <org-tree-node :data="orgData" @on-node-click="onNodeClick">
<org-tree-node v-if="orgData.children" v-for="child in orgData.children" :data="child" @on-node-click="onNodeClick" :key="child.id"></org-tree-node>
</org-tree-node> -->
</org-tree>
</div>
</template>

<script>
import {OrgTree, OrgTreeNode} from './components/org-tree'
export default {
name: 'app',
components: {
OrgTree,
OrgTreeNode
},
data () {
return {
orgData: {
id: 1,
label: '企易购科技有限公司',
children: [{
id: 2,
label: '研发部',
children: [{
id: 5,
label: '研发-前端'
}, {
id: 6,
label: '研发-后端'
}]
}, {
id: 3,
label: '销售部',
children: [{
id: 7,
label: '销售一部'
}, {
id: 8,
label: '销售二部'
}]
}, {
id: 4,
label: '财务部'
}, {
id: 9,
label: 'HR人事'
}]
}
}
},
methods: {
onNodeClick (node) {
console.log(node)
}
}
}
</script>
Binary file added src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/components/org-tree/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import OrgTree from './org-tree'
import OrgTreeNode from './org-tree-node'

const install = (Vue) => {
if (install.installed) {
return
}

install.installed = true

Vue.component(OrgTree.name, OrgTree)
Vue.component(OrgTreeNode.name, OrgTreeNode)
}

export {
OrgTree,
OrgTreeNode
}

export default {
OrgTree,
OrgTreeNode,
install
}
44 changes: 44 additions & 0 deletions src/components/org-tree/org-tree-node.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div class="org-tree-node">
<div class="org-tree-node-label" @click="$emit('on-node-click', data)">
<slot name="label" :data="data">{{data[props.label]}}</slot>
</div>
<div v-if="children && children.length" class="org-tree-node-children">
<slot :data="data">
<org-tree-node
v-if="children && children.length"
v-for="child in children"
:data="child"
:props="props"
:key="child.id"
@on-node-click="$emit('on-node-click', $event)"
></org-tree-node>
</slot>
</div>
</div>
</template>

<script>
export default {
name: 'OrgTreeNode',
props: {
data: {
type: Object,
required: true
},
props: {
type: Object,
default: () => ({
id: 'id',
label: 'label',
children: 'children'
})
}
},
computed: {
children () {
return this.data[this.props.children] || []
}
}
}
</script>
37 changes: 37 additions & 0 deletions src/components/org-tree/org-tree.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div class="org-tree-container" :class="{vertical}">
<slot :data="data">
<org-tree-node :data="data" :props="props" @on-node-click="$emit('on-node-click', $event)"></org-tree-node>
</slot>
</div>
</template>

<script>
import OrgTreeNode from './org-tree-node'
export default {
name: 'OrgTree',
components: {
OrgTreeNode
},
props: {
data: {
type: Object,
required: true
},
props: {
type: Object,
default: () => ({
id: 'id',
label: 'label',
children: 'children'
})
},
vertical: Boolean
}
}
</script>

<style lang="less">
@import '../../styles/org-tree';
</style>
7 changes: 7 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue'
import App from './App.vue'

new Vue({
el: '#app',
render: h => h(App)
})
Loading

0 comments on commit a3cd269

Please sign in to comment.