You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
skycaiji/public/static/js/admin/task.js

20 lines
4.1 KiB

/*
|--------------------------------------------------------------------------
| SkyCaiji (蓝天采集器)
|--------------------------------------------------------------------------
| Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
|--------------------------------------------------------------------------
| 使用协议 https://www.skycaiji.com/licenses
|--------------------------------------------------------------------------
*/
'use strict';function import_rule(ruleId,ruleName){$('#form_item input[name="rule_id"]').val(ruleId);$('#btn_import_rule').text('导入规则:'+ruleName);if(ruleId!='file'){$('#form_item [name="rule_file"]').val('')}
$('#myModal').modal('hide')}
function import_task(id,name){$('#form_item input[name="task_id"]').val(id);$('#btn_import_task').text('导入任务:'+name);$('#myModal').modal('hide')}
function task_init(){$('#form_item select[name="module"]').bind('change',function(){if($(this).val()!='pattern'){$('#btn_import_rule').parents('.input-group-btn').hide()}else{$('#btn_import_rule').parents('.input-group-btn').show()}});$('#form_item [name="rule_file"]').bind('change',function(){import_rule('file',$(this).val());$(this).parents('.dropdown').removeClass('open')});$('#form_item [name="config[download_img]"]').bind('click',function(){var open=!1;var val=$(this).val();if(val=='y'){open=!0}else if($(this).attr('data-global')){open=!0}
$('#config_download_img').css('background',open?'#fff':'#f9f9f9')});$('#form_item [name="config[img_name]"]').bind('change',function(){var val=$(this).val();if(val=='custom'){$('#config_img_name_custom').show()}else{$('#config_img_name_custom').hide()}});$('#config_img_name_custom').on('click','.name-custom-path a[data-val]',function(){insertAtCaret($('[name="config[name_custom_path]"]'),$(this).attr('data-val'))});$('#config_img_name_custom').on('click','.name-custom-name a[data-val]',function(){insertAtCaret($('[name="config[name_custom_name]"]'),$(this).attr('data-val'))});$('#form_item [name="config[img_func]"]').bind('change',function(){var open=!1;var val=$(this).val();if(val){if(val!='n'){open=!0}}else{if($(this).attr('data-global')){open=!0}}
if(open){$('#config_img_func').show()}else{$('#config_img_func').hide()}});$('#form_item .dropup-img-params .dropdown-menu a').bind('click',function(){var val=$(this).attr('data-val');if(val){var obj=$('#form_item [name="config[img_func_param]"]');var objVal=obj.val();objVal=objVal?(objVal+"\r\n"):'';obj.val(objVal+val)}})}
function task_load(taskData,fieldList){task_init();if(taskData){$('#form_item select[name="tg_id"]').val(parseInt(taskData.tg_id));$('#form_item select[name="module"]').val(taskData.module);$('#form_item input[name="auto"][value="'+parseInt(taskData.auto)+'"]').prop('checked','checked');var task_config=taskData.config;var imgFunc='';if(task_config){imgFunc=task_config.img_func;for(var i in task_config){if(task_config[i]){showPanelCollapse('#task_config');break}}
for(var i in task_config){var ele=$('#form_item').find('[name="config['+i+']"]').eq(0);var eleType=ele.attr('type');if(ele.is('input')&&eleType=='radio'){$('#form_item').find('[name="config['+i+']"][value="'+task_config[i]+'"]').prop('checked','checked')}else if(ele.is('input')&&eleType=='number'){task_config[i]=parseInt(task_config[i]);if(task_config[i]!=0){ele.val(task_config[i])}}else{ele.val(task_config[i])}}
$('#form_item [name="config[download_img]"][value="'+task_config.download_img+'"]').trigger('click');$('#form_item [name="config[img_name]"]').trigger('change');$('#form_item [name="config[img_func]"]').trigger('change')}
if(fieldList&&fieldList.length>0){$('#config_img_name_custom .name-custom-path-fields').html('');$('#config_img_name_custom .name-custom-name-fields').html('');for(var i in fieldList){var fieldHtml='[字段:'+fieldList[i]+']';fieldHtml='<li><a href="javascript:;" data-val="'+fieldHtml+'">'+fieldHtml+'</a></li>';$('#config_img_name_custom .name-custom-path-fields').append(fieldHtml);$('#config_img_name_custom .name-custom-name-fields').append(fieldHtml)}}}
loadPluginFunc({module:'downloadImg',boxObj:'#form_item',funcObj:'[name="config[img_func]"]',funcVal:imgFunc,paramObj:'[name="config[img_func_param]"]'})}