Skip to content

Poster 分享海报 ​

通过画布组合文字、图片、矩形、线条和二维码,再生成图片。nvue 页面使用 PosterWeex 海报。

支持平台 ​

以下为官网文档所列的平台支持情况,具体功能及版本限制请参见本页的平台说明。

App-vueApp-nvue微信小程序支付宝小程序百度小程序字节小程序QQ小程序H5PC快手小程序钉钉小程序
✓✓✓✓✓✓✓✓✓✓✓

官网的海报平台表将两个实现合并列出;App nvue 使用 fui-poster-weex,其他平台使用 fui-poster。

基础用法 ​

vue
<template>
  <!-- 海报画布 -->
  <fui-poster ref="posterRef" @ready="handlePosterReady" />
</template>

<script>
export default {
  methods: {
    /** 画布就绪后生成海报 */
    handlePosterReady() {
      const posterData = {
        texts: [{ x: 40, y: 60, text: '分享海报', fontSize: 32, color: '#333333' }]
      };
      this.$refs.posterRef.generatePoster(posterData, (filePath) => {
        if (filePath) {
          uni.previewImage({ urls: [filePath] });
        }
      });
    }
  }
};
</script>

属性 ​

属性类型说明官网默认值
widthNumber / String画布宽度,单位 rpx750
heightNumber / String画布高度,单位 rpx1024
pixelRatioNumber / String画布缩放比2

本地支付宝小程序的 pixelRatio 默认值为 3。

事件 ​

事件说明回调参数
ready画布初始化完成无

generatePoster(params, callback) 生成海报并通过回调返回路径;saveImage(filePath) 保存图片。H5 返回 base64,可预览并由用户保存;各平台保存相册的权限和能力不同。

海报数据 ​

params 可包含 texts、imgs、blocks、lines 和 qrcode 数组。坐标和尺寸通常使用 rpx,通过 zIndex 控制绘制顺序。

数组常用字段
textsx、y、text、fontSize、color、width、rows、lineHeight、textAlign、fontWeight、opacity、zIndex
imgsimgResource、type、x、y、width、height、crop、borderRadius、borderWidth、borderColor、zIndex
blocksx、y、width、height、backgroundColor、borderWidth、borderColor、borderRadius、gradientColor、gradientType、opacity、shadow、zIndex
linesx、y、endX、endY、color、width、zIndex
qrcodex、y、width、height、value、foreground、background、zIndex

图片 type 为 1 时直接使用资源,2 时先下载网络图片,3 时转换 base64;实际支持范围取决于平台。nvue 不支持矩形阴影。大尺寸画布在 iOS/Safari 上可能无法绘制。

插槽 ​

插槽说明
—官网未列出该组件的插槽