chengkun
2025-04-18 1bb985f32f2efe0f9dd69f3cf29a1c809b1cf96d
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
<script>
    var weburl = '{yun:}$config.sy_weburl{/yun}';
    var invite_reg_hbids = [];
 
    function getInviteRegHbList() {
        let lr = false;
        $.ajax({
            type: 'post',
            url: weburl + '/index.php?m=ajax&c=getInviteRegHbList',
            async: false,
            dataType: 'json',
            success: function(res){
                if(res && res.list && res.list.length > 0){
                    res.list.forEach(function (item) {
                        invite_reg_hbids.push(item.id);
                    });
 
                    lr = true;
                }
            }
        })
        return lr;
    }
 
    function getInviteRegHb(hb) {
        layer.closeAll();
        let hbNum = invite_reg_hbids.length;
 
        if(hbNum == 0){
            var lr = this.getInviteRegHbList();
            if(!lr){
                layer.msg("功能无法使用,请联系网站客服", 2, 8)
                return false;
            }
            hbNum = invite_reg_hbids.length; // 重新分配海报数量
        }
 
        const url = weburl + '/index.php?m=ajax&c=getInviteRegHb&hb=' + invite_reg_hbids[hb];
        if (hb < (parseInt(hbNum) - 1)) {
            var next = hb + 1;
        } else {
            var next = 0;
        }
 
        const loading = layer.load('生成中...', 0);
 
        var image = new Image();
        image.src = url;
        image.onload = function() {
            layer.closeAll();
 
            layer.open({
                type: 1,
                title: false,
                content: '<div class="hb_tc"><img src="' + image.src + '" style="max-width: 100%;"><div class="hb_tc_bth"><a href="javascript:;" onclick="getInviteRegHb(' + next + ');" class="hb_tc_hyz">换一张</a><a href="javascript:;" onclick="downInviteRegHb(' + hb + ');" class="hb_tc_xz">下载海报</a></div></div>',
                area: ['360px', 'auto'],
                offset: '55px',
                closeBtn: 0,
                shadeClose: true
            });
        };
    }
 
    function downInviteRegHb(hb) {
        const loading = layer.load('下载中...', 0);
        const url   =   weburl + '/index.php?m=ajax&c=getInviteRegHb&hb=' +  + invite_reg_hbids[hb];
        var image = new Image();
        image.src = url;
        image.onload = function() {
            layer.closeAll();
            var a = document.createElement('a');          // 创建一个a节点插入的document
            var event = new MouseEvent('click')           // 模拟鼠标click点击事件
            a.download = 'whb_' +invite_reg_hbids[hb];     // 设置a节点的download属性值
            a.href = url;                                 // 将图片的src赋值给a节点的href
            a.dispatchEvent(event);
        }
    }
 
</script>
<style>
    .hb_tc_bth{padding:10px 0; text-align: center;}
    .hb_tc_bth .hb_tc_hyz{width:120px;height:40px; line-height: 40px; text-align: center; display: inline-block; background-color: #3478ea;color:#fff;border-radius:3px;color:#fff;}
    .hb_tc_xz{width:120px;height:40px; line-height: 40px; text-align: center; display: inline-block; margin-left: 10px; background-color: #01af67;color:#fff;border-radius:3px;color:#fff;}
    .hb_tc_bth a:hover{color:#fff}
</style>