2.0.2 • Published 4 years ago

vuefabric2019 v2.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

vuefabric2019

Installation

基于原作者的vue-fabric开发新功能

npm install vuefabric2019 --save

依赖

下载customiseControls.min.js.和 fabric.min.js.到本地 static/js/文件下

本地项目 index.html 引入

<script type="text/javascript" src="./static/js/fabric.min.js"></script>
<script type="text/javascript" src="./static/js/customiseControls.min.js"></script>

Import

在main.js中
import 'vue-fabric/dist/vue-fabric.min.css';
import { Fabric } from 'vue-fabric';
Vue.use(Fabric);

使用

 <vue-fabric ref="canvas" :width="width" :height="height"></vue-fabric>

Usage

Props

NameTypeDefaultDescription
widthNumber0canvas width
heightNumber0canvas height

Function

方法调用 this.\$refs.canvas.方法名(params)

createImage(url,options) 绘制图片

paramsTypeDescription
urlStringimage url
optionsObjectid(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件)

createTextbox(text,options) 绘制文本

paramsTypeDescription
textStringtext content
optionsObjectwidth,left,top,fillColor(颜色),fontSize,id

createRect(options) 绘制矩形

optionsTypeDescription
leftNumberleft
topNumbertop
widthNumberRect width
heightNumberRect height
fillColorStringRect fillColor
idString唯一标识 id

freeDrawConfig(options) 开启/关闭自由绘制(画笔)

optionsTypeDescription
isDrawingModeBoolean是否开启自由绘制 true/false
colorString绘制线颜色
drawWidthNumber绘制线宽

createLine(options) 绘制直线

optionsTypeDescription
x,y,x1,y1Numberline points,直线两点坐标
fillColorStringfillColor 填充颜色
strokeColorStringstrokeColor 绘制颜色

drawDottedline(options) 绘制虚线

optionsTypeDescription
x,y,x1,y1Numberline points,直线两点坐标
colorString绘制线颜色
drawWidthNumber绘制线宽
offsetNumber默认 6,每隔 offset 个像素空 empty 个像素
emptyNumber默认 3,每隔 offset 个像素空 empty 个像素

drawArrowLine(options) 绘制箭头直线

optionsTypeDescription
x,y,x1,y1Numberline points,直线两点坐标
colorString绘制线颜色
drawWidthNumber绘制线宽
fillColorNumber默认透明,填充颜色
thetaNumber默认 35,箭头角度大小
headlenNumber默认 35,箭头角度大小

createTriangle(options) 绘制三角形

optionsTypeDescription
x,y,x1,y1,x2,y2Number三角形 3 点坐标位置
left,topNumberposition 位置
colorString绘制线颜色
fillColorStringfillColor 填充颜色
drawWidthNumber绘制线宽

createEqualTriangle(options) 绘制等边三角形

optionsTypeDescription
left,topNumberposition 位置
fillStringfillColor 填充颜色
widthNumber三角形底边宽度
heightNumber三角形高

drawByPath(pathArray,options) 根据轨迹绘制图形

paramsTypeDescription
pathArrayArray轨迹所在点数组,按顺序正时针或逆时针,如三角形 [50, 50, 120, 120, 80, 160]
optionsObjectleft,top,strokeColor,strokeWidth,fillColor

createCircle(options) 绘制圆

optionsTypeDescription
left,topNumberposition 位置
fillStringfillColor 填充颜色
radiusNumber圆形半径

createEllipse(options) 绘制椭圆

optionsTypeDescription
rx,ryNumberrx , ry 椭圆两个长轴尺寸和短轴尺寸
left,topNumberposition 位置
fillColorStringfillColor 填充颜色
strokeColorStringstrokeColor 绘制线颜色
angleNumberangle 倾斜角度

setRotate(angle) 旋转选中元素

paramsTypeDescription
angleNumber旋转角度

setBackgroundImage(url) 设置画布背景图片

paramsTypeDescription
urlString背景图片 Url

renderAll() 重新渲染画布

setBackgroundColor(color) 设置画布背景颜色

paramsTypeDescription
colorString背景颜色

toggleMirror(options) 设置图片元素镜像翻转

optionsTypeDescription
flipString可选值 X,Y 默认值 X , 镜像翻转 X,Y

setCornerIcons(options) 自定义旋转操作元素图片

optionsTypeDescription
sizeNpmber图片大小 px
borderColorString图片边框颜色
cornerBackgroundColorString设置背景颜色
cornerShapeString形状,默认'rect' ,可选'rect', 'circle'
tlStringtop left 左上角元素图片地址(本地只能 static 下的图片)
trStringtop right 右上角元素图片地址(本地只能 static 下的图片)
blStringbottom left 左下角元素图片地址(本地只能 static 下的图片)
brStringbottom right 右下角元素图片地址(本地只能 static 下的图片)
mlStringmiddle left 中间左边元素图片地址(本地只能 static 下的图片)
mrStringmiddle right 中间右边元素图片地址(本地只能 static 下的图片)
mtrStringmiddle top 顶部元素图片地址(本地只能 static 下的图片)

toNextLayer() 设置当前选中画布到下一层

toLastLayer() 设置当前选中画布到上一层

toBottomLayer() 设置当前选中画布到底层

toTopLayer() 设置当前选中画布到顶层

discardActive() 取消选中

getObjects() 获取当前画布上的所有元素对象

clear() 清除当前画布上的所有元素对象

toDataUrl() 返回当前画布的 base64 图片

toJson() 返回当前画布的 json 对象

loadFromJSON(json,cb) 从 json 对象中加载画布数据

paramsTypeDescription
jsonObjectjson 对象
cbFunction加载完成回调函数

toSvg() 返回当前画布的 svg 图片

removeCurrentObj() 删除当前选中对象

getEditObj() 返回当前选中对象,并不在画布上显示,用于编辑当前元素

setEditObj(obj) 设置添加对象到画布

事件

 <vue-fabric ref="canvas" @selection:created="selected" :width="width" :height="height"></vue-fabric>

鼠标事件

nameTypeDescription
mouse:downeventmouse down
mouse:upeventmouse up
mouse:moveeventmouse move
mouse:dblclickeventmouse dblclick
mouse:overeventmouse over
mouse:outeventmouse out

其它事件

nameTypeDescription
selection:createdevent选中 canvas 元素对象,单选和多选都会触发此事件
selection:updatedeventselection updated
selection:clearedeventselection cleared
before:selection:clearedeventbefore selection cleared
object:addedevent当有元素被添加进来时候触发
object:removedeventobject removed
object:modifiedeventobject modified
object:rotatingeventobject rotating
object:scalingeventobject scaling
object:movingeventobject moving

Changelog

2018.08.26

v0.1.4 * 初始化组件库

2018.09.20

v0.1.8 * 新增 api 常用接口创建文档

2019.01.19---v0.1.9

  • 新增画板事件,鼠标事件、选中事件等
  • 新增绘制三角形
  • 新增绘制虚线
  • 新增画笔自由绘制
  • 新增绘制箭头
  • 新增取消选中方法

2019.01.31---v0.1.10

  • 修改绘制图片(createImage 方法)不能定位 top 的 BUG
  • 修改镜像翻转函数 toggleMirror ,新增参数 options ,X 翻转和 Y 翻转

2019.05.09---v0.1.20

  • fix webpack-dev-server 版本导致的 npm run dev fail
  • 新增方法 drawByPath 根据轨迹绘制形状图形
2.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago