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
<script>
    var weburl = '{yun:}$config.sy_weburl{/yun}';
    var hbids = [];
    '{yun:}foreach from=$hbids item=v{/yun}'
    hbids.push('{yun:}$v{/yun}')
    '{yun:}/foreach{/yun}'
 
    function getComHb(hb) {
 
        layer.closeAll();
 
        const hbNum = '{yun:}$hbNum{/yun}';
        const id = '{yun:}$hb_uid{/yun}';
        const url = weburl + '/index.php?m=ajax&c=getComHb&uid=' + id + '&hb=' + 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="getComHb(' + next + ');" class="hb_tc_hyz">换一张</a><a href="javascript:;" onclick="downWhb(' + hb + ');" class="hb_tc_xz">下载海报</a></div></div>',
                area: ['360px', 'auto'],
                offset: '55px',
                closeBtn: 0,
                shadeClose: true
            });
        };
    }
 
    function downWhb(hb) {
        const loading = layer.load('下载中...', 0);
        const id = '{yun:}$hb_uid{/yun}';
        const url   =   weburl + '/index.php?m=ajax&c=getComHb&uid=' + id + '&hb=' +  + 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' + id + '_' +hbids[hb];     // 设置a节点的download属性值
            a.href = url;                                 // 将图片的src赋值给a节点的href
            a.dispatchEvent(event);
        }
    }
 
</script>