2020-06-19 vue html2canvas

import html2canvas from "html2canvas";

 <div class="tabs">

                <div class="tab">

                    <a @click="$router.back(-1)" class="pageback"></a>

                </div>

                <a class="tab" v-for="(tab,index) in tabs" @click="cur=index,goAssignBlock('block'+ index,150)"

                    :class="{active:cur==index}" :key="tab.type">

                    {{tab.type}}

                </a>

                <div class="tab" @click="openPoster">

                    <span class="icon share-icon"></span>

                </div>

            </div>

            <section class="share-poster" @click.stop="closePoster" style="display: none;">

                <div class="share-poster-wrapper">

                    <div class="share-poster-top-tip">长按保存图片</div>

                    <div id="share-poster-main" @click.stop="() => void 0">

                        <div class="share-poster-content">

                            <div class="share-poster-top">

                                <img :src="productList.Thumb" class="share-poster-top-img" @load="loadedThumb" />

                            </div>

                            <div class="share-poster-bottom">

                                <div class="share-poster-bottom-title" id="poster_title">

                                    <div style="font-size: 15px;">{{goodinfo.Title}}</div>

                                </div>

                                <div class="share-poster-bottom-price-wrapper">

                                    <span class="share-poster-bottom-price">

                                        <span v-for="(item,index) in priceDatalist"

                                            v-show="changeLeftBackground == index">

                                            <span v-if='item.payMethod=="2" ' style="font-size: 13px;">

                                                <span>{{item.lxb}}莲香币</span>

                                                <span>+</span>

                                                <span>¥{{item.cash}}</span>

                                            </span>aa

                                            <span v-else  style="font-size: 13px;">

                                                <span>¥{{item.cash}}</span>

                                            </span>

                                        </span>

                                    </span>

                                    <span v-if="goodinfo.IsAdvance == 1" class="share-poster-bottom-advance">订金:<span

                                            class="price">¥{{goodinfo.AdvanceResp.EarnestMoney}}元</span></span>

                                </div>

                                <div class="share-poster-bottom-code">

                                    <span class="share-poster-bottom-qrcode"></span>

                                    <span class="share-poster-code-tip">长按可识别图中的二维码</span>

                                    <span class="share-poster-code-logo">

                                        <img src="/images/lxd_logo.png" />

                                    </span>

                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>


    // 分享图片

            openPoster() {

                this.getShareQrcode();

            },

            // 关闭分享

            closePoster() {

                $('.share-poster').hide();

            },

            // 获取分享二维码

            getShareQrcode() {

                const _this = this;

                if (!this.loadedThumbStatus) {

                    return

                }

                let productID = this.productList.ID;

                if ($('.proPrice').html().length <= 0) return;

                // 判断用户是否登录

                if (!Boolean(getCookie('Id'))) {

                    Toast('您还未登录,跳转登录中...');

                    window.location.href = '/loginRegister/login.aspx?ReturnUrl=' + Base64.encode(window.location.href);

                    return;

                }

                $('.share-poster').show();

                if ($('#share-poster-img').length > 0) return;

                $(window).scrollTop(0);

                $('body').css('overflow', 'scroll');

                checkOverflow();

                _this.toastLoading = Toast.loading({

                    duration: 0, // 持续展示 toast

                    forbidClick: true,

                    message: '图片合成中...',

                });

                axios.get("/my.ashx", {

                    params: {

                        type: 'ProductShareUser',

                        pid: productID,

                    },

                    responseType: 'blob'

                }).then(data => {

                    if (data.status === 200) {

                        // 返回200

                        var blob = data.data;

                        var reader = new FileReader();

                        reader.readAsDataURL(blob);    // 转换为base64

                        reader.onload = function () {

                            var oImg = new Image();

                            oImg.src = this.result;

                            oImg.style = "width:1.12rem;height:1.12rem;pointer-events:none;"

                            $('.share-poster-bottom-qrcode').append(oImg);

                            setTimeout(() => {

                                _this.toastLoading.clear();

                                _this.mixPoster();

                            }, 2000)

                        }

                    }

                }).catch(err => {

                    console.log(err)

                })

            },

            loadedThumb() {

                this.loadedThumbStatus = true;

            },

            mixPoster() {

                html2canvas(document.querySelector("#share-poster-main"), {

                    useCORS: true,

                    scale: 2,

                    dpi: 192,

                }).then(function (canvas) {

                    document.querySelector("#share-poster-main").appendChild(canvas);

                    // 把画布内容放到img里面

                    $('#share-poster-img').css({

                        width: '100%',

                        height: 'auto',

                    });

                    // 插入img

                    var img = document.createElement('img');

                    img.id = 'share-poster-img';

                    img.width = $('#share-poster-main').width();

                    img.src = $('canvas')[0].toDataURL();

                    $('#share-poster-main').append(img);

                    $('.share-poster-content').remove();

                    $('canvas').remove();

                });

            },


//定位

        <section class="skip-home" @click="shipHome">

            <img src="../../../../src/assets/skiphome.png" alt="">

            <span>首页</span>

        </section>

//定位样式

 .skip-home {

        width: 1.18rem;

        height: 1.18rem;

        background-color: rgba(206, 61, 62, .9);

        border-radius: 50%;

        position: fixed;

        bottom: 1.14rem;

        right: .24rem;

        z-index: 100;

        display: flex;

        flex-direction: column;

        align-items: center;

        justify-content: center;

        box-shadow: 0px 0px 10px 2px rgba(83, 83, 83, 0.68);

    }

    .skip-home img {

        width: .44rem;

        height: .44rem;

        margin-bottom: 0.08rem;

    }

    .skip-home span {

        color: #fff;

        font-size: .22rem;

    }



    /* ===分享海报样式=== */

    .share-poster {

        /* display: none; */

        position: fixed;

        z-index: 500;

        left: 0;

        top: 0;

        width: 100%;

        height: 100%;

        z-index: 1000;

        background-color: rgba(0, 0, 0, .75);

        -webkit-touch-callout: none;

        -moz-touch-callout: none;

        -ms-touch-callout: none;

        touch-callout: none;

        -webkit-user-select: none;

    }

    .share-poster .share-poster-wrapper {

        position: absolute;

        left: 50%;

        top: 50%;

        transform: translate(-50%, -50%);

    }

    #share-poster-main {

        width: 84vw;

        background-color: #fff;

        overflow: hidden;

        border-radius: .12rem;

        position: relative;

    }

    .share-poster-content-bg {

        position: absolute;

        width: 100%;

        height: 100%;

        background-color: transparent;

        pointer-events: none;

        -webkit-touch-callout: none;

        -moz-touch-callout: none;

        -ms-touch-callout: none;

        touch-callout: none;

        -webkit-user-select: none;

    }

    .share-poster-content-bg .share-poster-content-bg-tip {

        width: 2rem;

        height: .5rem;

        display: block;

        position: absolute;

        z-index: 100;

        background-color: rgba(0, 0, 0, 0.5);

        border-radius: 2px;

        color: #fff;

        font-size: .24rem;

        left: 50%;

        top: 50%;

        transform: translate(-50%, -50%);

        line-height: .5rem;

        text-align: center;

    }

    .share-poster .share-poster-top-tip {

        color: #fff;

        font-size: .36rem;

        margin-bottom: 15px;

        text-align: center;

    }

    .share-poster .share-poster-top {

        position: relative;

        height: 76vw;

        overflow: hidden;

    }

    .share-poster .share-poster-top-img {

        width: 100%;

        height: auto;

        display: block;

        pointer-events: none;

    }

    .share-poster .share-poster-bottom {

        display: flex;

        padding: .3rem .24rem .4rem .24rem;

        flex-direction: column;

    }

    .share-poster .share-poster-bottom-info {

        display: flex;

        align-items: center;

        margin-bottom: .3rem;

    }

    .share-poster .share-poster-bottom-title {

        width: 100%;

        color: #666666;

        font-size: 15px;

        height: .88rem;

        text-align: left;

        word-break: break-all;

        /* margin-bottom: .3rem; */

        overflow-wrap: break-word;

    }

    .share-poster .share-poster-bottom-title>div {

        display: inline-block;

        line-height: .44rem;

    }

    .share-poster .share-poster-bottom-price-wrapper {

        color: #A40710;

        font-size: .24rem;

        margin-bottom: .3rem;

        text-align: left;

    }

    .share-poster .share-poster-bottom-advance {

        font-size: .22rem;

        margin-left: .18rem;

    }

    .share-poster .share-poster-bottom-code {

        display: flex;

        align-items: center;

    }

    .share-poster .share-poster-bottom-qrcode {

        display: inline-block;

        width: 1.12rem;

        height: 1.12rem;

        flex: none;

    }

    .share-poster .share-poster-bottom-qrcode img {

        width: 100%;

        height: 100%;

        pointer-events: none;

    }

    .share-poster .share-poster-code-tip {

        color: #999999;

        font-size: .2rem;

        flex: 1;

        text-align: center;

    }

    .share-poster .share-poster-code-logo img {

        width: 1.04rem;

        height: 1.09rem;

        pointer-events: none;

    }

    .share-poster .mix-share-poster-img {

        width: 100%;

        height: auto;

        display: block;

    }



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,271评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,275评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,151评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,550评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,553评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,559评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,924评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,580评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,826评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,578评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,661评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,363评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,940评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,926评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,156评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,872评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,391评论 2 342