更新记录

1.0.1(2025-04-10) 下载此版本

邀请生成海报支持分享和保存本地相册支持支付宝和微信


平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 4.31 × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序 鸿蒙元服务
× × × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×
导入
import Poster from '../../../components/Poster/Poster.vue'
在components中声明
export default {
    components: {
        Poster
    }
}
在template中使用
<poster ref="poster" :list="list" background-color="#FFF" :width="750" :height="1334"
            @on-success="posterSuccess" @on-error="posterError"></poster>
list参数说明
参数名 必选 类型 说明
type string 类型,可选值:image(图片),text(文字),textarea(多行文字)
x number x轴位置
y number y轴位置
path string 图片路径,type为image时必填
width string type为image时指定图片宽度,type为textarea时指定换行的宽度
height string type为image时必填指定图片高度,type为textarea时指定文本区域高度,溢出展示“...”
rotate number 旋转角度
shape string 可选值:circle 圆形
area object 绘制范围,超出该范围会被剪裁掉 该属性与shape暂时无法同时使用,area存在时,shape失效;例如: {x:10,y:10,width:100,height:100}
text string 文本内容,type为text或textarea时必填
color string 文本颜色
size number 文本字体大小
net string 本地图片参数('local')(默认网络)
lineSpace number 行间距,type为textarea时有效
textBaseline string 基线 默认top 可选值:'top'、'bottom'、'middle'、'normal'
代码示例
<template>
    <view>
        <button @click="startPic">生成</button>

        <!-- 生成图片 width和height调整生成图片大小-->
        <poster ref="posterComponent" :list="list" background-color="#FFF" :width="750" :height="1000"
            @on-success="posterSuccess" @on-error="posterError"></poster>

    </view>
</template>

<script setup>
    import Poster from '@/wxcomponents/tangyuan-posterxiao/tangyuan-posterxiao.vue'
    import {
        ref
    } from "vue"
    const posterComponent = ref(null)

    const posterSuccess = (url) => {
        console.log("成功的回调生成canvas图片", url);
        uni.showShareImageMenu({
            path: url,
            fail(err) {
                console.log(err);
            }
        })
    }
    const posterError = () => {
        console.log("失败回调");
    }
    // 本地图片需要加例子
    // {
    //      type: 'image',
    //      
    //      path: '本地路径',//直接/static/...
    //      x: 0,
    //      y: 0,
    //      net:"local"
    //      width: 750,
    //      height: 750
    //  }

    let list = [{
            type: 'image',
            // path替换成你自己的图片,注意需要在小程序开发设置中配置域名
            path: 'https://img1.baidu.com/it/u=3591704334,1673125027&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1067',
            x: 0,
            y: 0,
            width: 750,
            height: 750
        },

    ];
    const startPic = () => {

        posterComponent.value.generateImg()

    }
</script>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问