export default {
    data() {
        return {
            //设置默认的分享参数
            //如果页面不设置share，就触发这个默认的分享
            share: {
                title: '',
                path: '',
                imageUrl: '',
                desc: '',
                content: ''
            }
        }
    },
    onShareAppMessage(res) {
        let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
        let path = routes[routes.length - 1].route //获取当前页面路由
        let share_user_id
        try {
            share_user_id = this.$store.state.userInfo.id
        } catch (err) {
            console.log(err)
        }

        if (share_user_id) {
            path += `?share_user_id=${share_user_id}`
        }
        // console.log(path)
        return {
            title: this.share.title,
            path: this.share.path || path,
            imageUrl: this.share.imageUrl,
            desc: this.share.desc,
            content: this.share.content,
            success(res) {
                uni.showToast({
                    title: '分享成功'
                })
            },
            fail(res) {
                uni.showToast({
                    title: '分享失败',
                    icon: 'none'
                })
            }
        }
    }
}
