admin
2024-07-03 158b3be9024917bc5798486777dead4dd167abc7
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
layui.use(['layer', 'form', 'element', 'jquery', 'dialog'], function() {
    var layer = layui.layer;
    var element = layui.element;
    var form = layui.form;
    var $ = layui.jquery;
    var dialog = layui.dialog;
    var hideBtn = $('#hideBtn');
    var mainLayout = $('#main-layout');
    var mainMask = $('.main-mask');
    //监听导航点击
    element.on('nav(leftNav)', function(elem) {
        
        var navA = $(elem);
        
        console.log( $(elem).attr("data-url"));
        
        var id = navA.attr('data-id');
        var url = navA.attr('data-url');
        console.log("导航栏点击:"+url);
        var text = navA.attr('data-text');
        
        if(!url){
            return;
        }
        var isActive = $('.main-layout-tab .layui-tab-title').find("li[lay-id=" + id + "]");
        if(isActive.length > 0) {
            //切换到选项卡
            element.tabChange('tab', id);
        } else {
            element.tabAdd('tab', {
                title: text,
                content: '<iframe src="' + url + '" name="iframe' + id + '" class="iframe" framborder="0" data-id="' + id + '" scrolling="auto" width="100%"  height="100%"></iframe>',
                id: id
            });
            element.tabChange('tab', id);
            
        }
        mainLayout.removeClass('hide-side');
    });
    //监听导航点击
    element.on('nav(rightNav)', function(elem) {
        var navA = $(elem).find('a');
        var id = navA.attr('data-id');
        var url = navA.attr('data-url');
        var text = navA.attr('data-text');
        if(!url){
            return;
        }
        var isActive = $('.main-layout-tab .layui-tab-title').find("li[lay-id=" + id + "]");
        if(isActive.length > 0) {
            //切换到选项卡
            element.tabChange('tab', id);
        } else {
            element.tabAdd('tab', {
                title: text,
                content: '<iframe src="' + url + '" name="iframe' + id + '" class="iframe" framborder="0" data-id="' + id + '" scrolling="auto" width="100%"  height="100%"></iframe>',
                id: id
            });
            element.tabChange('tab', id);
            
        }
        mainLayout.removeClass('hide-side');
    });
    
    // 监听跨域切换
    // window.addEventListener('message', function(event) {
    //     // 处理接收到的消息
    //     console.log('Received message from layui:', event.data);
    // });
    window.addEventListener('message', function(event) {
        // 验证消息来源
    
        // 处理接收到的消息
        console.log('Received message from iframe child:', event.data);
    });
    
    //菜单隐藏显示
    hideBtn.on('click', function() {
        if(!mainLayout.hasClass('hide-side')) {
            mainLayout.addClass('hide-side');
        } else {
            mainLayout.removeClass('hide-side');
        }
    });
    //遮罩点击隐藏
    mainMask.on('click', function() {
        mainLayout.removeClass('hide-side');
    })
 
    //示范一个公告层
//    layer.open({
//          type: 1
//          ,title: false //不显示标题栏
//          ,closeBtn: false
//          ,area: '300px;'
//          ,shade: 0.8
//          ,id: 'LAY_layuipro' //设定一个id,防止重复弹出
//          ,resize: false
//          ,btn: ['火速围观', '残忍拒绝']
//          ,btnAlign: 'c'
//          ,moveType: 1 //拖拽模式,0或者1
//          ,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">后台模版1.1版本今日更新:<br><br><br>数据列表页...<br><br>编辑删除弹出功能<br><br>失去焦点排序功能<br>数据列表页<br>数据列表页<br>数据列表页</div>'
//          ,success: function(layero){
//            var btn = layero.find('.layui-layer-btn');
//            btn.find('.layui-layer-btn0').attr({
//              href: 'http://www.layui.com/'
//              ,target: '_blank'
//            });
//          }
//        });
});