更新记录
1.0.1(2025-04-10)
下载此版本
邀请生成海报支持分享和保存本地相册支持支付宝和微信
平台兼容性
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>