2020-08-13 08:12:57 +00:00
|
|
|
|
<template>
|
2021-01-19 02:16:45 +00:00
|
|
|
|
<view style="height: 100%;">
|
2020-08-13 08:12:57 +00:00
|
|
|
|
<view class='distribution-posters'>
|
2021-06-11 09:41:16 +00:00
|
|
|
|
<swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :circular="circular" :interval="interval"
|
|
|
|
|
:duration="duration" @change="bindchange" previous-margin="40px" next-margin="40px">
|
2020-08-13 08:12:57 +00:00
|
|
|
|
<block v-for="(item,index) in spreadList" :key="index">
|
|
|
|
|
<swiper-item>
|
2021-06-11 09:41:16 +00:00
|
|
|
|
<image :src="item.pic" class="slide-image" :class="swiperIndex == index ? 'active' : 'quiet'"
|
|
|
|
|
mode='aspectFill' />
|
2020-08-13 08:12:57 +00:00
|
|
|
|
</swiper-item>
|
|
|
|
|
</block>
|
|
|
|
|
</swiper>
|
|
|
|
|
<!-- #ifdef MP -->
|
|
|
|
|
<view class='keep bg-color' @click='savePosterPath'>保存海报</view>
|
|
|
|
|
<!-- #endif -->
|
|
|
|
|
<!-- #ifndef MP -->
|
|
|
|
|
<div class="preserve acea-row row-center-wrapper">
|
|
|
|
|
<div class="line"></div>
|
|
|
|
|
<div class="tip">长按保存图片</div>
|
|
|
|
|
<div class="line"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- #endif -->
|
|
|
|
|
</view>
|
|
|
|
|
<!-- #ifdef MP -->
|
2021-06-11 09:41:16 +00:00
|
|
|
|
<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
|
2020-08-13 08:12:57 +00:00
|
|
|
|
<!-- #endif -->
|
2021-01-19 02:16:45 +00:00
|
|
|
|
<view class="canvas" v-if="canvasStatus">
|
2020-08-13 08:12:57 +00:00
|
|
|
|
<canvas style="width:750px;height:1190px;" canvas-id="canvasOne"></canvas>
|
2021-06-11 09:41:16 +00:00
|
|
|
|
<canvas canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}" />
|
2020-08-13 08:12:57 +00:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
import uQRCode from '@/js_sdk/Sansnn-uQRCode/uqrcode.js'
|
|
|
|
|
// #endif
|
|
|
|
|
import {
|
|
|
|
|
getUserInfo,
|
|
|
|
|
spreadBanner
|
|
|
|
|
} from '@/api/user.js';
|
|
|
|
|
import {
|
|
|
|
|
toLogin
|
|
|
|
|
} from '@/libs/login.js';
|
|
|
|
|
import {
|
|
|
|
|
mapGetters
|
|
|
|
|
} from "vuex";
|
|
|
|
|
// #ifdef MP
|
2021-06-11 09:41:16 +00:00
|
|
|
|
import {
|
|
|
|
|
base64src
|
|
|
|
|
} from '@/utils/base64src.js'
|
2020-08-13 08:12:57 +00:00
|
|
|
|
import authorize from '@/components/Authorize';
|
|
|
|
|
import {
|
|
|
|
|
getQrcode
|
|
|
|
|
} from '@/api/api.js';
|
|
|
|
|
// #endif
|
|
|
|
|
import home from '@/components/home';
|
|
|
|
|
import {
|
|
|
|
|
imageBase64
|
|
|
|
|
} from "@/api/public";
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
// #ifdef MP
|
|
|
|
|
authorize,
|
|
|
|
|
// #endif
|
|
|
|
|
home
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
imgUrls: [],
|
|
|
|
|
indicatorDots: false,
|
|
|
|
|
circular: false,
|
|
|
|
|
autoplay: false,
|
|
|
|
|
interval: 3000,
|
|
|
|
|
duration: 500,
|
|
|
|
|
swiperIndex: 0,
|
|
|
|
|
spreadList: [],
|
|
|
|
|
poster: '',
|
|
|
|
|
isAuto: false, //没有授权的不会自动授权
|
|
|
|
|
isShowAuth: false, //是否隐藏授权
|
|
|
|
|
qrcodeSize: 1000,
|
|
|
|
|
PromotionCode: '',
|
2020-12-23 07:56:45 +00:00
|
|
|
|
base64List: [],
|
2021-01-19 02:16:45 +00:00
|
|
|
|
canvasStatus: true //海报绘图标签
|
2020-08-13 08:12:57 +00:00
|
|
|
|
};
|
|
|
|
|
},
|
2021-06-11 09:41:16 +00:00
|
|
|
|
computed: mapGetters(['isLogin', 'uid', 'userInfo']),
|
2021-03-19 10:26:43 +00:00
|
|
|
|
watch: {
|
|
|
|
|
isLogin: {
|
|
|
|
|
handler: function(newV, oldV) {
|
|
|
|
|
if (newV) {
|
|
|
|
|
this.userSpreadBannerList();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deep: true
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-08-13 08:12:57 +00:00
|
|
|
|
onLoad() {
|
|
|
|
|
if (this.isLogin) {
|
|
|
|
|
this.userSpreadBannerList();
|
|
|
|
|
} else {
|
|
|
|
|
toLogin();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
// #ifdef MP
|
|
|
|
|
onShareAppMessage: function() {
|
|
|
|
|
return {
|
|
|
|
|
title: this.userInfo.nickname + '-分销海报',
|
|
|
|
|
imageUrl: this.spreadList[0].pic,
|
2021-06-11 09:41:16 +00:00
|
|
|
|
path: '/pages/index/index?spid=' + this.uid,
|
2020-08-13 08:12:57 +00:00
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
// #endif
|
2021-06-11 09:41:16 +00:00
|
|
|
|
onReady() {},
|
2020-08-13 08:12:57 +00:00
|
|
|
|
methods: {
|
2020-12-23 07:56:45 +00:00
|
|
|
|
userSpreadBannerList: function() {
|
|
|
|
|
let that = this;
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: '获取中',
|
|
|
|
|
mask: true,
|
|
|
|
|
})
|
|
|
|
|
spreadBanner({
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 5
|
|
|
|
|
}).then(res => {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
that.$set(that, 'spreadList', res.data);
|
|
|
|
|
that.getImageBase64(res.data);
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-06-11 09:41:16 +00:00
|
|
|
|
getImageBase64: function(images) {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: '海报生成中',
|
|
|
|
|
mask: true
|
|
|
|
|
});
|
|
|
|
|
let that = this;
|
2020-12-23 07:56:45 +00:00
|
|
|
|
// #ifdef H5
|
2021-06-11 09:41:16 +00:00
|
|
|
|
let spreadList = []
|
|
|
|
|
// 生成一个Promise对象的数组
|
|
|
|
|
images.forEach(item => {
|
|
|
|
|
const oneApi = imageBase64({
|
|
|
|
|
url: item.pic
|
|
|
|
|
}).then(res => {
|
|
|
|
|
return res.data.code;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
})
|
2021-06-11 09:41:16 +00:00
|
|
|
|
spreadList.push(oneApi)
|
|
|
|
|
})
|
|
|
|
|
Promise.all(spreadList).then(result => {
|
|
|
|
|
that.$set(that, 'base64List', result);
|
|
|
|
|
that.make();
|
|
|
|
|
that.setShareInfoStatus();
|
2020-08-13 08:12:57 +00:00
|
|
|
|
})
|
2020-12-23 07:56:45 +00:00
|
|
|
|
// #endif
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-12-23 07:56:45 +00:00
|
|
|
|
// #ifdef MP
|
2021-06-11 09:41:16 +00:00
|
|
|
|
that.base64List = images.map(item => {
|
2020-12-23 07:56:45 +00:00
|
|
|
|
return item.pic
|
|
|
|
|
});
|
|
|
|
|
// #endif
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
// #ifdef MP
|
|
|
|
|
that.getQrcode();
|
|
|
|
|
// #endif
|
2020-08-13 08:12:57 +00:00
|
|
|
|
},
|
|
|
|
|
// 小程序二维码
|
2021-06-11 09:41:16 +00:00
|
|
|
|
getQrcode() {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
let that = this;
|
|
|
|
|
let data = {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
pid: that.uid,
|
2020-12-23 07:56:45 +00:00
|
|
|
|
path: 'pages/index/index'
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
2020-12-23 07:56:45 +00:00
|
|
|
|
let arrImagesUrl = "";
|
|
|
|
|
uni.downloadFile({
|
2021-06-11 09:41:16 +00:00
|
|
|
|
url: this.base64List[0],
|
2020-12-23 07:56:45 +00:00
|
|
|
|
success: (res) => {
|
|
|
|
|
arrImagesUrl = res.tempFilePath;
|
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
});
|
|
|
|
|
getQrcode(data).then(res => {
|
2020-12-23 07:56:45 +00:00
|
|
|
|
base64src(res.data.code, res => {
|
|
|
|
|
that.PromotionCode = res;
|
|
|
|
|
});
|
|
|
|
|
setTimeout(() => {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
that.PosterCanvas(arrImagesUrl, that.PromotionCode, that.userInfo.nickname, 0);
|
2021-01-19 02:16:45 +00:00
|
|
|
|
}, 300);
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: err
|
|
|
|
|
});
|
|
|
|
|
that.$set(that, 'canvasStatus', false);
|
|
|
|
|
});
|
2020-08-13 08:12:57 +00:00
|
|
|
|
},
|
|
|
|
|
// 生成二维码;
|
|
|
|
|
make() {
|
|
|
|
|
let that = this;
|
2021-06-11 09:41:16 +00:00
|
|
|
|
let href = '';
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
href = window.location.href.split('/pages')[0];
|
|
|
|
|
// #endif
|
2020-08-13 08:12:57 +00:00
|
|
|
|
uQRCode.make({
|
|
|
|
|
canvasId: 'qrcode',
|
2021-06-11 09:41:16 +00:00
|
|
|
|
text: href + '/pages/index/index?spread=' + that.uid,
|
2020-08-13 08:12:57 +00:00
|
|
|
|
size: this.qrcodeSize,
|
|
|
|
|
margin: 10,
|
|
|
|
|
success: res => {
|
|
|
|
|
that.PromotionCode = res;
|
2021-01-19 02:16:45 +00:00
|
|
|
|
setTimeout(() => {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
that.PosterCanvas(this.base64List[0], that.PromotionCode, that.userInfo
|
|
|
|
|
.nickname, 0);
|
2021-01-19 02:16:45 +00:00
|
|
|
|
}, 300);
|
|
|
|
|
},
|
2021-06-11 09:41:16 +00:00
|
|
|
|
complete: (res) => {},
|
2020-08-13 08:12:57 +00:00
|
|
|
|
fail: res => {
|
2021-01-19 02:16:45 +00:00
|
|
|
|
uni.hideLoading();
|
2020-08-13 08:12:57 +00:00
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: '海报二维码生成失败!'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2021-06-11 09:41:16 +00:00
|
|
|
|
PosterCanvas: function(arrImages, code, nickname, index) {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
let context = uni.createCanvasContext('canvasOne')
|
|
|
|
|
context.clearRect(0, 0, 0, 0);
|
|
|
|
|
let that = this;
|
|
|
|
|
uni.getImageInfo({
|
|
|
|
|
src: arrImages,
|
2020-12-23 07:56:45 +00:00
|
|
|
|
success: function(res) {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
context.drawImage(arrImages, 0, 0, 750, 1190);
|
|
|
|
|
context.save();
|
|
|
|
|
context.drawImage(code, 110, 925, 140, 140);
|
|
|
|
|
context.restore();
|
|
|
|
|
context.setFontSize(28);
|
|
|
|
|
context.fillText(nickname, 270, 980);
|
|
|
|
|
context.fillText('邀请您加入', 270, 1020);
|
2020-12-23 07:56:45 +00:00
|
|
|
|
setTimeout(() => {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
context.draw(true, function() {
|
2020-12-23 07:56:45 +00:00
|
|
|
|
uni.canvasToTempFilePath({
|
2021-06-11 09:41:16 +00:00
|
|
|
|
destWidth: 750,
|
|
|
|
|
destHeight: 1190,
|
|
|
|
|
canvasId: 'canvasOne',
|
|
|
|
|
fileType: 'jpg',
|
|
|
|
|
success: function(res) {
|
|
|
|
|
// 在H5平台下,tempFilePath 为 base64
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
that.spreadList[index].pic = res
|
|
|
|
|
.tempFilePath;
|
|
|
|
|
that.$set(that, 'poster', res
|
|
|
|
|
.tempFilePath);
|
|
|
|
|
that.$set(that, 'canvasStatus', false);
|
|
|
|
|
}
|
2020-12-23 07:56:45 +00:00
|
|
|
|
})
|
2021-06-11 09:41:16 +00:00
|
|
|
|
})
|
2020-12-23 07:56:45 +00:00
|
|
|
|
}, 100);
|
2020-08-13 08:12:57 +00:00
|
|
|
|
},
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: '无法获取图片信息'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onLoadFun: function(e) {
|
|
|
|
|
this.$set(this, 'userInfo', e);
|
|
|
|
|
this.userSpreadBannerList();
|
|
|
|
|
},
|
|
|
|
|
// 授权关闭
|
|
|
|
|
authColse: function(e) {
|
|
|
|
|
this.isShowAuth = e
|
|
|
|
|
},
|
|
|
|
|
bindchange(e) {
|
|
|
|
|
let base64List = this.base64List;
|
|
|
|
|
let index = e.detail.current;
|
|
|
|
|
this.swiperIndex = index;
|
2020-12-23 07:56:45 +00:00
|
|
|
|
let arrImagesUrl = "";
|
|
|
|
|
uni.downloadFile({
|
2021-06-11 09:41:16 +00:00
|
|
|
|
url: base64List[index],
|
2020-12-23 07:56:45 +00:00
|
|
|
|
success: (res) => {
|
|
|
|
|
arrImagesUrl = res.tempFilePath;
|
|
|
|
|
setTimeout(() => {
|
2021-01-19 02:16:45 +00:00
|
|
|
|
this.$set(this, 'canvasStatus', true);
|
2021-06-11 09:41:16 +00:00
|
|
|
|
this.PosterCanvas(arrImagesUrl, this.PromotionCode, this.userInfo.nickname,
|
|
|
|
|
index);
|
2021-01-19 02:16:45 +00:00
|
|
|
|
}, 300);
|
2020-12-23 07:56:45 +00:00
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
});
|
2020-08-13 08:12:57 +00:00
|
|
|
|
},
|
|
|
|
|
// 点击保存海报
|
|
|
|
|
savePosterPath: function() {
|
|
|
|
|
let that = this;
|
2021-01-19 02:16:45 +00:00
|
|
|
|
uni.getSetting({
|
|
|
|
|
success(res) {
|
|
|
|
|
if (!res.authSetting['scope.writePhotosAlbum']) {
|
|
|
|
|
uni.authorize({
|
|
|
|
|
scope: 'scope.writePhotosAlbum',
|
|
|
|
|
success() {
|
|
|
|
|
uni.saveImageToPhotosAlbum({
|
|
|
|
|
filePath: that.poster,
|
|
|
|
|
success: function(res) {
|
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: '保存成功',
|
|
|
|
|
icon: 'success'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fail: function(res) {
|
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: '保存失败'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
2021-01-19 02:16:45 +00:00
|
|
|
|
});
|
2020-08-13 08:12:57 +00:00
|
|
|
|
} else {
|
2021-01-19 02:16:45 +00:00
|
|
|
|
uni.saveImageToPhotosAlbum({
|
|
|
|
|
filePath: that.poster,
|
|
|
|
|
success: function(res) {
|
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: '保存成功',
|
|
|
|
|
icon: 'success'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fail: function(res) {
|
|
|
|
|
that.$util.Tips({
|
|
|
|
|
title: '保存失败'
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-08-13 08:12:57 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-19 02:16:45 +00:00
|
|
|
|
});
|
2020-08-13 08:12:57 +00:00
|
|
|
|
},
|
|
|
|
|
setShareInfoStatus: function() {
|
|
|
|
|
if (this.$wechat.isWeixin()) {
|
|
|
|
|
let configAppMessage = {
|
|
|
|
|
desc: '分销海报',
|
|
|
|
|
title: this.userInfo.nickname + '-分销海报',
|
2021-06-11 09:41:16 +00:00
|
|
|
|
link: '/pages/index/index?spread=' + this.uid,
|
2020-08-13 08:12:57 +00:00
|
|
|
|
imgUrl: this.spreadList[0].pic
|
|
|
|
|
};
|
2021-06-11 09:41:16 +00:00
|
|
|
|
this.$wechat.wechatEvevt(["updateAppMessageShareData", "updateTimelineShareData"],
|
|
|
|
|
configAppMessage)
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-06-11 09:41:16 +00:00
|
|
|
|
<style lang="scss" scoped>
|
2020-08-13 08:12:57 +00:00
|
|
|
|
page {
|
|
|
|
|
background-color: #a3a3a3 !important;
|
2021-01-19 02:16:45 +00:00
|
|
|
|
height: 100% !important;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
.canvas {
|
2021-01-19 02:16:45 +00:00
|
|
|
|
position: relative;
|
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
.distribution-posters {
|
2021-01-19 02:16:45 +00:00
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
.distribution-posters swiper {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 1000rpx;
|
|
|
|
|
position: relative;
|
|
|
|
|
margin-top: 40rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .slide-image {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
border-radius: 15rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .slide-image.active {
|
|
|
|
|
transform: none;
|
|
|
|
|
transition: all 0.2s ease-in 0s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .slide-image.quiet {
|
|
|
|
|
transform: scale(0.8333333);
|
|
|
|
|
transition: all 0.2s ease-in 0s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .keep {
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: #fff;
|
|
|
|
|
width: 600rpx;
|
|
|
|
|
height: 80rpx;
|
|
|
|
|
border-radius: 50rpx;
|
|
|
|
|
text-align: center;
|
|
|
|
|
line-height: 80rpx;
|
|
|
|
|
margin: 38rpx auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .preserve {
|
|
|
|
|
color: #fff;
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-top: 38rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .preserve .line {
|
|
|
|
|
width: 100rpx;
|
|
|
|
|
height: 1px;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.distribution-posters .preserve .tip {
|
|
|
|
|
margin: 0 30rpx;
|
|
|
|
|
}
|
|
|
|
|
</style>
|