const n = getApp();
Page({
    data: {
        list: null
    },
    onLoad: function() {
        wx.showShareMenu({
            withShareTicket: true,
            menus: ["shareAppMessage", "shareTimeline"]
        });
    },
    saveImage: function(e) {
        const n = e.currentTarget.dataset.url;
        wx.showActionSheet({
            itemList: ["保存图片"],
            success: function(e) {
                if (e.tapIndex === 0) {
                    wx.downloadFile({
                        url: n,
                        success: function(res) {
                            if (res.statusCode === 200) {
                                wx.saveImageToPhotosAlbum({
                                    filePath: res.tempFilePath,
                                    success: function() {
                                        wx.showToast({
                                            title: "保存成功",
                                            icon: "success",
                                            duration: 2000
                                        });
                                    },
                                    fail: function(err) {
                                        console.log(err);
                                        wx.showToast({
                                            title: "保存失败",
                                            icon: "none",
                                            duration: 2000
                                        });
                                    }
                                });
                            }
                        },
                        fail: function(err) {
                            console.log(err);
                            wx.showToast({
                                title: "下载失败",
                                icon: "none",
                                duration: 2000
                            });
                        }
                    });
                }
            },
            fail: function(err) {
                console.log(err);
            }
        });
    },
    onShow: function() {
        const e = this;
        n.check_status()
            .then(function(res) {
                console.log("获取文章信息", res);
                e.setData({
                    list: res.data.data.list
                });
            })
            .catch(function(err) {
                console.error("获取文章信息失败:", err);
            })
            .finally(function() {
                console.log("check_status调用完成");
            });
    },
    onAdClick: function() {
      n.广告();
  },
    onShareAppMessage: function() {
        return {
            title: "推荐一款免费又超好用的视频文案创作工具，分享给大家一起使用",
            path: "/pages/index/index?uuid=" + wx.getStorageSync("uuid"),
            imageUrl: "/images/share.jpg",
            success: function() {
                wx.showToast({
                    title: "分享成功",
                    icon: "success",
                    duration: 2000
                });
            },
            fail: function() {
                wx.showToast({
                    title: "分享失败",
                    icon: "none",
                    duration: 2000
                });
            }
        };
    },
    onShareTimeline: function() {
        return {
            title: "推荐一款免费又超好用的视频文案创作工具，分享给大家一起使用",
            path: "/pages/index/index?uuid=" + wx.getStorageSync("uuid"),
            imageUrl: "/images/share.jpg",
            success: function() {
                wx.showToast({
                    title: "分享成功",
                    icon: "success",
                    duration: 2000
                });
            },
            fail: function() {
                wx.showToast({
                    title: "分享失败",
                    icon: "none",
                    duration: 2000
                });
            }
        };
    }
});
