uniapp 分享例子做个记录

<template>

<view class="content">

<view class="invite-wrapper" v-if="inviteUrl">

<uni-qrcode class="invite-qrcode" ref="qrcode" cid="invite-qr-canvas" :text="inviteUrl" :margin="10" makeOnLoad

@makeComplete="qrcodeComplete" />

<view class="share-btn">

<button type="primary" @click="shareLink">分享链接</button>

<button type="primary" @click="shareImage">分享图片</button>

</view>

<view class="share-btn">

<button type="primary" @click="toInvitedUser">我邀请的用户</button>

</view>

<uni-popup id="popupShare" ref="popupShare" type="share">

<uni-popup-share title="分享到" :shareType="shareType" @select="select"></uni-popup-share>

</uni-popup>

</view>

</view>

</template>

<script>

import {

mapState

} from 'vuex'

export default {

data() {

return {

inviteUrl: '',

qrcodeImagePath: '',

qrcodePath: '',

shareType: ''

}

},

onLoad() {

uni.showLoading({

title: '加载中...'

})

uniCloud.callFunction({

name: 'user-center',

data: {

action: 'getInviteCode'

},

success: (res) => {

console.log(res);

if (res.result.code === 0) {

// 这里请修改为真实的邀请页面url

this.inviteUrl = 'https://login.tpl.dcloud.net.cn/#/pages/invite-reg/invite-reg?invite_code=' + res.result.myInviteCode

} else {

uni.showModal({

content: '获取用户邀请码失败:' + res.result.msg,

showCancel: false

})

}

},

fail: (err) => {

uni.showModal({

content: '获取用户邀请码失败,请稍后再试',

showCancel: false

})

},

complete() {

uni.hideLoading()

}

})

},

methods: {

copyInviteUrl() {

uni.setClipboardData({

data: this.inviteUrl

})

},

qrcodeComplete(path) {

this.qrcodeImagePath = path

},

shareLink() {

this.shareType = 'link'

this.$refs.popupShare.open()

},

shareImage() {

this.shareType = 'image'

this.$refs.popupShare.open()

},

select({

item

}) {

const shareTitle = '登录模板',

shareSummary = 'DCloud邀请您试用登录模板'

let params = {}

switch (`{this.shareType}_{item.name}`) {

case 'link_weixin':

params = {

type: 1,

summary: this.inviteUrl,

scene: 'WXSceneSession'

}

break;

case 'link_qq':

params = {

type: 1,

title: shareTitle,

summary: shareSummary,

href: this.inviteUrl

}

break;

case 'link_more':

uni.setClipboardData({

data: this.inviteUrl

})

return

case 'image_weixin':

params = {

type: 2,

imageUrl: this.qrcodeImagePath,

scene: 'WXSceneSession'

}

break;

case 'image_qq':

params = {

type: 2,

imageUrl: this.qrcodeImagePath

}

break;

case 'image_more':

uni.shareWithSystem({

type: 'image',

imageUrl: this.qrcodeImagePath

})

return

default:

break;

}

console.log(params);

uni.share({

provider: item.name,

...params,

success() {

uni.showModal({

content: '分享成功',

showCancel: false

})

},

fail(err) {

uni.showModal({

content: '分享失败:' + err.errMsg,

showCancel: false

})

}

})

},

toInvitedUser() {

uni.navigateTo({

url: '/pages/invited-user/invited-user'

})

}

}

}

</script>

<style>

.invite-wrapper {

display: flex;

padding: 20px;

flex-direction: column;

align-items: center;

}

.invite-qrcode {

border-radius: 10px;

box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 10px 1px;

overflow: hidden;

}

.share-btn {

display: flex;

flex-direction: row;

padding: 20px 0px 10px 0px;

}

.share-btn button {

flex: 1;

margin: 0px 10px;

border-radius: 40px;

}

</style>

相关推荐
鸭子嘎鹅子呱10 小时前
uniapp使用高德地图设置marker标记点,后续根据接口数据改变某个marker标记点,动态更新
uni-app·map·高德地图
计算机源码社15 小时前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
Angus-zoe18 小时前
uniapp+vue+微信小程序实现侧边导航
vue.js·微信小程序·uni-app
Pluto & Ethereal18 小时前
uni-app尺寸单位、flex布局于背景图片
uni-app
天空下sky1 天前
uniapp+若依 开发租房小程序源码分享
uni-app
帅过二硕ฅ1 天前
uniapp点击跳转到对应位置
前端·javascript·uni-app
佩淇呢1 天前
uniapp vue3 梯形选项卡组件
前端·vue.js·uni-app
[廾匸]1 天前
uni-app获取设备唯一值、静态IP以及公网IP的方法
uni-app·ip·imei·唯一值
luckycoke2 天前
小程序的右侧抽屉开关动画手写效果
前端·javascript·微信小程序·uni-app
微刻时光2 天前
好课程:uni-app实战音频小说app小程序
小程序·uni-app