xuruiqian
2025-06-04 17ce21955b4e3402d3d5868b52e50bfdd55bc572
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
  <view class="content">
    <button class="share" open-type="share" >分享</button>
  </view>
</template>
 
<script>
import { ref, reactive, toRefs, onMounted, getCurrentInstance } from "vue";
import { onLoad, onShow, onHide, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { useBasicInfoStore } from "../../store/basicInfo"
export default {
  setup() {
    const userStore = useBasicInfoStore()
    const { proxy } = getCurrentInstance();
    const state = reactive({
 
    })
 
    onMounted(() => {
      Init();
    });
 
    const Init = () => {
 
    }
 
 
    onShareAppMessage((res) => {
      // 分享事件来源:button(页面内分享按钮)、menu(右上角分享按钮)
      if (res.from === 'button') {// 来自页面内分享按钮
        return {
          //分享标题
          title: shopDetailsData.value?.GoodsName,
          //页面 path 
          path: '/pages/index/index',
          // 分享图标
         // imageUr: shopDetailsData.value?.GoodsCoverImg,
          success: function (res) {
            // 转发成功
            console.log('res', res);
          },
          fail: function (res) {
            // 转发失败
            console.log('res', res);
 
          }
        }
      } else {
        return {
          title: shopDetailsData.value?.GoodsName,
          path: '/pages/index/index',
          //imageUr: shopDetailsData.value?.GoodsCoverImg
        }
      }
    })
 
 
 
 
 
 
 
    return { ...toRefs(state), userStore }
  }
}
 
 
 
</script>
 
<style scoped lang="scss">
.center {
  display: flex;
  flex-direction: column;
  align-items: center;
}
 
.content {
  @extend .center;
  height: 100vh;
  width: 100%;
  background-color: #f5f5f5;
}
 
.share {
  width: 80%;
  margin-top: 60rpx;
  background-color: #eabb38;
  color: #fff;
}
</style>