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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
| <template>
| <view class="cl-share">
| <view class="cl-share__title">{{ text || $t("分享至") }}</view>
|
| <view class="cl-share__container">
| <!-- #ifdef APP -->
| <button class="item" @tap="shareQQ" v-if="qq">
| <image src="./qq.png" mode="aspectFit" />
| <text>{{ $t("QQ好友") }}</text>
| </button>
|
| <button class="item" @tap="shareWx('WXSceneTimeline')" v-if="wx">
| <image src="./wx2.png" mode="aspectFit" />
| <text>{{ $t("朋友圈") }}</text>
| </button>
| <!-- #endif -->
|
| <button class="item" open-type="share" @tap="shareWx('WXSceneSession')" v-if="wx">
| <image src="./wx.png" mode="aspectFit" />
| <text>{{ $t("微信好友") }}</text>
| </button>
| </view>
| </view>
| </template>
|
| <script lang="ts">
| import { defineComponent } from "vue";
|
| export default defineComponent({
| name: "cl-share",
|
| props: {
| type: {
| type: null,
| default: 0,
| },
| imageUrl: String,
| title: String,
| summary: String,
| href: String,
| mediaUrl: String,
| miniProgram: Object,
| text: String,
| qq: {
| type: Boolean,
| default: true,
| },
| wx: {
| type: Boolean,
| default: true,
| },
| },
|
| emits: ["choose", "success", "error"],
|
| setup(props, { emit }) {
| function share() {
| uni.shareWithSystem({
| type: props.type,
| href: props.href,
| summary: props.summary,
| imageUrl: props.imageUrl,
| success: () => {
| emit("success");
| },
| fail: (err: any) => {
| emit("error", err);
| },
| });
| }
|
| function shareWx(scene: any) {
| choose("wx");
|
| uni.share({
| provider: "weixin",
| type: props.type,
| title: props.title,
| scene,
| summary: props.summary,
| href: props.href,
| imageUrl: props.imageUrl,
| mediaUrl: props.mediaUrl,
| miniProgram: props.miniProgram,
| success: () => {
| emit("success");
| },
| fail: (err) => {
| console.error(err);
| share();
| },
| });
| }
|
| function shareQQ() {
| choose("qq");
|
| uni.share({
| provider: "qq",
| type: props.type,
| title: props.title,
| summary: props.summary,
| href: props.href,
| imageUrl: props.imageUrl,
| mediaUrl: props.mediaUrl,
| miniProgram: props.miniProgram,
| success: () => {
| emit("success");
| },
| fail: () => {
| share();
| },
| });
| }
|
| function choose(name: string) {
| emit("choose", name);
| }
|
| return {
| shareWx,
| shareQQ,
| share,
| };
| },
| });
| </script>
|
|