One Hat Cyber Team
  • Dir : ~/www/server/panel/BTPanel/static/vite/oldjs/
  • Edit File: docker.js
    \
    \ \
    \ ' + lan.docker.container.env_variable + '
    ' + lan.docker.container.one_line + '
    \
    \ \
    \
    \
    \ ' + lan.docker.container.restart_rule + '\
    \ \ *' + lan.docker.container.restart_rule_select_tips + '\
    \
    \ \ \ \ \ ', success:function(){ $(".add_container").on('click', '.tab-nav span', function () { var index = $(this).index(); $(this).addClass('on').siblings().removeClass('on'); $('.tabs_content .tabpanel').eq(index).removeAttr('style').siblings().attr('style','display:none') }); // <----------容器-----------> //服务器目录事件 $('[name=dk_server_path]').click(function(e){ var _ul = $(this).siblings('ul') if (_ul.hasClass('show')) { _ul.removeClass('show') } else { _ul.addClass('show') } $(document).one('click',function(){ _ul.removeClass('show'); }) e.stopPropagation(); }) // 服务器目录ul $('.dk_volumes li').click(function(){ $('[name=dk_server_path]').val($(this).data('key')) }) // 端口类型触发 $('[name=dk_port]').change(function(){ $(this).val() == 1 ? $('.dk_port_setting').hide() : $('.dk_port_setting').show(); }) //添加端口、目录tbody $('.plus').click(function(){ var _Arrinput = $(this).siblings('input'), _val_one = $(_Arrinput[0]).val(), _val_two = $(_Arrinput[1]).val(), THbody = $(this).siblings('.divtable').find('tbody'), _td = ''; if (_val_one == '') return layer.msg(lan.docker.public.please_enter + $(_Arrinput[0]).attr('placeholder'),{icon:2}) if (_val_two == '') return layer.msg(lan.docker.public.please_enter + $(_Arrinput[1]).attr('placeholder'),{icon:2}) switch($(this).data('type')){ case 'port': _td = '\ \ ' + _val_one + '\ ' + _val_two + '\ ' + lan.public.del + '\ ' break; case 'path': var pess_type = $('[name=volumes_type]').val(); _td = '\ \ \ \ ' + _val_one + '\ \ \ ' + pess_type + '\ \ \ '+_val_two+'\ \ \ ' + lan.public.del + '\ ' break; } if (THbody.find('td').length === 1) { $(THbody).html(_td) } else { $(THbody).append(_td) } //清空输入框内容 $(_Arrinput[0]).val('') $(_Arrinput[1]).val('') }) // 端口、目录删除 $('.add_container').on('click','.del-change-td',function(){ var tbody = $(this).parents('tbody') $(this).parents('tr').remove() if (tbody.find('tr').length == 0) { tbody.append('' + lan.site.data_empty + ''); } }) // 停止后自动删除容器事件 $('.add_container .shop_container_del').click(function(){ if ($(this).find('i').hasClass('active')) { $(this).find('i').removeClass('active').siblings('input').prop('checked',false) } else { $(this).find('i').addClass('active').siblings('input').prop('checked',true) } }); // <-----------------容器编排-------------------> var modelList = [] render_model_list() add_pro = bt_tools.form({ el:'#add_project_form', form: [ { label: lan.docker.public.compose_template, group:[ { type: 'select', name: 'template_id', width: '440px', list: modelList }, { type: 'link', title: lan.public_backup.create, event: function () { that.add_model_view(function(resolve){ if(resolve){ that.ajax_task_method('template_list', { tips: lan.docker.compose_template.getting_template, model_name: { dk_model_name: 'compose' } }, function (model_list) { that.dk_template = model_list['msg']['template'] render_model_list() add_pro['config']['form'][0]['group'][0]['list'] = modelList; // 模板列表 add_pro.$local_refresh("template_id", add_pro['config']['form'][0]['group'][0]) // 刷新局部数据 }) } }) } } ] }, { label: lan.public.name, group: { type: 'text', name: 'project_name', width: '440px', placeholder: lan.docker.compose.name_input_tips } }, { label: lan.one_click.description, group: { type: 'textarea', name: 'remark', style: { 'width': '440px', 'min-width': '380px', 'min-height': '130px', 'line-height': '22px', 'padding-top': '5px', 'resize': 'both' }, placeholder: lan.docker.compose.description_input_tips } } ] }) function render_model_list () { if (that.dk_template.length > 0) { $.each(that.dk_template,function(index,item){ modelList.push({title:item.name,value:item.id}) }) } else { modelList = [ { value:'dk_project_false', title: lan.docker.compose.compose_template_select_tips } ] } } }, yes: function (indexs) { // 创建容器 if ($('.add_container .tab-nav span.on').index() == 0) { var _name = $('[name=dk_container_name]').val(), _image = $('[name=dk_image]').val(), _port = $('[name=dk_port]').val(), _start_cmd = $('[name=dk_start_cmd]').val(), auto_remove = $('.form-checkbox').siblings('input').prop('checked')?1:0, _cpus = $('[name=dk_cpu_num]').val(), _size = $('[name=dk_cpu_size]').val(), _unit = $('[name=dk_cpu_unit]').val(), _tag = $('[name=dk_tag]').val(), _config = $('[name=dk_config]').val(), _reset = $('[name=dk_reset]').val(); // 验证 if (_name == '') return layer.msg(lan.docker.container.add_container_tips1, { icon: 2 }); if (_image == '') return layer.msg(lan.docker.container.add_container_tips2, { icon: 2 }); if (_cpus != '' && _cpus <= 0)return layer.msg(lan.docker.container.add_container_tips3, { icon: 2 }) if (_size != '' && _size <= 0)return layer.msg(lan.docker.container.add_container_tips4, { icon: 2 }) var _form = { name: _name, image:_image, publish_all_ports:_port, command:_start_cmd, auto_remove:auto_remove, environment:_config, cpuset_cpus:_cpus, mem_limit:_size+_unit, labels:_tag, restart_policy:{Name:_reset,MaximumRetryCount:5} } var port_array = {},path_array = {} // 端口 if ($('.dk_port_table tbody tr').length > 0) { $.each($('.dk_port_table tbody tr'), function(index, item) { if ($(item).find('td').length == 3) { port_array[$(item).find('td').eq(0).text()+'/tcp'] = $(item).find('td').eq(1).text(); } }); _form['ports'] = port_array; } // 路径 if ($('.dk_path_table tbody tr').length > 0) { $.each($('.dk_path_table tbody tr'),function(index,item){ if ($(item).find('td').length == 4) { path_array[$(item).find('td').eq(0).find('.size_ellipsis').text()] = { bind: $(item).find('td').eq(2).find('.size_ellipsis').text(), mode: $(item).find('td').eq(1).text() } } }) _form['volumes'] = path_array } //接口参数 that.ajax_task_method('run', { data: $.extend(_form,that.global), tips: lan.docker.container.add_container_api_tips }, function (res) { if (res.status) { layer.close(indexs); that.initTabConfig('container'); // 刷新列表 } bt_tools.msg(res); }) } else { var formValue = add_pro.$get_form_value() if (formValue.template_id === 'dk_project_false') return bt_tools.msg(lan.docker.compose.add_compose_tips1, 2) if (formValue.project_name == '') return layer.msg(lan.docker.compose.add_compose_tips2, { icon: 2 }) that.get_log_situation(); that.ajax_task_method('create', { data: formValue, tips: false, model_name: { dk_model_name: 'compose' } }, function (res) { that.remove_log_clearinterval(); if (res.status) { layer.closeAll(); $('#cutMode .tabs-item').eq(2).click() // 跳转到容器编排 } bt_tools.msg(res) }); } } }) }, /** * @description 添加Compose */ add_project:function(){ var that = this,add_pro = null bt_tools.open({ title: lan.docker.compose.add_btn, btn: [lan.public.submit, lan.site.no], area: ['560px', '380px'], content: '
    ', success: function () { var modelList = [] render_model_list() add_pro = bt_tools.form({ el:'#add_project_form', form: [{ label: lan.docker.public.compose_template, group:[ { type: 'select', name:'template_id', width:'300px', list:modelList }, { type:'link', title: lan.public_backup.create, event:function(){ that.add_model_view(function(resolve){ if (resolve) { that.ajax_task_method('template_list', { tips: lan.docker.compose_template.getting_template, model_name: { dk_model_name: 'compose' } }, function (model_list) { that.dk_template = model_list['msg']['template'] render_model_list() add_pro['config']['form'][0]['group'][0]['list'] = modelList; // 模板列表 add_pro.$local_refresh("template_id", add_pro['config']['form'][0]['group'][0]) // 刷新局部数据 }) } }) } } ] },{ label: lan.public.name, group: { type: 'text', name: 'project_name', width: '300px', placeholder: lan.docker.compose.name_input_tips } },{ label: lan.one_click.description, group: { type: 'textarea', name: 'remark', style: { 'width': '300px', 'min-width': '300px', 'min-height': '130px', 'line-height': '22px', 'padding-top': '5px', 'resize': 'both' }, placeholder: lan.docker.compose.description_input_tips } }] }) function render_model_list () { if (that.dk_template.length > 0) { $.each(that.dk_template, function(index, item) { modelList.push({ title: item.name, value: item.id }); }); }else{ modelList = [ { value:'dk_project_false', title: lan.docker.compose.compose_template_select_tips } ] } } }, yes:function(indexs){ var formValue = add_pro.$get_form_value() if (formValue.template_id === 'dk_project_false') return bt_tools.msg(lan.docker.compose.add_compose_tips1, 2) if(formValue.project_name == '')return layer.msg(lan.docker.compose.add_compose_tips2,{icon:2}) that.get_log_situation() that.ajax_task_method('create',{data:formValue,tips:false},function(res){ that.remove_log_clearinterval(); if(res.status){ layer.closeAll(); that.initTabConfig('compose') //刷新列表 } bt_tools.msg(res) }) } }) }, /** * @description 添加Compose模板 */ add_model_view:function(callback){ var that = this,loca_compose = null,search_list = [] var model_tabl = bt_tools.tab({ class:'pd20', type:0, active:1, theme: { nav: 'yaml' }, list:[{ title: lan.docker.compose_template.add_title, name:"addCompose", content: '
    \
    \ ' + lan.docker.compose_template.create_template + '\
    \ \
    \
    \
    \ ' + lan.one_click.remark + '\
    \ \
    \
    \
    \ ' + lan.docker.compose_template.content + '\
    \
    \
    \
    \
    ', success:function(){ _aceEditor = bt.aceEditor({ el: 'dkContntBody', content: '' }); } },{ title: lan.docker.compose_template.search_local_template, name:'searchCompose', content:'\
    \
    \ \
    \ \ \
    \ \ \
    \
    \
    ', success:function(){ var one = 0; loca_compose = bt_tools.table({ el:'#model_sc_table', data:search_list, height: '330px', column:[{ type: 'checkbox', class: '', width: 20 },{ width:180, title: lan.docker.compose_template.compose_template_name, template:function(row){ return ''+row.project_name+'' } },{ width:180, title: lan.docker.container.path, template:function(row){ return ''+row.conf_file+'' } },{ fid: 'remark', title: lan.one_click.description, type: 'input', blur: function (row, index, ev, key, thatc) { row.remark = ev.target.value }, keyup: function (row, index, ev) { if (ev.keyCode === 13) { $(this).blur(); } } }], success:function(){ if(one == 0){ one++ $('#model_sc_table').on('click', '.cust—checkbox', function (e) { var len = loca_compose.checkbox_list $('.lc_select').html(len.length+'个') }) $('.loca_compose_box').append('\ '); } } }) //停止后自动删除容器事件 $('.model_sc_child').click(function(){ if($(this).find('i').hasClass('active')){ $(this).find('i').removeClass('active').siblings('input').prop('checked',false) }else{ $(this).find('i').addClass('active').siblings('input').prop('checked',true) } }) // 模板搜索按钮 $('.model_search_btn').click(function(){ var _val = $('#model_sc_path').val(), _child = $('.form-checkbox').siblings('input').prop('checked')?1:0 if(_val == '') return bt_tools.msg(lan.docker.compose_template.search_folder_tips1, 2) that.ajax_task_method('get_compose_project',{ data: { path: _val, sub_dir: _child }, tips: lan.docker.compose.getting_compose, model_name:{ dk_model_name: 'compose' } }, function (mlist) { if(mlist.status == false)return bt_tools.msg(mlist.msg,2) if(mlist.length == 0)return bt_tools.msg(lan.docker.compose_template.search_folder_tips2, 0) loca_compose.$reader_content(mlist) }) }) } }] }) bt_tools.open({ title: lan.docker.compose_template.add_yaml_template, btn: [lan.public.submit, lan.site.no], skin:'model_sc_view', area: ['680px', '640px'], content:model_tabl.$reader_content(), success:function(){ model_tabl.$init(); }, yes:function(layers){ if (model_tabl.active == 0) { var _mName = $('[name=model_name]').val(), _mDesc = $('[name=model_desc]').val(), _Con = _aceEditor.ACE.getValue(); if (_mName == '') return layer.msg(lan.docker.compose_template.add_template_tips1,{icon:2}) if (_Con == '') return layer.msg(lan.docker.compose_template.add_template_tips2,{icon:2}) var _param = {name:_mName,remark:_mDesc,data:_Con} that.ajax_task_method('add_template', { data: _param, tips: lan.docker.compose_template.adding_template, model_name: { dk_model_name: 'compose' } }, function (res) { if (res.status) { layer.close(layers) if (callback) { callback(res.status) } else { that.initTabConfig('model') //刷新列表 } } var entry = { "'": "'", '"': '"', '<': '<', '>': '>' }; res.msg = res.msg.replace(/(['")-><&\\\/\.])/g, function ($0) { return entry[$0] || $0; }); bt_tools.msg(res) }) } else { var check_len = loca_compose.checkbox_list.length, array = [] $.each(loca_compose.data,function(index,item){ if ($.inArray(index,loca_compose.checkbox_list) != -1) { array.push(item); } }) if(check_len == 0) return layer.msg(lan.docker.compose_template.add_path_tips1,{icon:2}) layer.confirm(lan.docker.compose_template.add_path_tips2 + check_len + lan.docker.compose_template.add_path_tips3, { title: lan.docker.compose_template.add_template, icon: 3, closeBtn: 2 }, function () { that.ajax_task_method('add_template_in_path',{ data: { template_list: array }, tips: lan.docker.compose_template.adding_template, model_name: { dk_model_name: 'compose' } }, function (res) { if(res.status){ layer.close(layers) if (callback) { callback(res.status) }else{ that.initTabConfig('model') // 刷新列表 } } bt_tools.msg(res) }) }); } } }) }, /** * @description 模板添加、编辑界面 * @param {Object} edit 编辑数据 * @param callback 成功后回调 */ edit_model_view:function(edit){ var that = this,_aceEditor = null; layer.open({ type: 1, title: 'Edit template', btn: [lan.public.save, lan.site.no], area:'650px', shadeClose: false, closeBtn: 2, content: '
    \
    ' + lan.docker.compose_template.template_name + '\
    \ \
    \
    \
    ' + lan.one_click.description + '\
    \ \
    \
    \
    ' + lan.docker.compose_template.content + '\
    \
    \
    \
    \
    ', success:function(){ _aceEditor = bt.aceEditor({ el: 'dkContntBody', content: edit.content }); }, yes:function(layers){ var _mName = $('[name=model_name]').val(), _mDesc = $('[name=model_desc]').val(), _Con = _aceEditor.ACE.getValue(); if(_mName == '') return layer.msg(lan.docker.compose_template.add_template_tips1,{icon:2}) if(_mDesc == '') return layer.msg(lan.docker.compose.description_input_tips,{icon:2}) if(_Con == '') return layer.msg(lan.docker.compose_template.add_template_tips2,{icon:2}) var _param = {name:_mName,remark:_mDesc,data:_Con} if(edit) _param['id'] = edit.id that.ajax_task_method('edit_template',{data:_param,tips: lan.docker.compose_template.saving,model_name:{dk_model_name:'compose'}},function(res){ if(res.status){ layer.close(layers) that.initTabConfig('model') //刷新列表 } bt_tools.msg(res) }) } }) }, /** * @description 添加网络 */ add_network:function(){ var that = this,add_network = null bt_tools.open({ title: lan.docker.network.add, btn: [lan.public.submit, lan.site.no], area: ['540px','510px'], content: '
    ', success: function (layers) { add_network = bt_tools.form({ el:'#add_network_form', form: [{ label: lan.docker.network.name, group: { type: 'text', name: 'name', width: '384px', placeholder: lan.docker.network.name_input } },{ label: lan.docker.network.device, group:{ type: 'select', name:'driver', width:'160px', list:[ {title:'bridge',value:'bridge'}, {title:'ipvlan',value:'ipvlan'}, {title:'macvlan',value:'macvlan'}, {title:'overlay',value:'overlay'} ] } },{ label: lan.docker.network.parameter, group: { type: 'textarea', name: 'options', style: { 'width': '384px', 'min-width': '384px', 'min-height': '70px', 'line-height': '22px', 'padding-top': '5px', 'resize': 'both' }, placeholder: lan.docker.network.parameter_textarea } },{ label: lan.docker.network.sub_network, group:[{ type: 'text', name: 'subnet', width: '160px', placeholder: lan.docker.network.sub_network_input },{ label: lan.docker.network.gateway, type: 'text', name: 'gateway', width: '160px', placeholder: lan.docker.network.gateway_input }] },{ label: lan.docker.network.ip_range, group: { type: 'text', name: 'iprange', width: '384px', placeholder: lan.docker.network.ip_range_input } },{ label: lan.docker.container.tag, group: { type: 'textarea', name: 'labels', style: { 'width': '384px', 'min-width': '384px', 'min-height': '70px', 'line-height': '22px', 'padding-top': '5px', 'resize': 'both' }, placeholder: lan.docker.network.tag_textarea } }] }) }, yes:function(layers){ var formValue = add_network.$get_form_value() if(formValue.name == '')return layer.msg(lan.docker.network.add_tips1,{icon:2}) if(formValue.options == '')return layer.msg(lan.docker.network.add_tips2,{icon:2}) if(formValue.subnet == '')return layer.msg(lan.docker.network.add_tips3,{icon:2}) if(formValue.gateway == '')return layer.msg(lan.docker.network.add_tips4,{icon:2}) if(formValue.iprange == '')return layer.msg(lan.docker.network.add_tips5,{icon:2}) that.ajax_task_method('add',{data:formValue,tips:lan.docker.network.adding},function(res){ if(res.status){ layer.close(layers) that.initTabConfig('network') //刷新列表 } bt_tools.msg(res) }) } }) }, /** * @description 添加存储卷 */ add_volume:function(){ var that = this,add_volume = null bt_tools.open({ title: lan.docker.volume.add, btn: [lan.public.submit, lan.site.no], area:['540px','420px'], content: '
    ', success: function (layers) { add_volume = bt_tools.form({ el:'#add_volume_form', form: [{ label: lan.docker.public.volume, group: { type: 'text', name: 'name', width: '358px', placeholder: lan.docker.volume.name_input } },{ label: lan.docker.volume.driver, group:{ type: 'select', name:'driver', width:'160px', list:[ {title:'local',value:'local'} ] } },{ label: lan.docker.volume.option, group: { type: 'textarea', name: 'driver_opts', style: { 'width': '358px', 'min-width': '358px', 'min-height': '70px', 'line-height': '22px', 'padding-top': '5px', 'resize': 'both' }, placeholder: lan.docker.volume.option } },{ label: lan.docker.public.tag, group: { type: 'textarea', name: 'labels', style: { 'width': '358px', 'min-width': '358px', 'min-height': '70px', 'line-height': '22px', 'padding-top': '5px', 'resize': 'both' }, placeholder: lan.docker.volume.tag_textarea } }] }) }, yes:function(indexs){ var formValue = add_volume.$get_form_value() if(formValue.name == '')return layer.msg(lan.docker.volume.add_tips1,{icon:2}) that.ajax_task_method('add',{data:formValue,tips:lan.docker.volume.adding},function(res){ if(res.status){ layer.close(indexs); that.initTabConfig('volume') //刷新列表 } bt_tools.msg(res) }) } }) }, /** * @description 仓库添加、编辑界面 * @param {Object} edit 编辑数据 */ render_registry_view:function(edit){ var that = this,add_registry = null,is_edit = false if(edit){ edit['registry'] = edit['url'] is_edit = true } bt_tools.open({ title: (is_edit ? lan.public.edit : lan.public.add) + ' ' + lan.docker.public.repository.toLowerCase(), btn: [is_edit ? lan.site.save: lan.public.submit, lan.site.no], area:['580px','420px'], content: '
    ', success: function (layers) { add_registry = bt_tools.form({ el:'#add_registry_form', form: [{ label: lan.docker.repository.address, group: { type: 'text', name: 'registry', width: '340px', placeholder: lan.docker.repository.address_input } },{ label: lan.docker.repository.name, group: { type: 'text', name: 'name', width: '340px', placeholder: lan.docker.repository.name_input } },{ label: lan.docker.repository.username, group:[{ type: 'text', name: 'username', width: '340px', placeholder: lan.docker.repository.user_input }] }, { label: lan.docker.repository.pwd, group: [ { type: 'text', name: 'password', width: '340px', placeholder: lan.docker.repository.pwd_input } ] }, { label: lan.docker.repository.namespaces, group: [{ type: 'text', name: 'namespace', width: '340px', placeholder: lan.docker.repository.namespaces_input },{ type:'link', title: '?', class:'bt-ico-ask', event:function(){ window.open('https://www.bt.cn/bbs/thread-80965-1-1.html') } }] },{ label: lan.one_click.description, group: { type: 'text', name: 'remark', width: '340px', placeholder: lan.docker.compose.description_input_tips } }], data:edit?edit:{} }) }, yes:function(indexs){ var formValue = add_registry.$get_form_value() if(formValue.registry == '')return layer.msg(lan.docker.repository.form_tips1,{icon:2}) if(formValue.name == '')return layer.msg(lan.docker.repository.form_tips2,{icon:2}) if(formValue.username == '')return layer.msg(lan.docker.repository.form_tips3,{icon:2}) if(formValue.password == '')return layer.msg(lan.docker.repository.form_tips4,{icon:2}) if(formValue.namespace == '')return layer.msg(lan.docker.repository.form_tips5,{icon:2}) if(edit) formValue['id'] = edit['id'] that.ajax_task_method(is_edit?'edit':'add',{data:formValue,tips:(edit? lan.public.save : lan.public.add) + ' ' + lan.docker.public.repository.toLowerCase()},function(res){ if(res.status){ layer.close(indexs); that.initTabConfig('registry') //刷新列表 } bt_tools.msg(res) }) } }) }, /** * @description 构建镜像 */ construction_image:function(){ var that = this,_aceEditor = null; layer.open({ type: 1, title: lan.docker.image.build_title, btn: [lan.public.submit, lan.site.no], area:'580px', content: '
    \
    Dockerfile\
    \ \
    \ \ \
    \ \
    \
    \
    ' + lan.docker.container.tag + '\
    \ \
    \
    \
    ', success:function(){ _aceEditor = bt.aceEditor({ el: 'dkFileBody', content:'' }); $('[name=dockerfile_type]').change(function(){ switch($(this).val()){ case '0': $('.constr_image .df_type:eq(0)').show(); $('.constr_image .df_type:eq(1)').hide(); $('[name=df_path]').val(''); break; case '1': $('.constr_image .df_type:eq(1)').show(); $('.constr_image .df_type:eq(0)').hide(); _aceEditor.ACE.setValue('') break; } }) }, yes:function(layers){ var _mType = $('[name=dockerfile_type]').val(), _mDesc = $('[name=dk_tag]').val(), _Con = _aceEditor.ACE.getValue(), param = {tag:_mDesc} if(_mType == '0'){ param['path'] = $('[name=df_path]').val() }else{ param['data'] = _Con } that.get_log_situation() that.ajax_task_method('build',{data:param,tips:false},function(res){ that.remove_log_clearinterval(); if(res.status){ layer.closeAll() that.initTabConfig('model') //刷新列表 } bt_tools.msg(res) }) } }) }, /** * @description 容器监控【获取并整理实时数据,刷新图表】 * @param {Object} row 容器信息 */ transform_cont_chart_data:function(row){ var that = this,_time = new Date().getTime(); this.ajax_task_method('stats',{data:{id:row.id},tips:false,model_name:{dk_model_name:'status'}},function(res){ var _data = res.msg; if(!res.status){ that.remove_cont_chart_data(); bt_tools.msg(res); return false } //基础信息 $('.cont_chart_basis').eq(0).find('span').html(bt.format_size(_data.limit)) $('.cont_chart_basis').eq(1).find('span').html(lan.index.net_up + ': ' + bt.format_size(_data.tx_total)+' - '+ lan.index.net_down + ': '+bt.format_size(_data.rx_total)) that.cont_chart.time_list.push(_time) that.cont_chart.mem_list['usage'].push([_time, bt.format_size(_data.usage,false,null,'MB')]) that.cont_chart.mem_list['cache'].push([_time,bt.format_size(_data.cache,false,null,'MB')]) that.cont_chart.cpu_list.push([_time,_data.cpu_usage]) that.cont_chart.disk_list['read'].push([_time, bt.format_size(_data.read_total,false,null,'MB')]) that.cont_chart.disk_list['write'].push([_time, bt.format_size(_data.write_total,false,null,'MB')]) that.cont_chart.network_list['tx'].push([_time, bt.format_size(_data.tx,false,null,'KB')]) that.cont_chart.network_list['rx'].push([_time, bt.format_size(_data.rx,false,null,'KB')]) // console.log(that.cont_chart_id.cpu.getOption()); //实时更新图表数据 that.cont_chart_id.cpu.setOption({ series:[ { name: 'CPU', data: that.cont_chart.cpu_list } ], xAxis:that.cont_chart.time_list }) that.cont_chart_id.mem.setOption({ series: [ { name: lan.pythonmamager.mem, data: that.cont_chart.mem_list['usage'] }, { name: lan.site.cache, data: that.cont_chart.mem_list['cache'] } ] }) that.cont_chart_id.disk.setOption({ series: [ { name: lan.files.file_read, data: that.cont_chart.disk_list['read'] }, { name: lan.files.file_write, data: that.cont_chart.disk_list['write'] } ] }) that.cont_chart_id.network.setOption({ series: [ { name: lan.index.net_up, data: that.cont_chart.network_list['tx'] }, { name: lan.index.net_down, data: that.cont_chart.network_list['rx'] } ] }) }) }, /** * @description 容器监控【图表配置处理】 * @param {String} type 图表类型【CPU/内存/磁盘/网络】 * @return 返回处理好的图表配置 */ transform_cont_chart_option:function(type){ var _unit = '/MB' var _option = this.get_default_option(); switch(type){ case 'cpu': _option.tooltip.formatter = function (config) { var data = config[0]; return bt.format_data(data.data[0]) + '
    ' + data.seriesName + ': ' + data.data[1] + '%'; }; _option.yAxis.min = 0; _option.series = [ { name: 'CPU', type: 'line', symbol: 'none', smooth: true, itemStyle: { normal: { color: 'rgb(0, 153, 238)' } } } ] break; case 'network': _unit = '/KB' case 'mem': case 'disk': var third = { mem:[lan.pythonmamager.mem, lan.site.cache], disk:[lan.files.file_read, lan.files.file_write], network:[lan.index.net_up, lan.index.net_down], color:[ { mem:['rgb(185, 220, 253)','rgb(185, 220, 253,0.6)','rgb(185, 220, 253,0.3)','rgba(229,147,187)','rgba(229,147,187,0.6)','rgba(229,147,187,0.3)'], disk:['rgb(255, 70, 131)','rgb(255, 70, 131,0.6)','rgb(255, 70, 131,0.3)','rgba(46, 165, 186)','rgba(46, 165, 186,0.6)','rgba(46, 165, 186,0.3)'], network:['rgb(255, 140, 0)','rgb(255, 140, 0,0.6)','rgb(255, 140, 0,0.3)','rgb(30, 144, 255)','rgb(30, 144, 255,0.6)','rgb(30, 144, 255,0.3)'] } ] } _option.tooltip.formatter = function (config) { var data = config[0]; var time = data.data[0]; var date = bt.format_data(time / 1000); var _tips = ''; var _style = ' ' + config[i].seriesName + ':' _tips += config[i].data[1] + _unit + (config.length - 1 !== i ? '
    ' : ''); } return "时间:" + date + "
    " + _tips; }; _option.legend = { top: '18px', data: third[type] }; _option.series = [ { name: third[type][0], type: 'line', symbol: 'none', itemStyle: { normal: { color: third['color'][0][type][0], areaStyle: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{ offset: 0, color: third['color'][0][type][1] }, { offset: 1, color: third['color'][0][type][2] }]) } } } }, { name: third[type][1], type: 'line', symbol: 'none', itemStyle: { normal: { color: third['color'][0][type][4], areaStyle: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{ offset: 0, color: third['color'][0][type][4] }, { offset: 1, color: third['color'][0][type][5] }]) } } } } ]; break; } return _option }, /** * @description 渲染容器监控图表 * @param {Object} row 容器信息 */ render_cont_chart:function(row){ var that = this; this.cont_chart_id.cpu = echarts.init(document.getElementById('cont_cpu')) this.cont_chart_id.mem = echarts.init(document.getElementById('cont_mem')) this.cont_chart_id.disk = echarts.init(document.getElementById('cont_disk')) this.cont_chart_id.network = echarts.init(document.getElementById('cont_network')) $.each(['cpu','mem','disk','network'],function(index,item){ that.cont_chart_id[item].setOption(that.transform_cont_chart_option(item)) }) this.transform_cont_chart_data(row) //默认加载数据 }, /** * @description 获取默认图表配置 * @return 返回默认图表配置 */ get_default_option:function(){ return { tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, grid: { x: 50, //左 y: 50, //上 x2: 30,//右 y2: 30 //下 }, xAxis: { type: 'time', scale:true, splitNumber:4, boundaryGap: true, axisLine: { lineStyle: { color: "#666" } }, axisLabel: { // interval:0, formatter: function (value) { return bt.format_data(value / 1000, 'hh:mm:ss'); } }, }, yAxis: { type: 'value', boundaryGap: [0, '100%'], splitLine: { lineStyle: { color: "#ddd" } }, axisLine: { lineStyle: { color: "#666" } } } } }, /** * @description 容器详情配置 * @param {Object} row 容器信息 */ open_container_config:function(obj){ var that = this; layer.open({ type:1, title:'Container ['+obj.name+']', area:['780px','720px'], shadeClose: false, closeBtn: 2, btn:false, content:'
    \
    \

    Container configuration

    \

    Generate mirror image

    \
    \
    \
    ', success:function(){ that.set_cont_config(obj); // 菜单事件 $('.cn_menu p').click(function () { $('#container_box').html('').removeAttr('style'); $(this).addClass('bgw').siblings().removeClass('bgw'); that['set_cont_'+$(this).data('type')](obj); }) } }) }, /** * @description 容器终端 * @param {Object} row 容器信息 */ open_container_shell_view:function(row){ var that = this; web_shell(); var shell = setInterval(function(){ if($('.term-box').length == 0){ pdata_socket['data'] = 'exit\n' socket.emit('webssh',pdata_socket); setTimeout(function(){socket.emit('webssh',pdata_socket['data']);},1000); clearInterval(shell); } },500); setTimeout(function(){ that.ajax_task_method('docker_shell', { data: { container_id: row.id }, tips: lan.docker.container.execute_container_command, model_name: { dk_model_name: 'container' } }, function (res) { if (res.status) { pdata_socket['data'] = 'clear && ' + res.msg +'\n' socket.emit('webssh',pdata_socket); setTimeout(function(){ socket.emit('webssh',pdata_socket['data']); }, 1000); }else{ bt_tools.msg(res) } }) }); }, /** * @description 容器配置 * @param {Object} row 容器信息 */ set_cont_config:function(row){ $('#container_box').css({'padding-right':'25px','overflow':'overlay'}); var wrapper = document.getElementById("container_box") jsonTree.create(row.detail,wrapper) }, /** * @description 容器生成镜像 【可导出文件】 * @param {Object} row 容器信息 */ set_cont_create_image:function(row){ var that = this; bt_tools.form({ el:'#container_box', form:[{ label:'Mirror name', group:{ name:'repository', type: 'text', placeholder: 'Please enter the mirror name', width:'350px' } },{ label:'Tag', group:{ name:'tag', type: 'text', placeholder: 'Please enter the tag', width:'350px' } },{ label:'Submit description', group:{ name:'message', type: 'text', placeholder: 'Description before submission', width:'350px' } },{ label:'Author', group:{ name:'author', type: 'text', placeholder: 'Please enter the author', width:'350px' } },{ label: '', group: [{ type: 'button', size: '', name: 'cont_caimage_btn', title: 'Generate mirror image', event: function (formData) { if( formData.repository == '' || formData.tag == '' || formData.message == '' || formData.author == '' ){ return layer.msg('Please fill in the generated mirror information first',{icon:2}) } formData['id'] = row.id submitImage(formData) } },{ type: 'button', size: '', name: 'cont_caimage_export_btn', style: { 'display': 'block', 'margin-top': '15px' }, title: 'Export the compressed package after the image is generated', event: function (formData) { if( formData.repository == '' || formData.tag == '' || formData.message == '' || formData.author == '' ){ return layer.msg('Please fill in the generated mirror information first',{icon:2}) } bt_tools.open({ type: 1, title: 'Export ['+row.name+'] mirror image', area: '430px', btn: ['Export', lan.site.no], content: { 'class': "pd20", form: [{ label: "Path", group: { name: "path", type: "text", value: '', width: "240px", placeholder:'Please enter the mirror path', icon: { type: 'glyphicon-folder-open', event:function(){} } } },{ label: "File name", group: { name: "name", type: "text", value: formData.repository, width: "240px", disabled:true, placeholder:'Please enter the exposed file name', unit:'.tar' } }] }, yes: function (formD,indexs) { if (formD.path === '') return bt_tools.msg('The path cannot be empty!', 2) if (formD.name === '') return bt_tools.msg('Export file name cannot be empty!', 2) formData['id'] = row.id formData['path'] = formD.path formData['name'] = formD.name submitImage(formData,indexs) } }) } }] }] }) // 生成镜像 --导出文件 function submitImage(form,closeView){ that.ajax_task_method('commit',{data:form,tips:'Generate mirror image'},function(res){ if(res.status){ if(closeView) layer.close(closeView) } bt_tools.msg(res) }) } }, /** * @description 容器状态设置 * @param {String} type 设置状态 * @param {String} id 容器id * @param {Object} table 需要重新渲染的表格 */ container_status_setting:function(type,id,table,is_compose){ var config = {id:id}, tips = {start:'Start up',stop:'Stop',pause:'Pause',unpause:'Unpause',restart:'Restart',reload:'Reload'}, param = {tips:tips[type]+' container'} if(is_compose){ param['model_name'] = {dk_model_name:'container'} } param['data'] = config; this.ajax_task_method(type,param,function(res){ if(res.status){ table.$refresh_table_list(true) //刷新列表 } layer.msg(res.msg,{icon:res.status?1:2}) }) }, /** * @description 获取日志窗口状态 */ get_log_situation:function(){ var that = this; that.log_layer_open = layer.open({ title: lan.docker.public.execution, type: 1, closeBtn: false, maxmin: true, skin: 'dockertmp', area: ["730px", '450px'], content:"
    ",
                success:function(){
                    that.log_file_setInterval = setInterval(function(){that.get_log_speed()},1500)
                }
            })
        },
        /**
        * @description 获取日志进度
        */
        get_log_speed:function(){
            this.ajax_task_method('get_logs',{data:{logs_file:'/tmp/dockertmp.log'},tips:false,model_name:{dk_model_name:"image"}},function(ires){
                $("#dockertmp_pre").text(ires.msg);
                $('#dockertmp_pre').animate({
                    scrollTop: $('#dockertmp_pre').prop("scrollHeight")
                }, 400);
            })
        },
        /**
        * @description 删除容器监控数据和图表dom
        */
        remove_cont_chart_data:function(){
            clearInterval(this.cont_setInterval)
            this.cont_chart = {    
                cpu_list:[],
                mem_list:{
                    usage:[],
                    cache:[]
                },
                disk_list:{
                    read:[],
                    write:[]
                },
                network_list:{
                    tx:[],
                    rx:[]
                },
                time_list:[]
            }
            this.cont_chart_id = {
                cpu:null,
                mem:null,
                disk:null,
                network:null
            }
        },
        //删除日志定时器
        remove_log_clearinterval:function(){
            layer.close(layer.index)   //最新的弹层
            clearInterval(this.log_file_setInterval)
        },
        /**
        * @description 停止用户操作
        * @param {Boolean} is_install 是否docker安装
        * @param {Boolean} is_service 是否启动docker
        */
        stop_user_operation:function(is_install,is_service){
            var that = this;
            var tips = 'Docker service is not currently started. Please enable it in Docker Settings';
            if(!is_install) tips = 'Currently not installed docker or docker-compose, click install'
            $('.mask_layer').removeAttr('style');
            $('.prompt_description').html(tips)
            //安装docker
            $('.install_docker').click(function(){
                that.ajax_task_method('install_docker_program',{model_name:{dk_model_name:'setup'}},function(res){
                    bt_tools.msg(res)
                    messagebox()
                })
            });
    				$('.setting_docker').click(function () {
    					$('.tab-list .tabs-item[data-type="setup"]').click()
    				})
        },
        /**
         * @description docker请求方式转换
         * @param {String} action 请求方法
         * @param {Object} param data填写请求所需参数,tips填写请求时展示文字
         * @param {any} callback 数据回调
         */
        ajax_task_method:function(action,param,callback){
            var _config = $.extend({},param['data'] || {},this.global,{dk_def_name:action},param['model_name'] || {})
            bt_tools.send({
                url:this.global_api+'?action='+_config.dk_model_name+'-'+_config.dk_def_name+'',
                data:{data:JSON.stringify(_config)}
            },function(res){
                if(callback)callback(res)
            },{load:param['tips'],verify: false})
        },
        /**
         * @description docker批量操作参数处理
         * @param {String} action 请求方法
         * @param {Object} param 请求所需参数
         * @return 返回JSON格式参数
         */
        batch_param_convert:function(action,param){
            return JSON.stringify($.extend({},this.global,{dk_def_name:action},param || {}))
        },
        /**
         * @description UTC时间转换
         * @param {Object} utc_datetime utc时间
         * @return 返回处理后的时间
         */
        utc2beijing:function(utc_datetime) {
            // 转为正常的时间格式 年-月-日 时:分:秒
            var T_pos = utc_datetime.indexOf('T');
            var Z_pos = utc_datetime.indexOf('Z');
            var year_month_day = utc_datetime.substr(0,T_pos);
            var hour_minute_second = utc_datetime.substr(T_pos+1,Z_pos-T_pos-1);
            var new_datetime = year_month_day+" "+hour_minute_second; 
        
            // 处理成为时间戳
            timestamp = new Date(Date.parse(new_datetime));
            timestamp = timestamp.getTime();
            timestamp = timestamp/1000;
        
            // 增加8个小时,北京时间比utc时间多八个时区
            var timestamp = timestamp+8*60*60;
            return bt.format_data(timestamp)
        },
        initTabConfig:function(type){
            this.tabName = type;
            this.global.dk_model_name = type
            if(type == 'model') this.global.dk_model_name = 'compose'
            $('.mask_layer').hide();          //隐藏未安装或未启动提醒
            $('#dk_'+type+'_table').empty();  //清除Table
            this['get_'+type]();
        }
    }
    //默认触发
    $('#cutMode .tabs-item[data-type="' + (bt.get_cookie('docker_model') || 'container') + '"]').trigger('click');