123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <template>
- <view class="container" v-if="imageUrl || urlVal">
- <view class="qrcode-box x-c">
- <image class="qrcode" :src="imageUrl" mode="aspectFill" show-menu-by-longpress="true"></image>
- </view>
- <view class="share-inner">
- <!-- #ifdef MP-WEIXIN -->
- <view class="share-item" @click="downImg()">
- <view class="img">
- <uni-icons type="redo" size="30" color="#222"></uni-icons>
- </view>
- <text class="text">分享</text>
- </view>
- <!-- #endif -->
- <!-- #ifdef APP-PLUS -->
- <view class="share-item" @click="wxShare(0)">
- <image src="/static/images/icon_wx.png" mode=""></image>
- <text class="text">微信</text>
- <button class='share-btn'></button>
- </view>
- <view class="share-item" @click="wxShare(1)">
- <image src="/static/images/icon_pyq.png" mode=""></image>
- <text class="text">朋友圈</text>
- <button class='share-btn' open-type="share">
- </button>
- </view>
- <!-- #endif -->
- <!-- <view class="share-item" @click="copyUrl()">
- <image src="/static/images/icon_copy_link.png" mode=""></image>
- <text class="text">复制链接</text>
- </view> -->
- <!-- #ifndef H5 -->
- <view class="share-item" @click="downImg()">
- <view class="img">
- <uni-icons type="arrow-down" size="30" color="#222"></uni-icons>
- </view>
- <text class="text">保存图片</text>
- </view>
- <!-- #endif -->
- </view>
- </view>
- <u-empty style="padding-top: 20vh;" mode="data" v-else="imgurl"
- icon="https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png" text="暂无数据"></u-empty>
- </template>
- <script>
- import {
- getBindInfo
- } from "@/api/companyUser.js"
- export default {
- data() {
- return {
- imageUrl: '',
- urlVal: '',
- companyUserId: ''
- }
- },
- onShareAppMessage(res) {
- return {
- title: '立即绑定,享受更多权益',
- path: '/pages_user/bindCompanyUser?companyUserId=' + this.companyUserId,
- imageUrl: this.imageUrl
- }
- },
- //分享到朋友圈
- onShareTimeline(res) {
- return {
- title: '立即绑定,享受更多权益',
- path: '/pages_user/bindCompanyUser?companyUserId=' + this.companyUserId,
- imageUrl: this.imageUrl
- }
- },
- onLoad() {
- this.companyUserId = uni.getStorageSync('companyUserId') || '';
- this.getInfo()
- },
- methods: {
- getInfo() {
- getBindInfo().then(res => {
- if (res.code == 200) {
- this.imageUrl = res.imageUrl
- this.urlVal = res.url
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- })
- },
- wxShare(type) {
- // #ifdef APP-PLUS
- if (!plus.runtime.isAgreePrivacy()) {
- uni.showToast({
- title: "请同意隐私政策",
- icon: "none",
- position: 'top',
- duration: 2000
- })
- return;
- }
- let that = this;
- let sceneStr = type == 0 ? "WXSceneSession" : "WXSceneTimeline";
- // 仅支持分享微信小程序到微信聊天界面,想进入朋友圈需改为分享图片方式,在图片中包含小程序码
- uni.share({
- provider: "weixin",
- scene: sceneStr,
- type: 2,
- imageUrl: this.imageUrl, //分享封面图片
- success: function(res) {
- uni.showToast({
- title: "分享成功",
- icon: 'none'
- });
- },
- fail: function(err) {
- // 此处是调起微信分享失败的回调
- },
- complete: (e) => {
- console.log("WXSceneTimeline", e)
- }
- });
- // #endif
- },
- copyUrl() {
- uni.setClipboardData({
- data: this.urlVal,
- success: () => {
- uni.showToast({
- title: '复制成功',
- icon: 'none'
- });
- },
- fail: () => {
- uni.showToast({
- title: '复制失败',
- icon: 'none'
- });
- }
- });
- },
- downImg() {
- uni.showLoading({
- title: "图片保存中..."
- })
- uni.downloadFile({
- url: this.imageUrl,
- fail: function(res) {
- uni.showModal({
- title: '提示',
- content: '保存失败',
- })
- uni.hideLoading();
- },
- success: function(res) {
- var tempFilePath = res.tempFilePath;
- uni.saveImageToPhotosAlbum({
- filePath: tempFilePath,
- success: () => {
- uni.showToast({
- title: "保存成功",
- duration: 2000
- })
- },
- fail: () => {
- console.log("图片失败");
- uni.showToast({
- title: "图片失败",
- duration: 2000,
- icon: "error"
- })
- uni.hideLoading();
- },
- complete: function() {
- uni.hideLoading();
- }
- })
- },
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .container {
- padding: 40rpx 0;
- padding-top: 16vh;
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- align-items: center;
- position: relative;
- }
- .qrcode-box {
- width: 480rpx;
- height: 480rpx;
- box-sizing: border-box;
- overflow: hidden;
- flex-direction: column !important;
- border-radius: 16rpx;
- background-color: #fff;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #222;
- .qrcode {
- width: 450rpx;
- height: 450rpx;
- }
- .qrcode-title {
- font-weight: bold;
- font-size: 32rpx;
- color: #222;
- margin-bottom: 32rpx;
- }
- .qrcode-tip {
- margin: 32rpx;
- color: #999;
- text-align: center;
- }
- }
- .downbtn {
- width: 160rpx;
- min-height: 68rpx;
- border: 1px solid #FF5C03 !important;
- color: #FF5C03 !important;
- background-color: #fff !important;
- border-radius: 168rpx;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- &::after {
- border: none;
- }
- }
- .share-inner {
- width: 100%;
- box-sizing: border-box;
- padding: 0 10%;
- display: flex;
- flex-wrap: wrap;
- position: absolute;
- bottom: 0;
- left: 0;
- .share-item {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- margin-bottom: 66upx;
- position: relative;
- .img {
- width: 80upx;
- height: 80upx;
- margin-bottom: 20upx;
- background-color: #fff;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 50%;
- }
- image {
- width: 80upx;
- height: 80upx;
- margin-bottom: 20upx;
- }
- .text {
- font-size: 28upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #111111;
- line-height: 1;
- }
- }
- }
- .share-btn {
- position: absolute;
- left: 50%;
- top: 0;
- width: 80upx;
- height: 100%;
- transform: translateX(-50%);
- background-color: transparent !important;
- &::after {
- border: none;
- }
- }
- </style>
|