123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <template>
- <view class="content">
-
-
-
-
-
-
-
-
-
- <image :src="ctxSrc" mode="widthFix" class="tki-qrcode-canvas"></image>
-
-
- {{ loading ? '点击生成图片' : '长按二维码下载' }}
-
- </view>
- </template>
- <script>
- import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
- import { spreadBanner } from '@/api/shareQrCode.js';
- import { getUserInfo } from '@/api/login.js';
- import { weixindata, shareData, loadShareData } from '@/utils/wxAuthorized.js';
- import { mapState } from 'vuex';
- import { share } from '@/api/wx';
- export default {
- computed: {
- ...mapState(['baseURL', 'urlFile']),
- ...mapState('user', ['userInfo'])
- },
-
- data() {
- return {
- cid: 'tki-qrcode-canvas',
- size: 180,
- unit: 'upx',
-
- val: '',
- background: '#ffffff',
- foreground: '#333333',
- pdground: '#333333',
- icon: '',
- iconSize: 40,
- lv: 3,
- onval: false,
- loadMake: false,
- usingComponents: false,
- showLoading: false,
- loadingText: '二维码生成中',
- src: '',
- ratio: 1,
- ctxSrc: '',
- loading: true,
- canHeight: '',
- canWeidth: '',
- login: false
- };
- },
- onShow() {
- let obj = this;
- if (!obj.login) {
-
- getUserInfo()
- .then(e => {
- obj.login = true;
- uni.showLoading({
- title: '邀请图生成中',
- mask: true
- });
- obj.loadCodeList();
- })
- .catch(e => {
- console.log(e);
- });
- }
- },
- onReady() {
- let obj = this;
- let query = uni.createSelectorQuery();
-
- query
- .select('.content')
- .fields(
- {
- size: true
- },
- e => {
-
- this.ratio = e.width / 750;
- }
- )
- .exec();
-
- query
- .select('#qrShareBox')
- .fields(
- {
- size: true
- },
- e => {
- obj.canHeight = e.height;
- obj.canWeidth = e.width;
- }
- )
- .exec({});
- },
- methods: {
-
- setShare() {
- let obj = this;
-
-
- obj.loadSareData().then(e => {
- weixindata({
- link: obj.ctxSrc,
- imgUrl:obj.baseURL+obj.urlFile+'/img/logo.jpg',
- desc:'欢迎加入满园春',
- title: '满园春线上商城',
- success: function() {},
- fail: function() {}
- });
- });
-
- },
- loadSareData() {
- if (!shareData) {
- return loadShareData();
- } else {
- return new Promise((resolve, reject) => {
- resolve(shareData);
- });
- }
- },
- loadCodeList() {
- let obj = this;
-
- spreadBanner({
-
- type: 2,
-
-
- type: 1
-
- })
- .then(e => {
- console.log(e);
-
-
- obj.ctxSrc = e.data.wap_poster;
-
-
- uni.hideLoading();
-
- obj.setShare()
- })
- .catch(e => {
- uni.showModal({
- title: '生成失败请刷新页面',
- showCancel: false
- });
- uni.hideLoading();
- });
- },
-
- alertCanv() {
- uni.showModal({
- title: '请先点击生成图片',
- showCancel: false
- });
- },
-
- showImg() {
- uni.showLoading({
- title: '图片生成中',
- mask: true
- });
- let obj = this;
-
- setTimeout(function() {
- uni.canvasToTempFilePath({
- x: 0,
- y: 0,
- width: obj.canWeidth,
- height: obj.canHeight,
- destWidth: obj.canWeidth,
- destHeight: obj.canHeight,
- fileType: 'jpg',
- quality: 1,
- canvasId: 'qrShareBox',
- success: res => {
- uni.hideLoading();
- uni.showModal({
- title: '创建成功,长按二维码下载图片',
- showCancel: false
- });
-
- obj.loading = false;
- obj.ctxSrc = res.tempFilePath;
- },
- fail(e) {
- console.log(e);
- }
- });
- }, 50);
- },
-
- loadImg(src) {
- let obj = this;
- const ctxBg = '/static/img/img14.jpg';
- let context = uni.createCanvasContext('qrShareBox');
- const codeSize = this.size * this.ratio;
- const codeX = ((523 - this.size) * this.ratio) / 2;
- const codeY = 700 * this.ratio;
- const codeBoxColor = '#FFFFFF';
- const codeBoxWidht = 0;
- const codeBoxSize = (codeBoxWidht / 2) * this.ratio;
- const codeBoxX = codeX - codeBoxSize;
- const codeBoxY = codeY - codeBoxSize;
- const codeBoxEnd = codeSize + codeBoxWidht * this.ratio;
-
- const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 30) * this.ratio;
- const fontLeft = codeX - 50 * this.ratio;
- const fontSize = 14;
- const fontText = '邀请人:' + uni.getStorageSync('userInfo').nickname;
-
- context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
-
- context.setFontSize(fontSize);
- context.fillText(fontText, fontLeft, fontTop);
-
- context.beginPath();
- context.setLineJoin('round');
- context.setLineWidth(codeBoxWidht * this.ratio);
- context.setStrokeStyle(codeBoxColor);
- context.strokeRect(codeBoxX, codeBoxY, codeBoxEnd, codeBoxEnd);
- context.stroke();
-
- context.drawImage(src, codeX, codeY, codeSize, codeSize);
-
- context.draw();
- },
-
- creatQrcode() {
- this.$refs.qrcode._makeCode();
- },
-
- saveQrcode() {
- this.$refs.qrcode._saveCode();
- },
-
- qrR(res) {
- this.src = res;
- },
-
- clearQrcode(e) {
- this.$refs.qrcode._clearCode();
- this.val = '';
- }
- }
- };
- </script>
- <style lang="scss">
- .content {
- // padding-top: 30rpx;
- }
- // #qrShareBox {
- // position: absolute;
- // left: -9999rpx;
- // top: -9999rpx;
- // }
- .qrimg {
- position: absolute;
- left: -9999rpx;
- top: -9999rpx;
- }
- .tki-qrcode-canvas {
- // width: 700rpx;
- // height: 1245rpx;
- width: 750rpx;
- // height: 945rpx;
- margin: 0 auto;
- }
- .share-bottom {
- width: 560rpx;
- height: 80rpx;
- color: #ffffff;
- background-color: $base-color;
- margin: 0 auto;
- font-size: $font-lg - 2rpx;
- margin-top: 30rpx;
- border-radius: 99rpx;
- justify-content: center;
- &.action-share-bottom {
- background-color: $color-gray;
- }
- }
- </style>
|