• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

    vue-fabric: 基于fabric.js库 创建的vue版本fabric组件,定制画板,图片组合绘制 ...

    原作者: [db:作者] 来自: 网络 收藏 邀请

    开源软件名称:

    vue-fabric

    开源软件地址:

    https://gitee.com/_pure/vue-fabric

    开源软件介绍:

    vue-fabric

    purestart vue-fabric.

    Installation

    npm install vue-fabric --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
    idString"canvas"id
    widthNumber0canvas width
    heightNumber0canvas height

    Function

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

    createImage(url,options) 绘制图片

    paramsTypeDescription
    urlStringimage url
    optionsObjectid(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件),evented 是否可被点击选中,selectable 是否禁止被选中...其它属性

    createImageByImg(img,options) 绘制图片

    paramsTypeDescription
    imgImage对象new Image对象
    optionsObjectid(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件),evented 是否可被点击选中,selectable 是否禁止被选中...其它属性

    createTextbox(text,options) 绘制文本

    paramsTypeDescription
    textStringtext content
    optionsObjectwidth,left,top,fill(颜色),fontSize,id,fontFamily,strokeWidth,stroke,textAlign,textBackgroundColor,lineHeight,fontWeight,...其它属性

    createItext(text,options) 绘制可编辑文本(可换行显示文本)

    paramsTypeDescription
    textStringtext content
    optionsObjectwidth,left,top,fill(颜色),fontSize,id,editable(是否可编辑),fontFamily,fontSize,strokeWidth,stroke,textAlign,textBackgroundColor,lineHeight,fontWeight,...其它属性

    createRect(options) 绘制矩形

    optionsTypeDescription
    leftNumberleft
    topNumbertop
    widthNumberRect width
    heightNumberRect height
    fillColorStringRect fillColor
    idString唯一标识 id
    其它属性兼容all兼容原生其它属性

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

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

    eraseDrawConfig(options) 开启自由绘制橡皮擦(只对当前绘制画布有效)

    optionsTypeDescription
    colorString选填,擦除颜色默认白色
    drawWidthNumber橡皮擦线宽

    createLine(options) 绘制直线

    optionsTypeDescription
    x,y,x1,y1Numberline points,直线两点坐标
    fillColorStringfillColor 填充颜色
    strokeColorStringstrokeColor 绘制颜色
    其它属性兼容all兼容原生其它属性

    drawDottedline(options) 绘制虚线

    optionsTypeDescription
    x,y,x1,y1Numberline points,直线两点坐标
    colorString绘制线颜色
    drawWidthNumber绘制线宽
    offsetNumber默认 6,每隔 offset 个像素空 empty 个像素
    emptyNumber默认 3,每隔 offset 个像素空 empty 个像素
    其它属性兼容all兼容原生其它属性

    drawArrowLine(options) 绘制箭头直线

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

    createTriangle(options) 绘制三角形

    optionsTypeDescription
    x,y,x1,y1,x2,y2Number三角形 3 点坐标位置
    left,topNumberposition 位置
    colorString绘制线颜色
    fillColorStringfillColor 填充颜色
    drawWidthNumber绘制线宽
    其它属性兼容all兼容原生其它属性

    createEqualTriangle(options) 绘制等边三角形

    optionsTypeDescription
    left,topNumberposition 位置
    fillStringfillColor 填充颜色
    widthNumber三角形底边宽度
    heightNumber三角形高
    其它属性兼容all兼容原生其它属性

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

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

    createCircle(options) 绘制圆

    optionsTypeDescription
    left,topNumberposition 位置
    fillStringfillColor 填充颜色
    radiusNumber圆形半径
    其它属性兼容all兼容原生其它属性

    createEllipse(options) 绘制椭圆

    optionsTypeDescription
    rx,ryNumberrx , ry 椭圆两个长轴尺寸和短轴尺寸
    left,topNumberposition 位置
    fillColorStringfillColor 填充颜色
    strokeColorStringstrokeColor 绘制线颜色
    angleNumberangle 倾斜角度
    其它属性兼容all兼容原生其它属性

    setRotate(angle) 旋转选中元素

    paramsTypeDescription
    angleNumber旋转角度

    setSelection(flag) 设置画布是否可以框选

    paramsTypeDescription
    flagBoolean画布是否可以框选

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

    optionsTypeDescription
    imgUrlString背景图片 Url
    angleNumber旋转角度
    opacityNumber背景图片透明度
    widthNumber默认为canvas宽度 背景图片宽度
    heightNumber默认为canvas高度 背景图片高度
    scaleXNumber水平缩放
    scaleYNumber垂直缩放
    crossOriginString可为'anonymous',加载跨域图片

    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) 设置添加对象到画布

    deactivateOne(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 根据轨迹绘制形状图形

    2020.03.02---v0.1.26

    • 新增属性id 修复一个页面使用多个vue-fabric没有渲染成功的问题

    2020.04.15---v0.1.27

    • 修复id = "canvas"的情况下会报错的问题

    2020.05.08---v0.1.28

    • 修复更新Mirror只有图片生效的问题

    2020.07.07---v0.1.29

    • 新增优化图片无法被选中属性设置 evented 和 selectable 感谢 @jessieyyy
    • 新增取消单个选中的方法 deactivateOne(obj)
    • 修复image top 和 left 定位bug

    2020.07.21---v0.1.37

    • 新增createImageByImg(img, options)方法 其中参数img是Image对象
    • 新增setSelection(flag) 设置画布是否可以框选

    鲜花

    握手

    雷人

    路过

    鸡蛋
    该文章已有0人参与评论

    请发表评论

    全部评论

    专题导读
    热门推荐
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap