From 207cef200f61d5a13a2e65acc34e67b4bc312ab9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:58:07 +0800 Subject: [PATCH] update --- plugins/task_manager/js/task_manager.js | 87 +++++++++++++++--------------- plugins/task_manager/task_manager_index.py | 23 ++++++++ 2 files changed, 66 insertions(+), 44 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index db90aa075..a2272c628 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -116,67 +116,66 @@ $('.layui-layer').not($('.setting_ul_li')).click(function () { }); var isProcessing = false; // 设置标志 - $('.setting_ul_li').off('click').click(function (e) { - var that = $(this) +$('.setting_ul_li').off('click').click(function (e) { + var that = $(this); e.stopPropagation() // 检查标志 if (isProcessing) { - return; + return; } if (!$(this).hasClass('disabled')) { - isProcessing = true; // 点击事件被触发,设置标志 - var name = $(this).attr("name") - clearInterval(process_list_s); - bt_tools.send({ - url: 'plugin?action=a&name=task_manager&s=set_meter_head', - data: {meter_head_name: name} - }, function (data) { - isProcessing = false; // 操作完成,清除标志 - if (!data) { - layer.msg('设置失败'); - } - that.toggleClass('active') - get_process_list(null, null, false); + isProcessing = true; // 点击事件被触发,设置标志 + var name = $(this).attr("name"); clearInterval(process_list_s); - process_list_s = setInterval(function () { - if ($(".t-mana").length == 0) { - clearInterval(process_list_s); - process_list_s = 0; - console.log('进程列表轮询任务已停止'); - } - get_process_list(null, null, true); - }, 3000); - }) - } - }) - $('.setting_btn').on('click',function (e) { - e.stopPropagation() + tmPostCallback('set_meter_head',{meter_head_name: name}, function(data){ + console.log(data); + isProcessing = false; // 操作完成,清除标志 + if (!data) { + layer.msg('设置失败'); + } + that.toggleClass('active'); + get_process_list(null, null, false); + clearInterval(process_list_s); + process_list_s = setInterval(function () { + if ($(".t-mana").length == 0) { + clearInterval(process_list_s); + process_list_s = 0; + console.log('进程列表轮询任务已停止'); + } + get_process_list(null, null, true); + }, 3000); + }); + } +}); + +$('.setting_btn').on('click',function (e) { + e.stopPropagation(); var offset = $('.man-menu-sub').offset(); var x = e.pageX - offset.left; var y = e.pageY - offset.top; var width = $('.man-menu-sub').outerWidth(); if ($('.man-menu-sub').width() - x < width) { - $(".plug_menu").css({ - position: 'absolute', - right: "14.5px", - top:"40px", - }).toggle(); - $('.setting_ul').addClass('undisplay') + $(".plug_menu").css({ + position: 'absolute', + right: "14.5px", + top:"40px", + }).toggle(); + $('.setting_ul').addClass('undisplay') } $(".setting_ul").toggle(); - }) +}); - if (process_list_s === 0) { +if (process_list_s === 0) { process_list_s = setInterval(function () { - if ($(".t-mana").length == 0) { - clearInterval(process_list_s); - process_list_s = 0; - console.log('进程列表轮询任务已停止') - } - get_process_list(null, null, true); + if ($(".t-mana").length == 0) { + clearInterval(process_list_s); + process_list_s = 0; + console.log('进程列表轮询任务已停止') + } + get_process_list(null, null, true); }, 3000); - } +} function get_list_bytab(isblur) { if (isblur && $('.search-bar .search_input').val() === search_val) { diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 7cfaaa2be..9e474a44c 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -483,6 +483,24 @@ class mainClass(object): data['15'] = round(float(c[2]), 3) # float(c[2]) return data + def set_meter_head(self, get): + if not 'meter_head_name' in get: + return False + + meter_head_name = get['meter_head_name'] + meter_head_file = getServerDir()+'/meter_head.json' + try: + self.get_meter_head() + if meter_head_name not in self.meter_head.keys(): + return False + if meter_head_name in ['ps', 'memory_used', 'cpu_percent', 'name']: + return False + self.meter_head[meter_head_name] = not self.meter_head[meter_head_name] + mw.writeFile(meter_head_file, json.dumps(self.meter_head)) + return True + except: + return False + def get_meter_head(self, get=None): meter_head_file = getServerDir()+'/meter_head.json' if os.path.exists(meter_head_file): @@ -675,6 +693,8 @@ class mainClass(object): pass return mw.returnData(True, '已结束此进程树!') + + def get_process_list(self, args = {}): # https://hellowac.github.io/psutil-doc-zh/processes/process_class/oneshot.html if self.is_mac: @@ -1591,6 +1611,9 @@ def kill_process_all(args = {}): return mw.returnData(False, '缺少参数!') return mc_instance.kill_process_all(int(args['pid'])) +def set_meter_head(args = {}): + return mc_instance.set_meter_head(args) + def remove_service(args = {}): return mc_instance.remove_service(args)