123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <template>
- <view class="main">
- <view class="qrimg">
- <tki-qrcode :cid="cid" ref="qrcode" :val="val" :size="size" :unit="unit" :background="background"
- :foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconSize" :lv="lv" :onval="onval" :showLoading="showLoading"
- :loadMake="loadMake" :usingComponents="usingComponents" @result="qrR" />
- </view>
- <canvas :style="{ width: '600rpx', height: '1066rpx',}" canvas-id="myCanvas" id="myCanvas" class="hb"></canvas>
- <view class="btm-btn" v-if="fina">
- <view class="btn" @click="comfirm">
- <image src="../../static/icon/fzlj.png" mode=""></image>
- <view class="">
- 复制邀请链接
- </view>
- </view>
- <view class="btn" @click="saveShareQrcode">
- <image src="../../static/icon/fxhb.png" mode=""></image>
- <view class="">
- 保存分享海报
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- mapState,
- mapMutations
- } from 'vuex';
- import {
- getUserInfo
- } from '@/api/user.js';
- var that
- export default {
- data() {
- return {
- cid: 'tki-qrcode-canvas',
- size:300,
- unit: 'upx',
-
- val: '',
- background: '#ffffff',
- foreground: '#333333',
- pdground: '#333333',
- icon: '',
- iconSize: 40,
- lv: 3,
- onval: true,
- loadMake: true,
- usingComponents: false,
- showLoading: false,
- erweimasrc: '',
- canvasW: 0,
- canvasH: 0,
- SystemInfo: {},
- goodsImg: {},
- ewmImg: {},
- ewmW: 0,
- title: '',
- canvasShow: true,
- shareQrcodeUrl: '',
- ratio: '',
- fina: false,
- }
- },
- computed: {
- ...mapState(['baseURL', 'urlFile']),
- ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
- },
- onLoad(options) {
- const obj = this;
- if (!this.userInfo.uid) {
- getUserInfo({}).then(e => {
-
- obj.setUserInfo(e.data);
-
- uni.switchTab({
- url: '/pages/index/index'
- });
- });
- } else {
- this.val = this.baseURL + '/index/#/pages/index/index?spread=' + this.userInfo.uid
- }
- },
- methods: {
- uniCopy(content) {
-
-
- uni.setClipboardData({
- data: content,
- success: function() {
- console.log('success');
- return true;
- }
- });
-
-
-
-
- if (!document.queryCommandSupported('copy')) {
-
-
- return false;
- }
- let textarea = document.createElement('textarea');
- textarea.value = content;
- textarea.readOnly = 'readOnly';
- document.body.appendChild(textarea);
- textarea.select();
- textarea.setSelectionRange(0, content.length);
- let result = document.execCommand('copy');
- textarea.remove();
- return result;
-
- },
- comfirm() {
- const result = this.uniCopy(this.val);
- if (result === false) {
- uni.showToast({
- title: '不支持'
- });
- } else {
- uni.showToast({
- title: '复制成功',
- icon: 'none'
- });
- }
- },
- qrR(res) {
- this.erweimasrc = res
- console.log(res, 'erweima');
- this.createPoster()
- },
- async createPoster() {
- let that = this
-
- this.SystemInfo = await this.getSystemInfo();
-
- this.goodsImg = await this.getImageInfo('/static/img/sharebase.jpg');
- this.ewmImg = await this.getImageInfo(this.erweimasrc);
-
- this.ratio = this.SystemInfo.windowWidth / 750;
- this.canvasW = 600 * this.ratio;
- this.canvasH = 1066 * this.ratio;
-
- this.ewmW = 350 * this.ratio;
-
-
- this.ewmW = 250 * this.ratio;
-
- console.log(this.canvasH, 'this.canvasH')
-
-
- if (this.goodsImg.errMsg == 'getImageInfo:ok' && this.ewmImg.errMsg == 'getImageInfo:ok' && this
- .SystemInfo.errMsg == 'getSystemInfo:ok') {
- console.log('ok')
- uni.showToast({
- icon: 'loading',
- mask: true,
- duration: 10000,
- title: '海报绘制中',
- });
- setTimeout(() => {
- var ctx = uni.createCanvasContext('myCanvas', this);
-
- ctx.setFillStyle('#fff');
- ctx.fillRect(0, 0, this.canvasW, this.canvasH)
-
-
- ctx.drawImage(this.goodsImg.path, 0, 0, this.canvasW, this
- .canvasH)
-
- ctx.drawImage(this.ewmImg.path, (this.canvasW / 2 - this.ewmW / 2),this.canvasH - 85*this.ratio - this.ewmW,
- this.ewmW, this.ewmW)
-
-
-
- ctx.drawImage(this.ewmImg.path, (this.canvasW / 2 - this.ewmW / 2),this.canvasH - 170*this.ratio - this.ewmW,
- this.ewmW, this.ewmW)
-
-
-
- ctx.setFontSize(24);
- ctx.setFillStyle('#fff');
- ctx.textAlign = "center";
-
- ctx.fillText('邀请码:' + this.userInfo.uid,this.canvasW/2,this.canvasH -10)
- ctx.draw(false, (ret) => {
- console.log(ret)
- uni.showToast({
- icon: 'none',
- title: '生成成功!',
- });
- that.fina = true
- uni.canvasToTempFilePath({
- canvasId: 'myCanvas',
- quality: 1,
- fileType: 'jpg',
- complete: function(res) {
-
- console.log(res)
- that.canvasShow = false
- that.shareQrcodeUrl = res.tempFilePath
- that.$forceUpdate()
- setTimeout(function() {
- console.log(that.shareQrcodeUrl, that
- .canvasShow)
- }, 2000)
- },
- })
- });
- }, 1500)
- } else {
- console.log('err')
- }
- },
-
- getImageInfo(image) {
- return new Promise((req, rej) => {
- uni.getImageInfo({
- src: image,
- success: function(res) {
- req(res)
- },
- });
- })
- },
-
- getSystemInfo() {
- return new Promise((req, rej) => {
- uni.getSystemInfo({
- success: function(res) {
- req(res)
- }
- });
- })
- },
-
- saveShareQrcode() {
- console.log(this.shareQrcodeUrl)
- uni.saveImageToPhotosAlbum({
- filePath: this.shareQrcodeUrl,
- success: (res) => {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: "成功保存到相册",
- });
- },
- fail: (err) => {
-
- if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
- uni.showModal({
- title: '提示',
- content: '需要您授权保存相册',
- showCancel: false,
- success(res) {
- if (res.confirm) {
- uni.openSetting({
- success(settingdata) {
- if (settingdata.authSetting[
- 'scope.writePhotosAlbum']) {
- uni.showModal({
- title: '提示',
- content: '获取权限成功,再次保存图片即可成功',
- showCancel: false,
- })
- } else {
- uni.showModal({
- title: '提示',
- content: '获取权限失败,无法保存到相册',
- showCancel: false
- })
- }
- }
- })
- }
- }
- })
- }
- },
- })
- }
- }
- }
- </script>
- <style lang="scss">
- .hb {
- margin: auto;
- }
- .qrimg {
- position: absolute;
- left: -9999rpx;
- top: -9999rpx;
- }
- button {
- height: 88upx;
- background-color: #feca00;
- color: #fff;
- border-radius: 44upx;
- text-align: center;
- line-height: 88upx;
- width: 60%;
- margin: 0 auto;
- margin-top: 30upx;
- }
-
- .btm-btn {
- position: fixed;
- bottom: 0;
- width: 750rpx;
- height: 200rpx;
- display: flex;
- background-color: #fff;
- border-radius: 20rpx 20rpx 0 0;
- .btn {
- width: 50%;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- font-size: 26rpx;
-
- image {
- width: 66rpx;
- height: 66rpx;
- margin-bottom: 20rpx;
- }
- }
- }
- </style>
|