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]
            }));
相关推荐
moxiaoran575329 分钟前
uni-app学习笔记十六-vue3页面生命周期(三)
笔记·学习·uni-app
lqj_本人3 小时前
鸿蒙OS&UniApp自定义手势识别与操作控制实践#三方框架 #Uniapp
华为·uni-app·harmonyos
程序员小刘3 小时前
HarmonyOS鸿蒙Uniapp三方框架
华为·uni-app·harmonyos
^Rocky12 小时前
uniapp 实现腾讯云 IM 消息已读回执
uni-app·云计算·腾讯云
lqj_本人14 小时前
鸿蒙OS&UniApp导航栏组件开发:打造清新简约的用户界面#三方框架 #Uniapp
ui·uni-app·harmonyos
lyz24685915 小时前
动态报表筛选多项时的优化处理
javascript·uni-app·view design
lqj_本人17 小时前
鸿蒙OS&UniApp 开发的图文混排展示组件#三方框架 #Uniapp
华为·uni-app·harmonyos
lqj_本人21 小时前
鸿蒙OS&UniApp页面切换动效实战:打造流畅精致的转场体验#三方框架 #Uniapp
华为·uni-app·harmonyos
lqj_本人1 天前
鸿蒙OS&UniApp 移动端直播流播放实战:打造符合鸿蒙设计风格的播放器#三方框架 #Uniapp
华为·uni-app·harmonyos
lqj_本人1 天前
鸿蒙OS&UniApp复杂表单与动态验证实践:打造高效的移动端表单解决方案#三方框架 #Uniapp
华为·uni-app·harmonyos