web
20 小时以前 49fa0d82a40345342966e810b44429aec0480ef3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
    <view class="demo-block">
        <text class="demo-block__title-text ultra">QRCode</text>
        <text class="demo-block__desc-text">能够将文本转换生成二维码的组件,支持自定义配色和 Logo 配置</text>    
        <view class="demo-block__body">
            <view class="demo-block card">
                <text class="demo-block__title-text large">基础</text>
                <view class="demo-block__body">
                    <l-qrcode value="https://limeui.qcoon.cn" size="300rpx"></l-qrcode>
                </view>    
            </view>    
            
            <view class="demo-block card">
                <text class="demo-block__title-text large">icon</text>
                <view class="demo-block__body">
                    <image v-if="image !=''" :src="image" style="width: 300rpx;" mode="widthFix"></image>
                    <view style="flex-direction: row; justify-content: space-between">
                        <l-qrcode ref="qrcodeRef" value="https://limeui.qcoon.cn" size="300rpx" icon="https://img10.360buyimg.com/img/jfs/t1/182127/16/37474/11761/64659c31F0cd84976/21f25b952f03a49a.jpg" iconSize="70rpx"></l-qrcode>
                        <l-qrcode :useCanvasToTempFilePath="true" @success="success" value="https://limeui.qcoon.cn" size="300rpx" icon="https://img10.360buyimg.com/img/jfs/t1/182127/16/37474/11761/64659c31F0cd84976/21f25b952f03a49a.jpg" iconSize="70rpx"></l-qrcode>
                    </view>
                    <button type="primary" style="margin-top: 20rpx;" @click="onClick">生成图片</button>
                </view>    
            </view>
            
            <view class="demo-block card">
                <text class="demo-block__title-text large">颜色</text>
                <view class="demo-block__body">
                    <view style="flex-direction: row; justify-content: space-between">
                        <l-qrcode value="https://limeui.qcoon.cn" size="300rpx" color="rgb(82,196,26)"></l-qrcode>
                        <l-qrcode value="https://limeui.qcoon.cn" size="300rpx" color="rgb(22,119,255)" bgColor="rgb(245,245,245)"></l-qrcode>
                    </view>    
                </view>    
            </view>
            
            <view class="demo-block card">
                <text class="demo-block__title-text large">纠错比例</text>
                <view class="demo-block__body">
                    <l-qrcode value="img10.360buyimg.com/img/jfs/t1/182127/16/37474/11761/64659c31F0cd84976/21f25b952f03a49a.jpg" size="300rpx" :errorLevel="levels[index]"></l-qrcode>
                    <button type="primary" style="margin-top: 20rpx;" @click="onToggle">切换纠错等级:{{levels[index]}}</button>
                </view>    
            </view>
            
            <view class="demo-block card">
                <text class="demo-block__title-text large">动态</text>
                <view class="demo-block__body">
                    <l-qrcode :value="text" size="300rpx" :marginSize="1" bgColor="white"></l-qrcode>
                    <button type="primary" style="margin-top: 20rpx;"  @click="update">更新</button>
                </view>    
            </view>
            
        </view>    
    </view>
    
</template>
<script>
    // import {ComponentPublicInstance} from 'vue'
    export default {
        name: 'lime-qrcode',
        data() {
            return {
                text: 'qcoon.com.cn',
                image: '',
                index: 0,
                levels: ['L', 'M', 'Q', 'H']
            }
        },
        methods:{ 
            success(src: string) {
                console.log(`src`, src)
            },
            update() {
                this.text =  `qcoon.cn?v=${Math.random()}`
            },
            onToggle() {
                this.index++
                this.index = this.index % this.levels.length
            },
            onClick() {
                const el:LQrcodeComponentPublicInstance = this.$refs['qrcodeRef'] as LQrcodeComponentPublicInstance 
                el.canvasToTempFilePath({
                    success:(res: TakeSnapshotSuccess)=>{
                        this.image = res.tempFilePath
                    }
                })
            }
        },
        mounted() {
            
        }
    }
</script>
<style lang="scss">
    
    .demo-block {
        margin: 32px 10px 0;
        overflow: visible;
        &.card{
            background-color: white;
            padding: 30rpx;
            margin-bottom: 20rpx;
        }
        &__title {
            margin: 0;
            margin-top: 8px;
            &-text {
                color: rgba(0, 0, 0, 0.6);
                font-weight: 400;
                font-size: 14px;
                line-height: 16px;
                
                &.large {
                    color: rgba(0, 0, 0, 0.9);
                    font-size: 18px;
                    font-weight: 700;
                    line-height: 26px;
                }
                &.ultra {
                    color: rgba(0, 0, 0, 0.9);
                    font-size: 24px;
                    font-weight: 700;
                    line-height: 32px;
                }
            }
        }
        &__desc-text {
            color: rgba(0, 0, 0, 0.6);
            margin: 8px 16px 0 0;
            font-size: 14px;
            line-height: 22px;
        }
        &__body {
            margin: 16px 0;
            overflow: visible;
            .demo-block {
                // margin-top: 0px;
                margin: 0;
            }
        }
    }
</style>