移动系统liao
2024-05-15 d7c7a6e9d05eec7b38b41b8ae39f373f650ca891
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<template>
    <view class="coreshop-share-Box">
        <u-toast ref="uToast" />
        <view class="coreshop-share-pop">
            <view class="coreshop-share-item">
                <button class="coreshop-btn" open-type="share">
                    <u-icon label="分享微信好友" labelPos="bottom" size="40" name="/static/images/common/share-friend.png"></u-icon>
                </button>
            </view>
            <view class="coreshop-share-item">
                <button class="coreshop-btn" @click="$u.throttle(createPoster, 500)">
                    <u-icon label="生成海报" labelPos="bottom" size="40" name="/static/images/common/share-poster.png"></u-icon>
                </button>
            </view>
        </view>
        <view class="coreshop-share-bottomBox">
            <button class="coreshop-btn coreshop-btn-w coreshop-btn-square" @click="close()">关闭</button>
        </view>
    </view>
</template>
 
<script>
    export default {
        props: {
            // 通用传参id
            objectId: {
                type: Number,
                default: 0
            },
            // 商品id
            goodsId: {
                type: Number,
                default: 0
            },
            // 分享的图片
            shareImg: {
                type: String,
                default: ''
            },
            // 分享标题
            shareTitle: {
                type: String,
                default: ''
            },
            // 分享内容
            shareContent: {
                type: String,
                default: ''
            },
            // 分享链接
            shareHref: {
                type: String,
                default: ''
            },
            //分享类型
            shareType: {
                type: Number,
                default: 1
            },
            //拼团Id/团购Id/秒杀Id
            groupId: {
                type: Number,
                default: 0
            },
            //拼团的团队id
            teamId: {
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                providerList: [] // 分享通道 包含生成海报
            }
        },
        mounted() {
            //    console.log("类型:" + this.shareType);
        },
        methods: {
            // 关闭弹出层
            close() {
                this.$emit('close')
            },
            // 生成海报
            createPoster() {
                uni.showLoading({
                    title: '加载中',
                    mask: true
                });
                this.close()
                let data = {};
                if (this.shareType == this.$globalConstVars.shareType.index) {
                    data = {
                        page: this.shareType, //商品
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            goodsId: this.goodsId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                } else if (this.shareType == this.$globalConstVars.shareType.pinTuan) {
                    data = {
                        page: this.shareType,
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            groupId: this.groupId,
                            goodsId: this.goodsId,
                            teamId: this.teamId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                }
                else if (this.shareType == this.$globalConstVars.shareType.addPinTuan) {
                    data = {
                        page: this.shareType, //拼团
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            goodsId: this.goodsId,
                            groupId: this.groupId,
                            teamId: this.teamId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                }
                else if (this.shareType == this.$globalConstVars.shareType.group) {
                    data = {
                        page: this.shareType,
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            groupId: this.groupId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                }
                else if (this.shareType == this.$globalConstVars.shareType.seckill) {
                    data = {
                        page: this.shareType,
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            groupId: this.groupId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                }
                else if (this.shareType == this.$globalConstVars.shareType.goods) {
                    data = {
                        page: this.shareType, //拼团
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            goodsId: this.goodsId,
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                }
                else if (this.shareType == this.$globalConstVars.shareType.solitaire) {
                    data = {
                        page: this.shareType,
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            id: this.objectId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                } else if (this.shareType == this.$globalConstVars.shareType.serviceGoods) {
                    data = {
                        page: this.shareType,
                        url: this.$globalConstVars.shareUrl,
                        params: {
                            serviceGoodsId: this.objectId
                        },
                        type: this.$globalConstVars.shareModel.poster,
                        client: this.$globalConstVars.shareClient.wxMiNiProgram
                    }
                    let userToken = this.$db.get('userToken')
                    if (userToken) {
                        data.token = userToken
                    }
                }
                this.$u.api.share(data).then(res => {
                    if (res.status) {
                        uni.hideLoading();
                        if (
                            this.shareType == this.$globalConstVars.shareType.goods ||
                            this.shareType == this.$globalConstVars.shareType.pinTuan ||
                            this.shareType == this.$globalConstVars.shareType.addPinTuan ||
                            this.shareType == this.$globalConstVars.shareType.seckill ||
                            this.shareType == this.$globalConstVars.shareType.group ||
                            this.shareType == this.$globalConstVars.shareType.serviceGoods
                        ) {
                            //data.posterUrl = encodeURIComponent(res.data);
                            data.params.posterUrl = res.data;
                            data.params.shareType = this.shareType;
 
                            this.$u.route('/pages/share/shareNewPoster/shareNewPoster' + uni.$u.queryParams(data.params))
                        } else {
                            this.$u.route('/pages/share/sharePoster/sharePoster?poster=' + encodeURIComponent(res.data))
                        }
                    } else {
                        uni.hideLoading();
                        this.$u.toast(res.msg)
                    }
                });
            }
        }
    }
</script>