Skip to content
内容大纲
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

cv-draw-posters 绘制海报

简要

可以把图片文字等元素合并到一起

示例

vue
<template>
  <view>
    <view class="components-title">
      <view class="components-title-t">cv-draw-posters</view>
      <view class="components-title-d">绘制海报</view>
    </view>
    <cv-draw-posters :postersData="postersData" @success="onSuccessCreatePosters" @error="onPostersError" />

    <!-- 仅为生成二维码使用 -->
    <cv-draw-qrcode
      style="height: 0; overflow: hidden"
      :val="code"
      :onval="true"
      icon="/static/logo.png"
      loadMake
      @result="onResult"
    />
    <view style="text-align: center">
      <image
        :src="posterImg.path"
        v-bind:style="'width:' + postersData.width / 3 + 'px;' + 'height:' + postersData.height / 3 + 'px;'"
      />
    </view>
    <cv-form-base ref="refFormBase" style="padding: 0 10px" labelWidth="100">
      <cv-form-item label="邀请码">
        <cv-input-text v-model="code" />
      </cv-form-item>
      <cv-form-item label="二维码大小">
        <cv-input-text v-model="qrcode.width" />
      </cv-form-item>
      <cv-form-item label="二维码左边距">
        <cv-input-text v-model="qrcode.left" />
      </cv-form-item>
      <cv-form-item label="二维码上边距">
        <cv-input-text v-model="qrcode.top" />
      </cv-form-item>
    </cv-form-base>
    <cv-btn-base @click="initPostersConfig">生成</cv-btn-base>
  </view>
</template>
<script>
export default {
  data() {
    return {
      postersData: {},
      posterImg: {},
      code: 'LSKDGHKJH',
      qrcode: { width: 280, top: 965, left: 275 }
    };
  },
  onLoad() {},
  methods: {
    initPostersConfig() {
      const config = {
        clear: true,
        width: 830,
        height: 1435,
        background: '#ffffff',
        views: [
          {
            type: 'image',
            width: 830,
            height: 1435,
            top: 0,
            left: 0,
            // 封面图,测试的时候填上
            url: '/static/images/posters-background.png'
          },
          {
            type: 'text',
            width: 400,
            height: 50,
            left: 345,
            top: 1348,
            fontSize: 24,
            lineHeight: 40,
            bolder: true,
            breakWord: true,
            content: this.code,
            color: '#000000',
            MaxLineNumber: 2
          },
          {
            type: 'image',
            width: parseInt(this.qrcode.width),
            height: parseInt(this.qrcode.width),
            top: parseInt(this.qrcode.top),
            left: parseInt(this.qrcode.left),
            // 二维码图片路径,测试的时候填上
            url: this.qrcode.url || '/static/goods_list/face.jpg'
          }
        ]
      };
      this.$set(this, 'postersData', config);
      console.log({ ...this.postersData });
    },
    onSuccessCreatePosters(res) {
      console.log(res);
      this.$set(this, 'posterImg', res);
    },
    onPostersError(res) {
      console.log(res);
    },
    onResult(e) {
      this.qrcode.url = e;
      this.initPostersConfig();
    }
  }
};
</script>

属性

属性名类型必填描述
widthNumber画布宽度 (单位:px)
heightNumber画布高度(单位:px)
backgroundString画布背景颜色
radiusNumber圆角
viewsArray海报的所有元素

views.type='text'

字段类型必填描述
typeString类型,值:text
widthNumber(单位:px)宽度
heightNumber(单位:px)高度
leftNumber(单位:px)距离海报左边距
topNumber(单位:px)距离海报上边距
fontSizeNumber(单位:px)字体大小,默认:16
lineHeightNumber(单位:px)行高,默认:20
breakWordBoolean是否自动换行,默认:false
bolderBoolean是否加粗,默认:false
textAlignString对齐方式,可选值:left、center、right,默认:left
colorString字体颜色
contentString文本内容
MaxLineNumberNumber显示多少行,超出省略

views.type='rect'

字段类型必填描述
typeString类型,值:rect
widthNumber(单位:px)宽度
heightNumber(单位:px)高度
leftNumber(单位:px)距离海报左边距
topNumber(单位:px)距离海报上边距
radiusNumber(单位:px)圆角半径,如果radius === width / 2,则是个圆,和CSS一样
backgroundString填充背景色

views.type='image'

字段类型必填描述
typeString类型,值:image
tailorNumber(单位:px)裁剪方式,可选值:center
radiusNumber(单位:px)圆角半径,如果radius === width / 2,则是个圆,和CSS一样
widthNumber(单位:px)宽度
heightNumber(单位:px)高度
leftNumber(单位:px)距离海报左边距
topNumber(单位:px)距离海报上边距
urlString图片路径

事件

事件名返回值说明
successsuccessData海报生成成功时触发
error海报生成失败错误信息海报生成失败时触发
successData
json
{
    height: 394,
    path: "",//H5时,路径为base64
    width: 700,
}

感谢

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发