当前位置: 首页 > news >正文

uniapp中使用leaferui使用Canvas绘制复杂异形表格的实现方法

需求:

如下图,要实现左图的样式,先实现框架,文字到时候 往里填就行了,原来的解决方案是想用css,html来实现,发现实现起来蛮麻烦的。我也没找到合适的实现方法,最后换使用canvas来实现,使用的js库是leaferui

1.安装:用game是因为有一些交互,反正体积也不大

npm install leafer-game

2.wxml

    <canvas
            :style="'width:'+cabox.width+'px;height:'+cabox.height+'px;'"
            id="leafer"
            type="2d"
            :width="cabox.width"
            :height="cabox.height"
            catchtouchstart="receiveEvent"
            catchtouchmove="receiveEvent"
            catchtouchend="receiveEvent"
            catchtouchcancel="receiveEvent"
    ></canvas>

3.javascript

  lf = new Leafer({view: window, width: that.cabox.width, height: that.cabox.height})
            lf.add(Rect.one(0,0,that.cabox.width,that.cabox.height));
            lf.add(Rect.one({width: that.cabox.width, height: that.cabox.height, strokeWidth: 2, stroke: "black",}));
            lf.add(Rect.one({
                strokeWidth: 2,
                stroke: "black",
                width: (that.cabox.perBox * 11.5),
                height: (that.cabox.perBox * 11.5),
                x: that.cabox.perBox * 1.75,
                y: that.cabox.perBox * 1.75
            }));
            lf.add(Rect.one({
                strokeWidth: 2,
                stroke: "black",
                width: (that.cabox.perBox * 9),
                height: (that.cabox.perBox * 9),
                x: that.cabox.perBox * 3,
                y: that.cabox.perBox * 3
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [0, 0, that.cabox.perBox * 3, that.cabox.perBox * 3]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [that.cabox.width, 0, that.cabox.perBox * 12, that.cabox.perBox * 3]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [that.cabox.width, that.cabox.height, that.cabox.perBox * 12, that.cabox.perBox * 12]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [0, that.cabox.height, that.cabox.perBox * 3, that.cabox.perBox * 12]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [that.cabox.perBox*6, 0, that.cabox.perBox*6, that.cabox.height]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [that.cabox.perBox*9, 0, that.cabox.perBox*9, that.cabox.height]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [0, that.cabox.perBox*6, that.cabox.width, that.cabox.perBox*6]
            }));
            lf.add(Line.one({
                stroke: "black",
                strokeWidth: 2,
                points: [0, that.cabox.perBox*9, that.cabox.width, that.cabox.perBox*9]
            }));

相关文章:

  • 【工具】前端 js 判断当前日期是否在当前自然周内
  • 如何更改vim命令创建代码文件时的默认模板
  • 【Go】十七、grpc 服务的具体功能编写
  • 核弹级技术革命——搭配deepseek-r1满血版的腾讯云ai助手(codex)仅用14天独立开发出适配ARM架构的微内核操作系统!
  • python 学习笔记
  • 《 C++ 点滴漫谈: 二十七 》告别低效!C++ 输入输出操作你真的会用吗?
  • Apache Tomcat RCE 稳定复现 保姆级!(CVE-2024-50379)附视频+POC
  • Git:多人协作
  • 什么是 Netty
  • git从零学起
  • Windows用户如何零成本迁移Sketch项目?2025实测方案推荐
  • APISIX Dashboard上的配置操作
  • 本地快速搭建一套AI人脸识别技术研究学习的实验环境
  • 【Yonghong GoldenDB 】GoldenDB 安装部署
  • 深度学习-10.门控循环网络
  • AI数字人技术源码开发分享:革新短视频营销策略
  • DaoCloud 亮相 2025 GDC丨开源赋能 AI 更多可能
  • Python实现GO鹅优化算法优化Catboost回归模型项目实战
  • k8s新增Node节点 简单易上手 如何给k8s新添加node节点
  • 千字详解Spring bean的作用域
  • 马鞍山建设网站/国际新闻今天最新消息
  • web网站怎么做/搭建一个网站平台需要多少钱
  • 做淘宝网站报告/排名nba
  • 好的做外贸的网站/web网页制作教程
  • 网站建设 顺德/seo会被取代吗
  • 怎样在本机建设网站/免费浏览网站推广