File size: 16,861 Bytes
17e971c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<style>
    .module-check i.form-checkbox{
        vertical-align: bottom;
    }
    .module-check span{
        vertical-align: revert;
    }
    .module-check.check_disabled label,
    .module-check.check_disabled i{
        cursor: no-drop;
    }
    .panel_push_form .bt_select_updown .bt_select_list{
        max-height: 140px;
    }
    #bt_panel_push_table .divtable thead {
        position: relative;
        z-index: 999;
    }
    #bt_panel_push_table .divtable {
        border: 1px solid #ddd;
    }
    #bt_panel_push_table table {
        border: none;
    }
    .bt-form .bt-disabled{
        border: 1px solid #DDD;
        background-color: #F5F5F5;
        color: #ACA899;
    }
</style>
<div id="bt_panel_push_table"></div>

<!--面板消息推送模块-->
<script type="text/javascript">

    var panel_push = {
        all_info: {},
        module_name: 'panel_push',
        module_config: [],
        msg_list:[],
        push_type:'',
        init: function () {
            this.all_info = $('.alarm-view .bt-w-menu p.bgw').data('data'); //设置全局数据
            this.get_push_data();
        },
        /**
        *@description
        */
        get_push_data: function () {
            var _this = this,data = this.all_info.data,rdata = [];
            $.each(data,function(index,item){
                item['id'] = index;
                item['name'] = _this.module_name;
                rdata.push(item)
            })
            // console.log(rdata,'rdata')
            bt_tools.table({
                el: '#bt_panel_push_table',
                data: rdata,
                default: "列表为空",
                autoHeight: true,
                height:410,
                column: [
                    { fid: 'title', title: '标题' },
                    { fid: 'm_title', title: '推送通道' },
                    { fid: 'm_cycle', title: '执行周期' },
                    {
                        fid: 'status',
                        title: '状态',
                        config: {
                            icon: true,
                            list: [
                                [true, '正常', 'bt_success', 'glyphicon-play'],
                                [false, '停用', 'bt_danger', 'glyphicon-pause']
                            ]
                        },
                        type: 'status',
                        event: function(row){
                            bt_tools.send({
                                url:'/push?action=set_push_status',
                                data: {id:row.id,name:_this.module_name,status:row['status']?0:1}
                            },function(res){
                                if(res.status){
                                    panel_push.refresh_data();
                                }
                                bt_tools.msg(res)
                            },'设置推送状态')
                        }
                    },
                    {
                        title: '操作', type: 'group', width: 100, align: 'right', group: [{
                            title: '编辑', event: function(row){
                                var _typeA = []
                                _this.get_config_data(function(){
                                    $.each(_this.module_config,function(index,item){
                                        _typeA.push(item.project)
                                    })
                                    _this.panel_push_view($.extend(true,$.inArray(row.project,_typeA) < 0 ? {isOther:true} : {},row));
                                })
                            }
                        },{
                            title: '删除', event: function (row) {
                                bt.confirm({title:'删除推送通道',msg:'删除【'+row.title+'】推送,是否继续?'},function(){
                                    _this.del_push_config(row.id, function (res) {
                                        if (res.status) panel_push.refresh_data();
                                        bt_tools.msg(res)
                                    });
                                });
                            }
                        }]
                    }
                ],
                tootls:[{
                    type:'group',
                    positon: ['left', 'top'],
                    list: [{
                        title: '添加推送',
                        active: true,
                        event: function () {
                            _this.get_config_data(function(){
                                _this.panel_push_view();
                            })
                        }
                    }]
                }]
            });
        },
        /**
         *面板推送视图
         */
        panel_push_view:function(res){
            var _this = this,config = {title:'添加推送',btn:'添加'},proList = [],editIndex = 0,param = {} ;
            if(res){
                param = $.extend(true,{},res)
                config = {title:'编辑推送',btn:'保存'}
            }
            $.each(this.module_config,function(index,item){
                if(param && param.project === item.project) editIndex = index;
                proList.push({title:item.title,value:item.project})
            })
            bt_tools.open({
                type: 1,
                title: config.title,
                area:'520px',
                btn:[config.btn,'取消'],
                skin:'panel_push_form',
                content:{
                    class:'pd15',
                    data:param || {},
                    form:[{
                        label:'通知类型',
                        group:{
                            type: 'select',
                            name: 'project',
                            width: '300px',
                            value:'ssl',
                            class:'projectBox',
                            list: proList,
                            disabled:!!res,
                            change:function(formData,element,that){
                                var config = panel_push.switch_push_type(that,res?res:formData)
                                that.$again_render_form(config)
                            }
                        }
                    },{
                        label:'服务名称',
                        display: false,
                        group:{
                            type: 'text',
                            name: 'proName',
                            width: '300px',
                            placeholder:'请输入完整的服务名称',
                            value:''
                        }
                    },{
                        label:'服务状态',
                        display:false,
                        group:{
                            type: 'select',
                            name: 'key',
                            width: '300px',
                            placeholder:'无服务状态',
                            value:'stop',
                            list:[]
                        }
                    },{
                        label:'剩余天数',
                        group:[{
                            type: 'number',
                            name: 'cycle',
                            width: '100px',
                            unit: '天',
                            value:1,
                        }]
                    },{
                        label:'消息通道',
                        style:{'margin-top': '7px'},
                        group:[]  //动态获取
                    },{
                        label:'推送间隔',
                        display: false,
                        group:{
                            type: 'number',
                            name:'interval',
                            width: '100px',
                            class: 'group',
                            unit: '秒',
                            value:600
                        }
                    },{
                        group:{
                            type: 'help',
                            style: { 'margin-top': '0' },
                            class: 'none-list-style',
                            list: []
                        }
                    }]
                },
                success:function(layers,indexs,forms){
                    forms.element.find('[data-name="project"] ul li:eq('+editIndex+')').click()
                },
                yes:function(formData,index){

                    var _configD = {},eData = $.extend(true,{status:true,type:_this.push_type},formData);
                    // 默认添加的参数
                    _configD['name'] = _this.module_name;
                    _configD['id'] = res ? param['id'] : new Date().getTime();
                    eData['title'] = $('.projectBox .bt_select_content').html();

                    //删除推送类型
                    $.each(_this.msg_list,function(index,item){
                        delete eData[item.name]
                    })

                    //拼接选中推送方式
                    var isCheck = []
                    $('.module-check').not('.check_disabled').each(function(){
                        if($(this).find('input').prop('checked')){
                            isCheck.push($(this).find('input').prop('name'))
                        }
                    })
                    eData['module'] = isCheck.join();
                    eData['cycle'] = eData['cycle']?parseInt(eData['cycle']):1;
                    eData['interval'] = eData['interval']?parseInt(eData['interval']):600;
                    if(!eData['module']){
                        layer.msg('请选择一种消息通道',{icon:2});
                        return false
                    }
                    // 自定义类型时
                    if(eData.project === 'other'){
                        eData.project = eData.proName
                        eData['title'] = eData.proName+'服务停止'
                        delete eData.proName;   //删除临时服务名称
                    }
                    _configD['data'] = JSON.stringify(eData)
                    //提交
                    bt_tools.send({
                        url:'/push?action=set_push_config',
                        data:_configD
                    },function(Sres){
                        if(Sres.status){
                            layer.close(index);
                            panel_push.refresh_data();
                        }
                        bt_tools.msg(Sres)
                    },(res ?'保存':'添加')+'推送设置')
                }
            })
        },
        // 推送类型判断
        switch_push_type: function(config,formData){
            var that = this,_config = config.config.form,_checklist = [],isInvalid = false,isCheckType = [];
            if(!formData['project']) formData['project'] = 'ssl'
            formData['isOther'] ? formData['project'] = 'other':''
            $.each(this.module_config,function(index,item){
                if(formData.project === item.project){
                    if(formData['module']){
                        isCheckType = formData['module'].split(',')
                    }
                    $.each(item.push,function(indexP,ic){
                        if(typeof that.msg_list[ic] != 'undefined') {
                            _checklist.push({
                                type: 'checkbox',
                                name:that.msg_list[ic].name,
                                class:'module-check '+(!that.msg_list[ic].setup?'check_disabled':'')+'',
                                style:{'margin-right': '10px'},
                                disabled:!that.msg_list[ic].setup,
                                value:$.inArray(that.msg_list[ic].name,isCheckType) >= 0 ?1:0,
                                title:that.msg_list[ic].title+(!that.msg_list[ic].setup?'<span style="color:red;cursor: pointer;" onclick="panel_push.alarm_jump(\''+that.msg_list[ic].title+'\')">[点击安装]</span>':''),
                                event:function(formData,element,thatE){
                                    thatE.config.form[4].group[indexP].value = !formData[that.msg_list[ic].name]?0:1;
                                }
                            })
                        }
                    })
                    _config[0].group.value = formData.project;
                    _config[1].display = false;
                    _config[4].group = _checklist;
                    _config[6].group.list = item.helps;    //动态帮助提醒
                    formData['type'] = item.type;
                    if(formData.project === 'other'){
                        _config[1].display = true
                        _config[1].group.value = formData['title']?formData['title'].slice(0, -4):''
                    }
                    that.push_type = item.type;   //保存当前类型
                    switch(item.type){
                        case 'services':
                            var keyList = []
                            $.each(item.keys,function(indexK,ik){
                                keyList.push({title:ik.val,value:ik.key})
                            })
                            _config[2].display = true;
                            _config[2].group.list = keyList;
                            _config[3].display = false;
                            _config[5].display = true;
                            _config[5].group.value = item.interval
                            break;
                        default:
                            _config[2].display = false;
                            _config[3].display = true;
                            _config[3].group[0].value = parseInt(item.cycle);
                            _config[5].display = false;
                    }
                    isInvalid = true;
                    return true;
                }
            })
            if(isInvalid) return _config
        },
        //安装跳转提示
        alarm_jump:function(name){
            layer.confirm("当前模块<span style='color:red'>未安装</span>,是否跳转到安装界面,是否继续?",{title:"跳转提醒",icon:3,closeBtn:2}, function() {
                layer.closeAll();
                setTimeout(function(){
                    open_three_channel_auth(name)
                },200)
            })
        },
        get_config_data:function(callback){
            var _this = this;
            if(_this.module_config.length === 0 || _this.msg_list.length === 0){
                _this.get_module_config(function(res){
                    _this.module_config = res
                    _this.get_push_msg_list(function(list){
                        _this.msg_list = list
                        if(callback) callback(true)
                    })
                })
            }else{
                if(callback) callback(true)
            }
        },
        /**
         *@description 删除配置
         */
        del_push_config: function (id,callback) {
            var that = this
            $.post('/push?action=del_push_config', { name: that.module_name,id:id }, function (rdata) {
                if(callback) callback(rdata)
            })
        },
        /**
        *@description 刷新配置
        */
        refresh_data: function () {
            var that = this
            $.post('/push?action=get_modules_list', function (rdata) {
                $('#bt_panel_push_table').empty()
                that.all_info = rdata[that.module_name];
                $('.alarm-view .bt-w-menu p.bgw').data('data',rdata[that.module_name]);
                that.get_push_data()
            })
        },
        /**
        *@description 获取模块执行日志
        */
        get_module_logs: function () {
            var that = this
            $.post('/push?action=get_module_logs', { name: that.module_name }, function (rdata) {

            })

        },
        /**
        *@description 获取配置项
        */
        get_module_config: function (callback) {
            var that = this
            $.post('/push?action=get_module_config', { name: that.module_name }, function (rdata) {
                if(callback) callback(rdata)
            })
        },
        /**
         *@description 获取消息通道安装情况
         */
        get_push_msg_list: function(callback) {
            $.post('/push?action=get_push_msg_list', function (rdata) {
                if(callback) callback(rdata)
            })
        }
    }
</script>