├── .npmignore ├── .babelrc ├── src ├── components │ ├── image │ │ ├── line_dot.png │ │ ├── line_h.png │ │ ├── line_v.png │ │ ├── ruler_h.png │ │ ├── ruler_v.png │ │ ├── cur_move_h.cur │ │ └── cur_move_v.cur │ ├── event.js │ └── vue-ruler-tool.vue ├── index.js ├── main.js └── App.vue ├── .editorconfig ├── .gitignore ├── index.html ├── package.json ├── webpack.config.js └── README.md /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .git 3 | node_modules/ 4 | .idea/ 5 | npm-debug.log 6 | yarn-error.log 7 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }], 4 | "stage-3" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /src/components/image/line_dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/line_dot.png -------------------------------------------------------------------------------- /src/components/image/line_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/line_h.png -------------------------------------------------------------------------------- /src/components/image/line_v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/line_v.png -------------------------------------------------------------------------------- /src/components/image/ruler_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/ruler_h.png -------------------------------------------------------------------------------- /src/components/image/ruler_v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/ruler_v.png -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | Created by Gorky on 2018/9/15 3 | */ 4 | export { default } from './components/vue-ruler-tool' 5 | -------------------------------------------------------------------------------- /src/components/image/cur_move_h.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/cur_move_h.cur -------------------------------------------------------------------------------- /src/components/image/cur_move_v.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gorkys/vue-ruler-tool/HEAD/src/components/image/cur_move_v.cur -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | new Vue({ 5 | el: '#app', 6 | render: h => h(App) 7 | }) 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log 5 | yarn-error.log 6 | package-lock.json 7 | 8 | # Editor directories and files 9 | .idea 10 | *.suo 11 | *.ntvs* 12 | *.njsproj 13 | *.sln 14 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | vue-ruler-tool 6 | 7 | 13 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/components/event.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description 绑定事件 on(element, event, handler) 3 | */ 4 | export const on = (function () { 5 | if (document.addEventListener) { 6 | return function (element, event, handler) { 7 | if (element && event && handler) { 8 | element.addEventListener(event, handler, false) 9 | } 10 | } 11 | } else { 12 | return function (element, event, handler) { 13 | if (element && event && handler) { 14 | element.attachEvent('on' + event, handler) 15 | } 16 | } 17 | } 18 | })() 19 | 20 | /** 21 | * @description 解绑事件 off(element, event, handler) 22 | */ 23 | export const off = (function () { 24 | if (document.removeEventListener) { 25 | return function (element, event, handler) { 26 | if (element && event) { 27 | element.removeEventListener(event, handler, false) 28 | } 29 | } 30 | } else { 31 | return function (element, event, handler) { 32 | if (element && event) { 33 | element.detachEvent('on' + event, handler) 34 | } 35 | } 36 | } 37 | })() -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 41 | 42 | 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-ruler-tool", 3 | "description": "vue标尺辅助线", 4 | "version": "1.2.4", 5 | "author": "gorkys", 6 | "license": "MIT", 7 | "main": "dist/index.js", 8 | "jsnext:main": "src/index.js", 9 | "private": false, 10 | "scripts": { 11 | "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", 12 | "build": "cross-env NODE_ENV=production webpack --progress --hide-modules" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/gorkys/vue-ruler-tool.git" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/gorkys/vue-ruler-tool/issues" 20 | }, 21 | "homepage": "https://github.com/gorkys/vue-ruler-tool", 22 | "keywords": [ 23 | "vue", 24 | "component", 25 | "ruler", 26 | "tool" 27 | ], 28 | "dependencies": { 29 | "vue": "^2.5.11" 30 | }, 31 | "browserslist": [ 32 | "> 1%", 33 | "last 2 versions", 34 | "not ie <= 8" 35 | ], 36 | "devDependencies": { 37 | "babel-core": "^6.26.0", 38 | "babel-loader": "^7.1.2", 39 | "babel-preset-env": "^1.6.0", 40 | "babel-preset-stage-3": "^6.24.1", 41 | "cross-env": "^5.0.5", 42 | "css-loader": "^0.28.7", 43 | "file-loader": "^1.1.4", 44 | "node-sass": "^4.5.3", 45 | "sass-loader": "^6.0.6", 46 | "vue-loader": "^13.0.5", 47 | "vue-template-compiler": "^2.4.4", 48 | "webpack": "^3.8.0", 49 | "webpack-dev-server": "^2.9.7" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var webpack = require('webpack') 3 | 4 | module.exports = { 5 | entry: process.env.NODE_ENV === 'production' ? './src/index.js' : './src/main.js', 6 | output: { 7 | path: path.resolve(__dirname, './dist'), 8 | publicPath: '/dist/', 9 | filename: 'index.js', 10 | libraryTarget: 'umd', 11 | umdNamedDefine: true 12 | }, 13 | module: { 14 | rules: [ 15 | { 16 | test: /\.css$/, 17 | use: [ 18 | 'vue-style-loader', 19 | 'css-loader' 20 | ], 21 | }, 22 | { 23 | test: /\.scss$/, 24 | use: [ 25 | 'vue-style-loader', 26 | 'css-loader', 27 | 'sass-loader' 28 | ], 29 | }, 30 | { 31 | test: /\.sass$/, 32 | use: [ 33 | 'vue-style-loader', 34 | 'css-loader', 35 | 'sass-loader?indentedSyntax' 36 | ], 37 | }, 38 | { 39 | test: /\.vue$/, 40 | loader: 'vue-loader', 41 | options: { 42 | loaders: { 43 | // Since sass-loader (weirdly) has SCSS as its default parse mode, we map 44 | // the "scss" and "sass" values for the lang attribute to the right configs here. 45 | // other preprocessors should work out of the box, no loader config like this necessary. 46 | 'scss': [ 47 | 'vue-style-loader', 48 | 'css-loader', 49 | 'sass-loader' 50 | ], 51 | 'sass': [ 52 | 'vue-style-loader', 53 | 'css-loader', 54 | 'sass-loader?indentedSyntax' 55 | ] 56 | } 57 | // other vue-loader options go here 58 | } 59 | }, 60 | { 61 | test: /\.js$/, 62 | loader: 'babel-loader', 63 | exclude: /node_modules/ 64 | }, 65 | { 66 | test: /\.(png|jpg|gif|svg)$/, 67 | loader: 'file-loader', 68 | options: { 69 | name: '[name].[ext]?[hash]' 70 | } 71 | } 72 | ] 73 | }, 74 | resolve: { 75 | alias: { 76 | 'vue$': 'vue/dist/vue.esm.js' 77 | }, 78 | extensions: ['*', '.js', '.vue', '.json'] 79 | }, 80 | devServer: { 81 | historyApiFallback: true, 82 | noInfo: true, 83 | overlay: true 84 | }, 85 | performance: { 86 | hints: false 87 | }, 88 | devtool: '#eval-source-map' 89 | } 90 | 91 | if (process.env.NODE_ENV === 'production') { 92 | module.exports.devtool = '#source-map' 93 | // http://vue-loader.vuejs.org/en/workflow/production.html 94 | module.exports.plugins = (module.exports.plugins || []).concat([ 95 | new webpack.DefinePlugin({ 96 | 'process.env': { 97 | NODE_ENV: '"production"' 98 | } 99 | }), 100 | new webpack.optimize.UglifyJsPlugin({ 101 | sourceMap: true, 102 | compress: { 103 | warnings: false 104 | } 105 | }), 106 | new webpack.LoaderOptionsPlugin({ 107 | minimize: true 108 | }) 109 | ]) 110 | } 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![标尺辅助线.gif](https://upload-images.jianshu.io/upload_images/12792466-b910b0ac21305c52.gif?imageMogr2/auto-orient/strip) 2 | # vue-ruler-tool 3 | --- 4 | >一个基于vue的网页标尺辅助线工具 5 | 6 | ### 特点 7 | - 没有依赖 8 | - 可拖动的辅助线 9 | - 快捷键支持 10 | > 好吧,其实这个组件没什么太多的特点~ 11 | 12 | ### 安装与基本用法 13 | ``` 14 | $ npm install --save vue-ruler-tool 15 | ``` 16 | 全局注册 17 | ``` 18 | import Vue from 'vue' 19 | import VueRulerTool from 'vue-ruler-tool' 20 | 21 | Vue.component('vue-ruler-tool', VueRulerTool) 22 | ``` 23 | 你现在就可以使用该组件了 24 | ``` 25 | 36 | 37 | 51 | ``` 52 | ### Props 53 | **parent** 54 | 55 | 类型:`Boolean` 56 | 57 | 默认值: `false` 58 | 59 | 限制组件大小在父级内部 60 | ``` 61 | 62 | ``` 63 | **position** 64 | 65 | 类型:`String` 66 | 67 | 默认值: `relative` 68 | 69 | 可能值:`['absolute', 'fixed', 'relative', 'static', 'inherit']` 70 | 71 | 规定标尺工具的定位类型 72 | ``` 73 | 74 | ``` 75 | **isHotKey** 76 | 77 | 类型: `Boolean` 78 | 79 | 默认值: `true` 80 | 81 | 快捷键键开关,目前仅支持快捷键`R`标尺显示开关 82 | ``` 83 | 84 | ``` 85 | **visible** 86 | 87 | 类型: `Boolean` 88 | 89 | 默认值: `true` 90 | 91 | 是否显示,如果设为false则隐藏,可通过.sync接收来自`R`快捷键的修改 92 | ``` 93 | 94 | data() { 95 | return { 96 | visible: true 97 | } 98 | } 99 | ``` 100 | **isScaleRevise** 101 | 102 | 类型: `Boolean` 103 | 104 | 默认值: `false` 105 | 106 | 刻度修正(根据content进行刻度重置),意思就是从内容的位置开始从0计数 107 | ``` 108 | 109 | ``` 110 | 111 | **value(v-model)** 112 | 113 | 类型: `Array` 114 | 115 | 默认值: `[]` 116 | 117 | 接受格式:` [{ type: 'l', site: 50 }, { type: 'v', site: 180 }]` 118 | 119 | 预置参考线`l`代表水平线,`v`代表垂直线,`site`为Number类型 120 | ``` 121 | 122 | ``` 123 | **contentLayout** 124 | 125 | 类型: `Object` 126 | 127 | 默认值: `{ top: 0, left: 0 }` 128 | 129 | 内容部分布局分布,及内容摆放位置 130 | ``` 131 | 132 | ``` 133 | **stepLength** 134 | 135 | 类型: `Number` 136 | 137 | 默认值: `50` 138 | 139 | 步长设置(10的倍数) 140 | ``` 141 | 142 | ``` 143 | ### Methods 144 | 145 | **quickGeneration** 146 | 147 | 参数:`[{ type: 'l', site: 100 }, { type: 'v', site: 200 }]` 148 | 149 | 快速设置参考线,一般用来通过弹窗让用户输入 150 | ``` 151 | 152 | let params=[ 153 | { type: 'l', site: 100 }, 154 | { type: 'v', site: 200 } 155 | ] 156 | this.$refs.rulerTool.quickGeneration(params) 157 | ``` 158 | ### 优化项 159 | - [x] 标尺与窗口间距 160 | ## Build Setup 161 | 162 | ``` bash 163 | # install dependencies 164 | npm install 165 | 166 | # serve with hot reload at localhost:8080 167 | npm run dev 168 | 169 | # build for production with minification 170 | npm run build 171 | ``` 172 | 173 | For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader). 174 | -------------------------------------------------------------------------------- /src/components/vue-ruler-tool.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 340 | 341 | 470 | --------------------------------------------------------------------------------