async function request($url, $data, $method = 'POST') { return await new Promise((resolve, reject) => { $.ajax({ type: $method, url: $url, data: $data, success: (res) => { // if(res.code === 1012) { // window.location = 'http://localhost:8001/admin/login' // } resolve(res) }, error: (err) => { reject(err.message) } }) }) } // 搜索开关 function select_card_switch() { const element = $('#select_card_caviar') if(element.css('display') === 'none') { element.css('display','block'); $("#caviar_search_btn").val("关闭搜索") } else { element.css('display','none'); $("#caviar_search_btn").val("展开搜索") } } function check_params(p = []) { const index = p.findIndex(v => v !== undefined && v.toString().length > 0); return index >= 0; } function checkbox() { const isSelect = $("#check-all").is(":checked") isSelect ? $("input[class='checkbox_caviar']").each(function(i,n){ n.checked = true; }) : $("input[class='checkbox_caviar']").each(function(i,n){ n.checked = false; }) } async function caviar_checkbox_delete(url, hints = ['Check at least one box', 'Succeed'], title= 'Warn', content= 'Are you sure you want to delete the selected data?', btn = ['Confirm'], ids_data = undefined ) { const ids = $('.checkbox_caviar:checkbox:checked').map((index,el) => { return $(el).val(); }).get(); if(ids.length === 0 && ids_data === undefined) { layer.msg(hints[0],{icon: 5}) return false; } layer.open({ title, content, btn, yes: async (index, layero) => { const response = await request(url, {ids: ids_data ? ids_data.join(',') : ids.join(',')}); response.code === 200 ? layer.msg(hints[1], {icon: 1,time:500},() => { location.reload(); }) : layer.msg(res.message,{icon: 5}) layer.close(index); } }); } function deletingASingle(url, id, hints = ['Succeed'], title= 'Warn', content= 'Are you sure you want to delete the selected data?', btn = ['Confirm']) { layer.open({ title: title, content: content, btn: btn, yes: async (index, layero) => { const response = await request(url, { ids: id.toString()} ); response.code === 200 ? layer.msg(hints[0], {icon: 1,time:500},() => { location.reload(); }) : layer.msg(res.message,{icon: 5}) layer.close(index); } }); } function add(url = '', title = "Info", area = ['60%', '80%']) { layui.use('layer', function(){ var layer = layui.layer; layer.open({ title: title, type: 2, content:url, area: area, }); }); } function view(url = '', title = "Info", area = ['80%', '80%']) { layui.use('layer', function(){ var layer = layui.layer; layer.open({ title: title, type: 2, content:url, area: area, }); }); } function image_magnify() { let jishu=0; $(document).on('click', '.small-img', function(data){ var ImgUrl=$(this).attr('src'); if(jishu===0) { jishu=1; layer.open({ type:1 ,title:false ,closeBtn:0 ,skin:'layui-layer-nobg' ,shadeClose:true ,content:'' ,scrollbar:false }) }else{ jishu=0; layer.closeAll(); } }) } function deepTraversal(tree = []){ let nodes = []; const queues = tree.map(v => v); while (queues.length > 0) { const queue = queues.pop(); if (queue.children !== undefined && queue.children.length > 0) { queue.children.forEach(child => { queues.push(child) }) } nodes.push({ id: queue.id, title: queue.title, field: queue.field, checked: true, }) } return nodes; }