123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <template>
- <uni-popup ref="popupRef">
- <view class="share-box">
- <view class="share-status-bar" :style="{'height': `${statusBarHeight}px`}"></view>
- <!-- statusBarHeight -->
- <view class="share-content">
- <shareInvite v-if="shareType === 1">
- <template #qrcode>
- <tki-qrcode ref="qrcodeRef" :size="100" :showLoading="false" :val="qrcodeVal" />
- </template>
- </shareInvite>
- <shareOrder :shareVal="shareVal" v-if="shareType === 2">
- <template #qrcode>
- <tki-qrcode ref="qrcodeRef" :size="100" :showLoading="false" :val="qrcodeVal" />
- </template>
- </shareOrder>
- </view>
- <view class="share-footer">
- <view class="share-list">
- <view class="share-icons">
- <text class="share-icon iconfont" style="color: #00b1ff;"></text>
- <text class="share-text">复制链接</text>
- </view>
- <view class="share-icons">
- <text class="share-icon iconfont" style="color: #029a73;"></text>
- <text class="share-text">微信</text>
- </view>
- <view class="share-icons">
- <text class="share-icon iconfont" style="color: #02d9a2;"></text>
- <text class="share-text">朋友圈</text>
- </view>
- <view class="share-icons">
- <text class="share-icon iconfont" style="color: #1890ff;"></text>
- <text class="share-text">QQ</text>
- </view>
- <view class="share-icons" @click="my_js.onclicks">
- <text class="share-icon iconfont" style="color: #83a0e5"></text>
- <text class="share-text">保存图片</text>
- </view>
- </view>
- <view class="share-cancel" @click.stop="cancelShare">
- 取消
- </view>
- </view>
- </view>
- </uni-popup>
- </template>
- <script>
- import {
- mapGetters
- } from 'vuex'
- import shareInvite from "./share_01.vue"
- import shareOrder from "./share_02.vue"
- export default {
- name: "sharePage",
- components: {
- shareInvite,
- shareOrder
- },
- props: {
- tabBar: {
- type: Boolean,
- default: true
- },
- shareType: {
- type: Number,
- default: 1 // 1:邀请分享 2:订单分享
- },
- },
- data() {
- return {
- shareCode: '',
- shareVal:{}
- };
- },
- computed: {
- ...mapGetters([
- 'statusBarHeight'
- ])
- },
- created() {
- this.shareCode = this.$getStorageSync('shareCode')
- this.qrcodeVal = `${this.$config.shareLink}${this.shareCode}`;
- },
- mounted() {
-
- // this.$refs.popupRef.open()
- // setTimeout(() => {
- // this.$refs.qrcodeRef._makeCode()
- // console.log('$config', this.$refs.qrcodeRef)
- // },3000)
- },
- methods: {
- drawCode() {
- if (this.$refs.qrcodeRef) {
- this.$refs.qrcodeRef._makeCode()
- } else {
- setTimeout(() => {
- this.drawCode()
- }, 100)
- }
- },
- openShare(val) {
- this.shareVal = val
- this.drawCode()
- this.$nextTick(() => {
- this.showTabBar(false)
- this.$refs.popupRef.open()
- })
- },
- cancelShare() {
- this.$refs.popupRef.close()
- this.showTabBar()
- },
- showTabBar(type = true) {
- if (this.tabBar) {
- try {
- if (type) {
- uni.showTabBar();
- } else {
- uni.hideTabBar();
- }
- } catch {}
- }
- },
- saveBase64(imageStr) {
- uni.showLoading({
- title: "保存中",
- })
- try {
- let bitmap = new plus.nativeObj.Bitmap();
- bitmap.loadBase64Data(imageStr, function() {
- console.log('加载base64图片数据成功');
- //图片名称命名
- bitmap.save('_doc/' + new Date().getTime() + '.png', {
- quality: 100
- }, function(i) {
- // 将图片保存到相册
- uni.saveImageToPhotosAlbum({
- filePath: i.target,
- success: function() {
- bitmap.clear(); //销毁Bitmap图片
- // uni.$u.toast('保存图片成功')
- uni.showToast({
- title: '保存图片成功',
- icon: 'none',
- duration: 2000
- });
- // that.noPhoto = true;
- }
- });
- }, function(e) {
- console.log('保存图片失败:' + JSON.stringify(e));
- });
- }, function(e) {
- console.log('截屏绘制图片失败:' + JSON.stringify(e));
- });
- } catch {
- uni.hideLoading()
- }
- },
- }
- }
- </script>
- <script module="my_js" lang="renderjs">
- import html2canvas from 'html2canvas';
- export default {
- data() {
- return {}
- },
- methods: {
- onclicks(event, ownerInstance) {
- console.log(99)
- html2canvas(document.getElementById('share-content'), {
- backgroundColor: '#fff',
- useCORS: true,
- taintTest: true,
- timeout: 2000
- }).then(canvas => {
- let imgurl = canvas.toDataURL('image/jpg');
- ownerInstance.callMethod('saveBase64', imgurl)
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .share-box {
- width: 750rpx;
- height: 100vh;
- display: flex;
- flex-direction: column;
- .share-status-bar {
- flex-shrink: 0;
- width: 100%;
- background-color: rgba(255, 255, 255, 0.5);
- }
- .share-content {
- flex: 1;
- padding: 30rpx 40rpx;
- }
- .share-footer {
- flex-shrink: 0;
- .share-list {
- border-radius: 40rpx 40rpx 0 0;
- width: 100%;
- padding: 30rpx 30rpx;
- display: flex;
- justify-content: space-between;
- align-items: stretch;
- background-color: #f6f7fc;
- }
- .share-icons {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- .share-icon {
- font-size: 100rpx;
- color: red;
- }
- .share-text {
- font-size: 24rpx;
- padding-top: 10rpx;
- }
- }
- .share-cancel {
- width: 100%;
- height: 100rpx;
- line-height: 100rpx;
- background-color: #fff;
- text-align: center;
- font-size: 34rpx;
- color: #c0c0c0;
- }
- }
- // <view class="share-content"></view>
- // <view class="share-share"></view>
- }
- </style>
|