123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- <template>
- <view class="share-modal" v-show="visible">
- <view class="modal-overlay" @click="handleClose"></view>
- <transition name="fade-up">
- <view v-if="visible" class="modal-content">
- <view class="share-options">
- <view v-for="option in shareOptions" :key="option.id" class="share-item" @click="handleShare(option.id)">
- <view class="share-icon">
- <image :src="option.icon" :alt="option.title" mode="aspectFit"></image>
- </view>
- <text class="option-title">{{ option.title }}</text>
- </view>
- </view>
- </view>
- </transition>
- </view>
- </template>
- <script>
- import { generateSecureUrlParams } from '@/common/encryption.js'
- export default {
- name: 'ShareModal',
- props: {
- visible: {
- type: Boolean,
- default: false
- },
- userId: {
- default: 0
- },
- shareTitle: {
- type: String,
- default: ''
- },
- shareDesc: {
- type: String,
- default: '快来加入萌创星球吧!'
- },
- shareImg: {
- type: String,
- default: ''
- },
- view: {
- type: String,
- default: ''
- },
- isReportContent: {
- type: Boolean,
- default: false
- },
- link: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- shareOptions: [
- { id: 'wechat', title: '微信好友', icon: '/static/icon/sy_icon_weixin.png' },
- { id: 'moments', title: '朋友圈', icon: '/static/icon/sy_icon_pengyouquan.png' },
- // { id: 'qq', title: 'QQ好友', icon: '../../static/icon/sy_icon_qq.png' },
- { id: 'copy', title: '复制链接', icon: '/static/icon/sy_icon_fuzhilianjie.png' },
- { id: 'report', title: '举报', icon: '/static/icon/sy_icon_jubao01.png' },
- // { id: 'more', title: '更多', icon: '../../static/icon/sy_icon_gengduo.png' }
- ],
- from_id: 0
- }
- },
- computed: {
- shareUrl() {
- const urlParams = {
- userId: this.userId,
- action: this.view,
- timestamp: new Date().getTime(),
- from_id: this.from_id
- }
- const secureParams = generateSecureUrlParams(urlParams)
- return `${this.link || this.$shareUrl}?params=${secureParams}`
- }
- },
- created() {
- uni.$emit('check_login', () => {
- this.from_id = getApp().globalData.user_id
- })
- },
- methods: {
- handleClose() {
- this.$emit('close')
- },
- handleShare(type) {
- switch (type) {
- case 'copy':
- this.copyToClipboard(this.shareUrl)
- break
- case 'wechat':
- this.shareToWechat()
- break
- case 'moments':
- this.shareToMoments()
- break
- case 'report':
- this.handleReport()
- break
- case 'qq':
- this.qqShare()
- break
- case 'more':
- this.moreShare()
- break
- }
- },
- copyToClipboard(text) {
- // #ifdef H5
- const input = document.createElement('input')
- input.value = text
- document.body.appendChild(input)
- input.select()
- document.execCommand('copy')
- document.body.removeChild(input)
- // #endif
- // #ifdef APP-PLUS || MP
- uni.setClipboardData({
- data: text,
- success: () => {
- uni.showToast({
- title: '链接已复制',
- icon: 'success'
- })
- },
- fail: () => {
- uni.showToast({
- title: '复制失败',
- icon: 'none'
- })
- }
- })
- // #endif
- },
- shareToWechat() {
- // #ifdef APP-PLUS
- uni.share({
- provider: 'weixin',
- scene: 'WXSceneSession',
- type: 0,
- title: this.shareTitle,
- summary: this.shareDesc,
- imageUrl: this.shareImg || this.$icon,
- href: this.shareUrl,
- success: () => {
- uni.showToast({
- title: '分享成功',
- icon: 'success'
- })
- },
- fail: (err) => {
- uni.showToast({
- title: '分享失败',
- icon: 'none'
- })
- console.error('分享失败:', err)
- }
- })
- // #endif
- // #ifdef H5
- if (typeof wx !== 'undefined') {
- wx.ready(() => {
- wx.updateAppMessageShareData({
- title: this.shareTitle,
- desc: this.shareDesc,
- link: this.shareUrl,
- imgUrl: this.shareImg || this.$icon,
- success: () => {
- uni.showToast({
- title: '分享成功',
- icon: 'success'
- })
- },
- fail: (err) => {
- uni.showToast({
- title: '分享失败',
- icon: 'none'
- })
- console.error('分享失败:', err)
- }
- })
- })
- } else {
- uni.showToast({
- title: '请在微信中打开',
- icon: 'none'
- })
- }
- // #endif
- // #ifdef MP-WEIXIN
- uni.showShareMenu({
- withShareTicket: true,
- menus: ['shareAppMessage'],
- success: () => {
- uni.updateShareMenu({
- withShareTicket: true,
- isPrivateMessage: true
- })
- }
- })
- // #endif
- },
- shareToMoments() {
- // #ifdef APP-PLUS
- uni.share({
- provider: 'weixin',
- scene: 'WXSenceTimeline',
- type: 0,
- title: this.shareTitle,
- summary: this.shareDesc,
- imageUrl: this.shareImg || this.$icon,
- href: this.shareUrl,
- success: () => {
- uni.showToast({
- title: '分享成功',
- icon: 'success'
- })
- },
- fail: (err) => {
- uni.showToast({
- title: '分享失败',
- icon: 'none'
- })
- console.error('分享失败:', err)
- }
- })
- // #endif
- // #ifdef H5
- if (typeof wx !== 'undefined') {
- wx.ready(() => {
- wx.updateTimelineShareData({
- title: this.shareTitle,
- link: this.shareUrl,
- imgUrl: this.shareImg || this.$icon,
- success: () => {
- uni.showToast({
- title: '分享成功',
- icon: 'success'
- })
- },
- fail: (err) => {
- uni.showToast({
- title: '分享失败',
- icon: 'none'
- })
- console.error('分享失败:', err)
- }
- })
- })
- } else {
- uni.showToast({
- title: '请在微信中打开',
- icon: 'none'
- })
- }
- // #endif
- // #ifdef MP-WEIXIN
- uni.showShareMenu({
- withShareTicket: true,
- menus: ['shareTimeline']
- })
- // #endif
- },
- handleReport() {
- // 实现举报功能
- uni.$emit('check_login', () => {
- uni.navigateTo({
- url: '/pages/my/feedback?isReportContent=' + this.isReportContent
- })
- })
- },
- qqShare() {
- // #ifdef APP-PLUS
- uni.share({
- provider: 'qq',
- type: 0,
- title: this.shareTitle,
- summary: this.shareDesc,
- imageUrl: this.shareImg || this.$icon,
- href: this.shareUrl,
- success: () => {
- uni.showToast({
- title: '分享成功',
- icon: 'success'
- })
- }
- })
- // #endif
- },
- moreShare() {
- // 更多分享方式
- uni.showToast({
- title: '更多分享功能开发中',
- icon: 'none'
- })
- }
- }
- }
- </script>
- <style scoped>
- .share-modal
- {
- position: fixed;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- z-index: 1000;
- }
- .modal-overlay
- {
- position: absolute;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.4);
- }
- .modal-content
- {
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: #f2f6f2;
- border-top-left-radius: 12px;
- border-top-right-radius: 12px;
- padding: 16px;
- }
- /* 弹出动画 */
- .fade-up-enter-active, .fade-up-leave-active
- {
- transition: all 0.3s cubic-bezier(.55, 0, .1, 1);
- }
- .fade-up-enter, .fade-up-leave-to
- {
- opacity: 0;
- transform: translateY(100%);
- }
- .fade-up-leave, .fade-up-enter-to
- {
- opacity: 1;
- transform: translateY(0);
- }
- .share-options
- {
- display: flex;
- flex-wrap: wrap;
- padding: 8px 16px;
- }
- .share-item
- {
- width: 25%;
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 8px;
- padding: 8px 0;
- }
- .share-icon
- {
- width: 44px;
- height: 44px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .share-icon image
- {
- width: 100%;
- height: 100%;
- }
- .option-title
- {
- font-size: 13px;
- color: #333333;
- text-align: center;
- }
- </style>
|