海报画板插件<l-painter>的使用

插件地址

插件市场-海报画板

我的demo

<l-painter ref="painter"
			css="width: 750rpx; padding: 30rpx; background: linear-gradient(,#2b75fa 100%, #f5f5f5 0%);box-sizing:border-box;">
			<!-- //如果使用Template出现顺序错乱,可使用`template` 等所有变量完成再显示 -->
			<!-- 这里是加了水印 用户昵称和id -->			
            <l-painter-view
				css="background-color:#fff;width:100%;border-radius:30rpx;padding:30rpx;box-sizing:border-box;position:relative;overflow:hidden;">
				<l-painter-view css="position:absolute;left:10rpx;top:50%;transform:translateY(-50%) rotate(45deg) 0 0;text-align:center;">
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					
				</l-painter-view>
				<l-painter-view css="position:absolute;left:10rpx;top:10rpx;transform:rotate(45deg) 0 0;text-align:center;">
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					
				</l-painter-view>
				<l-painter-view css="position:absolute;left:10rpx;bottom:10rpx;transform:rotate(45deg) 0 0;text-align:center;">
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					<l-painter-text :text="nickname+ ' ' + ' user_id:' +user_id" css="font-size:32rpx;color:#eee;margin: 0 10rpx;"></l-painter-text>
					
				</l-painter-view>
				<l-painter-view
					css="display:flex;align-items:center;justify-content:space-between;margin-bottom:20rpx;">
					<l-painter-image src="/static/icon/titlelogo.png"
						css="width:152rpx;height:80rpx;margin-right:20rpx;"></l-painter-image>
					<l-painter-text css="font-weight:bold;font-size:64rpx;color:#3D3D3D;" :text="detail.names" />
					<l-painter-view css="width:152rpx;height:80rpx;margin-left:20rpx;"></l-painter-view>
				</l-painter-view>
				
				<l-painter-view css="display:flex;justify-content:center;margin-bottom:20rpx;width:100%;">
					<l-painter-image :src="cover" css="width:240rpx;height:305rpx;object-fit:cover;"></l-painter-image>
				</l-painter-view>
				<l-painter-view>
					<l-painter-text css="font-size: 36rpx;font-weight: bold;line-height: 48rpx;" text="情况说明" />
				</l-painter-view>
				<l-painter-view>
					<l-painter-text css="line-height: 48rpx;line-clamp:4;" :text="detail.detail"></l-painter-text>
				</l-painter-view>
				<l-painter-qrcode text="二维码内容 例limeui.qcoon.cn"
					css="width: 184rpx; height: 184rpx;margin:auto;"></l-painter-qrcode>
				<l-painter-view css="text-align:center;color:#999;font-size:24rpx;">
					<l-painter-text text="扫描二维码下载APP"
						css="text-align:center;color:#999;font-size:28rpx;margin:20rpx 0;"></l-painter-text>
				</l-painter-view>

			</l-painter-view>
			<l-painter-image src="/static/index/steps.png"
				css="width:100%;object-fit:contain;margin:20rpx 0;"></l-painter-image>
			
			
		</l-painter>

		
		<view class="btn" @click="save" v-if="detail.detail">保存图片</view>
//保存图片
save() {
				
				let that = this
				this.$refs.painter.canvasToTempFilePathSync({
					fileType: "jpg",
					// 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
					pathType: 'url',
					quality: 1,
					success: (res) => {
						console.log(res.tempFilePath);

						
						// 非H5 保存到相册
						// // H5 提示用户长按图另存
						 uni.saveImageToPhotosAlbum({
						     filePath: res.tempFilePath,
						     success:  ()=> {
						         console.log('save success');
						uni.showToast({
							title:'保存成功'
						})

						     }
						 });
					},
				});
			},

我的效果图

 

具体怎么使用请参考官方文档,第一次用,有错误的地方请指正!

### 关于 `l-painter-view` 组件的技术信息 #### 功能概述 `l-painter-view` 是用于在 uni-app 中创建可绘制视图的一个组件,允许开发者通过 JSON 配置来定义绘图内容。此方法简化了复杂图形界面的设计流程,并提供了灵活的数据驱动渲染机制[^3]。 #### 基本属性介绍 - **ref**: 设置当前实例的 `$refs` 名称以便后续操作该 DOM 节点。 - **isCanvasToTempFilePath**: 是否开启 canvas 导出图片功能,默认关闭。 - **pixel-ratio**: 定义导出图像时使用的像素比例,默认值为 1;提高数值可以得到更清晰的画面质量。 - **custom-style**: 自定义样式字符串,可用于调整位置和其他 CSS 属性。 #### 使用示例 下面是一个简单的例子展示如何利用 `<l-painter>` 和其子元素 `<l-painter-view>` 来构建一个带有背景颜色和文字描述的小程序卡片: ```html <template> <view class="container"> <!-- 显示生成后的图片 --> <image v-if="path" :src="path" mode="widthFix"></image> <!-- painter 组件 --> <l-painter ref="painter" isCanvasToTempFilePath @success="drawDone" pixel-ratio="2" custom-style="position:fixed;left:-9999px;"> <!-- view 子组件配置 --> <l-painter-view type="rect" backgroundColor="#ffffff"/> <!-- 添加更多 l-painter-view 可以组合成复杂的布局结构 --> <!-- 文字层 --> <l-painter-view type="text" text="Hello Painter!" fontSize="48" color="#000000" top="50%" left="50%" textAlign="center" /> </l-painter> <!-- 触发按钮 --> <button @click="createImage">生成图片</button> </view> </template> <script> export default { data() { return { path: '' }; }, methods: { createImage(){ this.$refs.painter.canvasToTempFilePath().then(res => { console.log('成功', res); this.path = res.tempFilePath; }).catch(err => { console.error('失败', err); }); }, drawDone(e){ console.log('完成回调:', e.detail); } } }; </script> ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值