
let  group=new $View.getView({id:'#group'})
group.set(GlobalObj);

let domMake=$M.find('#make')

domMake.listener
(
    'tap',(event,target)=>
    {
        if(target.innerHTML=="api列表")
        {
            target.innerHTML="公告"
            $Route.push('layout@content') 
        }
        else
        {
            target.innerHTML="api列表"
            $Route.push('layout@auto') 
        }
    }
)

if($Route.current()!=='layout@auto')domMake.innerHTML="公告"

$M.find('#list').rely
(
    'html','slide-index-update',(data)=>
    {
        data=data.detail
        switch (data.type) 
        {
            case 'set':
                group.set(data.data)
            break;

            case 'find':
                find(data.data)
            break;

            default:
                console.log('暂不支持此类型：',data.type)
            break;
        }
    }
)




$M.find('#list').listener
(
    'tap','[list-id]',(dom,target)=>
    {
        let fun=target.getAttribute('list-id')
        switch (fun) 
        {
            case 'make':
                make('/http/index/makeApi')
            break;
            case 'makeApp':
                make('/http/index/makeApp')
            break;
            case 'makeTable':
                make('/http/index/makeTable')
            break;
            case 'genTable':
                make('/http/index/genTable')
            break;
            case 'delApp':
                make('/http/index/delApp')
            break;
            case 'delZip':
                make('/http/index/delZip')
            break;
            
            default:
                console.log('暂不支持此类型',fun)
            break
        }
    }
)

$M.find('#group').listener
(
    'tap','[group-id]',(event,target)=>
    {
        target=event.target
        let attr=target.getAttribute('group-id')
        if(attr)find(attr)
        window.scrollTo(0,0);
        $M.stop(event)
    }
)

async function make(url,type)
{
    $M.dispatch('html','com-alert-update',{type:'add',message:'正在处理请等待...'})
    let back=await $Ajax.get({url})
    if(back==='true')
    {
        $M.dispatch('html','com-alert-update',{type:'set',message:'操作成功'})
        return 
    }
    if(typeof back == 'object' && !back.code)
    {
        switch (type) 
        {
            case 'make':
                obj=back;
                group.set(GlobalObj);
                let data=search(GlobalObj,'','',true)
                $M.dispatch('html','content-list-update',{type:'set',data})
            break;
        }
        $M.dispatch('html','com-alert-update',{type:'set',message:'操作成功'})
    }
    else
    {
        $M.dispatch('html','com-alert-update',{type:'set',message:'操作失败'})
    }
}


function find(group)
{
    GlobalFind=group;
    GlobalLookupName=''
    var _group=group;
    var newobj=GlobalObj;
    group=group.split('-')
    for (var key in group) 
    {
        newobj=newobj[group[key]];
    }
    if(newobj && newobj.$list)
    {
        for (var i in newobj.$list) 
        {
            try 
            {
                if(newobj.$list[i].index)
                {
                    newobj.$list[i].index=_group+'-$list-'+i;
                }
                else
                {
                    Object.defineProperty
                    (
                        newobj.$list[i], 'index', 
                        {
                            value: _group+'-$list-'+i,
                            enumerable: false
                        }
                    );
                }					
            } 
            catch (error) 
            {
                $M.info('接口查询提示',error);
            }
        }
        $M.dispatch('html','content-list-update',{type:'set',data:newobj.$list})
    }
    else
    {
        $M.dispatch('html','content-list-update',{type:'set',data:[]})
    }
}
