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

需求:

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

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

npm install leafer-game

2.wxml

html 复制代码
    <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

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]
            }));
相关推荐
学前端搞口饭吃42 分钟前
uniapp打ios包
ios·uni-app
```陪伴43 分钟前
uniapp打包IOS私钥证书过期了,如何在非mac系统操作
macos·ios·uni-app
Monly215 小时前
Uniapp:创建项目
uni-app
清晨細雨5 小时前
uniapp微信小程序:WIFI设备配网之TCP/UDP开发AP配网
前端·物联网·小程序·uni-app
寒寒_5 小时前
uni-app 安卓10以上上传原图解决方案
uni-app
敲代码的彭于晏6 小时前
2025 年必看!uni-app 结合 VSCode 实现高效跨平台开发入门
vue.js·uni-app
盛夏绽放7 小时前
uni-app 状态管理深度解析:Vuex 与全局方案实战指南
前端·javascript·uni-app
七七小报7 小时前
uniapp-商城-31-shop页面中的 我的订单
uni-app
小凯!在努力15 小时前
无线uniapp调试设备
uni-app
samuel91816 小时前
uniapp通过uni.addInterceptor实现路由拦截
前端·javascript·uni-app