cv-draw-qrcode 绘制二维码 ¶
简要 ¶
绘制二维码
示例 ¶
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>
属性 ¶
属性名 | 类型 | 默认值 | 可选值 | 说明 |
---|---|---|---|---|
cid | String | cv-draw-qrcode-canvas | canvasId,页面存在多个条形码组件时需设置不同的ID | |
unit | String | px | upx | 单位 |
show | Boolean | true | 默认使用组件中的image标签显示条形码 | |
val | String | 要生成的内容 | ||
background | String | #ffffff | 背景色 | |
onval | Boolean | false | 监听val值变化自动重新生成条形码 | |
loadMake | Boolean | false | 组件初始化完成后自动生成条形码,val需要有值 | |
foreground | String | #000000 | ||
pdground | String | #000000 | ||
icon | String | |||
iconSize | Number | 40 | ||
size | Number | 200 | ||
lv | Number | 3 | ||
usingComponents | Boolean | true | ||
showLoading | Boolean | true | ||
loadingText | String | '二维码生成中' |
事件 ¶
事件名 | 返回值 | 说明 |
---|---|---|
result | 生成的图片base64或图片临时地址 | 返回条形码路径 注:_clearCode()后返回空 |