PHPIndex

This page lists files in the current directory. You can view content, get download/execute commands for Wget, Curl, or PowerShell, or filter the list using wildcards (e.g., `*.sh`).

index.css
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/msgWarning/static/msg/index.css'
View Content
.artDialog.msgWarning-kwarn-dialog .kwarn-content {
    height: 220px;
    /* border: 1px solid #eee; */
    border-radius: 3px;
    margin: 0px 15px;
    overflow-y: auto;
    background: #fcfcfc;
}
.artDialog.msgWarning-kwarn-dialog .aui-outer .aui-buttons {
    border: none;
    background: #fff;
}

.artDialog.msgWarning-kwarn-dialog .kwarn-content .list-item {
    margin: 10px;
}
.artDialog.msgWarning-kwarn-dialog .kwarn-content .list-item.time {
    /* margin: 5px 10px -5px; */
    color: #ccc;
    margin-bottom: -5px;
    border-bottom: 1px solid #eee;
}
.artDialog.msgWarning-kwarn-dialog .kwarn-content .list-item .title>i {
    height: 10px;
    width: 10px;
    /* height: 8px;
    width: 8px; */
    display: inline-block;
    border-radius: 100%;
    margin-right: 5px;
}
.artDialog.msgWarning-kwarn-dialog .kwarn-content .list-item .content {
    margin-left: 15px;
    display: inline-block;
    color: #666;
}

.kui-notify .kui-notify-box .kui-notify-item .kui-notify-icon .notify-icon-warning.ntc-level-2:before {
    color: #ffce3d;
}
.kui-notify .kui-notify-box .kui-notify-item .kui-notify-icon .notify-icon-warning.ntc-level-4:before {
    color: #ff4d4f;
}
index.js
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/msgWarning/static/msg/index.js'
View Content
ClassBase.define({
	init: function (param) {
        this.ntcNotifyList = {};
        this.ntcRequesting = false;
    },

    // 显示异常信息
    showTips: function(){
        if (!_.get(G, 'user.userID')) return;
        if (this.ntcRequesting) return;
        this.ntcRequesting = true;

        // 获取消息
        var self = this;
        var getNotice = function(){
            // 非活动页不请求;$(document).on("visibilitychange", function);
            if (document.hidden) {
                self._delay(function(){getNotice();}, 1000 * 60);
                return;
            }
            kodApi.requestSend('plugin/msgWarning/notice', {}, function(result){
                self._delay(function(){getNotice();}, 1000 * 60);   // 每分钟请求一次
                if (!result || !result.code) return;
                if (!result.data) return;
                _.each(result.data, function(item, key){
                    if (!item) return true;
                    var func = 'show'+_.upperFirst(key);
                    if (self[func]) self[func](item);
                });
            });
        }
        getNotice();
    },

    // 显示系统信息
    showKtips: function(data){
        var self = this;
        var showNotify = function(item, event){
            var icon = 'info';
            if (item.level > 1) {
                // icon = item.level == 4 ? 'error' : 'warning';
                icon = 'warning ntc-level-'+item.level;
            }
            // var text = item.message.join('<br/>');
            var text = item.message[0]; // 只取第1行信息
            if (!self.ntcNotifyList) self.ntcNotifyList = {};
            if (self.ntcNotifyList[event]) {
                // 更新内容
                self.ntcNotifyList[event].icon(icon).content(text);
                return;
            }
            self.ntcNotifyList[event] = Tips.notify({
                icon:icon,
                // title:item.title,
                content:text,
                onClose:function(){
                    _.unset(self.ntcNotifyList, event);
                }
            });
        }
        // 循环显示所有消息
        var idx = 0;
        data = this.sortByLevel(data, true);   // 降序,严重的先显示
        _.each(data, function(item, event){
            // Tips.notify.tips(msg[0], 'warning');
            idx++;
            self._delay(function(){
                showNotify(item, event);
            }, idx*100);
        });
    },

    // 显示系统通知
    showKwarn: function(data){
        // 事件等级颜色
        var levels = {
            level1: 'blue',
            level2: 'yellow',
            level3: 'orange',
            level4: 'red',
        };
        var html = '';
        data = this.sortByLevel(data, true);   // 降序,严重的先显示
        _.each(data, function(item, event){
            // var text = item.message.join('<br/>');
            var text = item.message[0];
            html += '<div class="list-item">\
                        <span class="title"><i class="bg-'+levels['level'+item.level]+'-normal"></i>'+item.title+'</span><br/>\
                        <span class="content">'+text+'</span>\
                    </div>';
        });
        if (!html) return;
        html = '<div class="list-item time">## '+dateFormate(time(),'H:i')+'</div>'+html;

        // 没有关闭则追加到消息列表前面
        var dgId = 'msgWarning-kwarn-dialog';
        if ($.dialog.list[dgId]) {
            $.dialog.list[dgId].$main.find('.kwarn-content').prepend(html);
            return;
        }
        $.dialog({
            id: dgId,
            title:LNG['msgWarning.main.sysNotice'],
            // className:'',
            ico:"<i class='font-icon ri-volume-up-fill'></i>",
            width:'480px',height:'220px',
            lock:true,
            opacity:0.1,
            resize:false,
            content:'<div class="kwarn-content">'+html+'</div>',
            ok:function(){
                //
            }
        });

    },

    // 按等级排序
    sortByLevel: function(data, desc){
        var entries = Object.keys(data).map(function(key) {
            return [key, data[key]];
        });
        entries.sort(function(a, b) {
            if (desc) return b[1].level - a[1].level;
            return a[1].level - b[1].level;
        });
        var result = {};
        entries.forEach(function(item) {
            result[item[0]] = item[1];
        });
        return result;
    },

    onRemove: function () {
        // ntcNotifyList没必要销毁
    }

});
setting.js
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/msgWarning/static/msg/setting.js'
View Content
ClassBase.define({
	init: function (param) {
		this.initParentView(param);
        var package = this.formData();
		var form = this.initFormView(package); // parent: form.parent;
        form.setValue(G.msgWarningOption);

        var self = this;
        this.request = new kodApi.request({parent: this});
        // 系统消息赋值
        this.request.requestSend('plugin/msgWarning/message', {}, function(result){
            if (!result || !result.code) return;
            var msg = self.getMessage(result.data);
            // form.setValue({sysMsg: msg});    // html类型调用此方法无效
            var desc = LNG['msgWarning.config.sysNtcDesc'];
            form.$('.form-row.item-sysMsg .setting-content').html(desc+msg);
        });
        // 发送方式赋值
		this.request.requestSend('plugin/msgWarning/sendType',{},function(result){
			var data = [];
			var type = _.get(G, 'msgWarningOption.sendType');
				type = type ? _.split(type, ',') : [];
			_.each(result.data, function(val, key){
				if (val != '1') {
					form.$('.item-sendType input[value="'+key+'"]').parent().addClass('disabled');
				} else {
					if (_.includes(type, key)) data.push(key);
				}
			});
			form.setValue('sendType', _.join(data, ','));
		});
		// // 短信模板ID
		// form.$("[name=sendType][value=sms]").bind('change', function () {
		// 	var func = $(this).is(':checked') ? 'removeClass' : 'addClass';	// slideDown/Up
		// 	form.$('.item-smsCode')[func]('hidden');
		// });
	},
	saveConfig: function(data){
        if (_.parseInt(data.useTime) < 10) {
            this.$('.item-useTime input').focus();
            return Tips.tips(LNG['msgWarning.config.useTimeTips'], 'warning');
        }
        G.msgWarningOption = data;
		if(!data) return false;
		Tips.loading(LNG['explorer.loading']);
		this.adminModel.pluginConfig({app:'msgWarning',value:data},Tips.close);
	},

    // 获取系统消息
    getMessage: function(data){
        if (_.isString(data)) {
            return '<div class="info-alert info-alert-success">'+data+'</div>';
        }
        var msg = [];
        _.each(data, function(item, k) {
            if (msg.length && item.length) {
                msg.push('<hr style="border-color:#fff;margin:0.4em 0;">');
            }
            _.each(item, function(val) {
                var value = '<li>'+val+'</li>';
                if (k == 'user' && _.startsWith(val, '<a')) {
                    value = val;
                }
                msg.push(value);
            });
        });
        var status = 'error';
        if (!msg.length) {
            status = 'success';
            msg = [LNG['msgWarning.main.msgSysOK']];
        }
        return '<div class="info-alert info-alert-'+status+'">'+_.join(msg,'')+'</div>';
    },
	formData:function(){
        return {
            'sep001':'<h4>'+LNG['msgWarning.config.sysNtc']+'</h4>',
            'sysMsg': {
                'type':'html',
                'value':'',
                'display':''
            },
            'sep002':'<h4>'+LNG['msgWarning.config.setNtc']+'</h4>',
            'enable':{
                'type':'switch',
                'value':0,
                'className':'row-inline',
                'display':LNG['msgWarning.config.openNtc'],
                'desc':LNG['msgWarning.config.openNtcDesc'],
                'switchItem':{'0':'','1':'warnType,useRatio,useTime,sendType,target'}
            },
            'warnType':{
                'type':'checkbox',
                'value':'cpu,mem,store',
                'display':LNG['msgWarning.config.warnType'],
                'info':{
                    'cpu':LNG['msgWarning.config.warnTypeCpu'],'mem':LNG['msgWarning.config.warnTypeMem']
                },
                'require':1
            },
            'useRatio':{
                'type':'number',
                'value':'80',
                'titleRight':'&nbsp;%&nbsp;',
                'display':LNG['msgWarning.config.useRatio'],
                'desc':LNG['msgWarning.config.useRatioDesc'],
                'require':1
            },
            'useTime':{
                'type':'number',
                'value':'10',
                "info":{"from":10},
                'display':LNG['msgWarning.config.useTime'],
                'desc':LNG['msgWarning.config.useTimeDesc'],
                'require':1
            },
            'sendType':{
                'type':'checkbox',
                'value':'email',
                'display':LNG['msgWarning.config.sendType'],
                'info':{
					'dingTalk':LNG['msgWarning.config.dingTalk'],
					'weChat':LNG['msgWarning.config.weChat'],
					// 'sms':'短信',
					'email':LNG['msgWarning.config.email'],
				},
                'require':1
            },
            // 'smsCode': {
            //     'type': 'input',
            //     'value': '',
			// 	'display': '短信模板ID',
			// 	'desc': '变量格式:\${file}、\${content};模板申请参考【短信网关】插件,<a href="https://dysmsnext.console.aliyun.com/overview" target="_blank" style="position: relative;">短信服务平台</a>',
			// 	'attr':{'placeholder': 'SMS_14535****', 'style':'width:245px;'}
            // },
            'target':{
                'type':'user',
                'value':'1',
                'display':LNG['msgWarning.config.target'],
                'selectType':'mutil',
                'desc':LNG['msgWarning.config.targetDesc'],
                'require':1
            },
            // 'freqTime':{
            //     'type':'number',
            //     'value':'2',
            //     "info":{"from":1,"step":1},
            //     'display':'通知频率',
            //     'desc':'小时,如果触发预警,每N小时内通知一次',
            //     'require':1
            // },
        }
    }
});