├── static └── .gitkeep ├── config ├── prod.env.js ├── test.env.js ├── dev.env.js └── index.js ├── .DS_Store ├── src ├── .DS_Store ├── assets │ ├── .DS_Store │ └── logo.png ├── components │ ├── .DS_Store │ ├── TreeGrid.vue │ └── treeGrid2.0.vue ├── main.js └── App.vue ├── test ├── unit │ ├── .eslintrc │ ├── specs │ │ └── Hello.spec.js │ ├── index.js │ └── karma.conf.js └── e2e │ ├── specs │ └── test.js │ ├── custom-assertions │ └── elementCount.js │ ├── runner.js │ └── nightwatch.conf.js ├── index.html ├── package.json └── README.md /static/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/vue-tree-grid/master/.DS_Store -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/vue-tree-grid/master/src/.DS_Store -------------------------------------------------------------------------------- /src/assets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/vue-tree-grid/master/src/assets/.DS_Store -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/vue-tree-grid/master/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/vue-tree-grid/master/src/components/.DS_Store -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true, 7 | "sinon": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var devEnv = require('./dev.env') 3 | 4 | module.exports = merge(devEnv, { 5 | NODE_ENV: '"testing"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | treegrid 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App' 3 | import iView from 'iview'; 4 | import 'iview/dist/styles/iview.css'; 5 | 6 | Vue.use(iView); 7 | /* eslint-disable no-new */ 8 | new Vue({ 9 | el: 'body', 10 | components: { App } 11 | }) -------------------------------------------------------------------------------- /test/unit/specs/Hello.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Hello from 'src/components/Hello' 3 | 4 | describe('Hello.vue', () => { 5 | it('should render correct contents', () => { 6 | const vm = new Vue({ 7 | template: '
', 8 | components: { Hello } 9 | }).$mount() 10 | expect(vm.$el.querySelector('.hello h1').textContent).to.contain('Hello World!') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/unit/index.js: -------------------------------------------------------------------------------- 1 | // Polyfill fn.bind() for PhantomJS 2 | /* eslint-disable no-extend-native */ 3 | Function.prototype.bind = require('function-bind') 4 | 5 | // require all test files (files that ends with .spec.js) 6 | var testsContext = require.context('./specs', true, /\.spec$/) 7 | testsContext.keys().forEach(testsContext) 8 | 9 | // require all src files except main.js for coverage. 10 | // you can also change this to match only the subset of files that 11 | // you want coverage for. 12 | var srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) 13 | srcContext.keys().forEach(srcContext) 14 | -------------------------------------------------------------------------------- /test/e2e/specs/test.js: -------------------------------------------------------------------------------- 1 | // For authoring Nightwatch tests, see 2 | // http://nightwatchjs.org/guide#usage 3 | 4 | module.exports = { 5 | 'default e2e tests': function (browser) { 6 | 7 | // automatically uses dev Server port from /config.index.js 8 | // default: http://localhost:8080 9 | // see nightwatch.conf.js 10 | var devServer = browser.globals.devServerURL 11 | 12 | browser 13 | .url(devServer) 14 | .waitForElementVisible('#app', 5000) 15 | .assert.elementPresent('.logo') 16 | .assert.containsText('h1', 'Hello World!') 17 | .assert.elementCount('p', 3) 18 | .end() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/e2e/custom-assertions/elementCount.js: -------------------------------------------------------------------------------- 1 | // A custom Nightwatch assertion. 2 | // the name of the method is the filename. 3 | // can be used in tests like this: 4 | // 5 | // browser.assert.elementCount(selector, count) 6 | // 7 | // for how to write custom assertions see 8 | // http://nightwatchjs.org/guide#writing-custom-assertions 9 | exports.assertion = function (selector, count) { 10 | this.message = 'Testing if element <' + selector + '> has count: ' + count 11 | this.expected = count 12 | this.pass = function (val) { 13 | return val === this.expected 14 | } 15 | this.value = function (res) { 16 | return res.value 17 | } 18 | this.command = function (cb) { 19 | var self = this 20 | return this.api.execute(function (selector) { 21 | return document.querySelectorAll(selector).length 22 | }, [selector], function (res) { 23 | cb.call(self, res) 24 | }) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/e2e/runner.js: -------------------------------------------------------------------------------- 1 | // 1. start the dev server using production config 2 | process.env.NODE_ENV = 'testing' 3 | var server = require('../../build/dev-server.js') 4 | 5 | // 2. run the nightwatch test suite against it 6 | // to run in additional browsers: 7 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 8 | // 2. add it to the --env flag below 9 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 10 | // For more information on Nightwatch's config file, see 11 | // http://nightwatchjs.org/guide#settings-file 12 | var opts = process.argv.slice(2) 13 | if (opts.indexOf('--config') === -1) { 14 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) 15 | } 16 | if (opts.indexOf('--env') === -1) { 17 | opts = opts.concat(['--env', 'chrome']) 18 | } 19 | 20 | var spawn = require('cross-spawn') 21 | var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) 22 | 23 | runner.on('exit', function (code) { 24 | server.close() 25 | process.exit(code) 26 | }) 27 | 28 | runner.on('error', function (err) { 29 | server.close() 30 | throw err 31 | }) 32 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'] 18 | }, 19 | dev: { 20 | env: require('./dev.env'), 21 | port: 8080, 22 | assetsSubDirectory: 'static', 23 | assetsPublicPath: '/', 24 | proxyTable: {}, 25 | // CSS Sourcemaps off by default because relative paths are "buggy" 26 | // with this option, according to the CSS-Loader README 27 | // (https://github.com/webpack/css-loader#sourcemaps) 28 | // In our experience, they generally work as expected, 29 | // just be aware of this issue when enabling this option. 30 | cssSourceMap: false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/e2e/nightwatch.conf.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | var config = require('../../config') 3 | 4 | // http://nightwatchjs.org/guide#settings-file 5 | module.exports = { 6 | "src_folders": ["test/e2e/specs"], 7 | "output_folder": "test/e2e/reports", 8 | "custom_assertions_path": ["test/e2e/custom-assertions"], 9 | 10 | "selenium": { 11 | "start_process": true, 12 | "server_path": "node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.0.jar", 13 | "host": "127.0.0.1", 14 | "port": 4444, 15 | "cli_args": { 16 | "webdriver.chrome.driver": require('chromedriver').path 17 | } 18 | }, 19 | 20 | "test_settings": { 21 | "default": { 22 | "selenium_port": 4444, 23 | "selenium_host": "localhost", 24 | "silent": true, 25 | "globals": { 26 | "devServerURL": "http://localhost:" + (process.env.PORT || config.dev.port) 27 | } 28 | }, 29 | 30 | "chrome": { 31 | "desiredCapabilities": { 32 | "browserName": "chrome", 33 | "javascriptEnabled": true, 34 | "acceptSslCerts": true 35 | } 36 | }, 37 | 38 | "firefox": { 39 | "desiredCapabilities": { 40 | "browserName": "firefox", 41 | "javascriptEnabled": true, 42 | "acceptSslCerts": true 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "treegrid", 3 | "version": "1.0.0", 4 | "description": "基于vue1.0的树型表格", 5 | "author": "", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node build/dev-server.js", 9 | "build": "node build/build.js", 10 | "unit": "karma start test/unit/karma.conf.js --single-run", 11 | "e2e": "node test/e2e/runner.js", 12 | "test": "npm run unit && npm run e2e" 13 | }, 14 | "dependencies": { 15 | "babel-runtime": "^6.0.0", 16 | "iview": "^1.0.1", 17 | "vue": "^1.0.21" 18 | }, 19 | "devDependencies": { 20 | "babel-core": "^6.0.0", 21 | "babel-loader": "^6.0.0", 22 | "babel-plugin-transform-runtime": "^6.0.0", 23 | "babel-preset-es2015": "^6.0.0", 24 | "babel-preset-stage-2": "^6.0.0", 25 | "babel-register": "^6.0.0", 26 | "connect-history-api-fallback": "^1.1.0", 27 | "css-loader": "^0.23.0", 28 | "eventsource-polyfill": "^0.9.6", 29 | "express": "^4.13.3", 30 | "extract-text-webpack-plugin": "^1.0.1", 31 | "file-loader": "^0.8.4", 32 | "function-bind": "^1.0.2", 33 | "html-webpack-plugin": "^2.8.1", 34 | "http-proxy-middleware": "^0.12.0", 35 | "json-loader": "^0.5.4", 36 | "karma": "^0.13.15", 37 | "karma-coverage": "^0.5.5", 38 | "karma-mocha": "^0.2.2", 39 | "karma-phantomjs-launcher": "^1.0.0", 40 | "karma-sinon-chai": "^1.2.0", 41 | "karma-sourcemap-loader": "^0.3.7", 42 | "karma-spec-reporter": "0.0.24", 43 | "karma-webpack": "^1.7.0", 44 | "lolex": "^1.4.0", 45 | "mocha": "^2.4.5", 46 | "chai": "^3.5.0", 47 | "sinon": "^1.17.3", 48 | "sinon-chai": "^2.8.0", 49 | "inject-loader": "^2.0.1", 50 | "isparta-loader": "^2.0.0", 51 | "phantomjs-prebuilt": "^2.1.3", 52 | "chromedriver": "^2.21.2", 53 | "cross-spawn": "^2.1.5", 54 | "nightwatch": "^0.8.18", 55 | "selenium-server": "2.53.0", 56 | "ora": "^0.2.0", 57 | "shelljs": "^0.6.0", 58 | "url-loader": "^0.5.7", 59 | "vue-hot-reload-api": "^1.2.0", 60 | "vue-html-loader": "^1.0.0", 61 | "vue-loader": "^8.3.0", 62 | "vue-style-loader": "^1.0.0", 63 | "webpack": "^1.12.2", 64 | "webpack-dev-middleware": "^1.4.0", 65 | "webpack-hot-middleware": "^2.6.0", 66 | "webpack-merge": "^0.8.3" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/unit/karma.conf.js: -------------------------------------------------------------------------------- 1 | // This is a karma config file. For more details see 2 | // http://karma-runner.github.io/0.13/config/configuration-file.html 3 | // we are also using it with karma-webpack 4 | // https://github.com/webpack/karma-webpack 5 | 6 | var path = require('path') 7 | var merge = require('webpack-merge') 8 | var baseConfig = require('../../build/webpack.base.conf') 9 | var utils = require('../../build/utils') 10 | var webpack = require('webpack') 11 | var projectRoot = path.resolve(__dirname, '../../') 12 | 13 | var webpackConfig = merge(baseConfig, { 14 | // use inline sourcemap for karma-sourcemap-loader 15 | module: { 16 | loaders: utils.styleLoaders() 17 | }, 18 | devtool: '#inline-source-map', 19 | vue: { 20 | loaders: { 21 | js: 'isparta' 22 | } 23 | }, 24 | plugins: [ 25 | new webpack.DefinePlugin({ 26 | 'process.env': require('../../config/test.env') 27 | }) 28 | ] 29 | }) 30 | 31 | // no need for app entry during tests 32 | delete webpackConfig.entry 33 | 34 | // make sure isparta loader is applied before eslint 35 | webpackConfig.module.preLoaders = webpackConfig.module.preLoaders || [] 36 | webpackConfig.module.preLoaders.unshift({ 37 | test: /\.js$/, 38 | loader: 'isparta', 39 | include: path.resolve(projectRoot, 'src') 40 | }) 41 | 42 | // only apply babel for test files when using isparta 43 | webpackConfig.module.loaders.some(function (loader, i) { 44 | if (loader.loader === 'babel') { 45 | loader.include = path.resolve(projectRoot, 'test/unit') 46 | return true 47 | } 48 | }) 49 | 50 | module.exports = function (config) { 51 | config.set({ 52 | // to run in additional browsers: 53 | // 1. install corresponding karma launcher 54 | // http://karma-runner.github.io/0.13/config/browsers.html 55 | // 2. add it to the `browsers` array below. 56 | browsers: ['PhantomJS'], 57 | frameworks: ['mocha', 'sinon-chai'], 58 | reporters: ['spec', 'coverage'], 59 | files: ['./index.js'], 60 | preprocessors: { 61 | './index.js': ['webpack', 'sourcemap'] 62 | }, 63 | webpack: webpackConfig, 64 | webpackMiddleware: { 65 | noInfo: true 66 | }, 67 | coverageReporter: { 68 | dir: './coverage', 69 | reporters: [ 70 | { type: 'lcov', subdir: '.' }, 71 | { type: 'text-summary' } 72 | ] 73 | } 74 | }) 75 | } 76 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 100 | 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tree-grid 2 | 3 | > 基于vue和iview组件库的树型表格 4 |  主要使用了 iview(checkbox组件,icon组件,button组件) 同时部分表格渲染模仿iview表格 支持[iview](https://github.com/iview/iview) 5 | 6 | ### [DEMO](https://huanglong6828.github.io/vue-tree-grid/dist/index.html) 如果对您如果有帮助的话,给颗星谢谢 7 | 8 | ## 版本支持 9 | > VUE1.0/2.0 使用时请下载对应iview 10 | 11 | 12 | ## 自适应功能新增 13 | 1. width 字段增加 14 | 2. td总和大于容器宽宽度 出现滚动条 否则表格自适应 需要使用者下载组件后 修改源码中 document.body.clientWidth  修改为 document.getElementsByClassName('你的容器')[0].clientWidth 15 | 16 | ## 新增默认选中 17 | ``` bash 18 | 1. _checked字段增加 19 | 2. 给data项设置特殊 key _checked: true 20 | ``` 21 | 22 | ## 2.0 多选框样式错乱,默认选中问题 23 | ``` bash 24 | 1. 修改为元素checkbox 样式大概调整 25 | 2. 如果样式不好看 可以自行修改或者使用其他组件ui checkbox 26 | ``` 27 | 28 | ## API 29 | ### props 30 | | 属性 | 说明 | 类型 | 31 | | ------------- |:-------------:| -----:| 32 | | items| 显示的结构化数据|Array| 33 | | columns| 表格列的配置描述|Array| 34 | 35 | ### columns 36 | | 属性 | 说明 | 类型 | 默认值| 37 | | ----------- |:--------------:| -----:|-----:| 38 | | title | 列头显示文字 |String |# | 39 | | key | 对应列内容的字段名 |String |# | 40 | | width | 列宽名 |Number |# | 41 | | sortable | 排序功能 |Boolean|false| 42 | | type |'selection':多选功能|String|# | 43 | | type |'action' 操作功能, 必填参数:actions:[{}]|String|# 44 | 45 | ### events 46 | | 事件名 | 说明 | 返回值 | 47 | | ------------- |:--------------:| -------:| 48 | | @on-row-click | 单击行或者单击操作按钮方法|data,$event,index| 49 | | @on-selection-change| 返回选中数组 |arr| 50 | | @on-sort-change | 表格列的配置描述 |key和排序规则(值为 asc 或 desc)| 51 | 52 | 53 | ## 使用方式 54 | 55 | ```html 56 | 65 | 162 | ``` 163 | ## 使用方式 164 | ``` bash 165 | # 安装依赖 166 | npm install iview 167 | 168 | main.js 引入 169 | import iView from 'iview'; 170 | import 'iview/dist/styles/iview.css'; 171 | Vue.use(iView); 172 | 173 | treeGird 放入工程项目 例如 components/treeGird 174 | ``` 175 | -------------------------------------------------------------------------------- /src/components/TreeGrid.vue: -------------------------------------------------------------------------------- 1 | 14 | 53 | 406 | 480 | -------------------------------------------------------------------------------- /src/components/treeGrid2.0.vue: -------------------------------------------------------------------------------- 1 | 14 | 55 | 452 | 526 | --------------------------------------------------------------------------------